From a39fc148d4a922c6e9703a9b76248318b84a9996 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 5 Mar 2021 20:59:19 +0000 Subject: [PATCH] audiofile: tweaks to "waveform" preview Signed-off-by: falkTX --- source/native-plugins/audio-base.hpp | 7 +++++-- source/native-plugins/audio-file.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source/native-plugins/audio-base.hpp b/source/native-plugins/audio-base.hpp index 07ec6d3fa..243dba79a 100644 --- a/source/native-plugins/audio-base.hpp +++ b/source/native-plugins/audio-base.hpp @@ -394,7 +394,7 @@ public: { const float stepF = static_cast(i)/previewDataSizeF * fileNumFramesF; const uint step = carla_fixedValue(0U, fileNumFrames-1U, static_cast(stepF + 0.5f)); - previewData[i] = fPool.buffer[0][step]; + previewData[i] = std::max(std::fabs(fPool.buffer[0][step]), std::fabs(fPool.buffer[1][step])); } } else @@ -522,6 +522,8 @@ public: const float previewDataSizeF = static_cast(previewDataSize); const uint samplesPerRun = fFileNfo.channels; const uint maxSampleToRead = fileNumFrames - samplesPerRun; + CARLA_SAFE_ASSERT_INT_RETURN(samplesPerRun == 1 || samplesPerRun == 2, samplesPerRun,); + float tmp[2] = { 0.0f, 0.0f }; if (samplesPerRun == 2) previewDataSize -= 1; @@ -532,7 +534,8 @@ public: const uint pos = carla_fixedValue(0U, maxSampleToRead, static_cast(posF)); ad_seek(fFilePtr, pos); - ad_read(fFilePtr, previewData + i, samplesPerRun); + ad_read(fFilePtr, tmp, samplesPerRun); + previewData[i] = std::max(std::fabs(tmp[0]), std::fabs(tmp[1])); } } diff --git a/source/native-plugins/audio-file.cpp b/source/native-plugins/audio-file.cpp index b4443e93f..a0acee871 100644 --- a/source/native-plugins/audio-file.cpp +++ b/source/native-plugins/audio-file.cpp @@ -713,7 +713,7 @@ private: AudioFileReader fReader; NativeMidiPrograms fPrograms; - float fPreviewData[300]; + float fPreviewData[108]; #ifndef __MOD_DEVICES__ struct InlineDisplay : NativeInlineDisplayImageSurfaceCompat {