Skip to content

Commit 6d57583

Browse files
committed
Added makeup gain and dry wet mix
1 parent ee7d954 commit 6d57583

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

Sources/CSoundpipeAudioKit/Effects/DynamicRangeCompressorDSP.mm

+16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
DynamicRangeCompressorParameterThreshold,
1010
DynamicRangeCompressorParameterAttackDuration,
1111
DynamicRangeCompressorParameterReleaseDuration,
12+
DynamicRangeCompressorParameterGain,
13+
DynamicRangeCompressorParameterDryWetMix,
1214
};
1315

1416
class DynamicRangeCompressorDSP : public SoundpipeDSPBase {
@@ -19,13 +21,17 @@
1921
ParameterRamper thresholdRamp;
2022
ParameterRamper attackDurationRamp;
2123
ParameterRamper releaseDurationRamp;
24+
ParameterRamper gainRamp;
25+
ParameterRamper dryWetMixRamp;
2226

2327
public:
2428
DynamicRangeCompressorDSP() {
2529
parameters[DynamicRangeCompressorParameterRatio] = &ratioRamp;
2630
parameters[DynamicRangeCompressorParameterThreshold] = &thresholdRamp;
2731
parameters[DynamicRangeCompressorParameterAttackDuration] = &attackDurationRamp;
2832
parameters[DynamicRangeCompressorParameterReleaseDuration] = &releaseDurationRamp;
33+
parameters[DynamicRangeCompressorParameterGain] = &gainRamp;
34+
parameters[DynamicRangeCompressorParameterDryWetMix] = &dryWetMixRamp;
2935
}
3036

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

6571
sp_compressor_compute(sp, compressor0, &leftIn, &leftOut);
6672
sp_compressor_compute(sp, compressor1, &rightIn, &rightOut);
73+
74+
float gain = gainRamp.getAndStep();
75+
leftOut *= gain;
76+
rightOut *= gain;
77+
78+
float dryWetMix = dryWetMixRamp.getAndStep();
79+
outputSample(0, i) = dryWetMix * leftOut + (1.0f - dryWetMix) * leftIn;
80+
outputSample(1, i) = dryWetMix * rightOut + (1.0f - dryWetMix) * rightIn;
6781
}
6882
}
6983
};
@@ -73,3 +87,5 @@ void process(FrameRange range) override {
7387
AK_REGISTER_PARAMETER(DynamicRangeCompressorParameterThreshold)
7488
AK_REGISTER_PARAMETER(DynamicRangeCompressorParameterAttackDuration)
7589
AK_REGISTER_PARAMETER(DynamicRangeCompressorParameterReleaseDuration)
90+
AK_REGISTER_PARAMETER(DynamicRangeCompressorParameterGain)
91+
AK_REGISTER_PARAMETER(DynamicRangeCompressorParameterDryWetMix)

Sources/SoundpipeAudioKit/Effects/DynamicRangeCompressor.swift

+33-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,32 @@ public class DynamicRangeCompressor: Node {
6969

7070
/// Release Duration
7171
@Parameter(releaseDurationDef) public var releaseDuration: AUValue
72+
73+
/// Specification details for gain
74+
public static let gainDef = NodeParameterDef(
75+
identifier: "gain",
76+
name: "Makeup Gain",
77+
address: akGetParameterAddress("DynamicRangeCompressorParameterGain"),
78+
defaultValue: 1.0,
79+
range: 0.0 ... 8.0,
80+
unit: .linearGain
81+
)
82+
83+
/// Makeup gain applied only to processed signal
84+
@Parameter(gainDef) public var gain: AUValue
85+
86+
/// Specification details for dryWetMix
87+
public static let dryWetMixDef = NodeParameterDef(
88+
identifier: "dryWetMix",
89+
name: "Dry/Wet Mix",
90+
address: akGetParameterAddress("DynamicRangeCompressorParameterDryWetMix"),
91+
defaultValue: 1.0,
92+
range: 0.0 ... 1.0,
93+
unit: .percent
94+
)
95+
96+
/// Dry/Wet Mix
97+
@Parameter(dryWetMixDef) public var dryWetMix: AUValue
7298

7399
// MARK: - Initialization
74100

@@ -80,13 +106,17 @@ public class DynamicRangeCompressor: Node {
80106
/// - threshold: Threshold (in dB) 0 = max
81107
/// - attackDuration: Attack duration
82108
/// - releaseDuration: Release Duration
109+
/// - gain: Makeup gain (applied only to processing)
110+
/// - dryWetMix: Dry/Wet Mix
83111
///
84112
public init(
85113
_ input: Node,
86114
ratio: AUValue = ratioDef.defaultValue,
87115
threshold: AUValue = thresholdDef.defaultValue,
88116
attackDuration: AUValue = attackDurationDef.defaultValue,
89-
releaseDuration: AUValue = releaseDurationDef.defaultValue
117+
releaseDuration: AUValue = releaseDurationDef.defaultValue,
118+
gain: AUValue = gainDef.defaultValue,
119+
dryWetMix: AUValue = dryWetMixDef.defaultValue
90120
) {
91121
self.input = input
92122

@@ -96,5 +126,7 @@ public class DynamicRangeCompressor: Node {
96126
self.threshold = threshold
97127
self.attackDuration = attackDuration
98128
self.releaseDuration = releaseDuration
129+
self.gain = gain
130+
self.dryWetMix = dryWetMix
99131
}
100132
}

0 commit comments

Comments
 (0)