@@ -157,19 +157,18 @@ impl WaveShaperNode {
157
157
/// * `context` - audio context in which the audio node will live.
158
158
/// * `options` - waveshaper options
159
159
pub fn new < C : BaseAudioContext > ( context : & C , options : WaveShaperOptions ) -> Self {
160
- context. register ( move |registration| {
161
- let WaveShaperOptions {
162
- oversample,
163
- curve,
164
- channel_config,
165
- } = options;
160
+ let WaveShaperOptions {
161
+ oversample,
162
+ curve,
163
+ channel_config,
164
+ } = options;
166
165
166
+ let node = context. register ( move |registration| {
167
167
let sample_rate = context. sample_rate ( ) as usize ;
168
168
let channel_config = channel_config. into ( ) ;
169
169
170
170
let config = RendererConfig {
171
171
oversample,
172
- curve : curve. clone ( ) ,
173
172
sample_rate,
174
173
} ;
175
174
@@ -181,15 +180,15 @@ impl WaveShaperNode {
181
180
oversample : AtomicU32 :: new ( oversample as u32 ) ,
182
181
} ;
183
182
184
- if let Some ( c) = curve {
185
- // we are sure the OnceCell is empty, cannot fail
186
- let _ = node. curve . set ( c) ;
187
- }
188
-
189
183
( node, Box :: new ( renderer) )
190
- } )
184
+ } ) ;
185
+
186
+ // renderer has been sent to render thread, we can sent it messages
187
+ if let Some ( curve) = curve {
188
+ node. set_curve ( curve) ;
189
+ }
191
190
192
- // @todo - use node.set_curve(curve) here
191
+ node
193
192
}
194
193
195
194
/// Returns the distortion curve
@@ -235,17 +234,6 @@ impl WaveShaperNode {
235
234
}
236
235
}
237
236
238
- /// Helper struct which regroups all parameters
239
- /// required to build `WaveShaperRenderer`
240
- struct RendererConfig {
241
- /// oversample factor
242
- oversample : OverSampleType ,
243
- /// oversample factor
244
- curve : Option < Vec < f32 > > ,
245
- /// Sample rate (equals to audio context sample rate)
246
- sample_rate : usize ,
247
- }
248
-
249
237
#[ derive( Debug , Clone , PartialEq , Eq ) ]
250
238
struct ResamplerConfig {
251
239
channels : usize ,
@@ -363,6 +351,15 @@ impl Resampler {
363
351
}
364
352
}
365
353
354
+ /// Helper struct which regroups all parameters
355
+ /// required to build `WaveShaperRenderer`
356
+ struct RendererConfig {
357
+ /// oversample factor
358
+ oversample : OverSampleType ,
359
+ /// Sample rate (equals to audio context sample rate)
360
+ sample_rate : usize ,
361
+ }
362
+
366
363
/// `WaveShaperRenderer` represents the rendering part of `WaveShaperNode`
367
364
struct WaveShaperRenderer {
368
365
/// oversample factor
@@ -519,12 +516,8 @@ impl WaveShaperRenderer {
519
516
let RendererConfig {
520
517
sample_rate,
521
518
oversample,
522
- curve,
523
519
} = config;
524
520
525
- let curve_set = curve. is_some ( ) ;
526
- let curve = curve. unwrap_or ( Vec :: with_capacity ( 0 ) ) ;
527
-
528
521
let channels_x2 = 1 ;
529
522
let channels_x4 = 1 ;
530
523
@@ -540,8 +533,8 @@ impl WaveShaperRenderer {
540
533
541
534
Self {
542
535
oversample,
543
- curve,
544
- curve_set,
536
+ curve : Vec :: with_capacity ( 0 ) ,
537
+ curve_set : false ,
545
538
sample_rate,
546
539
channels_x2,
547
540
channels_x4,
0 commit comments