Skip to content

fix(firmware): the tuner reads a bass's low strings - #27

Open
VinSpee wants to merge 6 commits into
isod89:mainfrom
VinSpee:fm/openpocket-tuner-bass
Open

VinSpee wants to merge 6 commits into
isod89:mainfrom
VinSpee:fm/openpocket-tuner-bass

Conversation

@VinSpee

@VinSpee VinSpee commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

The tuner's longest lag was 180 samples at 11025 Hz, so its lowest note was 61 Hz: a bass's E (41 Hz) and A (55 Hz) strings showed nothing or a wrong note (issue #20). The lag now reaches 400 samples (27.6 Hz), enough for a five-string bass's low B (31 Hz) tuned up from flat.

The lag search now judges each lag as it is computed and stops at the bottom of the first dip, so the array of normalised differences is gone. The tuner's buffers grow by 80 bytes in all (the window copy grows by 880, the array of 1604 would have pushed the Bluetooth test image's NAM layer split out of the cache RAM). The difference window now starts 20 ms earlier in the buffer; guitar readings move by at most 0.1 cent.

The tuner moves to firmware/px_tuner.h so that tests/test_tuner.c runs it on a PC: bass and guitar notes, sine and plucked, in tune and off it, read every 100 ms. Before: 157 of 229 cases right (every bass note under 61 Hz wrong). After: 229 of 229, within 2 cents up to the high E string.

