You've already forked torvalds-GuitarPedal
mirror of
https://github.com/torvalds/GuitarPedal.git
synced 2026-08-18 13:13:35 +00:00
'Software' was the directory everything that was not KiCad ended up in, which stopped describing anything a while ago - Validation and the web app are software too. Worse, it put the shared parts inside the firmware, where they read as the firmware's own. They are not. Effects/ has three consumers built from it: the firmware, Validation's bench, and the web app's controls, all generated from the same POT: comments by gen_effects.py. Audio/ has two - the bench compiles the same biquads, the same envelope followers and the same single_sample(), which is the whole reason a measurement on a workstation says anything about the pedal. Neither belongs under Firmware/, so neither is under it any more: Effects/ one file per effect Audio/ the DSP they are built from, and the audio loop Firmware/ the rest of what runs on the pedal, and the submodules WebMIDI/ the web app scripts/ what the build runs Validation/ unchanged Hardware/, Documentation/, Images/ CMakeLists.txt and the wrapper Makefile move to the top with them, because the build now consumes four of those directories and generates into a fifth. board.local and build/ come along; MIDI_CC_MAP.md is generated into Documentation/ rather than into the old Software/ root. scripts/ goes with the build rather than staying under the firmware, because six of the ten had nothing to do with the firmware: gen_effects.py reads Effects/ and writes to three different places, pow2/log2/quarter_sine generate Audio/'s tables, check-readme.py compares Effects/ against the README, and server.py serves the web app. Four of them are invoked from Validation, which was reaching into Firmware/ for tooling - the same burying this commit is undoing. The four that really are about the firmware are ELF checks the top-level build drives anyway, and a second scripts directory would only be a second place to look. C includes say "Audio/foo.h" and the generated map says "Effects/bar.h", with the repository root on the include path for both the firmware and the bench. Spelling the directory out rather than relying on a bare name is what keeps Audio/cycles.h shimmable: a quoted include searches the including file's own directory first. The submodules are renamed as well as moved. git mv updates their paths but leaves the section names, and 'Software/pico-sdk' surviving in .gitmodules would be the word this commit removes, still load-bearing. That meant the nested modules under pico-sdk too - six .git files pointing into .git/modules/Software - which is why 'git submodule update --init --recursive' is worth running once after pulling this. Verified rather than assumed: a clean configure and build, make check (failing only on the missing-eeprom case it already failed on), check-effects, all four analysis pages reproducing every series and drawing every chart, and a flash to the board that still measures a routed reverb where it did before. One latent bug fell out of it. bench/coeff declared only quarter_sine.h of the three generated math tables, and Audio/util.h includes pow2.h and log2.h as well - so building that target with an empty gen/ could never have worked. 'make bench' builds bench/bench first, which generates all three, so it stayed hidden until this rebuilt everything from nothing. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
117 lines
4.4 KiB
C
117 lines
4.4 KiB
C
// NAME: Klonlike [KLON]
|
|
// PRIORITY: 50
|
|
// POT: "Gain" LINEAR(0 1) = 0.20
|
|
// POT: "Treble" LINEAR(0 1) = 0.50
|
|
// POT: "Output" LINEAR(0 1) = 0.40
|
|
|
|
// Klon pedal originally by Bryan Leavelle <bryanleavelle@gmail.com>
|
|
//
|
|
// Circuit modeled:
|
|
// Charge pump (18V headroom) -> input buffer -> op-amp driving germanium
|
|
// diodes (1N34A) to ground for hard clipping -> clean/dirty blend that tracks
|
|
// gain knob -> treble control with 1.7kHz presence peak.
|
|
//
|
|
// The Klon's signature: the clean/dirty blend is NOT a mix knob -- it's
|
|
// wired to a dual-gang gain pot. Low gain = mostly clean with a touch of edge.
|
|
// High gain = 100% clipped. The clean signal grounds out as gain increases.
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* DC blocker — 1-pole HP at ~20Hz */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
// NOTE! Bryan's original code didn't have the 2*pi correction, and so
|
|
// the alleged 20Hz filtering was actually a high-pass filter at around
|
|
// 3.2Hz.
|
|
//
|
|
// The real Klon Centaur has a 100nF input blocking capacitor with a
|
|
// 1M resistor to ground, so the DC blocking is actually more like a
|
|
// 1.5Hz high-pass filter.
|
|
//
|
|
// The output DC blocking is a 4.7uF cap with a 100k pulldown, which
|
|
// is even lower, but at that point we're so far away from any audio
|
|
// frequencies that it doesn't matter at all and we'll just use this
|
|
// for both cases
|
|
|
|
struct {
|
|
float drive, treble, level;
|
|
struct single_pole_state dc_in; /* DC blocking at input */
|
|
struct single_pole_state dc_out; /* DC blocking at output */
|
|
struct single_pole_state in_hp; /* 30Hz coupling cap */
|
|
struct single_pole_state pre_lp; /* 15kHz input bandwidth */
|
|
//
|
|
// Built in klon_init() rather than inline in the step. They are
|
|
// constants, but the coefficient for one is a pow2() now - see
|
|
// audio/single-pole.h - so an inline call would be four real
|
|
// function calls a sample rather than four folded constants.
|
|
//
|
|
struct single_pole_coeff dc_c, in_hp_c, pre_lp_c;
|
|
struct biquad tone_hs; /* treble control — hi shelf @ 2kHz */
|
|
struct biquad pres_pk; /* presence peak @ 1.7kHz */
|
|
} klon;
|
|
|
|
static inline float klon_dc_step(struct single_pole_state *state, float x)
|
|
{
|
|
return single_pole_hpf(x, state, klon.dc_c);
|
|
}
|
|
|
|
void klon_init(unsigned char pot[10])
|
|
{
|
|
klon.drive = klon_gain_pot(pot);
|
|
klon.treble = klon_treble_pot(pot); // 0 = dark, 1 = bright
|
|
klon.level = klon_output_pot(pot);
|
|
|
|
float hs_db = (klon.treble - 0.5f) * 12.0f; // -6 to +6 dB
|
|
float peaking_db = klon.treble * 6.0; // 0 to +6 dB (original effectively doubled the boost)
|
|
|
|
// Single-pole RC filters for coupling and bandwidth. The state is
|
|
// implicitly zero from static allocation; the coefficients are not,
|
|
// and are built here because they cost a pow2() each.
|
|
klon.dc_c = single_pole_rc(1e6, 100e-9);
|
|
klon.in_hp_c = single_pole_freq(30.0); /* coupling cap */
|
|
klon.pre_lp_c = single_pole_freq(15000.0); /* input bandwidth */
|
|
|
|
biquad_highshelf(&klon.tone_hs, 2000.0, 0.7, db_to_A(hs_db));
|
|
biquad_peaking(&klon.pres_pk, 1700.0, 1.5, db_to_A(peaking_db));
|
|
}
|
|
|
|
float klon_step(float in)
|
|
{
|
|
float drive = klon.drive;
|
|
float level = klon.level;
|
|
float pre, boost, ge_clip, clean_amt, dirty_amt, mixed, y;
|
|
|
|
/* Input conditioning */
|
|
pre = klon_dc_step(&klon.dc_in, in);
|
|
|
|
pre = single_pole_hpf(pre, &klon.in_hp, klon.in_hp_c); /* coupling cap */
|
|
pre = single_pole_lpf(pre, &klon.pre_lp, klon.pre_lp_c); /* input bandwidth */
|
|
|
|
/* Op-amp gain — 18V charge pump gives ~2x headroom vs 9V pedals */
|
|
boost = 1.0f + drive * drive * 55.0f;
|
|
pre = pre * boost;
|
|
|
|
/*
|
|
* Germanium diode pair (1N34A) to ground — 0.3V forward voltage
|
|
* (silicon is 0.7V — germanium clips softer, rounder, more compressed).
|
|
* Hard clipping to ground gives even harmonic content from the soft knee.
|
|
*/
|
|
ge_clip = tanhf(pre * 0.45f) * 1.8f;
|
|
|
|
/*
|
|
* THE KLON'S SIGNATURE: clean/dirty blend tracks the gain knob via a
|
|
* dual-gang pot.
|
|
* Low drive = mostly clean with a whisper of edge.
|
|
* High drive = 100% clipped, clean signal is fully grounded out.
|
|
*/
|
|
clean_amt = 1.0f - drive;
|
|
dirty_amt = drive;
|
|
mixed = in * clean_amt + ge_clip * dirty_amt;
|
|
|
|
/* Post-clip tone shaping */
|
|
y = biquad_step(&klon.tone_hs, mixed); /* treble shelf */
|
|
y = biquad_step(&klon.pres_pk, y); /* 1.7kHz presence peak */
|
|
y = klon_dc_step(&klon.dc_out, y); /* remove clipping DC offset */
|
|
|
|
return y * (0.3f + level * 1.5f);
|
|
}
|