Logarithmic Parameter for Filter Cutoff on Patch.Init()

Hi All, I’m using the Patch.Init() via DaisyDuino. I can get the MoogLadder Filter example running smoothly, but I want to use a knob on the patch.Init to control the filter cutoff. I’m trying to use a Parameter to map the knob to a logarithmic scale but, as soon as I do this, it starts generating an additional layer of noise that is louder than the desired audio signal. Not sure what I’m doing wrong here. Any help is much appreciated.

#include "DaisyDuino.h"

DaisyHardware patch;

size_t num_channels;

static MoogLadder flt;
static Oscillator osc;
static Parameter cutoff;
float freq;

void MyCallback(float **in, float **out, size_t size) {
  patch.ProcessAllControls();

  //Get mapped cutoff value from CV_2 knob
  freq = cutoff.Process();
  
  float saw, output;
  for (size_t i = 0; i < size; i++) {
    saw = osc.Process();

    flt.SetFreq(freq);
    output = flt.Process(saw);

    for (size_t chn = 0; chn < num_channels; chn++) {
      out[chn][i] = output;
    }
  }
}

void setup() {
  float sample_rate;
  // Initialize for Daisy pod at 48kHz
  patch = DAISY.init(DAISY_PATCH_SM, AUDIO_SR_48K);
  num_channels = 2;
  sample_rate = DAISY.get_samplerate();

  // initialize Moogladder object
  flt.Init(sample_rate);
  flt.SetRes(0.7);

  // Map CV_2 knob values from 20Hz to 20KHz with logarithmic scale
  cutoff.Init(patch.controls[1], 20.0f, 20000.0f, cutoff.LOGARITHMIC);

  // set parameters for sine oscillator object
  osc.Init(sample_rate);
  osc.SetWaveform(Oscillator::WAVE_POLYBLEP_SAW);
  osc.SetFreq(100);
  osc.SetAmp(0.25);

  DAISY.begin(MyCallback);
}

void loop() {}

Try setting the cutoff frequency just after you get the value from the knob, not inside the loop with the oscillator and filter. I.E. set the cutoff once per block, not once per sample.

Cheers

Thanks for the quick reply Jaradical! I tried setting the filter cutoff right after grabbing the value from the knob and I get the same result. I can hear it working in the background but there is garbled noise that changes as I turn the knob. Sounds kind of interesting actually, but not the desired effect. :slight_smile:

I’m just thinking out loud here, but maybe you need a LPF on the value read from the pot, and/or you need to greatly reduce the rate at which you call flt.SetFreq(). Maybe only call flt.SetFreq if the value changes more than some amount?

I don’t have any hardware to test these ideas.

EDIT: the first thing I’d do is try the DaisyDuino/examples/pod/SynthVoice, with whatever minor mods are required to run on patch.init. Note the ConditiionalParameter() function, which filters out small changes in the knob’s value.

Thanks for the tips @tele_player! I added in the function but I had to change the knob delta to 0.01 for it to make a difference. It lessened the level of the undesired noise, but it’s still there. What’s strange is in the moogladder example, the filter frequency is obtained from processing an LFO and setting the frequency, all within the final audio loop and it sounds perfect:

void MyCallback(float **in, float **out, size_t size) {
  float saw, freq, output;
  for (size_t i = 0; i < size; i++) {
    freq = 5000 + (lfo.Process() * 5000);
    saw = osc.Process();

    flt.SetFreq(freq);
    output = flt.Process(saw);

    for (size_t chn = 0; chn < num_channels; chn++) {
      out[chn][i] = output;
    }
  }
}

But using a knob value instead of the LFO creates a bunch of noise.

I’ve been trying to convince myself to order a patch.init… maybe this puzzle challenge will convince me.

Do it! I need more patch.init() friends! :smiley:

This is the first application I’ve attempted, so I can’t say it’s been a flawless experience, but it’s still been fun and convenient. It’s also missing calibrated v/oct and MIDI input, so applications are limited. But you could always pull the patch_sm off of it and make your own hardware for it!

Actually, the Versio and Legio from Noise Engineering run on daisy. Better hardware in my opinion, and you can install all the different module options from NE.