Skip to content

Commit 792fbf8

Browse files
authored
Added dry wet to distortion (#34)
1 parent ee7d954 commit 792fbf8

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Sources/CSoundpipeAudioKit/Effects/TanhDistortionDSP.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
TanhDistortionParameterPostgain,
1010
TanhDistortionParameterPositiveShapeParameter,
1111
TanhDistortionParameterNegativeShapeParameter,
12+
TanhDistortionParameterDryWetMix,
1213
};
1314

1415
class TanhDistortionDSP : public SoundpipeDSPBase {
@@ -19,13 +20,15 @@
1920
ParameterRamper postgainRamp;
2021
ParameterRamper positiveShapeParameterRamp;
2122
ParameterRamper negativeShapeParameterRamp;
23+
ParameterRamper dryWetMixRamp;
2224

2325
public:
2426
TanhDistortionDSP() {
2527
parameters[TanhDistortionParameterPregain] = &pregainRamp;
2628
parameters[TanhDistortionParameterPostgain] = &postgainRamp;
2729
parameters[TanhDistortionParameterPositiveShapeParameter] = &positiveShapeParameterRamp;
2830
parameters[TanhDistortionParameterNegativeShapeParameter] = &negativeShapeParameterRamp;
31+
parameters[TanhDistortionParameterDryWetMix] = &dryWetMixRamp;
2932
}
3033

3134
void init(int channelCount, double sampleRate) override {
@@ -65,6 +68,10 @@ void process(FrameRange range) override {
6568

6669
sp_dist_compute(sp, dist0, &leftIn, &leftOut);
6770
sp_dist_compute(sp, dist1, &rightIn, &rightOut);
71+
72+
float dryWetMix = dryWetMixRamp.getAndStep();
73+
outputSample(0, i) = dryWetMix * leftOut + (1.0f - dryWetMix) * leftIn;
74+
outputSample(1, i) = dryWetMix * rightOut + (1.0f - dryWetMix) * rightIn;
6875
}
6976
}
7077
};
@@ -74,3 +81,4 @@ void process(FrameRange range) override {
7481
AK_REGISTER_PARAMETER(TanhDistortionParameterPostgain)
7582
AK_REGISTER_PARAMETER(TanhDistortionParameterPositiveShapeParameter)
7683
AK_REGISTER_PARAMETER(TanhDistortionParameterNegativeShapeParameter)
84+
AK_REGISTER_PARAMETER(TanhDistortionParameterDryWetMix)

Sources/SoundpipeAudioKit/Effects/TanhDistortion.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,38 @@ public class TanhDistortion: Node {
7070
/// Like the positive shape parameter, only for the negative part.
7171
@Parameter(negativeShapeParameterDef) public var negativeShapeParameter: AUValue
7272

73+
/// Specification details for dryWetMix
74+
public static let dryWetMixDef = NodeParameterDef(
75+
identifier: "dryWetMix",
76+
name: "Dry/Wet Mix",
77+
address: akGetParameterAddress("TanhDistortionParameterDryWetMix"),
78+
defaultValue: 1.0,
79+
range: 0.0 ... 1.0,
80+
unit: .percent
81+
)
82+
83+
/// Dry/Wet Mix
84+
@Parameter(dryWetMixDef) public var dryWetMix: AUValue
85+
7386
// MARK: - Initialization
7487

7588
/// Initialize this distortion node
7689
///
7790
/// - Parameters:
7891
/// - input: Input node to process
7992
/// - pregain: Determines gain applied to the signal before waveshaping. A value of 1 gives slight distortion.
80-
/// - postgain: Gain applied after waveshaping
93+
/// - postgain: Gain applied after waveshaping (applied only to processed signal)
8194
/// - positiveShapeParameter: Shape of the positive part of the signal. A value of 0 gets a flat clip.
8295
/// - negativeShapeParameter: Like the positive shape parameter, only for the negative part.
96+
/// - dryWetMix: Dry/Wet Mix
8397
///
8498
public init(
8599
_ input: Node,
86100
pregain: AUValue = pregainDef.defaultValue,
87101
postgain: AUValue = postgainDef.defaultValue,
88102
positiveShapeParameter: AUValue = positiveShapeParameterDef.defaultValue,
89-
negativeShapeParameter: AUValue = negativeShapeParameterDef.defaultValue
103+
negativeShapeParameter: AUValue = negativeShapeParameterDef.defaultValue,
104+
dryWetMix: AUValue = dryWetMixDef.defaultValue
90105
) {
91106
self.input = input
92107

@@ -96,5 +111,6 @@ public class TanhDistortion: Node {
96111
self.postgain = postgain
97112
self.positiveShapeParameter = positiveShapeParameter
98113
self.negativeShapeParameter = negativeShapeParameter
114+
self.dryWetMix = dryWetMix
99115
}
100116
}

0 commit comments

Comments
 (0)