Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

FlipnoteSpeaker

Play anything the way a Nintendo DSi hears it: speaker colouring + fixed mic gain/clipping + the real IMA ADPCM "crush" from Flipnote Studio.

This is the cleaned-up successor to the experiments in Bitcrush/. It contains only the working filter, the desktop integration, examples, and documentation.

What it does

Signal chain (v2, aliasing-faithful):

host rate -> resample to the 32720 Hz ADC clock (wide ~16 kHz band limit)
          -> [32720 Hz] ADC DC blocker (15 Hz) -> speaker EQ -> optional hiss + fixed gain
          -> hard clip (int16) -> optional ~3.7 kHz pre-filter ("Alias %", 100 = bypass)
          -> point-sample every 4th ADC sample = 8180 Hz capture (HF folds down, no 4 kHz low-pass)
          -> IMA ADPCM encode/decode (predictor 0, step 0) -> zero-order hold x4 -> resample to host

The ADPCM stage is bit-exact with the DSi ROM implementation. The DC blocker, +27.5 dB mic PGA, AGC-off behaviour and 8180 Hz rate come from the DSi's documented codec registers — see research/HARDWARE.md. v2 removed the old 3.85 kHz pre-decimation low-pass that the hardware does not have, so HF above 4.09 kHz now folds into the recording. Alias % recreates the old filtered sound when turned down. The speaker EQ is a fitted approximation of the acoustic path (speaker/room/mic), which is where recordings differ — see DECISIONS.md.

Hiss is off by default. Real .ppm captures do have a low-frequency noise floor in their quiet passages (−50…−34 dBFS, mostly below 300 Hz), but no measurable broadband HF hiss, and the old fitted noise value came from source/Recording pairs that research proved were different performances. The Hiss knob is now a subtle optional "noisy tape" effect; a short noise gate keeps it from idling.

Testing in Carla

