Pergunta

I am recording bytes that coming from serial port and converting them to wav file using NAudio. However when I plot my wav file it does have a proper look. Its range is 0 to 1 but other wav files have the range -1 to 1. Is it related with the encoding or something else?

WaveFormat waveFormat = new WaveFormat(8000, 8, 1);
using (WaveFileWriter writer = new WaveFileWriter(fileName, waveFormat))
{
     writer.Write(audioBuffer, 0, audioBuffer.Length);
}
Foi útil?

Solução

This depends on the data type within your "audioBuffer".

32-bit floating point audio samples are usually in the range from -1.0 to 1.0. 16-bit integer audio samples are usually signed in the range -32768 to 32767. 8-bit integer audio samples are very commonly unsigned, with the range being 0 to 255, with 128 being the same as 0.0 in floating point.

Outras dicas

The -1 to +1 range is usually the working range when converting PCM data to 32 bit floats for more convenient mixing.

It allows a nice, normalised representation of amplitude whilst leaving plenty of head room for mixing.

If you get 0 to 1 range, something might be wrong in the conversion process: wavs are typically ( but not always ) stored as 16 bit signed integers, and converting to float implies multiplying by 32768 ( if bit depth is 16 and data represented in 16 bit signed integers ). Have a look at the wav's header to get more insight on the format - more info on wav headers here.

https://ccrma.stanford.edu/courses/422/projects/WaveFormat/

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top