I am using OnAudioStreamPacket.
So, how do I calculate the array size in bytes? Or actually in float/single?
The comments say:
- Code: Select all
// Based on |frames| and the |channel_layout| value
// passed to OnAudioStreamStarted you can calculate the size of the |data|
// array in bytes.
My current values are as follows:
- Code: Select all
// ChannelLayout = LayoutStereo
// FramesPerBuffer = 1024
// SampleRate = 44100
// channels = 2
I am trying to use NAudio to read the samples from the data array into a WAV file.
- Code: Select all
public void OnAudioStreamPacket(IWebBrowser chromiumWebBrowser, IBrowser browser, IntPtr data, int noOfFrames, long pts)
{
// ChannelLayout = LayoutStereo
// FramesPerBuffer = 1024
// SampleRate = 44100
// channels = 2
var length = noOfFrames / 4; // <== I am pretty sure I am calculating the length incorrectly.
var array = new float[length];
Marshal.Copy(data, array, 0, length);
this.waveFileWriter.WriteSamples(array, 0, length);
}
However, the file that is create is too small (10 second recording is only a couple of seconds long) and has no sound.