Two plugin formats are available, both running the same src/flipnote_speaker.c DSP:

  • LV2 — ~/.lv2/Flipnote.lv2/Flipnote.so (bundle URI https://github.com/cashmere/flipnote-filter). This is the one to use in Carla: it exposes all 11 controls below plus a latency port. All controls are declared automatable, so Carla applies knob changes live. If Carla still shows only the old dry/wet knobs, rescan plugins (or restart Carla) and remove and re-add the instance — the URI has not changed, so an existing instance keeps its cached port list.
  • LADSPA — bin/flipnote_speaker.so, useful for PipeWire filter-chains and offline rendering.

Useful controls:

Control What it does
Speaker 0 bright phone honk, 1 desk/neutral (default), 2 distant/bass-cut, 3 clean/crush-only. Fitted to distinct acoustic characters — see below.
Drive dB Fixed net mic gain — the main level knob. If hiss is enabled, it is added before this, so signal-to-hiss stays constant.
Output dB Output trim (−6 dB by default, close to the capture's level relative to the source). Preset loudness differs a lot — at this default Speaker 0 is about +0.6 dB and Speaker 2 about −16.6 dB relative to the input on broadband material — so this is the knob to use if you want the effect hotter or quieter.
Hiss Optional broadband noise (0–200%), 0% by default — real captures show no HF hiss, so this is flavour, not emulation.
Low-cut Hz (0=preset) Direct acoustic high-pass frequency. 0 follows the preset, negative bypasses it. Setting it explicitly also filters the mic hiss, so the thinning is actually audible.
High-cut Hz (0=preset) Direct acoustic low-pass frequency. 0 follows the preset, negative bypasses it. Setting it explicitly also filters the mic hiss and scales down the Sparkle grain, so the muffling is actually audible. The range ends at 4000 Hz because the capture rate is 8180 Hz — above ~3.7 kHz this filter is naturally off.
Presence trim dB Adds ±12 dB to the high shelf. Presets without a shelf use a neutral 2 kHz corner when this is non-zero, so the knob is never dead on Speaker 3.
Sparkle % Step-scaled ADPCM dither that produces the "crackle-sparkle" grain. 100% is the fitted default, 0% is a true off, and 200% adds 1.3 grain units on every preset. The Nyquist-shaped component has random signs, so it drives the ADPCM step hunting as crackle instead of a pure 4.09 kHz whine. High-cut Hz also scales the grain back down, so you can tame the fizz with that knob.
Alias % 100% (default) point-samples the 32720 Hz ADC every 4th sample with no pre-filter, so HF folds down as the hardware does. 0% applies a ~3.7 kHz 4th-order pre-filter, close to the old v1 sound; in between blends the two. This is the main A/B for the v2 capture-path change.
Auto level Legacy RMS follower. Off by default (real hardware AGC is off).
Noise gate dB Idle hiss suppression threshold (−45 dB, 5 ms attack / 80 ms release).

The DSP processes mono; the LV2 wrapper downmixes stereo to mono and duplicates the result to both outputs. It has a few ms of latency from the resampler; the LV2 build publishes this on its latency port, LADSPA does not.

Routing: there is now one DSP — the Flipnote Filter LV2 inside Carla. The old four Flipnote - Phone/Desk/Loud/Clean PipeWire chains were removed: they ran the DSP a second time and each injected its own hiss, which was the constant static and the dry-path masking. All app streams are routed to CarlaInput, which feeds the plugin, whose output is the only thing connected to HDMI. The flipnote-route.timer user timer repairs those links every 15 s after PipeWire restarts and re-applies all 11 saved Carla controls whenever Carla restarts (Carla can otherwise restore saved knobs incorrectly). Run python3 desktop/flipnote-desktop.py fix-routing to repair immediately, or status to inspect. HDMI should have only Flipnote Filter:Audio Output 1/2 as inputs; Carla's output link to the physical sink is direct and should not depend on whatever the current default sink is.

Trying the four EQ/grain knobs: Low-cut Hz is the acoustic high-pass (bass cut), High-cut Hz is the acoustic low-pass (treble cut), Prsnc is the shelf trim, and Sprkl is the codec grain. They respond on every preset, including Speaker 3 ("clean"), which used to have no cut, no shelf, and almost no grain. Useful extremes on a broadband source are Low-cut Hz ~1500 Hz, High-cut Hz ~2000 Hz, Prsnc +12 dB, and Sprkl 150–200%. Sprkl now adds grit without the old scraping-plate tone. For an A/B, use Carla's own Dry/Wet knob above the plugin controls: the former plugin Mix knob was removed because Mix=0 was just a delayed, trimmed copy of the input. The level difference you hear between dry and wet is the real capture level, not a hidden filter; compensate with Output dB if you want them equal. Remember: 0 follows the preset, a positive value overrides it, negative bypasses the filter entirely. The former Low-cut shift / High-cut shift controls were removed — they drove the same two biquads relatively and did nothing on presets with no cut, which made them look broken.

Why cry_flipnote still sounds different: research/NOTES.md shows that cry_original.flac and cry.ppm have envelope Pearson 0.34 — they are different recordings/performances, not the same audio before and after the DSi. The cry_flipnote.wav / Cry_export.mp4 sidecars correlate 0.92–0.998 with the PPM, so they are exports of the capture, not independent sources. No filter can turn a different performance into the capture; only the codec/speaker texture can be matched. cry.ppm still has a useful signature — a ~4 kHz period-2 ADPCM hunt (71.5% of codes alternate sign) riding on a band-limited speaker response (3–4 kHz +9 dB, sub-100 Hz −21 dB). Speaker 0 + Drive -7 reproduces that texture.

If you hear a steady 50/60 Hz hum, it is not the codec: with every app stream muted, the CarlaInput bus and this plugin measure as digital silence (all bins at the noise floor). Track the hum to an unmuted app stream or its source instead.

Fitted acoustic characters

The real .ppm recordings differ by up to 17 dB in upper-band balance relative to their sources — no single EQ can match all of them. Eight presets are available: the four original acoustic characters plus four fitted from repeated per-recording minima (research/fit_all.py).

Preset Low-cut High-cut Shelf Character
0 — bright phone 250 Hz off +10 dB @ 2 kHz bright, honky
1 — desk / neutral (default) 100 Hz off +6 dB @ 2 kHz neutral
2 — distant / bass-cut 1000 Hz 3000 Hz 0 dB bass-cut, distant
3 — clean / crush only off off 0 dB crush only
4 — bright open 400 Hz off +10 dB @ 2 kHz tight low end, open top
5 — bright tight 400 Hz 2500 Hz +14 dB @ 2 kHz tight and focused
6 — bright mid 250 Hz 2000 Hz +6 dB @ 2 kHz softened top
7 — clean distant off 2000 Hz +4 dB @ 2 kHz full-range, soft top

These are exported as real LV2 presets (pset:Preset) and named Speaker scale points, so they appear in Carla's preset dropdown rather than only as an anonymous 0–7 knob. The LV2 build script copies the generated presets.ttl into ~/.lv2/Flipnote.lv2/; check with lv2info https://github.com/cashmere/flipnote-filter if they are missing. Each preset also sets Drive/Alias/Sparkle to the median of the dense fits that selected that speaker character. Low-cut is written explicitly (250/100/1000 Hz, or 400/250 Hz for presets 4–6) so the knob shows that the high-pass is active; High-cut Hz stays at 0 because presets 2/5/6/7 already carry their own cutoff and an explicit override would rescale Sparkle twice. Presets 3 and 7 have no high-pass by design.

What the matched data actually says: of the fifteen available .ppm/source pairs, fourteen are confirmed matches by mean-centred Pearson envelope correlation with offset agreement across 2–30 s window lengths (research/aligned_validate.py): stillwaiting 0.69, balloon 0.93, movie 0.75, boom 0.91, sparta 0.66, pain 0.79, slenderman 0.77 (source at 610 s into the stream), face 0.60, dota 0.52, barrel 0.56, dropit 0.69, agree 0.62, steppin 0.76, enemy 0.90. Only cry (0.34) remains unmatched — its exact master appears to be a lost alternate remix. Earlier fit numbers from refit_presets.py / multi_validate.py used loud_chunk() at source offset 0 s — for pain the matching region is minutes into the song — so those numbers are invalid. The old single-window verdict that slenderman (0.48) and face (0.40) were unmatched was also unstable; the current matcher requires at least two windows to agree within 4 s.

On the fourteen confirmed pairs with correct alignment:

mean distance
raw source 15.01
current default 10.41
best per pair 5.02

Across those fourteen pairs the current default (preset 1, Drive 0, no cut overrides) scores 10.41; the best single grid setting is preset 0 / Drive 0 / no cuts at 9.56. Preset 0 wins 8 of 14 pairs but loses the other 6 by large margins (e.g. enemy +4.8, stillwaiting +3.0), so the choice is a per-recording tradeoff, not a clear global win.

A dense per-recording fit (research/fit_all.py, 1008-point grid plus texture refinement) reaches 3.67 mean — the residual is almost entirely low-frequency room/speaker shape; the 2 kHz and above bands are already within ±1 dB. Clustering those fits produced presets 4–7. With drive/Alias/ Sparkle free, the best choice from the four original presets scores 4.34 mean, while the best choice from all eight scores 3.81 (research/native_preset_check.py). None of the new presets beats preset 0 with default knobs, so the default is unchanged. For the closest possible match use examples/fit_recording.py with the original source for a specific PPM.

The "crackle-sparkle" grain

Sparkle % models the ADC/ADPCM quantizer texture heard in real captures: dither scaled by the current ADPCM step, gated by the signal envelope so idle stays silent, with a random-sign Nyquist component that drives the predictor's step hunting without a pure 4.09 kHz whine. The per-preset weights concentrate it on Speaker 0 (bright phone), where the strongest hunting was measured. research/survey.py establishes which traits are universal; research/grain_check.py checks they stay in range. On the confirmed matched pairs Sparkle has little effect on spectral distance, so 100 stays as the texture default.

Layout

  • src/flipnote_speaker.c — the actual filter (LADSPA, mono in/out; canonical DSP)
  • bin/ — built plugin (run ./build.sh to rebuild)
  • plugins/Flipnote/ — thin DPF LV2 wrapper; build.sh there copies the canonical DSP and installs ~/.lv2/Flipnote.lv2
  • DPF/ — DPF framework, pinned as a git submodule (https://github.com/DISTRHO/DPF.git)
  • desktop/ — PipeWire virtual sinks + per-app routing manager
  • examples/ — offline renderer, smoke test, demo WAVs, and fit_recording.py (per-recording fitter)
  • research/ — bit-exact PPM decoder/ADPCM encoder, hardware notes, and validation harnesses (aligned_validate.py for confirmed pairs, capture_validate.py for 8180 Hz capture-grid checks, survey.py, grain_check.py)
  • DECISIONS.md — design choices, rejected approaches, fidelity limits

Build

./build.sh
# or: gcc -O2 -shared -fPIC -o bin/flipnote_speaker.so src/flipnote_speaker.c -lm

Requires gcc, libm, Python 3 + numpy for the examples, and ffmpeg for file input. After cloning, run git submodule update --init (or clone with --recurse-submodules) to fetch DPF.

To rebuild the LV2 bundle used by Carla after changing the DSP:

plugins/Flipnote/build.sh

It copies src/flipnote_speaker.c into the DPF wrapper, regenerates the TTL port metadata and installs into ~/.lv2/Flipnote.lv2.

Offline use (no system audio changes)

python3 examples/smoke_test.py
python3 examples/render_with_plugin.py song.mp3 out.wav 0
# Fit settings for a known source/PPM pair:
python3 examples/fit_recording.py original.mp3 capture.ppm

Presets: 0 bright phone, 1 desk/neutral, 2 distant/bass-cut, 3 clean (crush only).

fit_recording.py aligns the source to the capture by envelope correlation, then searches preset/Drive/lowHz/highHz/Alias/Sparkle against spectral + capture-rate distance. It guards against gain-gaming (extreme Drive plus attenuation) and warns when correlation is below 0.5.

Desktop-wide use

Declares one permanent CarlaInput null sink (2 ch, 48 kHz) in ~/.config/pipewire/pipewire-pulse.conf.d/99-carla-input.conf and exposes the JACK ports CarlaInput:playback_FL/FR and CarlaInput:monitor_FL/FR. The flipnote-route.timer user timer runs fix-routing every 15 s to keep app streams on that bus and restore Carla's saved controls. There are no per-app filter sinks any more; install actively removes the old configs.

cd desktop
python3 flipnote-desktop.py generate      # dry run: only writes ./generated
python3 flipnote-desktop.py install       # installs config, removes legacy chains, restarts audio
python3 flipnote-desktop.py status
python3 flipnote-desktop.py fix-routing   # immediate repair (also called by the timer)
python3 flipnote-desktop.py uninstall

See desktop/README.md for the exact files touched.

Notes

  • Defaults are Speaker 1 (desk, 100 Hz high-pass, +6 dB shelf) + Drive 0 dB + Hiss 0% + Alias 100%. On fourteen aligned pairs it is within 0.85 of the best single grid setting (research/aligned_validate.py); the four added fitted presets (4–7) help when chosen per recording but none beats Speaker 0 with default knobs, so the default stays. The real DSi uses a fixed +27.5 dB analog PGA with hardware AGC off, so Auto level is off by default; turning it on measurably hurts envelope tracking.
  • Drive dB is a fixed net mic gain, not an auto-level. Per-recording level drift is real (−22…−12 dBFS RMS across the references), so this is the first knob to turn.
  • The optional hiss gate defaults to -45 dB with 5 ms attack / 80 ms release. The shorter release avoids a static-like tail after sound stops.
  • Mono in and out. System sounds and unmapped apps keep their normal output.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages