agentleFS
SpeakingColorsSpeakingColors/claude-skills/skills/js-to-cpp-dsp-port/SKILL.md

js-to-cpp-dsp-port

Skill0 starsChanged 23 days agoMITView on GitHub

Use when DSP written in JavaScript (a mockup engine) must be ported to C++ with the same results: function by function, same test cases, rounding and FFT conventions, STFT, phase vocoder, undo steps.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run the JS tests too, so both sides stay in step.

    line 13
  2. Very specific:

    Use a double precision pi.

    line 20

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Porting a JavaScript DSP engine to C++ with identical behaviour

Labels: MEASURED (ported spectral editing, phase vocoder stretch, formant preserving pitch shift, warp, YIN note detection and tempo detection; 662 checks pass), UNVERIFIED.

Method

  1. Port ONE function at a time, in a header only file with no JUCE (MeowDsp.h style), in the same order as the JS file. Keep the constants and the comments.
  2. Port the JS test file to C++ as checks, with the same inputs and tolerances. A port is done when the same cases pass, not when it compiles. Add a second layer: the plugin's editor calls the engine through one undo step (ed.transform("Label", fn)).
  3. Run the JS tests too, so both sides stay in step. Keep the JS as the reference for the mockup.

Conventions that bite

  • Math.round(x) rounds halves UP: use floor(x + 0.5), not std::round (which rounds away from zero for negatives).
  • JS typed arrays are zero filled and Float32Array rounds on store: keep intermediates in double, store float at the same places.
  • Inverse FFT by conjugation: conj(fft(conj(x))) / n. Overlap add with a Hann window at 75 percent overlap divides by 1.5.
  • Pitch tracks use NaN for "no pitch": test with isnan, never ==. Guard every neighbour index in smoothing windows.
  • Use a double precision pi. A float kPi already existed in the core and gave small errors in sinc kernels.
  • Phase vocoder with peak locking: keep the previous analysis phase and the synthesis phase per bin, assign every bin to its nearest peak, and note the analysis hop is st - prevSt (an integer). Time stretch then resample gives pitch shift; formant keeping needs a spectral envelope pass.
  • Randomness (grain texture mode) cannot match the JS generator: test length and level only.

Results that need no reference

  • Resample 48k to 44.1k keeps pitch within 1.5 Hz and RMS within 0.01. Stretch by 1.5 gives exactly 1.5 times the frames with the pitch within 3 Hz. Note detection finds 220 Hz as MIDI 57 within 0.1. MEASURED.
  • Spectral cut of a box removes the tone inside it by more than 50 dB and leaves tones outside it within 0.2 dB. MEASURED.

UI notes

  • Long jobs (stretch of minutes of audio) block the message thread: say so in the panel, or move them to a thread before shipping.
  • Preview = run the process on a copy and play that copy; never touch the real sound until Apply.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.