Skip to content
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

Added dry wet to distortion #34

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions Sources/CSoundpipeAudioKit/Effects/TanhDistortionDSP.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
TanhDistortionParameterPostgain,
TanhDistortionParameterPositiveShapeParameter,
TanhDistortionParameterNegativeShapeParameter,
TanhDistortionParameterDryWetMix,
};

class TanhDistortionDSP : public SoundpipeDSPBase {
Expand All @@ -19,13 +20,15 @@
ParameterRamper postgainRamp;
ParameterRamper positiveShapeParameterRamp;
ParameterRamper negativeShapeParameterRamp;
ParameterRamper dryWetMixRamp;

public:
TanhDistortionDSP() {
parameters[TanhDistortionParameterPregain] = &pregainRamp;
parameters[TanhDistortionParameterPostgain] = &postgainRamp;
parameters[TanhDistortionParameterPositiveShapeParameter] = &positiveShapeParameterRamp;
parameters[TanhDistortionParameterNegativeShapeParameter] = &negativeShapeParameterRamp;
parameters[TanhDistortionParameterDryWetMix] = &dryWetMixRamp;
}

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

sp_dist_compute(sp, dist0, &leftIn, &leftOut);
sp_dist_compute(sp, dist1, &rightIn, &rightOut);

float dryWetMix = dryWetMixRamp.getAndStep();
outputSample(0, i) = dryWetMix * leftOut + (1.0f - dryWetMix) * leftIn;
outputSample(1, i) = dryWetMix * rightOut + (1.0f - dryWetMix) * rightIn;
}
}
};
Expand All @@ -74,3 +81,4 @@ void process(FrameRange range) override {
AK_REGISTER_PARAMETER(TanhDistortionParameterPostgain)
AK_REGISTER_PARAMETER(TanhDistortionParameterPositiveShapeParameter)
AK_REGISTER_PARAMETER(TanhDistortionParameterNegativeShapeParameter)
AK_REGISTER_PARAMETER(TanhDistortionParameterDryWetMix)
20 changes: 18 additions & 2 deletions Sources/SoundpipeAudioKit/Effects/TanhDistortion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,38 @@ public class TanhDistortion: Node {
/// Like the positive shape parameter, only for the negative part.
@Parameter(negativeShapeParameterDef) public var negativeShapeParameter: AUValue

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

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

// MARK: - Initialization

/// Initialize this distortion node
///
/// - Parameters:
/// - input: Input node to process
/// - pregain: Determines gain applied to the signal before waveshaping. A value of 1 gives slight distortion.
/// - postgain: Gain applied after waveshaping
/// - postgain: Gain applied after waveshaping (applied only to processed signal)
/// - positiveShapeParameter: Shape of the positive part of the signal. A value of 0 gets a flat clip.
/// - negativeShapeParameter: Like the positive shape parameter, only for the negative part.
/// - dryWetMix: Dry/Wet Mix
///
public init(
_ input: Node,
pregain: AUValue = pregainDef.defaultValue,
postgain: AUValue = postgainDef.defaultValue,
positiveShapeParameter: AUValue = positiveShapeParameterDef.defaultValue,
negativeShapeParameter: AUValue = negativeShapeParameterDef.defaultValue
negativeShapeParameter: AUValue = negativeShapeParameterDef.defaultValue,
dryWetMix: AUValue = dryWetMixDef.defaultValue
) {
self.input = input

Expand All @@ -96,5 +111,6 @@ public class TanhDistortion: Node {
self.postgain = postgain
self.positiveShapeParameter = positiveShapeParameter
self.negativeShapeParameter = negativeShapeParameter
self.dryWetMix = dryWetMix
}
}
Loading