@@ -287,3 +287,42 @@ impl AudioProcessor for AnalyserRenderer {
287
287
false
288
288
}
289
289
}
290
+
291
+ #[ cfg( test) ]
292
+ mod tests {
293
+ use crate :: context:: { AudioContext , AudioContextOptions , BaseAudioContext } ;
294
+ use crate :: node:: { AudioNode , AudioScheduledSourceNode } ;
295
+ use float_eq:: assert_float_eq;
296
+
297
+ #[ test]
298
+ fn test_analyser_after_closed ( ) {
299
+ let options = AudioContextOptions {
300
+ sink_id : "none" . into ( ) ,
301
+ ..AudioContextOptions :: default ( )
302
+ } ;
303
+ let context = AudioContext :: new ( options) ;
304
+
305
+ let mut src = context. create_constant_source ( ) ;
306
+ src. start ( ) ;
307
+
308
+ let mut analyser = context. create_analyser ( ) ;
309
+ src. connect ( & analyser) ;
310
+
311
+ // allow buffer to fill
312
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 20 ) ) ;
313
+
314
+ let mut buffer = vec ! [ 0. ; 128 ] ;
315
+ analyser. get_float_time_domain_data ( & mut buffer) ;
316
+ assert_float_eq ! ( & buffer[ ..] , & [ 1. ; 128 ] [ ..] , abs_all <= 0. ) ; // constant source of 1.
317
+
318
+ // close context
319
+ context. close_sync ( ) ;
320
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 20 ) ) ;
321
+
322
+ let mut buffer = vec ! [ 0. ; 128 ] ;
323
+ analyser. get_float_time_domain_data ( & mut buffer) ; // should not crash or hang
324
+
325
+ // should contain the most recent frames available
326
+ assert_float_eq ! ( & buffer[ ..] , & [ 1. ; 128 ] [ ..] , abs_all <= 0. ) ;
327
+ }
328
+ }
0 commit comments