From 9dbadfbdc568d609dd0195f8c7ef2b6c5a90624c Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 18 Oct 2017 17:03:14 -0400 Subject: [PATCH] Remove gSampleRate, add engineGetSampleRate() --- include/engine.hpp | 2 +- src/app/Toolbar.cpp | 2 +- src/core/AudioInterface.cpp | 4 ++-- src/core/MidiInterface.cpp | 2 +- src/engine.cpp | 12 ++++++++---- src/settings.cpp | 3 +-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/engine.hpp b/include/engine.hpp index 50ceded7..93a89ccb 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -82,8 +82,8 @@ void engineRemoveWire(Wire *wire); void engineSetParam(Module *module, int paramId, float value); void engineSetParamSmooth(Module *module, int paramId, float value); void engineSetSampleRate(float sampleRate); +float engineGetSampleRate(); -extern float gSampleRate; extern bool gPaused; diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index bc14ec67..d14b37d9 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -90,7 +90,7 @@ struct SampleRateChoice : ChoiceButton { if (gPaused) text = "Paused"; else - text = stringf("%.0f Hz", gSampleRate); + text = stringf("%.0f Hz", engineGetSampleRate()); } }; diff --git a/src/core/AudioInterface.cpp b/src/core/AudioInterface.cpp index b27aef41..c9e4f6ce 100644 --- a/src/core/AudioInterface.cpp +++ b/src/core/AudioInterface.cpp @@ -155,7 +155,7 @@ void AudioInterface::step() { // Once full, sample rate convert the input // inputBuffer -> SRC -> inputSrcBuffer if (inputBuffer.full()) { - inputSrc.setRatio(sampleRate / gSampleRate); + inputSrc.setRatio(sampleRate / engineGetSampleRate()); int inLen = inputBuffer.size(); int outLen = inputSrcBuffer.capacity(); inputSrc.process(inputBuffer.startData(), &inLen, inputSrcBuffer.endData(), &outLen); @@ -194,7 +194,7 @@ void AudioInterface::stepStream(const float *input, float *output, int numFrames } // Pass output through sample rate converter - outputSrc.setRatio(gSampleRate / sampleRate); + outputSrc.setRatio(engineGetSampleRate() / sampleRate); int inLen = numFrames; int outLen = outputBuffer.capacity(); outputSrc.process(inputFrames, &inLen, outputBuffer.endData(), &outLen); diff --git a/src/core/MidiInterface.cpp b/src/core/MidiInterface.cpp index 9b17ace2..e3b945c3 100644 --- a/src/core/MidiInterface.cpp +++ b/src/core/MidiInterface.cpp @@ -303,7 +303,7 @@ void MIDIToCVInterface::step() { } if (resetLight > 0) { - resetLight -= resetLight / 0.55 / gSampleRate; // fade out light + resetLight -= resetLight / 0.55 / engineGetSampleRate(); // fade out light } diff --git a/src/engine.cpp b/src/engine.cpp index df7f77d0..4ce7ec17 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -14,7 +14,7 @@ namespace rack { -float gSampleRate; +float sampleRate; bool gPaused = false; @@ -60,7 +60,7 @@ static void engineStep() { smoothModule = NULL; } else { - value += delta * lambda / gSampleRate; + value += delta * lambda / sampleRate; smoothModule->params[smoothParamId].value = value; } } @@ -97,7 +97,7 @@ static void engineRun() { } } - float stepTime = mutexSteps / gSampleRate; + float stepTime = mutexSteps / sampleRate; ahead += stepTime; auto currTime = std::chrono::high_resolution_clock::now(); const float aheadFactor = 2.0; @@ -221,12 +221,16 @@ void engineSetParamSmooth(Module *module, int paramId, float value) { void engineSetSampleRate(float newSampleRate) { VIPLock vipLock(vipMutex); std::lock_guard lock(mutex); - gSampleRate = newSampleRate; + sampleRate = newSampleRate; // onSampleRateChange for (Module *module : modules) { module->onSampleRateChange(); } } +float engineGetSampleRate() { + return sampleRate; +} + } // namespace rack diff --git a/src/settings.cpp b/src/settings.cpp index 86e622b8..8f449489 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -32,8 +32,7 @@ static json_t *settingsToJson() { json_object_set_new(rootJ, "allowCursorLock", allowCursorLockJ); // sampleRate - float sampleRate = gSampleRate; - json_t *sampleRateJ = json_real(sampleRate); + json_t *sampleRateJ = json_real(engineGetSampleRate()); json_object_set_new(rootJ, "sampleRate", sampleRateJ); // plugLight