问题
I'm sending an stereo audiofile (WAV) via websockets and want to play it via the Web Audio Api. The Serversite technology is asp.net. Currently i have this:
ws.onmessage = function(evt) {
var d2 = new DataView(evt.data);
var data = new Float32Array(d2.byteLength / Float32Array.BYTES_PER_ELEMENT);
for (var jj = 0; jj < data.length; ++jj) {
data[jj] = d2.getFloat32(jj * Float32Array.BYTES_PER_ELEMENT, true);
}
var buffer = context.createBuffer(1, data.length, 44100);
buffer.getChannelData(0).set(data);
source = context.createBufferSource();
source.buffer = buffer;
source.start(startTime);
source.connect(context.destination);
startTime += buffer.duration;
}
With this i can hear the song but with A LOT of noise... i believe this might be because it is an stereo file and i only use 1 channel? If yes, how could i do it with two channels? I tried some things but the result was always the same or worse.
And i have another problem in understanding why it is working with Float32Array? In my first approach i used Uint8Array because i'm sending bytes to the client so i thought i would need Uint8Array to get the same values i send. But with Uint8Array i just hear noise and nothing from the song at all.
thanks for your help in advance!
Best Regards, metabolic
来源:https://stackoverflow.com/questions/27459436/play-bytestream-on-client-site-with-web-audio-api