Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding AudioBuffer to ArrayBuffer conversion

I have an AudioBuffer client-side that I'd like to AJAX to a express server.

This link shows how a XMLHttpRequest can send/receive binary data - ArrayBuffer.

An ArrayBuffer is different to an AudioBuffer (or so I believe) as I decoded an ArrayBuffer to make the AudioBuffer in the first place. This was done using decodeAudioData() as part of the Web Audio API.

So my question is, can I convert an AudioBuffer back to an ArrayBuffer?

If this is possible, I'd like to then send the ArrayBuffer to my express server and then forward it on to a S3 bucket as shown in this example.

In that example, the code PUTs a Buffer in a S3 bucket created via a fs.readFileSync(). I assume the difference between a Buffer and ArrayBuffer wont be an issue with S3 :S

like image 589
Ricardinho Avatar asked Oct 23 '25 10:10

Ricardinho


1 Answers

Use the copyFromChannel method, then convert the Float32Array to an ArrayBuffer.

var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate);  
var anotherArray = new Float32Array();
myArrayBuffer.copyFromChannel(anotherArray,1,0);
like image 86
Axel Isouard Avatar answered Oct 26 '25 02:10

Axel Isouard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!