diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57e5d17 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.o +*.so +*.log +.lock* +.vscode +build \ No newline at end of file diff --git a/README.md b/README.md index f43fc9d..0573d97 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,12 @@ Rectifying Octave === -This [lv2 plugin](https://en.wikipedia.org/wiki/LV2) does a pure octave by inverting all negative values of the input. This is basically what an electronic rectifyer (not the famous rectifyer ampplifiers) does. +This [lv2 plugin](https://en.wikipedia.org/wiki/LV2) does a pure octave by inverting all negative values of the input. This is basically what an electronic rectifier (not the famous rectifier ampplifiers) does. It is similiar to what fuzz octave pedals try to do but accomplishes this in an idealized manner without simulating electronic components and of course without the fuzz. -A potentially problematic DC offset is then removed by subtracting a rolling moving average of 2000 samples. -A gain of 1.5 partially restores the amplitude of the input after the rectification. -After a silence a suden loud attack can thus lead to some audible clipping which could only be avoided by sacrifying amplitude. - -Note: When adding the octaved signal to the original signal the upper part of a "wave" of an input will overshoot whereas the lower part will get cancelled out partly. This leaves not a lot of headroom for the signal in a song mix since clipping might occur pretty soon. This cannot be avoided using the taken approach. - -A built in "mix" control for mixing the original signal to the output could avoid this by removing the DC offset after the mix. -If this is a problem for your scenario I might implement that for you. +A potentially problematic DC offset is removed by subtracting a rolling moving average of 2000 samples. +NOTE: The output of the pure octaved signal is a little quieter than the input. This has to be ammended by a compressor with a gain of up to 2.0. Sudden loud attacks will reach maximum output until the rolling average takes care of the DC part of the output again. So using only an amplifier would clip the output. Install === diff --git a/rectifyingOctave.c b/rectifyingOctave.c index eec4aa2..ececc26 100644 --- a/rectifyingOctave.c +++ b/rectifyingOctave.c @@ -9,7 +9,7 @@ typedef enum { - GAIN = 0, + MIX = 0, INPUT = 1, OUTPUT = 2 } PortIndex; @@ -17,7 +17,7 @@ typedef enum typedef struct { // Port buffers - const float *gain; + const float *mix; const float *input; float *output; @@ -41,8 +41,8 @@ static void connect_port(LV2_Handle instance, uint32_t port, void *data) switch ((PortIndex)port) { - case GAIN: - distortion->gain = (const float *)data; + case MIX: + distortion->mix = (const float *)data; break; case INPUT: distortion->input = (const float *)data; @@ -67,16 +67,22 @@ static void run(LV2_Handle instance, uint32_t n_samples) float sample; float tempValue; + float mix = *distortion->mix; for (uint32_t pos = 0; pos < n_samples; pos++) { sample = input[pos]; + //NOTE: Octaving by rectifying tempValue = fabs(sample); + + //NOTE: mixing with original value. This should not clip. + tempValue = tempValue * mix + sample * (1.0 - mix); + //NOTE: applying rolling average on octaved/mixed value distortion->rollingAverage -= distortion->rollingAverage / 2000.0; distortion->rollingAverage += (double)tempValue / (double) 2000.0; - output[pos] = (tempValue - distortion->rollingAverage) * 1.5; + output[pos] = (tempValue - distortion->rollingAverage); } } diff --git a/rectifyingOctave.ttl b/rectifyingOctave.ttl index 3173660..6f450e2 100644 --- a/rectifyingOctave.ttl +++ b/rectifyingOctave.ttl @@ -16,11 +16,11 @@ a lv2:InputPort , lv2:ControlPort ; lv2:index 0 ; - lv2:symbol "gain" ; - lv2:name "Gain" ; - lv2:default 1.5 ; - lv2:minimum 0.02 ; - lv2:maximum 50.0 ; + lv2:symbol "mix" ; + lv2:name "Mix" ; + lv2:default 0.5 ; + lv2:minimum 0.0 ; + lv2:maximum 1.0 ; ] , [ a lv2:AudioPort , lv2:InputPort ;