Understanding AudioBuffer to ArrayBuffer conversion - javascript

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

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);

Related

fetch API to get ReadableStream

I was trying to get reader of ReadableStream using getReader() and response.body of fetch.
Even when I am not consuming data by calling read method, the buffer of stream is getting filled and it is even not applying any kind of backpressure and this is leading to huge memory usage. Is there any way to set WaterMark size on the ReadableStream returned by fetch. Is there any other way to control the buffer size of stream.

send arraybuffer from angularjs to c# endpoint

I have an ArrayBuffer in angularjs that I am trying to send to my backend endpoint in c#, I thought it was a regular byte array but it's not mapping appropriately
What would an ArrayBuffer map to as an object in c# if not a byte[]?.
I have a PDF file represented as that ArrayBuffer but now I would like to send it to the server, or perhaps is there a way to convert that ArrayBuffer to a File type in JavaScript and send it o the endpoint so that I can use something like an IFormFile?.
Thank you
I had a situation of same some long days back. What I did was, I converted the array buffer data to base 64 string in the js side and sent it to the backend c# code using post method,and again I decoded it to array buffer to regenerate the file on server side. By this way I achieved the mapping.
I used this code which helps to convert the array buffer to base 64 string in JS.
and this api of .net framework to convert back the base 64 string to file buffer.
I hope this would help you.

Jersey client side receive pojo us bytes

Is there any possibility to have a Restful method (Java EE) that returns back to the client a POJO serialized us bytes (using ByteArrayOutputStream, FlatBuffers or some other library)?
And the client to cast the bytes back to a POJO object by using jquery or javascript in general (us client side)?
What I had found until now, is receiving back a JSON/XML.
Directly converting POJO to bytes won't work as your client (javascript or so) won't know how to convert the bytes back to POJO. What you can do is this. Say your response is objA. The do this. Convert objA to String (JSON maybe) and then Base64 encode it to get byte[]. Put it inside a wrapper object objB. Return objB as a JSON from your service. Your client can just take that byte[] and since it knows that the byte[] is base64 it will be able to get the original information from there.
May I ask the intent of doing this instead of XML/JSON?

Sending a file chunk WITH meta data over a WebRTC Data Channel

I have a file chunking operation that splits a file via File Reader into slices which are read via readAsArrayBuffer. I would like to send those chunks one at a time over my data channel WITH meta information attached (a chunk id, for instance). Like:
// Build chunk wrapper
var block = {
chunkId: id,
data: buffer
};
// Send the chunk to peer
channel.send(JSON.stringify(block));
Now when I send that data as is demonstrated above the data in the ArrayBuffer buffer is lost. I would like to emphasize I'm not having any trouble sending data over my data channel.
I would like to know how I can send that data with its associated meta information so that the file chunks can be reassembled in the correct order on the other side?
Do I need to do something like make an ArrayBuffer with two sub arrays, one with the meta information, and the other with the actual data or is there a simpler way?
There are many ways you can solve this, but basically you'll need to serialize, encode and deserialize, decode your data.
If you want to send your metadata with the data, you'll need to either serialize both to a uint8array or to a string, and do the inverted operation on the receiver side.
For example Sharefest utilizes a TLV protocol: https://github.com/Peer5/ShareFest/blob/master/core/protocol/BinaryProtocol.js

Convert byte[] to audio(mp3) using javascript

I'm storing several mp3 files in MS SQL Server'08 as BLOB objects (I use filestream). There's a WCF service which can send one of this objects to html client.
Preliminarily I convert BLOB to byte[] using ToArray().
How to convert incoming byte[] array to audio(mp3) and play it?This's only javascript/html on client.
I use SoundManager2 http://www.schillmania.com/projects/soundmanager2/
to play audio.
Thanks!

Categories