1
1
use std:: any:: Any ;
2
- use std:: cell:: { OnceCell , RefCell } ;
3
- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
2
+ use std:: cell:: { Cell , OnceCell , RefCell } ;
4
3
5
4
use crate :: buffer:: AudioBuffer ;
6
5
use crate :: context:: { AudioContextRegistration , AudioParamId , BaseAudioContext } ;
@@ -104,7 +103,7 @@ pub struct AudioBufferSourceNode {
104
103
playback_rate : AudioParam , // has constraints, no a-rate
105
104
loop_state : RefCell < LoopState > ,
106
105
buffer : OnceCell < AudioBuffer > ,
107
- source_started : AtomicBool ,
106
+ source_started : Cell < bool > ,
108
107
}
109
108
110
109
impl AudioNode for AudioBufferSourceNode {
@@ -141,9 +140,10 @@ impl AudioScheduledSourceNode for AudioBufferSourceNode {
141
140
}
142
141
143
142
fn stop_at ( & self , when : f64 ) {
144
- if !self . source_started . load ( Ordering :: SeqCst ) {
145
- panic ! ( "InvalidStateError cannot stop before start" ) ;
146
- }
143
+ assert ! (
144
+ self . source_started. get( ) ,
145
+ "InvalidStateError cannot stop before start"
146
+ ) ;
147
147
148
148
self . registration . post_message ( ControlMessage :: Stop ( when) ) ;
149
149
}
@@ -212,7 +212,7 @@ impl AudioBufferSourceNode {
212
212
playback_rate : pr_param,
213
213
loop_state : RefCell :: new ( loop_state) ,
214
214
buffer : OnceCell :: new ( ) ,
215
- source_started : AtomicBool :: new ( false ) ,
215
+ source_started : Cell :: new ( false ) ,
216
216
} ;
217
217
218
218
if let Some ( buf) = buffer {
@@ -238,9 +238,11 @@ impl AudioBufferSourceNode {
238
238
///
239
239
/// Panics if the source was already started
240
240
pub fn start_at_with_offset_and_duration ( & self , start : f64 , offset : f64 , duration : f64 ) {
241
- if self . source_started . swap ( true , Ordering :: SeqCst ) {
242
- panic ! ( "InvalidStateError: Cannot call `start` twice" ) ;
243
- }
241
+ assert ! (
242
+ !self . source_started. get( ) ,
243
+ "InvalidStateError: Cannot call `start` twice"
244
+ ) ;
245
+ self . source_started . set ( true ) ;
244
246
245
247
let control = ControlMessage :: StartWithOffsetAndDuration ( start, offset, duration) ;
246
248
self . registration . post_message ( control) ;
0 commit comments