Skip to content

Commit 2a3a593

Browse files
authored
Added dry wet mix parameter for BitCrusher, Phaser, PitchShifter, and VariableDelay (#35)
* Added dry wet mix parameter to some more effects Adds dry wet mix control for BitCrusher, Phaser, PitchShifter, and Delay * Housekeeping
1 parent ffa6f90 commit 2a3a593

File tree

8 files changed

+100
-4
lines changed

8 files changed

+100
-4
lines changed

Sources/CSoundpipeAudioKit/Effects/BitCrusherDSP.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
enum BitCrusherParameter : AUParameterAddress {
88
BitCrusherParameterBitDepth,
99
BitCrusherParameterSampleRate,
10+
BitCrusherParameterDryWetMix
1011
};
1112

1213
class BitCrusherDSP : public SoundpipeDSPBase {
@@ -15,11 +16,13 @@
1516
sp_bitcrush *bitcrush1;
1617
ParameterRamper bitDepthRamp;
1718
ParameterRamper sampleRateRamp;
19+
ParameterRamper dryWetMixRamp;
1820

1921
public:
2022
BitCrusherDSP() {
2123
parameters[BitCrusherParameterBitDepth] = &bitDepthRamp;
2224
parameters[BitCrusherParameterSampleRate] = &sampleRateRamp;
25+
parameters[BitCrusherParameterDryWetMix] = &dryWetMixRamp;
2326
}
2427

2528
void init(int channelCount, double sampleRate) override {
@@ -57,10 +60,15 @@ void process(FrameRange range) override {
5760

5861
sp_bitcrush_compute(sp, bitcrush0, &leftIn, &leftOut);
5962
sp_bitcrush_compute(sp, bitcrush1, &rightIn, &rightOut);
63+
64+
float dryWetMix = dryWetMixRamp.getAndStep();
65+
outputSample(0, i) = dryWetMix * leftOut + (1.0f - dryWetMix) * leftIn;
66+
outputSample(1, i) = dryWetMix * rightOut + (1.0f - dryWetMix) * rightIn;
6067
}
6168
}
6269
};
6370

6471
AK_REGISTER_DSP(BitCrusherDSP, "btcr")
6572
AK_REGISTER_PARAMETER(BitCrusherParameterBitDepth)
6673
AK_REGISTER_PARAMETER(BitCrusherParameterSampleRate)
74+
AK_REGISTER_PARAMETER(BitCrusherParameterDryWetMix)

Sources/CSoundpipeAudioKit/Effects/PhaserDSP.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
PhaserParameterFeedback,
1515
PhaserParameterInverted,
1616
PhaserParameterLfoBPM,
17+
PhaserParameterDryWetMix
1718
};
1819

1920
class PhaserDSP : public SoundpipeDSPBase {
@@ -28,6 +29,7 @@
2829
ParameterRamper feedbackRamp;
2930
ParameterRamper invertedRamp;
3031
ParameterRamper lfoBPMRamp;
32+
ParameterRamper dryWetMixRamp;
3133

3234
public:
3335
PhaserDSP() {
@@ -40,6 +42,7 @@
4042
parameters[PhaserParameterFeedback] = &feedbackRamp;
4143
parameters[PhaserParameterInverted] = &invertedRamp;
4244
parameters[PhaserParameterLfoBPM] = &lfoBPMRamp;
45+
parameters[PhaserParameterDryWetMix] = &dryWetMixRamp;
4346
}
4447

4548
void init(int channelCount, double sampleRate) override {
@@ -79,6 +82,10 @@ void process(FrameRange range) override {
7982
float &rightOut = outputSample(1, i);
8083

8184
sp_phaser_compute(sp, phaser, &leftIn, &rightIn, &leftOut, &rightOut);
85+
86+
float dryWetMix = dryWetMixRamp.getAndStep();
87+
outputSample(0, i) = dryWetMix * leftOut + (1.0f - dryWetMix) * leftIn;
88+
outputSample(1, i) = dryWetMix * rightOut + (1.0f - dryWetMix) * rightIn;
8289
}
8390
}
8491
};
@@ -93,3 +100,4 @@ void process(FrameRange range) override {
93100
AK_REGISTER_PARAMETER(PhaserParameterFeedback)
94101
AK_REGISTER_PARAMETER(PhaserParameterInverted)
95102
AK_REGISTER_PARAMETER(PhaserParameterLfoBPM)
103+
AK_REGISTER_PARAMETER(PhaserParameterDryWetMix)

Sources/CSoundpipeAudioKit/Effects/PitchShifterDSP.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
PitchShifterParameterShift,
99
PitchShifterParameterWindowSize,
1010
PitchShifterParameterCrossfade,
11+
PitchShifterParameterDryWetMix
1112
};
1213

