Wav file buffer flush

I’m trying to write some data to a wav file, but the code hangs when I try to delete the audioFormatWriter object in order to ensure that all data is written. I’m using VS2008 which gives an error which it says may be due to corruption of the heap. Code is show below, and any help is much appreciated.

mark

[code]File outputFile(“C:\Users\wood\Documents\engineering\4yp\testsignals\largeData.wav”);
AudioFormatWriter *wavWriter;

FileOutputStream outputStream(outputFile,false);

wavWriter = wavBase.createWriterFor(&outputStream,96000,2,32,NULL,0);

//Write the data as many times as needed
for (int i=0;i<1;i++){

if(wavWriter->writeFromAudioReader(*wavReader,0,750120)==false){

int j=0;
}
}
//outputStream.flush();

delete wavWriter;[/code]

Update: The data is actually being written to disk succesfully, so the break must be occuring somewhere during the delete command but after the data is written

mark

The writer deletes the output stream, doesn’t it? So you shouldn’t create a stream as a stack object.

(It’s better to use File::createOutputStream anyway, rather than creating one directly)

Ah ok thanks for that, I’ve not long started c++ so my memory management skills are not up to much.

mark