Playback of raw PCM audio programs in Web Audio

I have an array of sound samples (16 bit):

[0, 120, 320, 120, 0, -100, -30000, 65, 2, 3, 10, ...]

      

They range from -32768 to 32767. I would like to be able to play samples using the web audio API.

I know he expects the original buffer to be ArrayBuffer

, but I can't figure out how to convert a bunch of samples ArrayBuffer

to playable using the web audio API.

Any advice?

+3


source to share


1 answer


create a new AudioContext, use CreateBuffer to create an AudioBuffer with the correct length and number of channels, and then use getChannelData to access the bits - then loop through which for each sample sets bufferData [i] = (original_data [i] / 32768);



+3


source







All Articles