From 712df3b69b7e865dfb231545e6bb6c23075715de Mon Sep 17 00:00:00 2001 From: Michael Witte Date: Fri, 26 Apr 2024 23:57:05 +0200 Subject: [PATCH 1/3] Change cpu calculation to AudioProcessLoadMeasurer Class --- CMakeLists.txt | 1 + source/PluginProcessor.cpp | 10 +++-- source/PluginProcessor.h | 3 ++ .../Footer/FooterComponent.cpp | 2 +- source/utils/SystemSpecs.cpp | 43 +++++++++++-------- source/utils/SystemSpecs.h | 3 ++ 6 files changed, 39 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc34d2a..0b1acd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,6 +182,7 @@ target_link_libraries(${TARGET_NAME} juce::juce_graphics juce::juce_gui_basics juce::juce_gui_extra + juce::juce_audio_basics onnxruntime PUBLIC diff --git a/source/PluginProcessor.cpp b/source/PluginProcessor.cpp index 029a4f6..0e3e626 100644 --- a/source/PluginProcessor.cpp +++ b/source/PluginProcessor.cpp @@ -23,7 +23,9 @@ AudioPluginAudioProcessor::AudioPluginAudioProcessor() grainDelay1(1), grainDelay2(2), processorCompressor(parameters) -{ +{ + // resets the state + network1Name = "Funk"; network2Name = "Djembe"; @@ -169,6 +171,7 @@ void AudioPluginAudioProcessor::prepareToPlay (double sampleRate, int samplesPer void AudioPluginAudioProcessor::releaseResources() { // When playback stops, you can use this as an opportunity to free up any // spare memory, etc. + measurer.reset(); } bool AudioPluginAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const { @@ -195,9 +198,8 @@ bool AudioPluginAudioProcessor::isBusesLayoutSupported (const BusesLayout& layou void AudioPluginAudioProcessor::processBlock (juce::AudioBuffer& buffer, juce::MidiBuffer& ) { - juce::AudioProcessLoadMeasurer::ScopedTimer s(measurer); + juce::AudioProcessLoadMeasurer::ScopedTimer s(measurer, buffer.getNumSamples()); { - dryWetMixer.setDrySamples(buffer); stereoToMono(monoBuffer, buffer); @@ -249,7 +251,7 @@ void AudioPluginAudioProcessor::processBlock (juce::AudioBuffer& buffer, } cpuLoad = measurer.getLoadAsPercentage(); - // std::cout << "CPU: " << (int)(cpuLoad) << " %\n"; + std::cout << "CPU: " << (int)(cpuLoad) << " %\n"; // std::cout << "latency: " << (latency*1000) << " ms\n"; } diff --git a/source/PluginProcessor.h b/source/PluginProcessor.h index 2052447..3c7b11e 100644 --- a/source/PluginProcessor.h +++ b/source/PluginProcessor.h @@ -11,6 +11,7 @@ #include "dsp/gain/ProcessorGain.h" #include "dsp/Filter/IIRCutoffFilter.h" #include "dsp/grainDelay/GrainDelay.h" +//#include //============================================================================== @@ -123,6 +124,8 @@ float latency; + + //============================================================================== JUCE_HEAVYWEIGHT_LEAK_DETECTOR (AudioPluginAudioProcessor) }; diff --git a/source/ui/CustomComponents/Footer/FooterComponent.cpp b/source/ui/CustomComponents/Footer/FooterComponent.cpp index 00b19ca..13ae78d 100644 --- a/source/ui/CustomComponents/Footer/FooterComponent.cpp +++ b/source/ui/CustomComponents/Footer/FooterComponent.cpp @@ -60,7 +60,7 @@ void FooterComponent::updateSpecs(){ latencySeconds = (float)latencySamples / float(sampleRate); //processorUse = processor.getCpuLoad(); - processorUse = systemSpecs.getCPULoad(); + processorUse = processor.getCpuLoad(); std::string cpuString = "CPU: " + std::to_string((int)processorUse ) + " %"; cpuLabel.setText(cpuString, juce::dontSendNotification); diff --git a/source/utils/SystemSpecs.cpp b/source/utils/SystemSpecs.cpp index c959502..2cd3766 100644 --- a/source/utils/SystemSpecs.cpp +++ b/source/utils/SystemSpecs.cpp @@ -104,35 +104,42 @@ } #elif JUCE_MAC + #include #include #include #include + SystemSpecs::SystemSpecs() { + } + + SystemSpecs::~SystemSpecs() {} + + static unsigned long long _previousTotalTicks = 0; static unsigned long long _previousIdleTicks = 0; double SystemSpecs::getCPULoad() { -// host_cpu_load_info_data_t cpuinfo; -// mach_msg_type_number_t count = HOST_CPU_LOAD_INFO_COUNT; -// if (host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&cpuinfo, &count) == KERN_SUCCESS) -// { -// unsigned long long totalTicks = 0; -// for(int i=0; i 0) ? ((float)idleTicksSinceLastTime)/totalTicksSinceLastTime : 0); -// _previousTotalTicks = totalTicks; -// _previousIdleTicks = idleTicks; -// return ret; - return 0.0; + double SystemSpecs::calculateCPULoad(unsigned long long idleTicks, unsigned long long totalTicks) { + unsigned long long totalTicksSinceLastTime = totalTicks-_previousTotalTicks; + unsigned long long idleTicksSinceLastTime = idleTicks-_previousIdleTicks; + double ret = 1.0f*100-((totalTicksSinceLastTime > 0) ? ((double)(idleTicksSinceLastTime/totalTicksSinceLastTime)) : 0); + _previousTotalTicks = totalTicks; + _previousIdleTicks = idleTicks; + return ret; + // return 0.0; } #endif diff --git a/source/utils/SystemSpecs.h b/source/utils/SystemSpecs.h index b19cda5..0064e36 100644 --- a/source/utils/SystemSpecs.h +++ b/source/utils/SystemSpecs.h @@ -12,7 +12,10 @@ class SystemSpecs { ~SystemSpecs(); double getCPULoad(); + double calculateCPULoad(); + // Mac + double calculateCPULoad(unsigned long long idleTicks, unsigned long long totalTicks); private: juce::SystemStats::OperatingSystemType os; }; From ba8496adc8ff3e8dd17dd5e957f0448f7889b595 Mon Sep 17 00:00:00 2001 From: Christian Scheer Date: Sat, 27 Apr 2024 00:19:59 +0200 Subject: [PATCH 2/3] Delete old SystemSpecs class files. --- source/PluginProcessor.cpp | 2 +- .../CustomComponents/Footer/FooterComponent.h | 3 - source/utils/SystemSpecs.cpp | 146 ------------------ source/utils/SystemSpecs.h | 26 ---- 4 files changed, 1 insertion(+), 176 deletions(-) delete mode 100644 source/utils/SystemSpecs.cpp delete mode 100644 source/utils/SystemSpecs.h diff --git a/source/PluginProcessor.cpp b/source/PluginProcessor.cpp index 0e3e626..ba22871 100644 --- a/source/PluginProcessor.cpp +++ b/source/PluginProcessor.cpp @@ -251,7 +251,7 @@ void AudioPluginAudioProcessor::processBlock (juce::AudioBuffer& buffer, } cpuLoad = measurer.getLoadAsPercentage(); - std::cout << "CPU: " << (int)(cpuLoad) << " %\n"; + // std::cout << "CPU: " << (int)(cpuLoad) << " %\n"; // std::cout << "latency: " << (latency*1000) << " ms\n"; } diff --git a/source/ui/CustomComponents/Footer/FooterComponent.h b/source/ui/CustomComponents/Footer/FooterComponent.h index 37a5ad0..5a777fa 100644 --- a/source/ui/CustomComponents/Footer/FooterComponent.h +++ b/source/ui/CustomComponents/Footer/FooterComponent.h @@ -9,7 +9,6 @@ #include "../../../PluginParameters.h" #include "../../../PluginProcessor.h" #include "../../../ui/LookAndFeel/CustomFontLookAndFeel.h" -#include "../../../utils/SystemSpecs.h" class FooterComponent : public juce::Component, juce::Timer { public: @@ -39,8 +38,6 @@ class FooterComponent : public juce::Component, juce::Timer { CustomFontLookAndFeel customFontLookAndFeel; juce::Font font; - SystemSpecs systemSpecs; - }; diff --git a/source/utils/SystemSpecs.cpp b/source/utils/SystemSpecs.cpp deleted file mode 100644 index 2cd3766..0000000 --- a/source/utils/SystemSpecs.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// -// Created by schee on 22/08/2023. -// - -#include "SystemSpecs.h" - -#if JUCE_WINDOWS - #include "windows.h" - - static ULARGE_INTEGER lastCPU, lastSysCPU, lastUserCPU; - static int numProcessors; - static HANDLE self; - - SystemSpecs::SystemSpecs() { - SYSTEM_INFO sysInfo; - FILETIME ftime, fsys, fuser; - - GetSystemInfo(&sysInfo); - numProcessors = sysInfo.dwNumberOfProcessors; - - GetSystemTimeAsFileTime(&ftime); - memcpy(&lastCPU, &ftime, sizeof(FILETIME)); - - self = GetCurrentProcess(); - GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser); - memcpy(&lastSysCPU, &fsys, sizeof(FILETIME)); - memcpy(&lastUserCPU, &fuser, sizeof(FILETIME)); - } - SystemSpecs::~SystemSpecs() {} - - double SystemSpecs::getCPULoad() { - - FILETIME ftime, fsys, fuser; - ULARGE_INTEGER now, sys, user; - double percent; - - GetSystemTimeAsFileTime(&ftime); - memcpy(&now, &ftime, sizeof(FILETIME)); - - GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser); - memcpy(&sys, &fsys, sizeof(FILETIME)); - memcpy(&user, &fuser, sizeof(FILETIME)); - percent = (sys.QuadPart - lastSysCPU.QuadPart) + - (user.QuadPart - lastUserCPU.QuadPart); - percent /= (now.QuadPart - lastCPU.QuadPart); - percent /= numProcessors; - lastCPU = now; - lastUserCPU = user; - lastSysCPU = sys; - - return percent * 100; - } - -#elif JUCE_LINUX - #include "stdlib.h" - #include "stdio.h" - #include "string.h" - #include "sys/times.h" - #include "sys/vtimes.h" - - static clock_t lastCPU, lastSysCPU, lastUserCPU; - static int numProcessors; - - SystemSpecs::SystemSpecs(){ - FILE* file; - struct tms timeSample; - char line[128]; - - lastCPU = times(&timeSample); - lastSysCPU = timeSample.tms_stime; - lastUserCPU = timeSample.tms_utime; - - file = fopen("/proc/cpuinfo", "r"); - numProcessors = 0; - while(fgets(line, 128, file) != NULL){ - if (strncmp(line, "processor", 9) == 0) numProcessors++; - } - fclose(file); - } - - double SystemSpecs::getCPULoad(){ - struct tms timeSample; - clock_t now; - double percent; - - now = times(&timeSample); - if (now <= lastCPU || timeSample.tms_stime < lastSysCPU || - timeSample.tms_utime < lastUserCPU){ - //Overflow detection. Just skip this value. - percent = -1.0; - } - else{ - percent = (timeSample.tms_stime - lastSysCPU) + - (timeSample.tms_utime - lastUserCPU); - percent /= (now - lastCPU); - percent /= numProcessors; - percent *= 100; - } - lastCPU = now; - lastSysCPU = timeSample.tms_stime; - lastUserCPU = timeSample.tms_utime; - - return percent; - } - -#elif JUCE_MAC - - #include - #include - #include - #include - - SystemSpecs::SystemSpecs() { - } - - SystemSpecs::~SystemSpecs() {} - - - static unsigned long long _previousTotalTicks = 0; - static unsigned long long _previousIdleTicks = 0; - - double SystemSpecs::getCPULoad() { - host_cpu_load_info_data_t cpuinfo; - mach_msg_type_number_t count = HOST_CPU_LOAD_INFO_COUNT; - if (host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&cpuinfo, &count) == KERN_SUCCESS) - { - unsigned long long totalTicks = 0; - for(int i=0; i 0) ? ((double)(idleTicksSinceLastTime/totalTicksSinceLastTime)) : 0); - _previousTotalTicks = totalTicks; - _previousIdleTicks = idleTicks; - return ret; - // return 0.0; - } -#endif - - diff --git a/source/utils/SystemSpecs.h b/source/utils/SystemSpecs.h deleted file mode 100644 index 0064e36..0000000 --- a/source/utils/SystemSpecs.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// Created by schee on 22/08/2023. -// - -#ifndef SCYCLONE_SYSTEMSPECS_H -#define SCYCLONE_SYSTEMSPECS_H -#include "JuceHeader.h" - -class SystemSpecs { - public: - SystemSpecs(); - ~SystemSpecs(); - - double getCPULoad(); - - double calculateCPULoad(); - // Mac - double calculateCPULoad(unsigned long long idleTicks, unsigned long long totalTicks); - private: - juce::SystemStats::OperatingSystemType os; -}; - - - - -#endif //SCYCLONE_SYSTEMSPECS_H From 9c91b46131a2a52418a8276313252f4c1819f6d5 Mon Sep 17 00:00:00 2001 From: Michael Witte Date: Sun, 28 Apr 2024 16:47:06 +0200 Subject: [PATCH 3/3] Bugfix for dissapearing model names after clicking ArrowButtons --- source/PluginProcessor.cpp | 4 +--- source/ui/CustomComponents/XYPad/XYPad.cpp | 7 +------ 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/source/PluginProcessor.cpp b/source/PluginProcessor.cpp index ba22871..69e11cb 100644 --- a/source/PluginProcessor.cpp +++ b/source/PluginProcessor.cpp @@ -23,9 +23,7 @@ AudioPluginAudioProcessor::AudioPluginAudioProcessor() grainDelay1(1), grainDelay2(2), processorCompressor(parameters) -{ - // resets the state - +{ network1Name = "Funk"; network2Name = "Djembe"; diff --git a/source/ui/CustomComponents/XYPad/XYPad.cpp b/source/ui/CustomComponents/XYPad/XYPad.cpp index e07418b..5491612 100644 --- a/source/ui/CustomComponents/XYPad/XYPad.cpp +++ b/source/ui/CustomComponents/XYPad/XYPad.cpp @@ -102,12 +102,7 @@ void XYPad::resized() void XYPad::parameterChanged(const juce::String& parameterID, float newValue) { - if (parameterID == PluginParameters::SELECT_NETWORK1_ID.getParamID() && newValue == 0.f) { - updateKnobName(1, network1Name); - } else if (parameterID == PluginParameters::SELECT_NETWORK2_ID.getParamID() && newValue == 0.f) { - updateKnobName(2, network2Name); - } - + if (parameterID == PluginParameters::FADE_ID.getParamID()){ float fadeValue = parameters.getRawParameterValue(PluginParameters::FADE_ID.getParamID())->load(); onModelMixChange(fadeValue);