Skip to content

Grain 0.2.0-experimental: EDGE, four ways to treat the sample's edges - #2115

Draft
AForceTrulyEvil wants to merge 9 commits into
repeat98:mainfrom
AForceTrulyEvil:grain-0.2.0-edge
Draft

AForceTrulyEvil wants to merge 9 commits into
repeat98:mainfrom
AForceTrulyEvil:grain-0.2.0-edge

Conversation

@AForceTrulyEvil

Copy link
Copy Markdown
Contributor

Hi Jannik, this is the Grain 0.2.0-experimental author update, on top of 0.1.3 (thanks for merging 0.1.2 and 0.1.3). It adds a knob, so I bumped the minor version. Like the earlier ones it needs your owner approval (sdk/approvals/grain-build-approval.json covers older versions), so I'm opening it as a draft.

What changes for players

  • New EDGE knob (SRC SETUP, knob E) with four values. It sets what happens at the start and end of the sample, for a grain that SPRY would push past an edge and for a grain that reaches an edge while it plays.
    • CLMP (default): SPRY can't push a grain past an end. A grain that runs off one end carries on from the other.
    • WRAP: the sample is a loop. A grain pushed or running off one end comes out of the other. This is 0.1.2.
    • STOP: grains stay inside. SPRY can't push one past an end, and a grain that reaches an end stops there. This is what 0.1.0 and 0.1.1 did, with one change: the grain is shortened so that its window ends at the edge, so it no longer clicks.
    • BNCE: SPRY can't push a grain past an end. A grain that reaches an end plays back the other way.
  • One change to existing projects. The default is CLMP, so a project saved with 0.1.3 or earlier opens in CLMP, and a grain that SPRY threw past an edge is born on that edge instead of wrapping. Away from the edges nothing changes. WRAP restores 0.1.2, and STOP is the old 0.1.0 and 0.1.1 sound without the click. It's in the changelog and the README. If you'd rather the default stayed WRAP, it's one constant and I'll change it.
  • Screenshots recaptured on 0.2.0; SRC SETUP shows EDGE.

Package e8d7c794… (31,524 bytes; 30,424 in 0.1.3), rebuilt on 0.1.3 with scripts/octatrack-module-packages.py in the pinned toolchain; the previous package is removed. It loads 30,148 bytes of code and data and reserves 2,864 of BSS (33,012 bytes of static memory). The deepest Grain-only audio stack is 780 bytes by the same method as before (768 in 0.1.2).

How it's stored. EDGE lives in SETUP E, the byte stock calls TSTR, whose range 0 to 3 passes the power-on check, so a project opened without the module still plays as a Flex track. In the engine it sits in each track (gran_set_edge), not in GranParams, so the structure your new PTCH check in verify_lanes.py reads is unchanged. No new addresses and no new stock hooks.

Cost. The two loops that run for every sample, stereo_page and stereo_paged, compile to the same instructions as in 0.1.2. The new code runs when a grain is born or reaches an edge: a few compares, and for STOP a multiplication and a compare (a division only for a grain that does reach an edge).

Tests

  • verify.py runs every case in all four modes (optimized against plain paths, five pitches, mono and stereo), keeps 0.1.2's three references for WRAP and adds ones for CLMP, STOP and BNCE.
  • WRAP renders match 0.1.2 bit for bit over 7,200 combinations (sample length, mono and stereo, POS, SIZE, DENS, SPRY, DIR, SCAN, pitch), and STOP matches 0.1.1's engine bit for bit where no grain comes near an edge (96 cases).
  • On a clean 220 Hz tone, the one-sample steps over 2,500 in STOP went from 118 to 0 at POS 124 (10 to 0 at POS 100, 7 to 0 at POS 110 with SPRY 60).
  • range_test.c: births at both edges and a sounding grain at both edges, in every mode. verify_lanes.py: the compiled kernels, including your 0.1.3 PTCH checks, all pass.
  • npm run check -- --base origin/main (with MODWERK_EVIDENCE_PENDING=1): prepare, licences, machines, modules, release notes, lint, typecheck, the bundle and the web tests pass, except the three items below that depend on you. sdk:check fails in other packages' builds because my local m68k-elf-gcc 13.3 lacks -fno-late-combine-instructions; the package itself was built in the pinned Docker toolchain.

