rserota / wad

Web Audio DAW. Use the Web Audio API for dynamic sound synthesis. It's like jQuery for your ears.
MIT License
1.88k stars 160 forks source link

unpausing a second time plays back from the location of the first pause #116

Closed alittlebitweird closed 4 years ago

alittlebitweird commented 4 years ago

This is for an audio waveform. Steps to reproduce:

  1. wad.play()
  2. wad.pause()
  3. wad.unpause();
  4. wad.pause()
  5. wad.unpause() <------this is playing the audio starting from the pause at step 2 instead of step 4

Is this the intended behavior?

alittlebitweird commented 4 years ago

I recommend this audio file for testing as it's easy to hear where it's unpausing at the wrong time: https://freesound.org/people/Shuinvy/sounds/257360/

In addition to unpausing at the wrong time, it's also inconsistent, plus or minus a few miliseconds.

rserota commented 4 years ago

Thanks for raising this issue. There was a bug in the unpause() method. If you pull down the latest version (4.7.2), it should work the way you expect.

alittlebitweird commented 4 years ago

@rserota Thanks for fixing that, although now I'm encountering another issue. It seems that when pausing an audio clip, the amount of time the clip was paused for is subtracted from the duration of the clip in the calculation of when to resolve the promise returned by the completion of the play function. In other words, the promise that should resolve on completion of the audio playback resolves before the unpaused audio actually finished playing. This is breaking my intended use of your plugin because my code relies upon accurate resolution of the play function promise.

rserota commented 4 years ago

Ok, if you pull down version 4.7.4, the play promises should now resolve more accurately. Thanks for finding that.

alittlebitweird commented 4 years ago

@rserota no problem, and thank you for fixing it quickly, seems to be working as intended. I have yet another question. Is it possible to update a wad's sprite list, or do i have to create a new wad in order to change it? when i try manually setting sprite key/value pairs they don't seem to be available on the wad object.

alittlebitweird commented 4 years ago

@rserota also, is it possible to have sprite playback resolve a promise just like regular playback?

rserota commented 4 years ago

Currently, it's not possible to update a wad's sprite list. You would have to create a new wad. Another option is to pass an offset parameter to play(), so you can start an audio clip from any point in the middle.

Sprite playback already returns a promise. You should be able to chain .then() off of sprite playback, just the same as regular calls to play().

alittlebitweird commented 4 years ago

ok, thanks. I got rate to work by creating a new wad, but ideally I'd like to be able to adjust rate/filter in real time.

That said, I have discovered another issue. Adjusting the rate to be faster behaves as expected; the audio file plays more quickly and the promise resolves earlier, when the sped up audio completes. However, when adjusting the rate to be slower, the play promise resolves earlier than expected. It seems like the promise resolves at the completion of the 1x rate instead of at the completion of the longer duration of the time-stretched sample.

rserota commented 4 years ago

It looks like you've found another bug. Pull down version 4.7.5, and the play promises should resolve when you expect them to, regardless of the rate setting.