EXAMPLE Chorus Example

untamedfrontier

Well-known member
Here's the petal chorus example ported over.
There are definitely some issues with it. Things that are obviously wrong are related to the encoder. I didn't have any success applying advice from the knobs as encoder thread, because I've been unable to debug the pot_rotary not being declared in this scope error, so you'll see this code just has me seeing if I could figure out how to set dry/wet using a knob (I could not).

I commented out the LED stuff related to the encoder in the main, but I probably also did something wrong there. However, that being said, this will build and actually sounds pretty decent having not tweaked anything yet. I can share a bin if anyone has issues.

Code:
// porting chorus example - v1.0
#include "daisy_petal.h"
#include "daisysp.h"
#include "terrarium.h"

using namespace daisy;
using namespace daisysp;
using namespace terrarium;

DaisyPetal hw;
Chorus  ch; //defaults to 2 delay lines

bool  effectOn;
float wet;
Led led1, led2;

float deltarget, del;
float lfotarget, lfo;

void Controls()
{
    hw.ProcessAllControls();

    //knobs
    float k = hw.knob[Terrarium::KNOB_1].Process();
    ch.SetLfoFreq(k * k * 20.f);
    lfo = hw.knob[Terrarium::KNOB_2].Process();
    del = hw.knob[Terrarium::KNOB_3].Process();
    ch.SetFeedback(hw.knob[Terrarium::KNOB_4].Process());

    //footswitch
    // effectOn ^= hw.switches[0].RisingEdge();
    if (hw.switches[Terrarium::FOOTSWITCH_1].RisingEdge())
    {
        effectOn = !effectOn;
        led1.Set(effectOn ? 0.0f : 1.0f);
    }

    //encoder
    // wet += hw.encoder.Increment() * .05f;
    wet += hw.knob[Terrarium::KNOB_6].Process();
    wet = fclamp(wet, 0.f, 1.f);

    wet = hw.encoder.RisingEdge() ? .9f : wet;
}

void InitLeds(void)
{
    led1.Init(hw.seed.GetPin(Terrarium::LED_1),true);
    led2.Init(hw.seed.GetPin(Terrarium::LED_2),false);
}

void AudioCallback(float **in, float **out, size_t size)
{
    Controls();
    led1.Update();
    led2.Update();

    for(size_t i = 0; i < size; i++)
    {
        fonepole(del, deltarget, .0001f); //smooth at audio rate
        ch.SetDelay(del);

        fonepole(lfo, lfotarget, .0001f); //smooth at audio rate
        ch.SetLfoDepth(lfo);


        out[0][i] = in[0][i];
        out[1][i] = in[1][i];

        if(effectOn)
        {
            ch.Process(in[0][i]);

            out[0][i] = ch.GetLeft() * wet + in[0][i] * (1.f - wet);
            out[1][i] = ch.GetRight() * wet + in[1][i] * (1.f - wet);
        }
    }
}

int main(void)
{
    hw.Init();
    float sample_rate = hw.AudioSampleRate();

    InitLeds();

    ch.Init(sample_rate);

    effectOn  = true;
    wet       = .9f;
    deltarget = del = 0.f;
    lfotarget = lfo = 0.f;

    hw.StartAdc();
    hw.StartAudio(AudioCallback);
    while(1)
    {
        hw.DelayMs(6);

        /* hw.ClearLeds();
        hw.SetFootswitchLed((DaisyPetal::FootswitchLed)0, (float)effectOn);

        int   wet_int  = (int)(wet * 8.f);
        float wet_frac = wet - wet_int;
        for(int i = 0; i < wet_int; i++)
        {
            hw.SetRingLed((DaisyPetal::RingLed)i, 1.f, 0.f, 0.f);
        }

        if(wet_int < 8)
        {
            hw.SetRingLed((DaisyPetal::RingLed)wet_int, wet_frac, 0.f, 0.f);
        }
        */
        hw.UpdateLeds();
    }
}
 
Would definitely like a bin. I'm a n00b at coding and I've yet to finish setting all up on my computer, between work, kids, building and shoveling!
 
In the Pd space i have had some success getting knobs to take, but not always. If i can find out reasons then that may help in general.
 
Back
Top