@@ -411,25 +411,15 @@ impl AudioProcessor for AudioBufferSourceRenderer {
411
411
params : AudioParamValues < ' _ > ,
412
412
scope : & AudioWorkletGlobalScope ,
413
413
) -> bool {
414
- // single output node
414
+ // Single output node
415
415
let output = & mut outputs[ 0 ] ;
416
416
417
417
let sample_rate = scope. sample_rate as f64 ;
418
418
let dt = 1. / sample_rate;
419
419
let block_duration = dt * RENDER_QUANTUM_SIZE as f64 ;
420
420
let next_block_time = scope. current_time + block_duration;
421
421
422
- let LoopState {
423
- is_looping,
424
- start : loop_start,
425
- end : loop_end,
426
- } = self . loop_state ;
427
-
428
- // these will only be used if `loop_` is true, so no need for `Option`
429
- let mut actual_loop_start = 0. ;
430
- let mut actual_loop_end = 0. ;
431
-
432
- // return early if start_time is beyond this block
422
+ // Return early if start_time is beyond this block
433
423
if self . start_time >= next_block_time {
434
424
output. make_silent ( ) ;
435
425
return true ;
@@ -444,6 +434,16 @@ impl AudioProcessor for AudioBufferSourceRenderer {
444
434
Some ( b) => b,
445
435
} ;
446
436
437
+ let LoopState {
438
+ is_looping,
439
+ start : loop_start,
440
+ end : loop_end,
441
+ } = self . loop_state ;
442
+
443
+ // these will only be used if `loop_` is true, so no need for `Option`
444
+ let mut actual_loop_start = 0. ;
445
+ let mut actual_loop_end = 0. ;
446
+
447
447
// compute compound parameter at k-rate, these parameters have constraints
448
448
// https://webaudio.github.io/web-audio-api/#audioparam-automation-rate-constraints
449
449
let detune = params. get ( & self . detune ) [ 0 ] ;
@@ -456,15 +456,20 @@ impl AudioProcessor for AudioBufferSourceRenderer {
456
456
// we just linearly interpolate, thus favoring performance vs quality
457
457
let sampling_ratio = buffer. sample_rate ( ) as f64 / sample_rate;
458
458
459
- // In addition, if the buffer has more than one channel, then the
460
- // AudioBufferSourceNode output must change to a single channel of silence
461
- // at the beginning of a render quantum after the time at which any one of
462
- // the following conditions holds:
459
+ // Load the buffer time from the render state.
460
+ // The render state has to be updated before leaving this method!
461
+ let mut buffer_time = self . render_state . buffer_time . load ( Ordering :: Relaxed ) ;
463
462
463
+ // The output must change to a single channel of silence at the beginning of a render
464
+ // quantum after the time at which any one of the following conditions holds:
464
465
// 1. the stop time has been reached.
465
466
// 2. the duration has been reached.
467
+ // 3. the end of the buffer has been reached.
466
468
if scope. current_time >= self . stop_time
467
469
|| self . render_state . buffer_time_elapsed >= self . duration
470
+ || !is_looping
471
+ && ( computed_playback_rate > 0. && buffer_time >= buffer_duration
472
+ || computed_playback_rate < 0. && buffer_time < 0. )
468
473
{
469
474
output. make_silent ( ) ; // also converts to mono
470
475
@@ -477,31 +482,6 @@ impl AudioProcessor for AudioBufferSourceRenderer {
477
482
return false ;
478
483
}
479
484
480
- // Load the buffer time from the render state.
481
- // The render state has to be updated before leaving this method!
482
- let mut buffer_time = self . render_state . buffer_time . load ( Ordering :: Relaxed ) ;
483
-
484
- // 3. the end of the buffer has been reached.
485
- if !is_looping {
486
- if computed_playback_rate > 0. && buffer_time >= buffer_duration {
487
- output. make_silent ( ) ; // also converts to mono
488
- if !self . ended_triggered {
489
- scope. send_ended_event ( ) ;
490
- self . ended_triggered = true ;
491
- }
492
- return false ;
493
- }
494
-
495
- if computed_playback_rate < 0. && buffer_time < 0. {
496
- output. make_silent ( ) ; // also converts to mono
497
- if !self . ended_triggered {
498
- scope. send_ended_event ( ) ;
499
- self . ended_triggered = true ;
500
- }
501
- return false ;
502
- }
503
- }
504
-
505
485
output. set_number_of_channels ( buffer. number_of_channels ( ) ) ;
506
486
507
487
// go through the algorithm described in the spec
0 commit comments