A Bitcoin block hash is 32 bytes of proof-of-work noise. dubdutduc does not map those bytes onto pitches. It turns the hash into a deterministic random stream, then walks a fixed composition pipeline — and every fork in that pipeline asks the stream for the next number.
How the hash is used
Think of the hash as a playlist seed, not as music data. The composer never reads “byte 3 → MIDI note 60”. Instead:
- Take the block hash (lowercase hex). If it is exactly 32 bytes of hex, those 32 bytes are the seed. Otherwise hash the string with SHA-256 and use that.
- Feed the 32-byte seed into a ChaCha8 pseudorandom number generator. From here on, the hash itself is never looked at again — only this RNG stream.
- Run a fixed recipe (key → form → melody → harmony → bass → drums). Whenever the recipe must choose among prepared options (which mode? which chord row? which rhythm? which pitch among legal candidates?), it draws the next integer or float from the RNG.
block hash
|
v
32-byte seed ---> ChaCha8 RNG ---> stream of numbers
|
v
choose(mode), choose(progression),
choose(rhythm), pick(pitch), ...
|
v
MIDI notes (deterministic)
Same hash → same RNG stream → same choices → same MIDI. Change one bit of the hash → a different stream → different picks at every fork, so the piece changes, while it still obeys the same musical rules.
Weighted choices (e.g. Ionian more often than Lydian) roll
IntN(totalWeight) and walk the weight table.
Uniform lists (tempos, ensembles, pitch candidates) use
xs[IntN(len(xs))].
Probabilistic rules (e.g. “70% chord tone on the strong beat”) roll a float in [0,1).
What the RNG decides, in order
The stream is consumed left-to-right. Early draws set the piece’s identity; later draws fill in notes. Approximate order:
| Step | Drawn from the hash-seeded RNG |
|---|---|
| 1. Key | Root (0–11), then weighted mode |
| 2. Groove | Meter (4/4 or 3/4), BPM from a fixed list, chip ensemble |
| 3. Harmony plan | One open / middle / cadence chord-degree row for that mode |
| 4. Melody rhythms | Body patterns a,b / x,y and phrase endings |
| 5. Melody pitches | Among legal scale/chord tones under contour rules; floats for “which rule branch” |
| 6. Comping | Pulse style, or arp direction / step size |
| 7. Bass | Which root/fifth pattern for the meter |
| 8. Drums | Groove + fill patterns; small velocity jitter per hit |
| Throughout | Velocity accents get a tiny ± jitter from the same stream |
Everything not listed — 16-bar form, allowed progressions, scale grammar, MIDI registers — is hard-coded. The hash only steers which legal option wins.
Global parameters
| Parameter | How the RNG picks it |
|---|---|
| Root | IntN(12) — uniform pitch class |
| Mode | All 7 modes, weighted: Ionian/Dorian/Mixolydian/Aeolian 16, Phrygian 14, Lydian 12, Locrian 10 |
| Meter | Weighted: 4/4 (3) or 3/4 (1) |
| BPM | Uniform from {100, 112, 124, 136, 148, 160, 172, 184, 196, 208} |
| Ensemble | Uniform chip lead / chords / bass set (drums always on) |
Timing uses PPQ = 480 ticks per quarter. One sixteenth = 120 ticks.
A bar is beats × 480 ticks.
Form — always 16 bars
Structure is fixed. The hash only picks which progression rows fill it.
bars 1–4 phrase A open progression <-- RNG picks one open row bars 5–8 phrase A same chords; melody mostly restated bars 9–12 phrase B middle / contrast <-- RNG picks one middle row bars 13–16 cadence ends on tonic <-- RNG picks one cadence row
Degrees are 0-based scale degrees — e.g. Ionian {0, 4, 5, 3} → I–V–vi–IV.
If a bar is IV and the next is I, and the IV seventh is dominant in that key,
it becomes a dominant 7th (secondary-dominant color into I). That rule is fixed, not random.
Chord voicing
Voicings are not random. Each bar picks the close-position layout in MIDI 47–64 that best matches the previous bar (least motion, near center 55). The hash already chose the chord; this step only finds its register.
Melody
Rhythm (RNG picks patterns)
From meter-specific catalogs, the stream picks body patterns and endings:
| Bars | Pattern |
|---|---|
| 1–4 | a, b, a, end — a/b/end drawn from weighted lists |
| 5–8 | reuse a, b, a; new end; bars 5–7 copy melody pitches from 1–3 (no new pitch draws) |
| 9–12 | new x, y, x, end |
| 13–16 | a, b, y, final (final = whole-bar hold, fixed) |
Pitch (RNG picks among legal tones)
For each attack, hard rules first narrow the candidates (scale tones, chord tones, leap resolution, approach into the next bar, final tonic). Only then does the RNG break ties or take a probabilistic branch:
| When | Rule (RNG role) |
|---|---|
| Last note of the piece | Tonic — deterministic among nearest tonics |
| Downbeat | Chord tone; 40% roll asks to avoid repeating previous pitch |
| Long note (≥ 6 sixteenths) | Chord tone, avoid repeat; pick among best-cost tones |
| Strong beat (beat 3 in 4/4) | 70% roll → chord tone, else walk |
| Last note filling a non-final bar | Approach tone into next chord (side may be random if tied) |
| Otherwise | Walk: float picks step / repeat / skip / leap among scale indices |
Non-final notes are shortened to 85% of the slot. Velocity uses a fixed phrase swell plus a small hash-driven jitter.
Harmony track
- chip-arp — RNG: up (70%) vs down, step 2 vs 1 (35%). Notes are the bar’s voicing tones in order. Final bar holds the root.
- chip-chord — RNG picks a pulsed rhythm; every hit plays all voicing pitches. Length ≈ 70% of the slot (full on the final bar).
Bass
RNG picks a meter-specific root/fifth/rest pattern. Pitch placement in MIDI 34–48 (nearest previous root) is deterministic. Final bar = one root for the whole bar. Non-final notes shortened to 92%.
Drums
General MIDI channel 10 pitches are fixed:
kick 36 snare 38 closed hat 42 open hat 46
- RNG picks a body groove for the meter
- RNG picks a fill for every 4th bar (not the last)
- Final bar uses a fixed ending figure
- Each hit gets velocity ±2 from the stream
MIDI file
After composition, notes are encoded as a format-1 Standard MIDI File
(no further hash draws): conductor track with title Block <hash>,
tempo and meter; then melody, harmony, bass, and drums on channel 10.
In one sentence
The block hash seeds a RNG; the composer asks that RNG at every choice point inside a fixed rulebook; the result is a unique but musically legal 16-bar chiptune for that block.