Tested on a unit: MKI, OS 1.40C, official base 6d23e888, card set with Grain, E-Verb, Mini Verb, syntiz, FM Synth, BBD Delay and Tape Echo, by the author (A Force Truly Evil). A sample of eight tones, one a second from C3 to E5, shows which part of the sample each grain reads. With SIZE 64, DENS 100, SCAN 0 and PTCH 0, the notes heard in CLMP, WRAP and BNCE were the ones the host renders give (POS 0 and 127 with SPRY 0 and 60, and POS 0 with DIR 127), on the first build of this release (8a4555de, STOP without the shortening). STOP was nearly silent at POS 127.8, as expected, and played as expected at POS 120. The author heard a click when a STOP grain reached an edge; the shortening is the change made for it. A later build (0e4bebd4, with the shortening) loaded and played, and the author ran the rest of the release checklist (the STOP click, EDGE across a save and a power cycle, a p-lock on EDGE, an older project) and reported nothing wrong. CPU meter (stock meter, read by eye, DENS and SPRY at maximum, PTCH +24, all four EDGE modes): 65 to 68 %, about 66 to 67 % on average in every mode.

What I haven't done, and what I need from you

  • Unit run of the final package. The unit runs above were on builds made on 0.1.2, before I merged 0.1.3. e8d7c794 is the same engine and EDGE code on top of 0.1.3 (your PTCH, audition and chromatic changes untouched; verify_lanes.py passes), but it hasn't been on a unit.
  • Owner approval for 0.2.0. The module-qualification test and the module doctor fail only on that (grain-build-approval.json covers 0.1.3), and on the next point.
  • Frame cost. evidence/frame-cost.json is 0.1.3's (first 33.3, each 33.3, refused on the medium pattern). I haven't measured a curve for 0.2.0: it needs a unit on the development base. The render path is the same as 0.1.3's apart from the edge code, so I'd expect the same numbers, but I haven't measured it. I see 0.1.3's TESTING says the next Grain release is held to a first instance that fits a medium pattern, and this one is dated 24 November. Grain's first instance doesn't fit, so this is your call: waive it again, or tell me what you'd like. I didn't want to hide it.
  • MKII: not run, I don't have one.

Edge cases

Case Why this change makes it a risk How run Result
WRAP against 0.1.2 the edge code is shared host renders, 7,200 combinations pass (bit-identical)
STOP away from the edges against 0.1.1 the old behaviour comes back host renders against 0.1.1's engine and 0.1.2's tables, 96 cases pass (bit-identical)
Births at both edges, every mode new birth rule range_test.c, 32,768-frame sample pass
Sounding grain at both edges, every mode new stop and bounce range_test.c with one-frame pages pass
Click at an edge in STOP the reason for the shortening host renders of a clean tone 118 jumps to 0 at POS 124
Optimized paths against plain, every mode the new branch is in the shared mixer verify.py pass
Compiled kernels, with 0.1.3's PTCH checks code changed verify_lanes.py pass
Eight-tone sample on the unit edges in every mode MKI, first build of this release pass
STOP click, EDGE across a save and a power cycle, p-lock on EDGE, an older project the fixes and the storage MKI, 0e4bebd4, the release checklist nothing wrong reported
CPU meter, DENS and SPRY at maximum, PTCH +24, four modes the edge code is in the mixer MKI 65-68 % in every mode, about 66-67 % on average
Final package e8d7c794 on a unit built on 0.1.3 after the unit runs not run not run yet
Frame-cost curve for 0.2.0 admission and the new cost rule not measured not measured: needs your decision
MKII untested hardware not run not run: no MKII available

What the guides lacked or got wrong: nothing.

  • Changing a module someone else wrote: its author said yes before I started, and I link it here. (Not applicable: Grain is mine.)

  • I read the guide for its category in docs/module-guides/, and TESTING.md lists what I did not test.

  • Source and media are mine or properly licensed, with authors and full licence texts kept. Nothing comes from Elektron firmware.

  • Screenshots are real captures of the current module UI. Hardware results are what a named person saw on the build named beside each one; emulator results are labelled as emulator results.

  • Automatically merge and publish my module update after checks pass.

  • I verified the source, licences, UI and qualification reports, including instance isolation and Part/project/reboot persistence where applicable; no required acceptance check is failed or untested.

One more thing: I don't plan another release for a good while. I think Grain is in a good place and quite complete, and unless someone reports a bug I'll leave it as it is. The four EDGE modes are a big step in what you can do creatively with a granular machine, and I think they make Grain a very complete one. Thanks for all the help and the careful reviews!

@repeat98

Copy link
Copy Markdown
Owner

