Hi,
I’m working on importing QuickTime supported formats, rendering them to uncompressed PCM. I’ve had 100% success importing files containing PCM and AAC (.mp4/.m4a) encoded audio tracks. However, with MP3 I end up with gaps in the audio, and the file length is always truncated to 1/2 or 1/4 the input length (BTW this is on the Mac). I’m reading from a QTAudioReader (returned by QuickTimeAudioFormat::createReaderFor()) and writing to a PCM format writer (using WAV for my example below).
My code basically looks like this (assume we pass in a valid qtFile and reader created by an AudioFormatManager that has properly registered QuickTimeAudioFormat):
void importQuickTimeFile(const File &qtFile, AudioFormatReader &reader)
{
WavAudioFormat wavFormat;
File wavFile(qtFile.withFileExtension("wav"));
FileOutputStream *outStream = wavFile.createOutputStream();
if (outStream)
{
AudioFormatWriter *writer = wavFormat.createWriterFor( outStream,
reader.sampleRate,
reader.numChannels,
kDefaultBitDepth,
StringPairArray(), 0 );
if (writer)
{
int numSamples = 32768;
int samplesRead = 0;
while (samplesRead < reader.lengthInSamples)
{
writer->writeFromAudioReader(reader, samplesRead, numSamples);
samplesRead += numSamples;
// get the last remaining samples
if (reader.lengthInSamples - samplesRead < numSamples)
numSamples = (int)reader.lengthInSamples - samplesRead;
}
delete writer;
}
}
}
Anyone had this problem? Anything I’m doing wrong? I did notice that QTAudioReader makes heavy use of the QuickTime 7 API, and wondering if that has something to do with it. The JUCE code I’m using is very close to the 1.51 release (I diffed the juce_QuickTimeAudioFormat source and it is functionally identical).
Thanks!