Hello,
I can’t have a non-silent FLAC file written with current Juce revision… modifying the demo’s record page code to replace WaveAudioFormat with FlacAudioFormat can easily show the problem. The resulting recorded file is likely to be silent or just invalid FLAC stream maybe…
I just took the head revision again, recompiled the (unhacked) juce demo in another folder, recorded with wav AudioFormat, checked the result (it works, generated WAV is OK), changed again the WavAudioFormat line in AudioDemoRecordPage.cpp to FlacAudioFormat, and still had the same problem: generated Flac is valid but silent. I used foobar2k and Winamp to play the files.
my modified lines are:
from l61:
[code] if (fileStream != 0)
{
// Now create a WAV writer object that writes to our output stream…
/WavAudioFormat wavFormat;
AudioFormatWriter writer = wavFormat.createWriterFor (fileStream, sampleRate, 1, 16, StringPairArray(), 0);/
FlacAudioFormat wavFormat;
AudioFormatWriter writer = wavFormat.createWriterFor (fileStream, sampleRate, 1, 16, StringPairArray(), 0);
if (writer != 0)
{
fileStream.release(); // (passes responsibility for deleting the stream to the writer object that is now using it)
// Now we'll create one of these helper objects which will act as a FIFO buffer, and will
// write the data to disk on our background thread.
threadedWriter = new AudioFormatWriter::ThreadedWriter (writer, backgroundThread, 32768);
// And now, swap over our active writer pointer so that the audio callback will start using it..
const ScopedLock sl (writerLock);
activeWriter = threadedWriter;
}
}[/code]
The output FLAC file is valid and seen by foobar/winamp as such:
[attachment=0]JuceDemo_RecordedFLAC_File_Foobar2k_Properties.png[/attachment]
The only problem is that it’s silent instead of what me whistling in the microphone during the recording (the waveform meter moved accordingly during the record).
Try playing it back in the juce demo itself, that worked for me, and it also played ok in VLC. Or do some debugging and see if you can follow the audio data to see whether it’s getting lost somewhere.
it appears that the data (samplesToWrite) passed to FLAC__stream_encoder_process is always freed before the function due to the HeapBlock<int> temp which gets out of the if (bitsToShift > 0) scope.
I guess that using this code in release does not necessarily causes any problem, but in Debug, the freed Heap data is always filled with 0xfeeefeee… which probably explains the silent FLAC files I get as I only used it in Debug so far…