I have a float32Array from decodeAudioData method, which I want to convert it to Uint8Array while preserving the float32 IEEE 754 audio data.
So far I tried,
var length = float32Array.length;
var emptyBuffer = new ArrayBuffer(length * 4);
var view = new DataView(emptyBuffer);
for (var i = 0; i < length; i++) {
view.setFloat32(i * 4, float32Array[i], true);
}
var outputArray = new Uint8Array(length);
for (var j = 0; j < length; j++) {
outputArray[j] = view.getUint8(j * 4);
}
return outputArray;
Edit:
I just need to hold on to the binary representation just as in this answer.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…