1
1
use std:: any:: Any ;
2
2
use std:: fmt:: Debug ;
3
3
use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
4
- use std:: sync:: Arc ;
5
4
6
5
use crate :: context:: { AudioContextRegistration , AudioParamId , BaseAudioContext } ;
7
6
use crate :: param:: { AudioParam , AudioParamDescriptor , AutomationRate } ;
@@ -132,7 +131,7 @@ pub struct OscillatorNode {
132
131
/// A detuning value (in cents) which will offset the frequency by the given amount.
133
132
detune : AudioParam ,
134
133
/// Waveform of an oscillator
135
- shared_type : Arc < AtomicU32 > ,
134
+ type_ : AtomicU32 ,
136
135
}
137
136
138
137
impl AudioNode for OscillatorNode {
@@ -215,11 +214,8 @@ impl OscillatorNode {
215
214
let ( det_param, det_proc) = context. create_audio_param ( det_param_opts, & registration) ;
216
215
det_param. set_value ( detune) ;
217
216
218
- let shared_type = Arc :: new ( AtomicU32 :: new ( type_ as u32 ) ) ;
219
-
220
217
let renderer = OscillatorRenderer {
221
218
type_,
222
- shared_type : Arc :: clone ( & shared_type) ,
223
219
frequency : f_proc,
224
220
detune : det_proc,
225
221
phase : 0. ,
@@ -236,7 +232,7 @@ impl OscillatorNode {
236
232
channel_config : channel_config. into ( ) ,
237
233
frequency : f_param,
238
234
detune : det_param,
239
- shared_type ,
235
+ type_ : AtomicU32 :: new ( type_ as u32 ) ,
240
236
} ;
241
237
242
238
// if periodic wave has been given, init it
@@ -271,7 +267,7 @@ impl OscillatorNode {
271
267
/// Returns the oscillator type
272
268
#[ must_use]
273
269
pub fn type_ ( & self ) -> OscillatorType {
274
- self . shared_type . load ( Ordering :: Acquire ) . into ( )
270
+ self . type_ . load ( Ordering :: Acquire ) . into ( )
275
271
}
276
272
277
273
/// Set the oscillator type
@@ -291,10 +287,11 @@ impl OscillatorNode {
291
287
) ;
292
288
293
289
// if periodic wave has been set specified, type_ changes are ignored
294
- if self . shared_type . load ( Ordering :: Acquire ) == OscillatorType :: Custom as u32 {
290
+ if self . type_ . load ( Ordering :: Acquire ) == OscillatorType :: Custom as u32 {
295
291
return ;
296
292
}
297
293
294
+ self . type_ . store ( type_ as u32 , Ordering :: Release ) ;
298
295
self . registration . post_message ( type_) ;
299
296
}
300
297
@@ -303,11 +300,8 @@ impl OscillatorNode {
303
300
/// Calling this sets the oscillator type to `custom`, once set to `custom`
304
301
/// the oscillator cannot be reverted back to a standard waveform.
305
302
pub fn set_periodic_wave ( & self , periodic_wave : PeriodicWave ) {
306
- // Already store the oscillator type, so you can't call set_type with conflicting settings
307
- // immediately after this call.
308
- self . shared_type
303
+ self . type_
309
304
. store ( OscillatorType :: Custom as u32 , Ordering :: Release ) ;
310
-
311
305
self . registration . post_message ( periodic_wave) ;
312
306
}
313
307
}
@@ -316,8 +310,6 @@ impl OscillatorNode {
316
310
struct OscillatorRenderer {
317
311
/// The shape of the periodic waveform
318
312
type_ : OscillatorType ,
319
- /// The shape of the periodic waveform (shared with control thread)
320
- shared_type : Arc < AtomicU32 > ,
321
313
/// The frequency of the fundamental frequency.
322
314
frequency : AudioParamId ,
323
315
/// A detuning value (in cents) which will offset the frequency by the given amount.
@@ -439,7 +431,6 @@ impl AudioProcessor for OscillatorRenderer {
439
431
440
432
fn onmessage ( & mut self , msg : & mut dyn Any ) {
441
433
if let Some ( & type_) = msg. downcast_ref :: < OscillatorType > ( ) {
442
- self . shared_type . store ( type_ as u32 , Ordering :: Release ) ;
443
434
self . type_ = type_;
444
435
return ;
445
436
}
0 commit comments