I'm using NAudio with C# to convert wave files to 48,000, 8bit, Mono. I'm storing the converted data in a byte array. My code is below. It works fine, but the new wave file data is unsigned, and I need it to be signed.
WaveFormat target = new WaveFormat(48000, 8, 1);
WaveStream stream = new WaveFileReader(this.FilePath);
WaveFormatConversionStream conv = new WaveFormatConversionStream(target, stream);
this.ConvertedData = new byte[conv.Length];
conv.Position = 0;
conv.Read(this.ConvertedData, 0, Convert.ToInt32(conv.Length));
stream.Dispose();
conv.Dispose();
I've tried looping through the byte array after the data is converted, and subtracting 128 from each byte, which is a solution that I found on this site.
for (int i = 0; i < end; i++)
{
signed = (int)this.ConvertedData[i] - 128;
this.Data[i] = (byte)signed;
}
This kind of works, but is not fool proof, and I'm sure there has to be a better way. Any suggestions would be greatly appreciated. Thanks.