1314
class PitchShifterDSP : public SoundpipeDSPBase {
@@ -17,12 +18,14 @@
1718
ParameterRamper shiftRamp;
1819
ParameterRamper windowSizeRamp;
1920
ParameterRamper crossfadeRamp;
21+
ParameterRamper dryWetMixRamp;
2022

2123
public:
2224
PitchShifterDSP() {
2325
parameters[PitchShifterParameterShift] = &shiftRamp;
2426
parameters[PitchShifterParameterWindowSize] = &windowSizeRamp;
2527
parameters[PitchShifterParameterCrossfade] = &crossfadeRamp;
28+
parameters[PitchShifterParameterDryWetMix] = &dryWetMixRamp;
2629
}
2730

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

6669
sp_pshift_compute(sp, pshift0, &leftIn, &leftOut);
6770
sp_pshift_compute(sp, pshift1, &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
};
@@ -73,3 +80,4 @@ void process(FrameRange range) override {
7380
AK_REGISTER_PARAMETER(PitchShifterParameterShift)
7481
AK_REGISTER_PARAMETER(PitchShifterParameterWindowSize)
7582
AK_REGISTER_PARAMETER(PitchShifterParameterCrossfade)
83+
AK_REGISTER_PARAMETER(PitchShifterParameterDryWetMix)

Sources/CSoundpipeAudioKit/Effects/VariableDelayDSP.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
enum VariableDelayParameter : AUParameterAddress {
99
VariableDelayParameterTime,
1010
VariableDelayParameterFeedback,
11+
VariableDelayParameterDryWetMix
1112
};
1213

1314
class VariableDelayDSP : public SoundpipeDSPBase {
@@ -17,11 +18,13 @@
1718
float maximumTime = 10.0;
1819
ParameterRamper timeRamp;
1920
ParameterRamper feedbackRamp;
21+
ParameterRamper dryWetMixRamp;
2022

2123
public:
2224
VariableDelayDSP() : SoundpipeDSPBase(1, false) {
2325
parameters[VariableDelayParameterTime] = &timeRamp;
2426
parameters[VariableDelayParameterFeedback] = &feedbackRamp;
27+
parameters[VariableDelayParameterDryWetMix] = &dryWetMixRamp;
2528
}
2629

2730
void setMaximumTime(float maxTime) {
@@ -68,6 +71,10 @@ void process(FrameRange range) override {
6871

6972
sp_vdelay_compute(sp, vdelay0, &leftIn, &leftOut);
7073
sp_vdelay_compute(sp, vdelay1, &rightIn, &rightOut);
74+
75+
float dryWetMix = dryWetMixRamp.getAndStep();
76+
outputSample(0, i) = dryWetMix * leftOut + (1.0f - dryWetMix) * leftIn;
77+
outputSample(1, i) = dryWetMix * rightOut + (1.0f - dryWetMix) * rightIn;
7178
}
7279
}
7380
};
@@ -81,3 +88,4 @@ void akVariableDelaySetMaximumTime(DSPRef dspRef, float maximumTime) {
8188
AK_REGISTER_DSP(VariableDelayDSP, "vdla")
8289
AK_REGISTER_PARAMETER(VariableDelayParameterTime)
8390
AK_REGISTER_PARAMETER(VariableDelayParameterFeedback)
91+
AK_REGISTER_PARAMETER(VariableDelayParameterDryWetMix)

Sources/SoundpipeAudioKit/Effects/BitCrusher.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ public class BitCrusher: Node {
4444
/// The sample rate of signal output.
4545
@Parameter(sampleRateDef) public var sampleRate: AUValue
4646

47+
/// Specification details for dryWetMix
48+
public static let dryWetMixDef = NodeParameterDef(
49+
identifier: "dryWetMix",
50+
name: "Dry/Wet Mix",
51+
address: akGetParameterAddress("BitCrusherParameterDryWetMix"),
52+
defaultValue: 1.0,
53+
range: 0.0 ... 1.0,
54+
unit: .percent
55+
)
56+
57+
/// Dry/Wet Mix
58+
@Parameter(dryWetMixDef) public var dryWetMix: AUValue
59+
4760
// MARK: - Initialization
4861

4962
/// Initialize this bitcrusher node
@@ -52,17 +65,20 @@ public class BitCrusher: Node {
5265
/// - input: Input node to process
5366
/// - bitDepth: The bit depth of signal output. Typically in range (1-24). Non-integer values are OK.
5467
/// - sampleRate: The sample rate of signal output.
68+
/// - dryWetMix: Dry/Wet Mix
5569
///
5670
public init(
5771
_ input: Node,
5872
bitDepth: AUValue = bitDepthDef.defaultValue,
59-
sampleRate: AUValue = sampleRateDef.defaultValue
73+
sampleRate: AUValue = sampleRateDef.defaultValue,
74+
dryWetMix: AUValue = dryWetMixDef.defaultValue
6075
) {
6176
self.input = input
6277

6378
setupParameters()
6479

6580
self.bitDepth = bitDepth
6681
self.sampleRate = sampleRate
82+
self.dryWetMix = dryWetMix
6783
}
6884
}

Sources/SoundpipeAudioKit/Effects/Phaser.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ public class Phaser: Node {
135135
/// Between 24 and 360
136136
@Parameter(lfoBPMDef) public var lfoBPM: AUValue
137137

138+
/// Specification details for dryWetMix
139+
public static let dryWetMixDef = NodeParameterDef(
140+
identifier: "dryWetMix",
141+
name: "Dry/Wet Mix",
142+
address: akGetParameterAddress("PhaserParameterDryWetMix"),
143+
defaultValue: 1.0,
144+
range: 0.0 ... 1.0,
145+
unit: .percent
146+
)
147+
148+
/// Dry/Wet Mix
149+
@Parameter(dryWetMixDef) public var dryWetMix: AUValue
150+
138151
// MARK: - Initialization
139152

140153
/// Initialize this phaser node
@@ -150,6 +163,7 @@ public class Phaser: Node {
150163
/// - feedback: Between 0 and 1
151164
/// - inverted: 1 or 0
152165
/// - lfoBPM: Between 24 and 360
166+
/// - dryWetMix: Dry/Wet Mix
153167
///
154168
public init(
155169
_ input: Node,
@@ -161,7 +175,8 @@ public class Phaser: Node {
161175
depth: AUValue = depthDef.defaultValue,
162176
feedback: AUValue = feedbackDef.defaultValue,
163177
inverted: AUValue = invertedDef.defaultValue,
164-
lfoBPM: AUValue = lfoBPMDef.defaultValue
178+
lfoBPM: AUValue = lfoBPMDef.defaultValue,
179+
dryWetMix: AUValue = dryWetMixDef.defaultValue
165180
) {
166181
self.input = input
167182

@@ -176,5 +191,6 @@ public class Phaser: Node {
176191
self.feedback = feedback
177192
self.inverted = inverted
178193
self.lfoBPM = lfoBPM
194+
self.dryWetMix = dryWetMix
179195
}
180196
}

Sources/SoundpipeAudioKit/Effects/PitchShifter.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ public class PitchShifter: Node {
5757
/// Crossfade (in samples)
5858
@Parameter(crossfadeDef) public var crossfade: AUValue
5959

60+
/// Specification details for dryWetMix
61+
public static let dryWetMixDef = NodeParameterDef(
62+
identifier: "dryWetMix",
63+
name: "Dry/Wet Mix",
64+
address: akGetParameterAddress("PitchShifterParameterDryWetMix"),
65+
defaultValue: 1.0,
66+
range: 0.0 ... 1.0,
67+
unit: .percent
68+
)
69+
70+
/// Dry/Wet Mix
71+
@Parameter(dryWetMixDef) public var dryWetMix: AUValue
72+
6073
// MARK: - Initialization
6174

6275
/// Initialize this pitchshifter node
@@ -66,12 +79,14 @@ public class PitchShifter: Node {
6679
/// - shift: Pitch shift (in semitones)
6780
/// - windowSize: Window size (in samples)
6881
/// - crossfade: Crossfade (in samples)
82+
/// - dryWetMix: Dry/Wet Mix
6983
///
7084
public init(
7185
_ input: Node,
7286
shift: AUValue = shiftDef.defaultValue,
7387
windowSize: AUValue = windowSizeDef.defaultValue,
74-
crossfade: AUValue = crossfadeDef.defaultValue
88+
crossfade: AUValue = crossfadeDef.defaultValue,
89+
dryWetMix: AUValue = dryWetMixDef.defaultValue
7590
) {
7691
self.input = input
7792

@@ -80,5 +95,6 @@ public class PitchShifter: Node {
8095
self.shift = shift
8196
self.windowSize = windowSize
8297
self.crossfade = crossfade
98+
self.dryWetMix = dryWetMix
8399
}
84100
}

Sources/SoundpipeAudioKit/Effects/VariableDelay.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ public class VariableDelay: Node {
4444
/// Feedback amount. Should be a value between 0-1.
4545
@Parameter(feedbackDef) public var feedback: AUValue
4646

47+
/// Specification details for dryWetMix
48+
public static let dryWetMixDef = NodeParameterDef(
49+
identifier: "dryWetMix",
50+
name: "Dry/Wet Mix",
51+
address: akGetParameterAddress("VariableDelayParameterDryWetMix"),
52+
defaultValue: 1.0,
53+
range: 0.0 ... 1.0,
54+
unit: .percent
55+
)
56+
57+
/// Dry/Wet Mix
58+
@Parameter(dryWetMixDef) public var dryWetMix: AUValue
59+
4760
// MARK: - Initialization
4861

4962
/// Initialize this delay node
@@ -53,12 +66,14 @@ public class VariableDelay: Node {
5366
/// - time: Delay time (in seconds) This value must not exceed the maximum delay time.
5467
/// - feedback: Feedback amount. Should be a value between 0-1.
5568
/// - maximumTime: The maximum delay time, in seconds.
69+
/// - dryWetMix: Dry/Wet Mix
5670
///
5771
public init(
5872
_ input: Node,
5973
time: AUValue = timeDef.defaultValue,
6074
feedback: AUValue = feedbackDef.defaultValue,
61-
maximumTime: AUValue = 5
75+
maximumTime: AUValue = 5,
76+
dryWetMix: AUValue = dryWetMixDef.defaultValue
6277
) {
6378
self.input = input
6479

@@ -68,5 +83,6 @@ public class VariableDelay: Node {
6883

6984
self.time = time
7085
self.feedback = feedback
86+
self.dryWetMix = dryWetMix
7187
}
7288
}

0 commit comments

Comments
 (0)