diff --git a/source/native-plugins/audio-base.hpp b/source/native-plugins/audio-base.hpp index 4b8ec9bbd..8a19010de 100644 --- a/source/native-plugins/audio-base.hpp +++ b/source/native-plugins/audio-base.hpp @@ -347,7 +347,7 @@ public: const uint pollTempSize = poolNumFrames * fFileNfo.channels; uint resampleTempSize = 0; - carla_zeroFloats(previewData, 300); + readFilePreview(previewDataSize, previewData); fPool.create(poolNumFrames, true); @@ -490,6 +490,24 @@ public: return true; } + void readFilePreview(const uint32_t previewDataSize, float* previewData) + { + carla_zeroFloats(previewData, previewDataSize); + + const uint fileNumFrames = static_cast(fFileNfo.frames); + const float fileNumFramesF = static_cast(fileNumFrames); + const float previewDataSizeF = static_cast(previewDataSize); + + for (uint i=0; i(i)/previewDataSizeF * fileNumFramesF; + const uint pos = carla_fixedValue(0U, fileNumFrames-2U, static_cast(posF + 0.5f)); + + ad_seek(fFilePtr, pos); + ad_read(fFilePtr, previewData + i, 2); + } + } + void readEntireFileIntoPool(const bool needsResample) { CARLA_SAFE_ASSERT_RETURN(fPool.numFrames > 0,);