diff --git a/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp b/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp index 3a155b07d6..1f4fb29f70 100644 --- a/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp @@ -39,10 +39,10 @@ struct AudioThumbnail::MinMaxValue inline char getMinValue() const noexcept { return values[0]; } inline char getMaxValue() const noexcept { return values[1]; } - inline void setFloat (const float newMin, const float newMax) noexcept + inline void setFloat (Range newRange) noexcept { - values[0] = (char) jlimit (-128, 127, roundFloatToInt (newMin * 127.0f)); - values[1] = (char) jlimit (-128, 127, roundFloatToInt (newMax * 127.0f)); + values[0] = (char) jlimit (-128, 127, roundFloatToInt (newRange.getStart() * 127.0f)); + values[1] = (char) jlimit (-128, 127, roundFloatToInt (newRange.getEnd() * 127.0f)); if (values[0] == values[1]) { @@ -115,7 +115,7 @@ public: } } - void getLevels (int64 startSample, int numSamples, Array& levels) + void getLevels (int64 startSample, int numSamples, Array >& levels) { const ScopedLock sl (readerLock); @@ -132,11 +132,10 @@ public: if (reader != nullptr) { - float l[4] = { 0 }; - reader->readMaxLevels (startSample, numSamples, l[0], l[1], l[2], l[3]); + if (levels.size() < reader->numChannels) + levels.insertMultiple (0, Range(), (int) (reader->numChannels - levels.size())); - levels.clearQuick(); - levels.addArray ((const float*) l, 4); + reader->readMaxLevels (startSample, numSamples, levels.getRawDataPointer(), (int) reader->numChannels); lastReaderUseTime = Time::getMillisecondCounter(); } @@ -202,8 +201,8 @@ public: private: AudioThumbnail& owner; - ScopedPointer source; - ScopedPointer reader; + ScopedPointer source; + ScopedPointer reader; CriticalSection readerLock; uint32 lastReaderUseTime; @@ -230,23 +229,26 @@ private: const int lastThumbIndex = sampleToThumbSample (startSample + numToDo); const int numThumbSamps = lastThumbIndex - firstThumbIndex; - HeapBlock levelData ((size_t) numThumbSamps * 2); - MinMaxValue* levels[2] = { levelData, levelData + numThumbSamps }; + HeapBlock levelData ((size_t) numThumbSamps * numChannels); + HeapBlock levels (numChannels); + + for (int i = 0; i < numChannels; ++i) + levels[i] = levelData + i * numThumbSamps; + + HeapBlock > levelsRead (numChannels); for (int i = 0; i < numThumbSamps; ++i) { - float lowestLeft, highestLeft, lowestRight, highestRight; + reader->readMaxLevels ((firstThumbIndex + i) * owner.samplesPerThumbSample, + owner.samplesPerThumbSample, levelsRead, numChannels); - reader->readMaxLevels ((firstThumbIndex + i) * owner.samplesPerThumbSample, owner.samplesPerThumbSample, - lowestLeft, highestLeft, lowestRight, highestRight); - - levels[0][i].setFloat (lowestLeft, highestLeft); - levels[1][i].setFloat (lowestRight, highestRight); + for (int j = 0; j < numChannels; ++j) + levels[j][i].setFloat (levelsRead[j]); } { const ScopedUnlock su (readerLock); - owner.setLevels (levels, firstThumbIndex, 2, numThumbSamps); + owner.setLevels (levels, firstThumbIndex, (int) numChannels, numThumbSamps); } numSamplesFinished += numToDo; @@ -452,7 +454,7 @@ private: if (timePerPixel * rate <= sampsPerThumbSample && levelData != nullptr) { int sample = roundToInt (startTime * rate); - Array levels; + Array > levels; int i; for (i = 0; i < numSamples; ++i) @@ -470,11 +472,10 @@ private: { levelData->getLevels (sample, jmax (1, nextSample - sample), levels); - const int totalChans = jmin (levels.size() / 2, numChannelsCached); + const int totalChans = jmin (levels.size(), numChannelsCached); for (int chan = 0; chan < totalChans; ++chan) - getData (chan, i)->setFloat (levels.getUnchecked (chan * 2), - levels.getUnchecked (chan * 2 + 1)); + getData (chan, i)->setFloat (levels.getReference (chan)); } } @@ -714,8 +715,7 @@ void AudioThumbnail::addBlock (const int64 startSample, const AudioSampleBuffer& for (int i = 0; i < numToDo; ++i) { const int start = i * samplesPerThumbSample; - Range range (FloatVectorOperations::findMinAndMax (sourceData + start, jmin (samplesPerThumbSample, numSamples - start))); - dest[i].setFloat (range.getStart(), range.getEnd()); + dest[i].setFloat (FloatVectorOperations::findMinAndMax (sourceData + start, jmin (samplesPerThumbSample, numSamples - start))); } }