Browse Source

Remove gSampleRate, add engineGetSampleRate()

tags/v0.5.0
Andrew Belt 7 years ago
parent
commit
9dbadfbdc5
6 changed files with 14 additions and 11 deletions
  1. +1
    -1
      include/engine.hpp
  2. +1
    -1
      src/app/Toolbar.cpp
  3. +2
    -2
      src/core/AudioInterface.cpp
  4. +1
    -1
      src/core/MidiInterface.cpp
  5. +8
    -4
      src/engine.cpp
  6. +1
    -2
      src/settings.cpp

+ 1
- 1
include/engine.hpp View File

@@ -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;




+ 1
- 1
src/app/Toolbar.cpp View File

@@ -90,7 +90,7 @@ struct SampleRateChoice : ChoiceButton {
if (gPaused)
text = "Paused";
else
text = stringf("%.0f Hz", gSampleRate);
text = stringf("%.0f Hz", engineGetSampleRate());
}
};



+ 2
- 2
src/core/AudioInterface.cpp View File

@@ -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);


+ 1
- 1
src/core/MidiInterface.cpp View File

@@ -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
}




+ 8
- 4
src/engine.cpp View File

@@ -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<std::mutex> lock(mutex);
gSampleRate = newSampleRate;
sampleRate = newSampleRate;
// onSampleRateChange
for (Module *module : modules) {
module->onSampleRateChange();
}
}

float engineGetSampleRate() {
return sampleRate;
}


} // namespace rack

+ 1
- 2
src/settings.cpp View File

@@ -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


Loading…
Cancel
Save