VinSpee and others added 6 commits November 12, 2026 11:59
The tuner's longest lag was 180 samples at 11025 Hz, so its lowest note was
61 Hz: a bass's E (41 Hz) and A (55 Hz) strings showed nothing or a wrong note
(issue #20). The lag now reaches 400 samples (27.6 Hz), enough for a
five-string bass's low B (31 Hz) tuned up from flat.

The lag search now judges each lag as it is computed and stops at the bottom
of the first dip, so the array of normalised differences is gone. The tuner's
buffers grow by 80 bytes in all (the window copy grows by 880, the array of
1604 would have pushed the Bluetooth test image's NAM layer split out of the
cache RAM). The difference window now starts 20 ms earlier in the buffer;
guitar readings move by at most 0.1 cent.

The tuner moves to firmware/px_tuner.h so that tests/test_tuner.c runs it on
a PC: bass and guitar notes, sine and plucked, in tune and off it, read every
100 ms. Before: 157 of 229 cases right (every bass note under 61 Hz wrong).
After: 229 of 229, within 2 cents up to the high E string.
…dd THRU (#28)

* docs: the base firmware's design

docs/BASE-FIRMWARE.md states what the base holds, what an app provides, how
an app declares its memory regions and reads the controls, how a second image
is built from the same tree, what the base leaves out, and how the layout
merges with upstream changes.

* refactor(firmware): move the board and the controls to firmware/base

The chip includes, the pins, the screen and its text go to base/board.h, and
the controls' pins, the ADC, the battery and the debounce go to
base/controls.h. openpocket.c includes both where the code was. The lines are
moved as they were: firmware/openpocket.bin and both packages are the same
bytes as before (SHA-256 compared).

build.sh adds firmware/ to the include path, so that a file under base/ finds
font8x8.h and ui_text.h.

* refactor(firmware): move the start and its diagnostics to firmware/base

base/diag.h takes the crash screen, the boot stages kept across a reset and
the stacks' paint. base/start.h takes fm1_cstart and now comes before
app_main, which it declares. base/boot_screens.h takes the boot screen and the
last start's report as statements that app_main includes: as functions they
changed app_main's stack layout, and the image must stay the same bytes.

The app's file names itself (OP_NAME) and its RAM code (OP_RAM_CODE) for those
screens. The line helpers b_num, b_str and b_fix2 move from px_audio.h to
base/board.h, where the start's screens find them.

firmware/openpocket.bin and both packages are the same bytes as before.

* refactor(firmware): move the audio's way in and out to firmware/base

base/audio.h takes the I2S driver's glue, the block's buffers and figures, the
output stage (dsp_out), the load and its bypass (dsp_load), the tuner's
capture and the volume. Three stages get a name so that an app can call them:
a_input (the middle of a_block), a_output (the end of a_send) and
audio_io_start (the end of audio_start).

px_audio.h keeps OpenPocket's part: the engine, the two cores, the NAM
pipeline, the wet lanes and the preset's way to the engine. It defines
a_block, a_send and a_collect, which the base declares.

The compiler inlines the three new functions where their code was:
firmware/openpocket.bin and both packages are the same bytes as before.

* refactor(firmware): the app declares the flash it writes and the update's buffer

px_usb.h let the app write the update's staging area, OpenPocket's preset
store, its NAM models and its IRs. The three ranges that are OpenPocket's own
now come from OP_FLASH_OWN, which openpocket.c defines. An app that defines
nothing may write the staging area only.

The buffer that px_models.h lends to an update (OTA_SCRATCH) is declared in
openpocket.c. An app that lends none uses the one in ota.c.

firmware/openpocket.bin is the same bytes as before.

* build(firmware): the app declares its memory regions and its sources

app.ld keeps the chip's regions and includes memory.ld, which holds the app's
own: RAM, POOL and RAMTEXT. firmware/memory.ld is OpenPocket's, with the three
lines as they were. A link-time check refuses regions that overlap or reach
the stacks.

build.sh reads the regions for its memory report from the linker's map, so
the report is right for any layout. OP_APP=<name> builds firmware/apps/<name>
on the base in place of OpenPocket: the app's app.sh names its C file, its
engine and its RAM code, and the outputs go to build/apps/<name>.

Without OP_APP the commands, the report and the outputs are the same:
firmware/openpocket.bin, symbols.txt and both packages are the same bytes.

* refactor(firmware): the MASTER knob's smoothing as a base function

master_follow in base/controls.h holds the knob's moving average and its
hysteresis, which were in OpenPocket's main loop. An app with a main loop of
its own calls it. The compiler inlines it where the code was:
firmware/openpocket.bin is the same bytes as before.

* feat(firmware): THRU, the smallest app on the base

firmware/apps/thru is a second image built from the same tree: the guitar
straight to the output, the MASTER knob, the load on the screen. It includes
the base's files and none of OpenPocket's, so it is the build's proof that the
base stands without the amp modeller. It declares its own memory regions: 320
KiB for an engine where OpenPocket has 248.

base/audio_plain.h gives an app without a schedule of its own the three
entries the base's audio needs: the sound made in the I2S interrupt, on one
core, from the app's app_sound.

  node tools/op.mjs app thru   (make app APP=thru)   ->   build/apps/thru/

tests/test_base_audio.c runs the base's audio stages under that schedule on a
PC: levels, MASTER, the mutes, the soft knee, the NaN guard, the load's
bypass, the tuner's capture.

CI builds THRU too: the build fails when a base file comes to need a name
from OpenPocket.

THRU has not run on a pedal. OpenPocket's outputs are the same bytes.

* docs: the app build in BUILDING.md, the README and the verify map

* no-mistakes(document): Repoint moved audio symbols to base/audio.h
Main split a shared base from the OpenPocket app (#28) and moved the tuner,
with the rest of the audio's way in and out, from firmware/px_audio.h to
firmware/base/audio.h. The tuner fix now applies there: base/audio.h defines
TN_MEM and TN_READY and includes px_tuner.h in place of the old tuner, and
px_audio.h is main's. px_tuner.h names base/audio.h as its includer, and
docs/BASE-FIRMWARE.md lists px_tuner.h with the base's audio files.

tests/run_tests.sh runs both new tests: the tuner's and the base audio's.
…lternative firmware (#29)

* test: pin OpenPocket's release image and packages by SHA-256

`node tools/op.mjs package` now ends with tests/release_pin.sh. It compares
the image, both packages and the manifest with tests/release.sha256 and
fails when one differs. The sums are those of upstream's published v42
packages, of CI's build of main, and of a local build.

A change to the base firmware or to another app can no longer change
OpenPocket without a failed build.

* feat(base): an app's sound may be stereo

An app that defines A_CH 2 fills a left and a right block. The base's
output stages (the NaN guard, the mutes, the change fade, MASTER, the
soft knee) treat the two sides alike, and the I2S block gets one side
on each channel. The guitar stays mono.

OpenPocket compiles to the same object: the mono path is the same text,
and the right side's lines are under A_CH == 2.

The base audio test runs twice, mono and stereo. A mutation check of the
stereo lines caught 12 of 12 changes.

* feat(base): the controls as events for an app

base/input.h reads the encoder, the buttons, the footswitches, the
keypad, the MASTER knob and the battery, as OpenPocket's main loop
does, and gives an app events: down, hold, click, release, a detent,
the volume. The app supplies each button's hold time and decides what
an event means.

base/controls.h lets a host build define the chip's ports, so the test
runs the pedal's own code from the pins to the events. OpenPocket
compiles to the same object.

A mutation check caught 13 of 13 changes.

* feat(base): musical MIDI for an app, and a ring that is always read

base/midi.h empties usb.c's MIDI input ring and gives an app's map each
Program Change, Control Change, clock and transport message, with the
time it arrived. midi_tempo turns the clock into a quarter note.

The ring must be read by every app. The USB test now shows why, with
the pedal's own usb.c: a ring nobody reads takes 48 events, then leaves
the host's packets unread, and the installer's identity query is in the
same packets. THRU never read it.

OpenPocket keeps its own reader and map. A mutation check caught 10 of
10 changes.

* feat(base): a store for an app's own data in flash

base/store.h keeps one block of an app's data (at most 19184 bytes) in
0xE5000..0xEF000, which OpenPocket never writes: two copies written in
turn, the header last, a sequence number and a CRC16. A power cut
during a save leaves the copy before it.

Every sector's last 256 bytes stay erased. The boot code and each
update loader read a record there, and OpenPocket's loader does not
know this range by address, so those bytes are what keeps an app's
data through a stay on OpenPocket.

The test saves data made of update records and cuts the power at every
step of a save. A mutation check caught 17 of 17 changes.

* feat: an alternative firmware is its own product, with a starter to copy

The base firmware gains what a second product needs, and THRU becomes
STARTER (firmware/apps/starter), a whole small product built on it.

Identity. An app holds a product descriptor (base/product.h). The
packager reads it: the packages are named after the app and the
manifest says which product they are. On the pedal the app answers the
editor protocol's INFO with protocol 0, which no OpenPocket has, then
its id, name, version and what it can do. The update handshake stays
Model_9NN, so an installer of any age finds the pedal and can put
OpenPocket back. The flasher installs an alternative firmware only with
--app NAME, names the product a pedal runs, checks it after an install,
and ends with the way back.

Declaration. base/loop.h holds the start and the main loop's duties that
keep a pedal recoverable. base/audio_plain.h resets an app's sound after
a NaN and makes a change in silence. base/flashmap.h is the flash an app
may write.

STARTER. A stereo engine of its own in the POOL region, eight presets in
its own flash, the controls, a MIDI map, its own editor requests.

Simulator. `node tools/op.mjs sim --app starter` compiles the app's own
C files for this computer with tests/host as the chip. The start, the
loop, the controls, the audio stages, the store, MIDI and INFO are the
pedal's own code.

OpenPocket compiles to the same object as before.

* feat(installer): an alternative firmware is a separate choice, with a way back

The installer page names the product a pedal runs. It offers an
alternative firmware only with ?app=NAME, in a card of its own beside
OpenPocket, with what it replaces and how to go back. While a pedal
runs one, the button of step 2 reads "Back to OpenPocket". Rescue mode
installs OpenPocket, as before, and asks no second question first.

The web editor says which product answered and how to put OpenPocket
back. It opens again by itself once OpenPocket answers. The log tool
names the product.

The local server and the simulator serve an app's packages from
build/apps, where the build puts them.

Tests: the page flow in a browser (install, the product named, back to
OpenPocket), the editor's notice, the flasher's product check when a
pedal does not say what it runs, the log tool, and the UBOOT rescue of a
pedal that holds an alternative firmware.

* build: one command for both products, and the documents

`node tools/op.mjs all` builds OpenPocket with its release pin, then
each app of firmware/apps, then runs the tests with the packages it
built (`test --built`). CI builds STARTER, keeps its packages, and runs
the tests the same way. `serve app NAME` opens the installer with that
app offered.

docs/ALT-FIRMWARE.md is the how-to: start an alternative firmware from
STARTER, install it, go back, recover, and the step-by-step checks that
still need a pedal. docs/BASE-FIRMWARE.md is the reference for the base
as it is now, with the table for merging upstream.

* docs: the README points at the alternative firmware how-to

* docs: say what the full run must show before a pedal check
Main made the base firmware usable for an alternative firmware (#29).
docs/BASE-FIRMWARE.md keeps main's rows and lists the tuner with px_tuner.h
among the base's audio files, as the first merge did. tests/run_tests.sh
keeps the tuner test and main's base audio, controls and store tests.
The tuner fix changes OpenPocket's image on purpose, so the release pin
from #29 failed. tests/release.sha256 now holds the sums of v42 with the
fix: the same bytes as this branch's build before the base merges.

The pin's text names v42 with the bass tuner fix in place of upstream's
published v42, says that a change made to OpenPocket on purpose is pinned
the same way, and points to section 9 of BASE-FIRMWARE.md, where the pin
is described.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant