Skip to content

Added makeup gain and dry wet mix to DynamicRangeCompressor #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Sources/CSoundpipeAudioKit/Effects/DynamicRangeCompressorDSP.mm
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
DynamicRangeCompressorParameterThreshold,
DynamicRangeCompressorParameterAttackDuration,
DynamicRangeCompressorParameterReleaseDuration,
DynamicRangeCompressorParameterGain,
DynamicRangeCompressorParameterDryWetMix,
};

class DynamicRangeCompressorDSP : public SoundpipeDSPBase {
@@ -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 {
@@ -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;
}
}
};
@@ -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
@@ -70,6 +70,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

/// Initialize this compressor node
@@ -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

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