Skip to content

Commit

Permalink
tweak master comp behaviour and parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
m-m-adams committed Nov 7, 2023
1 parent 5a9c21d commit 785d669
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 30 deletions.
7 changes: 6 additions & 1 deletion src/deluge/dsp/compressor/compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ int32_t Compressor::render(uint16_t numSamples, int32_t shapeValue) {
pos += numSamples * getActualReleaseRate();

if (pos >= 8388608) {
status = EnvelopeStage::OFF;
if (!follower) {
status = EnvelopeStage::OFF;
}
else {
status = EnvelopeStage::HOLD;
}
goto doOff;
}

Expand Down
32 changes: 16 additions & 16 deletions src/deluge/dsp/master_compressor/master_compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
#include "util/fast_fixed_math.h"
MasterCompressor::MasterCompressor() {
//compressor.setAttack((float)attack / 100.0);
attack = attackRateTable[2] << 2;
release = releaseRateTable[5] << 2;
attack = attackRateTable[5];
release = releaseRateTable[15];
//compressor.setRelease((float)release / 100.0);
//compressor.setThresh((float)threshold / 100.0);
//compressor.setRatio(1.0 / ((float)ratio / 100.0));
shape = getParamFromUserValue(Param::Unpatched::COMPRESSOR_SHAPE, 1);
shape = getParamFromUserValue(Param::Unpatched::COMPRESSOR_SHAPE, 0);
//an appropriate range is 0-50*one q 15
threshold = ONE_Q31;
rawThreshold = 0;
Expand All @@ -54,7 +54,7 @@ void MasterCompressor::updateER() {
134217728, cableToLinearParamShortcut(currentSong->paramManager.getUnpatchedParamSet()->getValue(
Param::Unpatched::GlobalEffectable::VOLUME)))
>> 1;
songVolume = std::log(volumePostFX);
songVolume = std::log(volumePostFX) - 2;
}
else {
songVolume = 16;
Expand All @@ -66,18 +66,18 @@ void MasterCompressor::updateER() {

void MasterCompressor::render(StereoSample* buffer, uint16_t numSamples, q31_t volAdjustL, q31_t volAdjustR) {
ratio = (rawRatio >> 1) + (3 << 28);
threshold = ONE_Q31 - rawThreshold;
threshold = ONE_Q31 - (rawThreshold >> 2);
updateER();

q31_t over = std::max<float>(0, (meanVolume - threshdb) / 21) * ONE_Q31;
q31_t clip = std::max<float>(0, (meanVolume - 18) / 21) * ONE_Q31;
q31_t over = std::max<float>(0, (meanVolume - threshdb) / 21.0) * ONE_Q31;

//add some extra reduction if we're into clipping

if (over > 0) {
registerHit(over);
}
out = Compressor::render(numSamples, shape);
out = (multiply_32x32_rshift32(out, ratio) << 1) - (multiply_32x32_rshift32(clip, ONE_Q31 - ratio));
out = (multiply_32x32_rshift32(out, ratio) << 1);
//out = multiply_32x32_rshift32(out, ratio) << 1;

//21 is the max internal volume (i.e. one_q31)
Expand Down Expand Up @@ -112,7 +112,7 @@ void MasterCompressor::render(StereoSample* buffer, uint16_t numSamples, q31_t v
} while (++thisSample != bufferEnd);
//for LEDs
//9 converts to dB, quadrupled for display range since a 30db reduction is basically killing the signal
gainReduction = std::clamp<int32_t>(-(reduction)*9 * 4, 0, 127);
gainReduction = std::clamp<int32_t>(-(reduction) * 9 * 4, 0, 127);
//calc compression for next round (feedback compressor)
meanVolume = calc_rms(buffer, numSamples);
}
Expand All @@ -126,20 +126,20 @@ float MasterCompressor::calc_rms(StereoSample* buffer, uint16_t numSamples) {
q31_t offset = 0; //to remove dc offset
float lastMean = mean;
do {
q31_t s = std::abs(thisSample->l) + std::abs(thisSample->r);
q31_t s = std::max(std::abs(thisSample->l), std::abs(thisSample->r));
sum += multiply_32x32_rshift32(s, s) << 1;
offset += thisSample->l;

} while (++thisSample != bufferEnd);

float ns = float(numSamples);
float rms = ONE_Q31 * sqrt((float(sum) / ONE_Q31f) / ns);
float dc = std::abs(offset) / ns;
//warning this is not good math but it's pretty close and way cheaper than doing it properly
mean = rms - dc / 1.4f;
mean = std::max(mean, 1.0f);
// float dc = 0;

// //warning this is not good math but it's pretty close and way cheaper than doing it properly
// mean = rms - dc / 1.4f;
mean = (rms + lastMean) / 2;

float logmean = std::log((mean + lastMean) / 2);
float logmean = std::log(std::max(mean, 1.0f));

return logmean;
}
Expand Down
8 changes: 4 additions & 4 deletions src/deluge/model/global_effectable/global_effectable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@ int32_t GlobalEffectable::getKnobPosForNonExistentParam(int32_t whichModEncoder,
break;

case CompParam::ATTACK:
current = getLookupIndexFromValue(AudioEngine::mastercompressor.attack >> 2, attackRateTable, 50);
current = getLookupIndexFromValue(AudioEngine::mastercompressor.attack, attackRateTable, 50);
displayLevel = (current * 128) / 50;
break;

case CompParam::RELEASE:
current = getLookupIndexFromValue(AudioEngine::mastercompressor.release >> 1, releaseRateTable, 50);
current = getLookupIndexFromValue(AudioEngine::mastercompressor.release, releaseRateTable, 50);
displayLevel = (current * 128) / 50;
break;
}
Expand Down Expand Up @@ -358,13 +358,13 @@ ActionResult GlobalEffectable::modEncoderActionForNonExistentParam(int32_t offse
break;

case CompParam::ATTACK:
current = getLookupIndexFromValue(AudioEngine::mastercompressor.attack >> 2, attackRateTable, 50);
current = getLookupIndexFromValue(AudioEngine::mastercompressor.attack, attackRateTable, 50);
current += offset;
current = std::clamp(current, 1, 50);
displayLevel = current;
ledLevel = (displayLevel * 128) / 50;

AudioEngine::mastercompressor.attack = attackRateTable[current] << 2;
AudioEngine::mastercompressor.attack = attackRateTable[current];
break;

case CompParam::RELEASE:
Expand Down
10 changes: 5 additions & 5 deletions src/deluge/model/song/song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ Song::Song() : backedUpParamManagers(sizeof(BackedUpParamManager)) {
reverbCompressorShape = -601295438;
reverbCompressorSync = SYNC_LEVEL_8TH;

masterCompressorAttack = attackRateTable[2] << 2;
masterCompressorRelease = releaseRateTable[5] << 2;
masterCompressorAttack = attackRateTable[5];
masterCompressorRelease = releaseRateTable[15];
masterCompressorThresh = 0;
masterCompressorRatio = ONE_Q31 >> 1;
masterCompressorRatio = 0;
AudioEngine::mastercompressor.gainReduction = 0.0;

dirPath.set("SONGS");
Expand Down Expand Up @@ -2670,7 +2670,7 @@ int32_t Song::getCurrentPresetScale() {
// If we're here, must be this one!
return p;

notThisOne : {}
notThisOne: {}
}

return 255;
Expand Down Expand Up @@ -4559,7 +4559,7 @@ Instrument* Song::changeInstrumentType(Instrument* oldInstrument, InstrumentType
return NULL;
}

gotAnInstrument : {}
gotAnInstrument: {}
}

// Synth or Kit
Expand Down
8 changes: 4 additions & 4 deletions src/deluge/processing/engines/audio_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ void routine() {
smoothedSamples = numSamples;

if (numSamplesLastTime < numSamples) {
Debug::print("rendered ");
Debug::print(numSamplesLastTime);
Debug::print(" samples but output ");
Debug::println(numSamples);
logAction("rendered ");
logAction(numSamplesLastTime);
logAction(" samples but output ");
logAction(numSamples);
}

// Consider direness and culling - before increasing the number of samples
Expand Down

0 comments on commit 785d669

Please sign in to comment.