Skip to content

Commit

Permalink
added mixer control
Browse files Browse the repository at this point in the history
  • Loading branch information
rominator committed Oct 9, 2022
1 parent aac1397 commit 9817cb0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.o
*.so
*.log
.lock*
.vscode
build
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
===
Expand Down
16 changes: 11 additions & 5 deletions rectifyingOctave.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

typedef enum
{
GAIN = 0,
MIX = 0,
INPUT = 1,
OUTPUT = 2
} PortIndex;

typedef struct
{
// Port buffers
const float *gain;
const float *mix;
const float *input;
float *output;

Expand All @@ -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;
Expand All @@ -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);
}
}

Expand Down
10 changes: 5 additions & 5 deletions rectifyingOctave.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down

0 comments on commit 9817cb0

Please sign in to comment.