anthumchris / fetch-stream-audio

Low Latency web audio playback examples for decoding audio streams in chunks with Fetch & Streams APIs
https://fetch-stream-audio.anthum.com
MIT License
378 stars 23 forks source link

Fix wav decoder with mono-channel #45

Closed neo closed 8 months ago

neo commented 8 months ago

Problem

It breaks when it tries to stream a wav with only one channel with the following error:

worker-decoder-wav.js:12 Uncaught TypeError: Cannot read properties of undefined (reading 'buffer')
    at self.onmessage (worker-decoder-wav.js:12:32)

because channelData would only have one item

Solution

By using .map() to iteration through each channel and obtain the buffer, it can now accommodate for an arbitrary amount of channels other than two.

anthumchris commented 8 months ago

No UX problem/resolution described

neo commented 8 months ago

sorry I thought it was self explanatory enough 😅 I was trying to stream a mono PCM, and it was erroring out because there's only one item from the decoded channelData array

and I suspect this would also accommodate the case where there are more than two channels from the WAV file

neo commented 8 months ago

@anthumchris I just updated the PR description to include the problem and solution, thanks!