From ba2287033c208e5cd460ef7ec2aac98ab1fe7bc2 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 16 Nov 2011 21:10:09 +0000 Subject: [PATCH] Fixed a problem when reading mono audio formats. --- .../format/juce_AudioFormatReader.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp b/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp index 074f274abe..fa9927cb47 100644 --- a/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp +++ b/modules/juce_audio_formats/format/juce_AudioFormatReader.cpp @@ -117,12 +117,13 @@ void AudioFormatReader::read (AudioSampleBuffer* buffer, if (numSamples > 0) { + const int numTargetChannels = buffer->getNumChannels(); int* chans[3]; if (useReaderLeftChan == useReaderRightChan) { chans[0] = reinterpret_cast (buffer->getSampleData (0, startSample)); - chans[1] = (numChannels > 1 && buffer->getNumChannels() > 1) ? reinterpret_cast (buffer->getSampleData (1, startSample)) : nullptr; + chans[1] = (numChannels > 1 && numTargetChannels > 1) ? reinterpret_cast (buffer->getSampleData (1, startSample)) : nullptr; } else if (useReaderLeftChan || (numChannels == 1)) { @@ -155,7 +156,7 @@ void AudioFormatReader::read (AudioSampleBuffer* buffer, } } - if (numChannels > 1 && (chans[0] == nullptr || chans[1] == nullptr)) + if (numTargetChannels > 1 && (chans[0] == nullptr || chans[1] == nullptr)) { // if this is a stereo buffer and the source was mono, dupe the first channel.. memcpy (buffer->getSampleData (1, startSample), @@ -221,9 +222,9 @@ void AudioFormatReader::readMaxLevels (int64 startSampleInFile, rmin = lmin; } - lowestLeft = lmin; - highestLeft = lmax; - lowestRight = rmin; + lowestLeft = lmin; + highestLeft = lmax; + lowestRight = rmin; highestRight = rmax; } else @@ -266,9 +267,9 @@ void AudioFormatReader::readMaxLevels (int64 startSampleInFile, rmin = lmin; } - lowestLeft = lmin / (float) std::numeric_limits::max(); - highestLeft = lmax / (float) std::numeric_limits::max(); - lowestRight = rmin / (float) std::numeric_limits::max(); + lowestLeft = lmin / (float) std::numeric_limits::max(); + highestLeft = lmax / (float) std::numeric_limits::max(); + lowestRight = rmin / (float) std::numeric_limits::max(); highestRight = rmax / (float) std::numeric_limits::max(); } }