Trying to write WAV file


#1

Hi,

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);
buffer->clear();

WavAudioFormat* test = new WavAudioFormat();

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

AudioFormatWriter* writer = test->createWriterFor(outputTo, 44100, 1, 16,NULL, 0);
buffer->writeToAudioWriter(writer,0,buffer->getNumSamples());
delete outputTo;
[/code]

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)

Thanks,

Nicolas


Get AudioStream of a track to convert it to wav file
#2

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


#3

Working !

Thanks a lot,

Nicolas


#4