Just want to write a simple wave file

Nov 24, 2010 at 7:03 PM

float[][] buffer <= several channels buffer, value from -1.0~1.0

public static void toWavFile(string fileName, float[][] buffer)        {

WaveFileWriter writer = new WaveFileWriter(fileName, AdpcmWaveFormat.CreateALawFormat(44100,2));

// WaveFileWriter writer = new WaveFileWriter(fileName, WaveFormat.CreateALawFormat(44100,2)); also doesn't work

writer.WriteData16(buffer, 0, 2);





the resulting file can't be played by foobar2000, and looks very strange in CoolEdit. (very strong noise in left channel, very weak noise in right channel, looks chopped at +-0.2).

How to write a generated sound into a wave file? Thanks.

Nov 25, 2010 at 6:23 PM

you almost certainly don't want to use ALaw. Just a normal new WaveFormat(44100,16,2) would be better

Also, that overload of WriteData16 is obsolete and doesn't exist in the latest NAudio. I'm not sure how reliable it is. The latest WaveFileWriter has a WriteSample method which should be used in preference if you are able to use the latest code.


Nov 27, 2010 at 12:01 PM

Problem solved, thank you very much!

I'm the first time using NA, so it was a kinda stupid question ^ ^