anthumchris / fetch-stream-audio

Low Latency web audio playback examples for decoding audio streams in chunks with Fetch & Streams APIs

Home Page:https://fetch-stream-audio.anthum.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

noise when playing 24 bit wav files

st-h opened this issue · comments

commented

Thanks a lot for putting this together. It's been really helpful. However, I have been running into an issue when trying to play 24 bit wav files.
I have been trying to use the wav decoder as it is provided within this repo and I tried to add a wav header to each chunk and tried to decode via audioContext.decodeAudioData. However, in both cases 24 bit files emit a very unpleasant noise. Yet, the first chunk seems to play correctly. I was suspecting that this might be related to the buffer size used to split up the chunks, however I haven't been successful in finding a value that would fix play back. Might this be related to the usage of Uint8Array to handle the audio stream data (yet, if this would be the case, the first chunk should show similar behaviour, which it doesn't)?

Do you possibly have any other idea what might be the issue here?

commented

I finally figured it out: The current demo implementation does not take the header data into account. To fix this, the buffer would need to strip away the header data and then only put the actual audio data into the buffer, so the buffer can be split cleanly.
I think with 24 bit files the issue is that depending on the length of the header, the audio data could be split at a position which will split the 24 bit word. This probably could also cause issues with 16 bit files, like swapping channels.

I have added some code to the buffered-stream-reader, which would parse the wav header until it finds the data chunk and then strips away that information (and stores it to reuse with the decoder). I'll be happy to share that code, if you would find that useful. Otherwise, please feel free to close this issue.

commented

Additionally, I found that it is crucial to read the length of the data chunk, that contains the audio data and make sure to not process any data that is stored after that section. Otherwise this may lead to unpleasant noise being played back after the audio file has ended.

Thanks @st-h! I can't speak much for the third-party WAV decoder and only tested with a limited set of WAV files, presumably all 16-bit.