I just recently started using JUCE and have found it very useful so far but I’m having a problem saving a .wav file to disk. The code giving me trouble is is:
//save the filtered output
ScopedPointer<WavAudioFormat> wavFormat = new WavAudioFormat();
File output("C:\\DEV\\FFT2\\filtered_output.wav");
FileOutputStream *fost = output.createOutputStream();
AudioSampleBuffer write_to_disk(&float_output, 1, M + P - 1);
ScopedPointer<AudioFormatWriter> writer = wavFormat->createWriterFor(fost, 44100, 1, 16, StringPairArray(), 0);
writer->writeFromAudioSampleBuffer(write_to_disk, 0, M + P - 1);
I know the data in float_output is good because I wrote it to a .txt file and imported it in Matlab to verify. I’m not sure if I’m opening the file/creating the streams/or calling write correctly.
Matlab gives the following output.
>> output = wavread('filtered_output.wav');
??? Error using ==> wavread at 166
Incorrect chunk size information in WAV file.
Any help would be greatly appreciated.
Writing the file to disk is the last thing the program does before exiting. I give a prompt telling me it’s finished and then it waits for me to hit enter.
Even when I delete the writer Matlab gives me the same error and I can’t play the file in Windows Media Player. Is there something else I’m doing wrong?
FYI be careful copying the code above - there’s some really bad C++ style in there. Search the juce repo for writeFromAudioSampleBuffer and I’m sure you’ll find some better example code to copy.