From b77b1cdf84d784b8bafe9ffd72a4ab221b979744 Mon Sep 17 00:00:00 2001 From: pszsh Date: Sat, 31 Jan 2026 20:06:41 -0800 Subject: [PATCH] perfromance on mobile --- CMakeLists.txt | 28 ++++++++++++++++++++++++---- src/AudioEngine.cpp | 5 +++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 029f7df..961f78a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,21 @@ include(FetchContent) option(BUILD_ANDROID "Build for Android" OFF) option(BUILD_IOS "Build for iOS" OFF) +# --- Feature Flags --- +# Default to OFF for mobile to save resources, ON for desktop +if(BUILD_ANDROID OR BUILD_IOS) + option(ENABLE_TEMPO_ESTIMATION "Enable Loop Tempo Estimator for BPM detection" OFF) +else() + option(ENABLE_TEMPO_ESTIMATION "Enable Loop Tempo Estimator for BPM detection" ON) +endif() + +if(ENABLE_TEMPO_ESTIMATION) + message(STATUS "Tempo Estimation (Entropy) Enabled") + add_compile_definitions(ENABLE_TEMPO_ESTIMATION) +else() + message(STATUS "Tempo Estimation (Entropy) Disabled") +endif() + find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Multimedia OpenGLWidgets) # --- FFTW3 Configuration (Double Precision) --- @@ -88,9 +103,11 @@ else() endif() # --- Loop Tempo Estimator --- -set(BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE) -set(BUILD_VAMP_PLUGIN OFF CACHE BOOL "Build Vamp plugin" FORCE) -add_subdirectory(libraries/loop-tempo-estimator) +if(ENABLE_TEMPO_ESTIMATION) + set(BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE) + set(BUILD_VAMP_PLUGIN OFF CACHE BOOL "Build Vamp plugin" FORCE) + add_subdirectory(libraries/loop-tempo-estimator) +endif() # ========================================== # --- ICON GENERATION --- @@ -216,9 +233,12 @@ endif() target_link_libraries(YrCrystals PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Multimedia Qt6::OpenGLWidgets ${FFTW_TARGET} - loop-tempo-estimator ) +if(ENABLE_TEMPO_ESTIMATION) + target_link_libraries(YrCrystals PRIVATE loop-tempo-estimator) +endif() + if(BUILD_ANDROID) target_link_libraries(YrCrystals PRIVATE log m) set_property(TARGET YrCrystals PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") diff --git a/src/AudioEngine.cpp b/src/AudioEngine.cpp index ff97e9b..ba820b8 100644 --- a/src/AudioEngine.cpp +++ b/src/AudioEngine.cpp @@ -12,6 +12,8 @@ #include #include // Added for QPointer #include "Utils.h" + +#ifdef ENABLE_TEMPO_ESTIMATION #include "LoopTempoEstimator/LoopTempoEstimator.h" // --- Helper: Memory Reader for BPM --- @@ -38,6 +40,7 @@ private: long long m_numFrames; int m_sampleRate; }; +#endif // ========================================================= // AudioEngine (Playback) Implementation @@ -243,6 +246,7 @@ void AudioEngine::onFinished() { if (totalFrames > 0) { // 1. BPM Detection +#ifdef ENABLE_TEMPO_ESTIMATION MemoryAudioReader reader(rawFloats, totalFrames, newData->sampleRate); auto bpmOpt = LTE::GetBpm(reader, LTE::FalsePositiveTolerance::Lenient, nullptr); @@ -253,6 +257,7 @@ void AudioEngine::onFinished() { QMetaObject::invokeMethod(self, "analysisReady", Qt::QueuedConnection, Q_ARG(float, bpm), Q_ARG(float, 1.0f)); } +#endif // 2. Hilbert Transform std::vector inputL(totalFrames), inputR(totalFrames);