But apparently reader->lengthInSamples is always 0 so I dont get my buffer as it should. Is this the right way to do it or I am skipping something?
Cila
Your problem is, that the writer does not finish, because it is leaking.
The length of a wav file will be written into the header, when the writer object is destroyed.
Best practice is to put the writer into a unique_ptr:
MemoryBlock wavData;
{
// MemoryOutputStream is owned, if the writer was created successfully
std::unique_ptr<AudioFormatWriter> writer (format.createWriterFor (new MemoryOutputStream (wavData, false), 48000, 1, 16, StringPairArray(), 0));
writer->writeFromAudioSampleBuffer(impulseResponse, 0, impulseResponse.getNumSamples());
// end of scope flushes the writer
}
auto response = parentXml->getChildByName ("ImpulseResponse");
if (response)
response->setAttribute ("AudioFile", wavData.toBase64Encoding());