I'm trying to sample playing audio in order to chart it. When I play the file I hear the audio well but the float array that is coming out is, I think, wrong. The values are all tiny. Any ideas what I am doing wrong?
private void WavOutChartTimeInterrupt(object waveReader)
{
lock (AudioLock) //todo add skipto code, use audio lock to do it.
{
try
{
var curPos = _waveOut.GetPositionTimeSpan(); //get currentPos
if (curPos <= AudioCurrentPosition)
{
AudioCurrentPosition = curPos;
return;
}
var bufferLength = (curPos - AudioCurrentPosition);
var blockAlign = _waveOutSampleProvider.WaveFormat.BlockAlign;
var samplesSec = _waveOutSampleProvider.WaveFormat.SampleRate;
var channels = _waveOut.OutputWaveFormat.Channels;
var length = (int)(bufferLength.TotalSeconds * samplesSec * channels) % (samplesSec * channels);//(samplesSec * channels);
length -= length % (blockAlign / channels);
var wavOutBuffer = new float[length];
_waveOutSampleProvider.Read(wavOutBuffer, 0, length);
_audioCharter.ProcessBuffer(wavOutBuffer);
AudioCurrentPosition = curPos; //update for vCNC with where we are
}
catch (Exception e)
{
throw new ArgumentException(@"Wave out buffer crashed" + e + e.StackTrace);
}
}
}