It is possible to create an AudioBuffer from memory, i.e. Int8Array

Is there a way to add raw data from memory as a sample in Web Audio Api? I would like to add Int8Array (or Int16Array) as a buffer, there are only samples and WAV or MP3 format in the buffer. I tried audioContext.createBuffer and without it.

Something like that:

var buffer = audioContext.createBuffer(1,8192, 22000);
var intArray = new Int8Array(....);
// -- fill intarray
buffer.buffer = intArray;
...
var source = context.createBufferSource();
source.buffer = buffer;
source.connect(context.destination); 

If this is not possible, is there a sound format compatible with contetx.decodeAudio () that is easy to "emulate" in memory? Those. just a headline or something like that.

+1
source share
1 answer

It is neither very intuitive nor explicitly documented in the specifications, nor is it very easy to find on the net:

Float32Array, getChannelData(<idx of channel>) .

[-1, 1]

intArray floatArray, :

floatArray = buffer.getChannelData(0)
+4

Source: https://habr.com/ru/post/1546995/


All Articles