0
mirror of https://github.com/torvalds/GuitarPedal.git synced 2026-08-18 13:13:35 +00:00
Files
Linus Torvalds 0c1b9c3db3 Split Software/ into the four things it actually was
'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>
2026-08-11 13:48:26 -07:00

107 lines
4.9 KiB
C

// NAME: Tone [TONE]
// PRIORITY: 10
// COPIES: 2
// GRAPH: LOSHELF:0.707 PEAKING:MID_Q HISHELF:0.707
// POT: "Bass Freq" EXPONENTIAL(20.0 20480.0) = 200.0 Hz
// POT: "Bass" LINEAR(-15.0 15.0) = 0.0 dB
// POT: "Mid Freq" EXPONENTIAL(20.0 20480.0) = 800.0 Hz
// POT: "Mid" LINEAR(-15.0 15.0) = 0.0 dB
// POT: "Treble Freq" EXPONENTIAL(20.0 20480.0) = 3000.0 Hz
// POT: "Treble" LINEAR(-15.0 15.0) = 0.0 dB
// POT: "Mid Q" EXPONENTIAL(0.3 4.0) = 0.707
//
// A tone stack: bass, mid and treble.
//
// The analogue circuit is a feedback network around one gain stage, and
// its two controls interact through it - which is most of what makes a
// Baxandall sound like a Baxandall rather than like two filters. Digital
// has no such constraint, so this is what the circuit was always trying
// to be: a low shelf and a high shelf in series, independent, and the
// corner frequencies adjustable because there is no reason for them not
// to be. Four multiply-adds a sample either way.
//
// Worth having next to the five-band EQ rather than instead of it. The
// EQ is the better instrument and the worse tool: most of the time the
// answer is "a bit less low end and a bit more air", and reaching for
// five bands to say that means deciding four things you did not want to
// think about. This is the same picture with three nodes in it.
//
// The mid is a peaking band, and it is here because two shelves cannot
// make a hump. A low shelf lifts everything below a corner and a high
// shelf everything above one, so the only way to raise the middle with
// two of them is to overlap opposing shelves and let their skirts add -
// which works, and is a trick rather than a control. Every guitar tone
// stack ever built is bass/mid/treble for this reason.
//
// The shelves are fixed at Q 0.707. The mid's is a pot, because a mid
// is the one band where width is a decision rather than a default: 0.707
// is about two octaves, the broad "more body" a tone control is for,
// while the narrow end reaches far enough to pull a single resonance out
// of a boxy guitar. It reads as Q rather than as a width because that
// is what it is, and the graph shows what it does the moment it moves.
//
// The GRAPH: line names Mid Q, and that is the only place the connection
// is made - the generator writes the Q out from that declaration, so the
// number the app draws with and the number the filter is built from
// cannot be different ones.
//
// There are two of these, which is what 'COPIES: 2' above asks for.
// Two rather than one because an effect owns one set of state, so
// routing the same one twice would run a filter through its own delay
// line and produce nonsense - and one file rather than two copies
// because twins that are edited separately stop being twins.
//
// The copies differ in exactly one thing, which is that each has its
// own state. So the generator emits the pot accessors and the Q table
// once and both copies share them - they are pure functions of the pot
// array and two of each would only be two things to keep in step - and
// generates just the state, the init and the step per copy. Those
// three are the only names here that cannot be written down, because
// this file does not know which copy it is being included as; SELF()
// is how it refers to them, and the generator supplies the name at
// each include.
//
// This used to be a symlink, tone2.h pointing here, and the second
// copy existed only in a directory listing. Saying it in the file is
// better mostly because it is visible from inside the file.
//
// Which one goes where is not decided here either. They are ordinary
// routable effects, so put one at the front, or one at the back, or
// both, or neither. Unrouted they cost exactly nothing.
//
// A shelf at 0dB is not approximately transparent, it is exactly
// transparent: with a gain of 1 the numerator and denominator of the
// section come out identical term by term. So there is no need to
// detect the flat case and skip it, and no click when it stops being
// flat, and the default of flat/flat is a genuine no-op that still
// leaves the filter's state warm.
//
// 0.707 rather than the EQ's 1.0 on the shelves. A shelf at Q=1
// overshoots slightly before it turns over, which is useful when aiming
// a band at something and wrong when tilting the whole top or bottom of
// a signal.
static struct {
struct biquad bass, mid, treble;
} SELF(_state);
static void SELF(_init)(unsigned char pot[10])
{
float q[3];
tone_graph_q(q, pot);
biquad_lowshelf(&SELF(_state).bass, tone_bass_freq_pot(pot), q[0],
db_to_A(tone_bass_pot(pot)));
biquad_peaking(&SELF(_state).mid, tone_mid_freq_pot(pot), q[1],
db_to_A(tone_mid_pot(pot)));
biquad_highshelf(&SELF(_state).treble, tone_treble_freq_pot(pot), q[2],
db_to_A(tone_treble_pot(pot)));
}
static float SELF(_step)(float in)
{
float val = biquad_step(&SELF(_state).bass, in);
val = biquad_step(&SELF(_state).mid, val);
return biquad_step(&SELF(_state).treble, val);
}