Trying to write WAV file



I’m trying to write a simple wav file mono, 16bits , of 500000 samples set to zero, at 44100 HZ, in this little code :

[code]int size=500000;
AudioSampleBuffer* buffer=new AudioSampleBuffer(1,size);

WavAudioFormat* test = new WavAudioFormat();

File outputFile = File(“c:\test.wav”);
FileOutputStream* outputTo = outputFile.createOutputStream();

AudioFormatWriter* writer = test->createWriterFor(outputTo, 44100, 1, 16,NULL, 0);
delete outputTo;

But while the file is created ok, the wav chunk shows that the file is actually 0 byte long (the size just after the RIFF in header wav chunk). So it can open in any editor, but without any sample.

However the buffer does write to the file and I got a ‘correct’ 1 000 044 byte size on the file.

Any advice about what I’m doing wrong ? (or any example code)



Get AudioStream of a track to convert it to wav file

You need to delete the Writer, not the output stream.


Working !

Thanks a lot,