Skip to content

Instantly share code, notes, and snippets.

@AdrienFromToulouse
Created October 31, 2015 12:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AdrienFromToulouse/5906a791a135dd00c8ce to your computer and use it in GitHub Desktop.
Save AdrienFromToulouse/5906a791a135dd00c8ce to your computer and use it in GitHub Desktop.
Streaming - Web Audio API
var audioCtx = new AudioContext();
myScriptProcessor = audioCtx.createScriptProcessor(16384, 1, 1);
var rawAudioTemp = new Float32Array(data); // Your raw PCM incoming data
for (i = 0 ; i < rawAudioTemp.length ; i++) {
rawAudio.push(rawAudioTemp[i]);
}
streamingNode.onaudioprocess = function(event) {
for (chan= 0 ; chan< event.outputBuffer.numberOfChannels ; chan++) {
var out = event.outputBuffer.getChannelData(chan);
for (sample = 0 ; sample < 16384 ; sample++) {
out[sample] = rawAudio[sample + k * 16384];
}
} k++;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment