Question

I am getting 16 bit audio from server and currently sending it from server. It is interleaved. That means I need to loop and separate right and left into 2 32 bit arrays in javascript. Well this is just too slow for javascript to execute and schedule the play time. things get out of sync. This is a live stream. So web api seems to be implemented for only local syths and such. Streaming pcm does not seem to be a good approach.I know that you would never send PCM to begin with. Well say i wanna send vorbis or something similar. They have to be in a container like .ogg or webm or something but browsers have their internal buffering and we have very little /no control.

so O tried sending ADPCM and decoding it to PCM on client in Javascript. That is also too slow.

If i send my data and preprocess it on server. Uninterleave onserver and convert it to 32 bit floats and send it to client. The data size doubles. 16 bit to 32 bit.

So what is the best way to render 16 audio with out processing on client side.

Also can you play audio from worker threads. Would implementing the conversions in a worker thread help. I mean there is all that websocket communication going on and JS is single threaded.

I would also Like to add that doing the computation on chrome on mac pro works (much better, I almost hear no glitch between samples) when I compare it to a client running on a pc,

Was it helpful?

Solution

No, you cannot currently play audio from Worker threads. However, I really doubt that your problem is in the cost of de-interleaving audio data; have you tried just sending a mono stream? Properly synchronizing and buffering a stream in a real network environment is quite complex.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top