private int readAsFloat(float[] buffer, int count)
{
int reads = 0;
// Detect the underlying stream format.
if (waveStream.Format.Encoding == WaveFormatEncoding.Pcm)
{
// The wave is in standard PCM format. We'll need
// to convert it to IeeeFloat.
switch (waveStream.Format.BitsPerSample)
{
case 8: // Stream is 8 bits
{
byte[] block = new byte[bufferSize];
reads = read(block, count);
SampleConverter.Convert(block, buffer);
}
break;
case 16: // Stream is 16 bits
{
short[] block = new short[bufferSize];
reads = read(block, count);
SampleConverter.Convert(block, buffer);
}
break;
case 32: // Stream is 32 bits
{
int[] block = new int[bufferSize];
reads = read(block, count);
SampleConverter.Convert(block, buffer);
}
break;
default:
throw new NotSupportedException();
}
}
else if (waveStream.Format.Encoding == WaveFormatEncoding.IeeeFloat)
{
// Format is 16-bit IEEE float,
// just copy to the buffer.
reads = read(buffer, count);
}
else
{
throw new NotSupportedException("The wave format isn't supported");
}
return reads; // return the number of bytes read
}