Thanks for the clear write-up, and for raising the cost rule instead of working around it. Here's where 0.2.0 stands and what's next:

  1. The curve: you can read it on your MKI. A development twin runs on an MKI too. That's step 9 of the test procedure on your own unit, and two other contributors did it on MKIs today. The driving guide's first line said "MKII", which is my fault, and Docs: a development twin runs on an MKI too, on the contributor's own unit #2123 fixes it. npm run device:price -- --write --curve T1,T3,T6,T7 --base ID --scene TEXT grain with the final package e8d7c794 also gives you the unit run of the final package, which is still open. Grain's first instance (about 33 % of a frame) will probably be refused on the medium pattern: record that as it comes out.
  2. The cost rule. From 24 November a machine release needs its first instance admitted on the medium pattern, and Grain's isn't. Since Fix: the owner's approval of one exact version can waive the release cost rule #2122, my approval can waive that for one exact version. I'll decide for 0.2.0 once the curve is in.
  3. My approval. Grain has no qualification record of its own (there's no static cycle bound for it), so every Grain version ships on my approval, and that names one exact source. The curve goes into evidence/ and changes that source, so I sign after it's pushed.

repeat98 added a commit that referenced this pull request Nov 24, 2026
… unit (#2123)

The guide opened with "Drive an Octatrack MKII", and a Grain author's agent
concluded the frame-cost curve needed the owner's unit (#2115). Contributors
ran the whole procedure on their own MKI twins on 24 November (#2081, #2116).
Room made under the 40 KiB cap: a repeated boot sentence and the 72 s boot note.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@AForceTrulyEvil

Copy link
Copy Markdown
Contributor Author

Hi Jannik, here is the frame-cost curve for 0.2.0, read on my MKI (OS 1.40C) with package e8d7c794 on a development twin (4c7eb79b, built from this branch with the beta base's flags and --dev), RAM-booted over USB and rolled back afterwards.

Scene: pattern A01 at 126 BPM, trigs on steps 1/5/9/13 of T1, T2, T3, T6 and T7. T1 and T3 Flex slots hold the same loaded 16-bit stereo sample (1.30 MB); T2 a one-shot kick; T6 and T7 have trigs and no sample; T5 and T8 are empty. T4 is a mono loop with time stretch on. Picks on an empty A02. Grain on T1 at its default knobs.

Results:

  • At rest (installed, not used): +0.1 points of the frame.
  • First instance on T1: +24.4 points (frame max 72.4 % to 96.8 % on the medium pattern). A second instance on T3 is refused by the base, as expected.
  • Medium pattern with T4 silent (its trigs cleared): admitted, longest frame 97.4 %, 0 dropped, 0 stalls. Empty pattern: admitted, longest frame 52.0 %, 0 dropped, 0 stalls.
  • Medium pattern with T4 sounding (the loop with time stretch on): 102.2 % with Grain on T1. Over 100 %, so not admitted.

So in this scene Grain fits only while T4 is silent. With T4 sounding, with time stretch, it does not fit. I have not measured other combinations (for example a second Grain track, or Grain next to FM Synth).

Notes: I ran the curve on T1 only (not T1,T3,T6,T7). The declared price (35, meter 17) is unchanged; the measured first instance (24.4) is below that reserve. The evidence files are modified locally and not pushed yet; I will push them only when you say so.

@repeat98

Copy link
Copy Markdown
Owner

Thanks, that's the curve I asked for, and the unit run of the final package e8d7c794 along with it. Reading T1 only is fine for this push. The refused second instance turned out not to be the cost table: Grain's descriptor prices a track at 35 % of a frame (.reserved = {35, 17} in grain_machine.c, cpuPrice 35), and a Part's CPU budget is 45 %, so a second Grain track never fits. 35 dates from before a price became the mean cost a track adds (MODULE_PERFORMANCE.md, the guard method). If you'd like two Grain tracks in a Part, re-read the price that way; it can go in this release or the next, your call.

Please push now. In point 3 I meant that I sign after the evidence is pushed, so you don't need to wait for another go from me. With the same push:

  1. Merge main (merge, don't rebase). The branch is about 200 commits behind and conflicts in src/engine/assets/octatrack-module-packages.json. Regenerate the generated files with npm run modules:generate rather than resolving them by hand, so frame-costs.json follows your new curve.
  2. The record. TESTING.md and the description still list the unit run of e8d7c794 and the frame-cost curve as "not run". Please move both into the record: twin 4c7eb79b, MKI OS 1.40C, your scene, and the four results, including 102.2 % with T4's time-stretched loop sounding.

Then I'll decide on the cost rule for 0.2.0 and write the approval for the pushed source.

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.

3 participants