Set range of potentiometers

Hi everyone,

Back again with some trouble!
I’m trying to build a tremolo pedal based on the tremolo effect from DaisySP controling rate and depth with two potentiometers. I got to do it thanks to this post but I don’t seem to have the frequency parameter between the desired range which is from 0.1 Hz to 20 Hz

This is my tremolo.cpp:

#include “tremolo.h”
#include <math.h>
using namespace daisysp;
void Tremolo::Init(float sample_rate)
{
sample_rate_ = sample_rate;
osc_.Init(sample_rate_);
SetDepth(1.f);
SetFreq(1.f);
}
float Tremolo::Process(float in)
{
float modsig = dc_os_ + osc_.Process();
return in * modsig;
}
void Tremolo::SetFreq(float freq)
{
// THIS IS WHERE I TRY TO SET THE FREQ RANGE
freq = fclamp(freq, 0.1f, 20.f);
freq *= .5f;
osc_.SetFreq(freq);
}
void Tremolo::SetWaveform(int waveform)
{
osc_.SetWaveform(waveform);
}
void Tremolo::SetDepth(float depth)
{
depth = fclamp(depth, 0.f, 1.f);
depth *= .5f;
osc_.SetAmp(depth);
dc_os_ = 1.f - depth;
}

As you can see I basically tried to clamp the values as it’s done with the depth parameter by default but I never get as “fast” as 20Hz.

Any suggestions for make this work properly please?

I’m also thinking about using the parameter class to manage the knobs well and the logger class to read the knob values on screen, but haven’t got that far yet.

Thanks in advance for any help!

Alex

From looking at the above, it’s not clear what you’re sending to the setters’ arguments. So I may be stating a few things you already know:

The fclamp function doesn’t do any scaling, it only ensures that the input does not go below or above the thresholds set by the min/max arguments. So in the above, you would have to be sending the frequency you desire to the setter, not a normalized 0-1 value (like the output of the AnalogControl::Process would return).

I also see that you’re scaling the frequency (and depth) by half, after clamping them. This means that with your current setter, the osc_ member’s freq parameter will never be greater than 10Hz. (This may be the maximum you’re seeing right now depending on what you’re passing in).

The parameter class would be useful here if you want to map the value of a single AnalogControl to a new range, its a quick way to try different response curves as well. You may find that the higher frequency stuff takes up a lot of the knob once this works, and you can shift everything over by using the exponential curve.

Hope that helps! :slight_smile:

2 Likes

Without looking at all your code, I also guess that you are sending a value from 0.0 to 1.0f into Tremolo::SetFreq().

I would (probably) write it more like this (w/o doing any error checking):

void Tremolo::SetFreq(float freq)
{
// assume freq parameter is from 0.0 to 1.0
osc_.SetFreq(freq * 20.0f);
}

Does this work for you?

And if not, if you really are sending a frequency, and you want to map it, use a map function that scales your value:

float map(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

(adapted from map() - Arduino Reference)

so your method would look like:

void Tremolo::SetFreq(float freq)
{
// assume freq parameter is from 0.0 to 1.0
osc_.SetFreq(map(freq, 0.0f, 48000.0f, 0.0f, 20.0f));
}

The 48000.0f number is depending on your implementation.

2 Likes

It was taking the parameter from 0.0 to 1.0 for sure cause the osc_.SetFreq(freq * 20.0f) saved the day. Doing this I have the range I want and I can play with it to set it up in a different range now.

Thanks for helping me out so much guys you’re the best! :hugs: :hugs:

3 Likes

Awesome @RatherBeAlex, happy to help!

Don’t forget to share your project in the forum when it is finished! :slight_smile:

2 Likes