Make sure you flush() your wavWriter1 before attempting to read what it has written (this happens automatically when the writer is destroyed).
If you try to read from the memoryblock while the writer is still in existence, its content may still be in an inconsistent state (e.g. the samples number stated there may be still 0 because that gets updated on flush)
Digging deeper into juce::FlacAudioFormat reveals that juce is not using metadataValues for setting up the blocksize for the flac encoding.
AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
unsigned int numberOfChannels,
const StringPairArray& /*metadataValues*/,
if (out != nullptr && getPossibleBitDepths().contains (bitsPerSample))
std::unique_ptr<FlacWriter> w (new FlacWriter (out, sampleRate, numberOfChannels,
(uint32) bitsPerSample, qualityOptionIndex));
This means the flac encoder defaults to a fixed block size of 1152 for max_lpc_order of 0, which itself is set due to a qualityOptionIndex of 0 (from FlacAudioFormat::createWriterFor()) . In stream_encoder.c:
Is it on the horizon to be able to set the flac min and max blocksize with FlacAudioFormat::createWriterFor() via metadataValues?
Or, are we expected to set qualityOptionIndex to 0, pad the AudioBuffer with 0s to make its size a multiple of 1152, and then make sure the receiving AudioBuffer knows the original length (i.e. to trim the padding zeroes)?