Commit f8eec8d
committed
Wrap pitch mod 256 to match BBC byte register
The BBC's per-channel pitch is a single 8-bit byte and the OS uses
the 6502 ADC for envelope PI updates, so adding a negative PI to a
low pitch wraps up to a high pitch (e.g. 1 + -26 = 0xE7 = 231), not
to a clamped low value.
pitchToHz was clamping to 0..255 and the visualiser was plotting the
unwrapped basePitch + offset directly, so any envelope that drove the
pitch negative came out flat at the lowest BBC note instead of
producing the wrapping pitch effect heard on real hardware. The BBC
User Guide reference envelope 1,1,-26,-36,-45,255,255,255,127,0,0,0,
126,0 exposed this.
Fix is centralised in pitchToHz (clamp -> & 0xff) so any caller can
pass a signed integer; the visualiser now also computes wrapped
pitches for its plot and auto-scale, so what's drawn matches what's
audible.1 parent 38a2272 commit f8eec8d
2 files changed
Lines changed: 12 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
289 | 293 | | |
290 | 294 | | |
291 | | - | |
| 295 | + | |
292 | 296 | | |
293 | 297 | | |
294 | 298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
117 | 119 | | |
118 | 120 | | |
119 | | - | |
| 121 | + | |
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
| |||
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
160 | | - | |
| 162 | + | |
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
| |||
0 commit comments