Skip to content

Commit

Permalink
Added makeup gain and dry wet mix
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt54 committed Jul 26, 2024
1 parent ee7d954 commit 6d57583
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Sources/CSoundpipeAudioKit/Effects/DynamicRangeCompressorDSP.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
DynamicRangeCompressorParameterThreshold,
DynamicRangeCompressorParameterAttackDuration,
DynamicRangeCompressorParameterReleaseDuration,
DynamicRangeCompressorParameterGain,
DynamicRangeCompressorParameterDryWetMix,
};

class DynamicRangeCompressorDSP : public SoundpipeDSPBase {
Expand All @@ -19,13 +21,17 @@
ParameterRamper thresholdRamp;
ParameterRamper attackDurationRamp;
ParameterRamper releaseDurationRamp;
ParameterRamper gainRamp;
ParameterRamper dryWetMixRamp;

public:
DynamicRangeCompressorDSP() {
parameters[DynamicRangeCompressorParameterRatio] = &ratioRamp;
parameters[DynamicRangeCompressorParameterThreshold] = &thresholdRamp;
parameters[DynamicRangeCompressorParameterAttackDuration] = &attackDurationRamp;
parameters[DynamicRangeCompressorParameterReleaseDuration] = &releaseDurationRamp;
parameters[DynamicRangeCompressorParameterGain] = &gainRamp;
parameters[DynamicRangeCompressorParameterDryWetMix] = &dryWetMixRamp;
}

void init(int channelCount, double sampleRate) override {
Expand Down Expand Up @@ -64,6 +70,14 @@ void process(FrameRange range) override {

sp_compressor_compute(sp, compressor0, &leftIn, &leftOut);
sp_compressor_compute(sp, compressor1, &rightIn, &rightOut);

float gain = gainRamp.getAndStep();
leftOut *= gain;
rightOut *= gain;

float dryWetMix = dryWetMixRamp.getAndStep();
outputSample(0, i) = dryWetMix * leftOut + (1.0f - dryWetMix) * leftIn;
outputSample(1, i) = dryWetMix * rightOut + (1.0f - dryWetMix) * rightIn;
}
}
};
Expand All @@ -73,3 +87,5 @@ void process(FrameRange range) override {
AK_REGISTER_PARAMETER(DynamicRangeCompressorParameterThreshold)
AK_REGISTER_PARAMETER(DynamicRangeCompressorParameterAttackDuration)
AK_REGISTER_PARAMETER(DynamicRangeCompressorParameterReleaseDuration)
AK_REGISTER_PARAMETER(DynamicRangeCompressorParameterGain)
AK_REGISTER_PARAMETER(DynamicRangeCompressorParameterDryWetMix)
34 changes: 33 additions & 1 deletion Sources/SoundpipeAudioKit/Effects/DynamicRangeCompressor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ public class DynamicRangeCompressor: Node {

/// Release Duration
@Parameter(releaseDurationDef) public var releaseDuration: AUValue

/// Specification details for gain
public static let gainDef = NodeParameterDef(
identifier: "gain",
name: "Makeup Gain",
address: akGetParameterAddress("DynamicRangeCompressorParameterGain"),
defaultValue: 1.0,
range: 0.0 ... 8.0,
unit: .linearGain
)

/// Makeup gain applied only to processed signal
@Parameter(gainDef) public var gain: AUValue

/// Specification details for dryWetMix
public static let dryWetMixDef = NodeParameterDef(
identifier: "dryWetMix",
name: "Dry/Wet Mix",
address: akGetParameterAddress("DynamicRangeCompressorParameterDryWetMix"),
defaultValue: 1.0,
range: 0.0 ... 1.0,
unit: .percent
)

/// Dry/Wet Mix
@Parameter(dryWetMixDef) public var dryWetMix: AUValue

// MARK: - Initialization

Expand All @@ -80,13 +106,17 @@ public class DynamicRangeCompressor: Node {
/// - threshold: Threshold (in dB) 0 = max
/// - attackDuration: Attack duration
/// - releaseDuration: Release Duration
/// - gain: Makeup gain (applied only to processing)
/// - dryWetMix: Dry/Wet Mix
///
public init(
_ input: Node,
ratio: AUValue = ratioDef.defaultValue,
threshold: AUValue = thresholdDef.defaultValue,
attackDuration: AUValue = attackDurationDef.defaultValue,
releaseDuration: AUValue = releaseDurationDef.defaultValue
releaseDuration: AUValue = releaseDurationDef.defaultValue,
gain: AUValue = gainDef.defaultValue,
dryWetMix: AUValue = dryWetMixDef.defaultValue
) {
self.input = input

Expand All @@ -96,5 +126,7 @@ public class DynamicRangeCompressor: Node {
self.threshold = threshold
self.attackDuration = attackDuration
self.releaseDuration = releaseDuration
self.gain = gain
self.dryWetMix = dryWetMix
}
}

0 comments on commit 6d57583

Please sign in to comment.