Skip to content

Commit

Permalink
lichen-community-systemsgh-63: Adds stage mixing as per Valimaki and …
Browse files Browse the repository at this point in the history
…Huovilainen.
  • Loading branch information
colinbdclark committed May 26, 2023
1 parent 9bc7201 commit 85187b8
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ struct sig_dsp_Branch* rightFrequencyCVSkewed;
struct sig_dsp_LinearToFreq* rightFrequency;
struct sig_daisy_AudioIn* leftIn;
struct sig_daisy_AudioIn* rightIn;
struct sig_dsp_LadderLPF* leftFilter;
struct sig_dsp_LadderLPF* rightFilter;
struct sig_dsp_Ladder* leftFilter;
struct sig_dsp_Ladder* rightFilter;
struct sig_daisy_AudioOut* leftOut;
struct sig_daisy_AudioOut* rightOut;

void UpdateOled() {
bluemchen.display.Fill(false);

displayStr.Clear();
displayStr.Append(" ~bob~ ");
displayStr.Append(" Bifocals");
bluemchen.display.SetCursor(0, 0);
bluemchen.display.WriteString(displayStr.Cstr(), Font_6x8, true);

Expand Down Expand Up @@ -82,14 +82,16 @@ void buildSignalGraph(struct sig_SignalContext* context,
frequencyKnob = sig_daisy_FilteredCVIn_new(&allocator, context, host);
sig_List_append(&signals, frequencyKnob, status);
frequencyKnob->parameters.control = sig_daisy_Bluemchen_CV_IN_KNOB_1;
frequencyKnob->parameters.scale = 9.5f; // 7.25f for Bob
frequencyKnob->parameters.offset = -4.5f; // -4.0f for Bob
frequencyKnob->parameters.scale = 10.0f;
frequencyKnob->parameters.offset = -5.0f;
frequencyKnob->parameters.time = 0.1f;

vOctCVIn = sig_daisy_FilteredCVIn_new(&allocator, context, host);
sig_List_append(&signals, vOctCVIn, status);
vOctCVIn->parameters.control = sig_daisy_Bluemchen_CV_IN_CV1;
vOctCVIn->parameters.scale = 2.5f;
vOctCVIn->parameters.offset = -1.25f;
vOctCVIn->parameters.scale = 4.0f;
vOctCVIn->parameters.offset = -2.0f;
vOctCVIn->parameters.time = 0.1f;

frequencyKnobPlusVOct = sig_dsp_Add_new(&allocator, context);
sig_List_append(&signals, frequencyKnobPlusVOct, status);
Expand All @@ -101,6 +103,7 @@ void buildSignalGraph(struct sig_SignalContext* context,
frequencySkewCV->parameters.control = sig_daisy_Bluemchen_CV_IN_CV2;
frequencySkewCV->parameters.scale = 5.0f;
frequencySkewCV->parameters.offset = -2.5f;
frequencySkewCV->parameters.time = 0.1f;

rectifiedSkew = sig_dsp_Abs_new(&allocator, context);
sig_List_append(&signals, rectifiedSkew, status);
Expand Down Expand Up @@ -134,13 +137,13 @@ void buildSignalGraph(struct sig_SignalContext* context,
resonanceKnob = sig_daisy_FilteredCVIn_new(&allocator, context, host);
sig_List_append(&signals, resonanceKnob, status);
resonanceKnob->parameters.control = sig_daisy_Bluemchen_CV_IN_KNOB_2;
resonanceKnob->parameters.scale = 1.7f; // 4.0f for Bob
resonanceKnob->parameters.scale = 1.8f; // 4.0f for Bob

leftIn = sig_daisy_AudioIn_new(&allocator, context, host);
sig_List_append(&signals, leftIn, status);
leftIn->parameters.channel = 0;

leftFilter = sig_dsp_LadderLPF_new(&allocator, context);
leftFilter = sig_dsp_Ladder_new(&allocator, context);
sig_List_append(&signals, leftFilter, status);
leftFilter->parameters.overdrive = 1.1f;
leftFilter->parameters.passbandGain = 0.5f;
Expand All @@ -157,7 +160,7 @@ void buildSignalGraph(struct sig_SignalContext* context,
sig_List_append(&signals, rightIn, status);
rightIn->parameters.channel = 1;

rightFilter = sig_dsp_LadderLPF_new(&allocator, context);
rightFilter = sig_dsp_Ladder_new(&allocator, context);
sig_List_append(&signals, rightFilter, status);
rightFilter->parameters.overdrive = 1.1f;
leftFilter->parameters.passbandGain = 0.5f;
Expand All @@ -177,7 +180,7 @@ int main(void) {
struct sig_AudioSettings audioSettings = {
.sampleRate = 96000,
.numChannels = 2,
.blockSize = 8
.blockSize = 16
};

struct sig_Status status;
Expand Down
60 changes: 34 additions & 26 deletions libsignaletic/include/libsignaletic.h
Original file line number Diff line number Diff line change
Expand Up @@ -1627,23 +1627,32 @@ void sig_dsp_TwoOpFM_destroy(struct sig_Allocator* allocator,
struct sig_dsp_TwoOpFM* self);


struct sig_dsp_Filter_Inputs {
struct sig_dsp_FourPoleFilter_Inputs {
float_array_ptr source;
float_array_ptr frequency;
float_array_ptr resonance;
float_array_ptr stage1Mix;
float_array_ptr stage2Mix;
float_array_ptr stage3Mix;
float_array_ptr stage4Mix;
};


struct sig_dsp_FourPoleFilter_Outputs {
/**
* @brief The four pole 24 dB output from the filter.
* @brief A mix of all filter stages based on the stage mix inputs.
*/
float_array_ptr main;

/**
* @brief A two pole 12 dB output from the second stage of the filter.
* @brief The full two pole 12 dB output of the filter.
*/
float_array_ptr twoPole;

/**
* @brief The full four pole 24 dB output from the filter.
*/
float_array_ptr fourPole;
};

void sig_dsp_FourPoleFilter_Outputs_newAudioBlocks(
Expand Down Expand Up @@ -1682,9 +1691,9 @@ void sig_dsp_FourPoleFilter_Outputs_destroyAudioBlocks(
* - frequency: the cutoff frequency in Hz
* - resonance: the resonance; values > 4 lead to instability
*/
struct sig_dsp_BobLPF {
struct sig_dsp_Bob {
struct sig_dsp_Signal signal;
struct sig_dsp_Filter_Inputs inputs;
struct sig_dsp_FourPoleFilter_Inputs inputs;
// TODO: Add outputs for the other filter poles.
struct sig_dsp_FourPoleFilter_Outputs outputs;

Expand All @@ -1701,19 +1710,19 @@ struct sig_dsp_BobLPF {
float stepSize;
};

struct sig_dsp_BobLPF* sig_dsp_BobLPF_new(
struct sig_dsp_Bob* sig_dsp_Bob_new(
struct sig_Allocator* allocator, struct sig_SignalContext* context);
void sig_dsp_BobLPF_init(struct sig_dsp_BobLPF* self,
void sig_dsp_Bob_init(struct sig_dsp_Bob* self,
struct sig_SignalContext* context);
float sig_dsp_BobLPF_clip(float value, float saturation,
float sig_dsp_Bob_clip(float value, float saturation,
float saturationInv);
void sig_dsp_BobLPF_generate(void* signal);
void sig_dsp_BobLPF_destroy(struct sig_Allocator* allocator,
struct sig_dsp_BobLPF* self);
void sig_dsp_Bob_generate(void* signal);
void sig_dsp_Bob_destroy(struct sig_Allocator* allocator,
struct sig_dsp_Bob* self);



struct sig_dsp_LadderLPF_Parameters {
struct sig_dsp_Ladder_Parameters {
/**
* @brief The passband gain of the filter (best between 0.0-0.5),
* higher values will amplify the lower frequencies when resonance is high.
Expand All @@ -1738,11 +1747,10 @@ struct sig_dsp_LadderLPF_Parameters {
* - frequency: the cutoff frequency in Hz
* - resonance: the resonance (stable values in the range 0 - 1.8)
*/
struct sig_dsp_LadderLPF {
struct sig_dsp_Ladder {
struct sig_dsp_Signal signal;
struct sig_dsp_Filter_Inputs inputs;
struct sig_dsp_LadderLPF_Parameters parameters;
// TODO: Add outputs for the other filter poles.
struct sig_dsp_FourPoleFilter_Inputs inputs;
struct sig_dsp_Ladder_Parameters parameters;
struct sig_dsp_FourPoleFilter_Outputs outputs;

uint8_t interpolation;
Expand All @@ -1758,18 +1766,18 @@ struct sig_dsp_LadderLPF {
float prevInput;
};

struct sig_dsp_LadderLPF* sig_dsp_LadderLPF_new(
struct sig_dsp_Ladder* sig_dsp_Ladder_new(
struct sig_Allocator* allocator, struct sig_SignalContext* context);
void sig_dsp_LadderLPF_init(
struct sig_dsp_LadderLPF* self,
void sig_dsp_Ladder_init(
struct sig_dsp_Ladder* self,
struct sig_SignalContext* context);
void sig_dsp_LadderLPF_calcCoefficients(
struct sig_dsp_LadderLPF* self, float freq);
float sig_dsp_LadderLPF_calcStage(
struct sig_dsp_LadderLPF* self, float s, uint8_t i);
void sig_dsp_LadderLPF_generate(void* signal);
void sig_dsp_LadderLPF_destroy(struct sig_Allocator* allocator,
struct sig_dsp_LadderLPF* self);
void sig_dsp_Ladder_calcCoefficients(
struct sig_dsp_Ladder* self, float freq);
float sig_dsp_Ladder_calcStage(
struct sig_dsp_Ladder* self, float s, uint8_t i);
void sig_dsp_Ladder_generate(void* signal);
void sig_dsp_Ladder_destroy(struct sig_Allocator* allocator,
struct sig_dsp_Ladder* self);



Expand Down
Loading

0 comments on commit 85187b8

Please sign in to comment.