I have certain TCP
packets that contain audio datas in it.
I am a newbie to Js and html5.
I had written something like this which creates a buzzing sound. I wanted to know how audio samples look like in a TCP
packet.
I had captured TCP
packets using wire-shark, the data segment shows some characters and its ASCII value.
I believe these characters are the audio data. Assuming so, How can I pass those to myArrayBuffer
like below?
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var source = audioCtx.createBufferSource();
function Set1()
{
try {
// Create an empty three-second stereo buffer at the sample rate of the AudioContext
var myArrayBuffer = audioCtx.createBuffer(2, audioCtx.sampleRate * 30, audioCtx.sampleRate);
// Fill the buffer with white noise;
// just random values between -1.0 and 1.0
for (var channel = 0; channel < myArrayBuffer.numberOfChannels; channel++) {
// This gives us the actual array that contains the data
var nowBuffering = myArrayBuffer.getChannelData(channel);
for (var i = 0; i < myArrayBuffer.length; i++) {
// Math.random() is in [0; 1.0]
// audio needs to be in [-1.0; 1.0]
nowBuffering[i] = Math.random() * 2 - 1;
}
}
// set the buffer in the AudioBufferSourceNode
source.buffer = myArrayBuffer;
// connect the AudioBufferSourceNode to the
// destination so we can hear the sound
source.connect(audioCtx.destination);
// start the source playing
source.start();
}
catch(e) {
alert('Web Audio API is not supported in this browser');
}
}
function stop()
{
try {
source.stop();
}
catch(e) {
alert('Unable to stop file');
}
}