0
mirror of https://github.com/torvalds/GuitarPedal.git synced 2026-06-07 04:55:36 +00:00
Files
Linus Torvalds c88f369fd3 Fix up lots more default pot settings
Bah.  It wasn't just the echo that had gotten messed up in the
conversion to the new and more legible pot metadata.

The *new* metadata defaults are pretty clear and obvious, but the old
ones were not, and I clearly should have been a whole lot more careful
in converting them, because half the effects had various messed up
default values.  Lots of "zero meant pot at noon - so float value 0.5"
turned into just plain "zero means zero".

So I do think the new model is a lot better, but "Mistakes were made".

I tried to go through every effect and double-check it against what it
used to be.  Not that all the old defaults were sane (I'm looking at
you, boost effect), but the metadata conversion wasn't meant to change
them.

Fixes: 9c208692f7 ("Convert effects to metadata-driven boiler plate generation")
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-06-01 08:34:11 -07:00

67 lines
1.9 KiB
C

// NAME: Pitch [PITCH]
// PRIORITY: 100
// POT: "Octave" LINEAR(-2.0 2.0) = 1.0
// POT: "Feedback" LINEAR(0.0 1.0) = 0.5
// POT: "Mix" LINEAR(0.0 1.0) = 0.5
//
// Entirely random pitch shifting effect walking the
// sample buffer at varying speeds, and hiding the
// discontinuities in the sequence by picking two
// different delays, and multiplying them with sin/cos
//
// sin/cos are zero at the respective discontinuities,
// and the signal power is proportional to the square
// of the voltage. With sin^2 * cos^2 = 1, the result
// should be a unity signal power gain.
//
#define DISCONT_SHIFT 12
#define DISCONT_STEPS (1 << DISCONT_SHIFT)
struct {
float step, feedback, mix;
unsigned phase, idx;
float array[4*DISCONT_STEPS];
} pitch;
static void pitch_init(unsigned char pot[10])
{
// Which direction do we walk the samples?
// Walking backwards lowers the pitch
// Walking forwards raises the pitch
// Staying at the same delay keeps the pitch the same
//
float step = pow2(pitch_pot0(pot[0])); // 0.25 .. 4
pitch.step = step - 1; // -0.75 .. 3
pitch.feedback = pitch_pot1(pot[1]);
pitch.mix = pitch_pot2(pot[2]);
}
// i is discontinuous when sin**2 is 0
// ni is discontinuous when cos**2 (aka 1-sin**2) is 0
static float pitch_step(float in)
{
const u32 mask = DISCONT_STEPS-1;
u32 phase = pitch.phase++;
u32 i = phase & mask;
u32 ni = (i + DISCONT_STEPS/2) & mask;
// The 31 is because we only use half the phase,
// so sin walks 0..0.5 and cos walks 0.25..0.75
phase <<= 31-DISCONT_SHIFT;
struct sincos w = fastsincos(u32_to_fraction(phase));
float step = pitch.step;
float delay = (step > 0) ? DISCONT_STEPS*step : 1;
float d1 = sample_array_read(delay - i*step, &pitch.idx, pitch.array) * w.sin;
float d2 = sample_array_read(delay - ni*step, &pitch.idx, pitch.array) * w.cos;
float out = d1+d2;
sample_array_write(linear(pitch.feedback, in, out), &pitch.idx, pitch.array);
return linear(pitch.mix, in, out);
}