@@ -82,8 +82,8 @@ void engineRemoveWire(Wire *wire); | |||||
void engineSetParam(Module *module, int paramId, float value); | void engineSetParam(Module *module, int paramId, float value); | ||||
void engineSetParamSmooth(Module *module, int paramId, float value); | void engineSetParamSmooth(Module *module, int paramId, float value); | ||||
void engineSetSampleRate(float sampleRate); | void engineSetSampleRate(float sampleRate); | ||||
float engineGetSampleRate(); | |||||
extern float gSampleRate; | |||||
extern bool gPaused; | extern bool gPaused; | ||||
@@ -90,7 +90,7 @@ struct SampleRateChoice : ChoiceButton { | |||||
if (gPaused) | if (gPaused) | ||||
text = "Paused"; | text = "Paused"; | ||||
else | else | ||||
text = stringf("%.0f Hz", gSampleRate); | |||||
text = stringf("%.0f Hz", engineGetSampleRate()); | |||||
} | } | ||||
}; | }; | ||||
@@ -155,7 +155,7 @@ void AudioInterface::step() { | |||||
// Once full, sample rate convert the input | // Once full, sample rate convert the input | ||||
// inputBuffer -> SRC -> inputSrcBuffer | // inputBuffer -> SRC -> inputSrcBuffer | ||||
if (inputBuffer.full()) { | if (inputBuffer.full()) { | ||||
inputSrc.setRatio(sampleRate / gSampleRate); | |||||
inputSrc.setRatio(sampleRate / engineGetSampleRate()); | |||||
int inLen = inputBuffer.size(); | int inLen = inputBuffer.size(); | ||||
int outLen = inputSrcBuffer.capacity(); | int outLen = inputSrcBuffer.capacity(); | ||||
inputSrc.process(inputBuffer.startData(), &inLen, inputSrcBuffer.endData(), &outLen); | 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 | // Pass output through sample rate converter | ||||
outputSrc.setRatio(gSampleRate / sampleRate); | |||||
outputSrc.setRatio(engineGetSampleRate() / sampleRate); | |||||
int inLen = numFrames; | int inLen = numFrames; | ||||
int outLen = outputBuffer.capacity(); | int outLen = outputBuffer.capacity(); | ||||
outputSrc.process(inputFrames, &inLen, outputBuffer.endData(), &outLen); | outputSrc.process(inputFrames, &inLen, outputBuffer.endData(), &outLen); | ||||
@@ -303,7 +303,7 @@ void MIDIToCVInterface::step() { | |||||
} | } | ||||
if (resetLight > 0) { | if (resetLight > 0) { | ||||
resetLight -= resetLight / 0.55 / gSampleRate; // fade out light | |||||
resetLight -= resetLight / 0.55 / engineGetSampleRate(); // fade out light | |||||
} | } | ||||
@@ -14,7 +14,7 @@ | |||||
namespace rack { | namespace rack { | ||||
float gSampleRate; | |||||
float sampleRate; | |||||
bool gPaused = false; | bool gPaused = false; | ||||
@@ -60,7 +60,7 @@ static void engineStep() { | |||||
smoothModule = NULL; | smoothModule = NULL; | ||||
} | } | ||||
else { | else { | ||||
value += delta * lambda / gSampleRate; | |||||
value += delta * lambda / sampleRate; | |||||
smoothModule->params[smoothParamId].value = value; | smoothModule->params[smoothParamId].value = value; | ||||
} | } | ||||
} | } | ||||
@@ -97,7 +97,7 @@ static void engineRun() { | |||||
} | } | ||||
} | } | ||||
float stepTime = mutexSteps / gSampleRate; | |||||
float stepTime = mutexSteps / sampleRate; | |||||
ahead += stepTime; | ahead += stepTime; | ||||
auto currTime = std::chrono::high_resolution_clock::now(); | auto currTime = std::chrono::high_resolution_clock::now(); | ||||
const float aheadFactor = 2.0; | const float aheadFactor = 2.0; | ||||
@@ -221,12 +221,16 @@ void engineSetParamSmooth(Module *module, int paramId, float value) { | |||||
void engineSetSampleRate(float newSampleRate) { | void engineSetSampleRate(float newSampleRate) { | ||||
VIPLock vipLock(vipMutex); | VIPLock vipLock(vipMutex); | ||||
std::lock_guard<std::mutex> lock(mutex); | std::lock_guard<std::mutex> lock(mutex); | ||||
gSampleRate = newSampleRate; | |||||
sampleRate = newSampleRate; | |||||
// onSampleRateChange | // onSampleRateChange | ||||
for (Module *module : modules) { | for (Module *module : modules) { | ||||
module->onSampleRateChange(); | module->onSampleRateChange(); | ||||
} | } | ||||
} | } | ||||
float engineGetSampleRate() { | |||||
return sampleRate; | |||||
} | |||||
} // namespace rack | } // namespace rack |
@@ -32,8 +32,7 @@ static json_t *settingsToJson() { | |||||
json_object_set_new(rootJ, "allowCursorLock", allowCursorLockJ); | json_object_set_new(rootJ, "allowCursorLock", allowCursorLockJ); | ||||
// sampleRate | // sampleRate | ||||
float sampleRate = gSampleRate; | |||||
json_t *sampleRateJ = json_real(sampleRate); | |||||
json_t *sampleRateJ = json_real(engineGetSampleRate()); | |||||
json_object_set_new(rootJ, "sampleRate", sampleRateJ); | json_object_set_new(rootJ, "sampleRate", sampleRateJ); | ||||
// plugLight | // plugLight | ||||