If i’m writing a wav with AudioFormatWriter and FileOutputStream to disk than its ok.
When i’m writing it with MemoryOutputStream and than write it to disk, the wav is broken.
First it thought there is a missing flush, but also the header is different.
Wav with FileOutputStream (right) HEX
4952 4646 105c 0000 4157 4556 554a 4b4e
0034 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 6d66 2074 0010 0000
0003 0001 bb80 0000 ee00 0002 0004 0020
6164 6174 0ffc 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 4952 4646 105c 0000 4157 4556
554a 4b4e 0034 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 6d66 2074
0010 0000 0003 0001 bb80 0000 ee00 0002
0004 0020 6164 6174 0ffc 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 4952 4646 105c 0000
4157 4556 554a 4b4e 0034 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
6d66 2074 0010 0000 0003 0001 bb80 0000
ee00 0002 0004 0020 6164 6174 0ffc 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000
Wav with MemoryOutputStream (broken)
[code]4952 4646 0060 0000 4157 4556 554a 4b4e // look at byte 5/6
0034 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 6d66 2074 0010 0000
0003 0001 bb80 0000 ee00 0002 0004 0020
6164 6174 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000[/code]
I’m just doing
[code] AudioSampleBuffer asb(1,1023);
asb.clear();
File f(File::getSpecialLocation(File::userHomeDirectory).getChildFile("test.wav"));
WavAudioFormat wavFormat;
MemoryOutputStream* fos = new MemoryOutputStream();
ScopedPointer<AudioFormatWriter> writer ( wavFormat.createWriterFor(fos, 48000., asb.getNumChannels(), 32, StringPairArray(), 0));
if (writer==nullptr)
{
jassertfalse;
delete fos;
} else
{
writer->writeFromAudioSampleBuffer(asb, 0, asb.getNumSamples());
MemoryBlock mb(fos->getMemoryBlock());
f.deleteFile();
f.appendData(mb.getData(),mb.getSize());;
}[/code]