# ADPCM-B (delta-T) One channel of variable-rate 4-bit ADPCM from the ADPCM-B ROM bus, with linear interpolation to the 55.5 kHz output rate. The YM2610 manual says it "seems to be the same as the ADPCM in the YM2608" [DOC AM "Additional Information"], so the OPNA manual's ADPCM chapter (pp. 43-54) is the algorithm's source, restricted to what the YM2610 has: ROM playback only (no CPU memory access, recording, DRAM, prescaler, limit, DAC or PCM registers). Citations as in [registers.md](registers.md). ## Registers (part I) | Address | Bits | Function | Evidence | | --- | --- | --- | --- | | $10 | D7 START, D4 REPEAT, D0 RESET | start; loop at the end; reset (also clears REPEAT) | DOC AM "Control 1" | | $11 | D7 L, D6 R | outputs | DOC AM "Control 2" | | $12, $13 | start address bits 15-8, 23-16 | 256-byte units | DOC AM "Start Address" | | $14, $15 | end address bits 15-8, 23-16 | 256-byte units | DOC AM "End Address" | | $19, $1A | delta-N low, high | the rate | DOC AM "Delta-N" | | $1B | level | linear, $FF = maximum | DOC AM "EG Control"; OPNA p. 49 | | $1C | flag control | see registers.md (C2) | | - /IC clears $10, $11 and $1C; the others are undefined. [DOC AM §9(b)] ymfm resets them all to 0 and forces $10's external-memory bit on and its record bit off for the YM2610. [DOC ymfm ymfm_opn.cpp:2016-2020, ymfm_adpcm.cpp:362-367] ## Rate - f = delta-N / 65536 x 55.5 kHz: OPNA "DELTA-N = (f / 55.5 kHz) x 2^16" [DOC OPNA p. 49]. The closed box takes one nibble per output sample at delta-N 65535 and one every two at 32768. [OBSERVED lle:adpcmb] The ajworld transcription prints "delta-N / 256 x 55.5 kHz" with a translator's note that the original read "216" [DOC AM "Delta-N"]: a garbled 2^16, contradiction **C7**, not followed. - The manual's range 1.8-55.5 kHz. [DOC AM §3] ## The decoder From the OPNA manual's synthesis (the analysis formulas used in reverse): [DOC OPNA pp. 44-45, Table 5-1] - x(n+1) = x(n) + (1 - 2 L4) (L3 + L2/2 + L1/4 + 1/8) delta(n) - delta(n+1) = f(L3 L2 L1) x delta(n), f = 57/64 (x4), 77/64, 102/64, 128/64, 153/64; delta clamped to 127..24576; start x = 0, delta = 127. - ymfm computes the step as (2L + 1) x delta / 8 with one truncation, clamps x to 16 bits, and scales delta by the same factors with integer division. [DOC ymfm ymfm_adpcm.cpp:521-531, ymfm_adpcm.h:301-302] - The closed box saturates: a constant $77 stream holds at +16,316 in the word, $F0 and $0F at -16,320. [OBSERVED lle:adpcmb] That fits a 16-bit clamp scaled by level / 2^11 (32767 x 255 / 2048 = 4,080 x 4). [HYPOTHESIS, from the numbers] - Linear interpolation between the last two decoded values, at 55.5 kHz [DOC AM §3; OPNA p. 49]: at delta-N 16384 the closed box's word steps every second sample, not every fourth. [OBSERVED lle:adpcmb] ymfm weights the two values by the 16-bit position counter. [DOC ymfm ymfm_adpcm.cpp:546-551] ## Output scaling: U2, C8 - The closed box's ADPCM-B contribution is always a multiple of 4. A $00 stream (x = 15, 30, 45, ...) at level $FF, delta-N 65535 gives 8, 16, 24, 32, 40, 48, 52, 60, ...; an $88 stream gives -12, -20, -28, ...; streams that alternate +15 and 0 ($08, $80) give **0 throughout**. [OBSERVED lle:adpcmb] - ymfm's (interpolated x x level) >> 9 gives 7, 14, 22, ... for the first and +-7 for the alternating ones. [DOC ymfm ymfm_adpcm.cpp:548-551] Contradiction **C8**. The rounding (and whether the alternating case is a dead zone near zero or a property of the interpolator) is **U2**: the experiment is a sweep of constant bytes, levels and delta-N through `lle2610_probe adpcmb`, fitted like `fit_adpcma.py` does for ADPCM-A. Until then the core's scaling is provisional and the ADPCM-B rung compares with the closed box directly. ## End, repeat and flags - The end address is inclusive: start = end = $0000 raised the end flag (status 1 bit 7) after 73,397 clocks at delta-N 65535, about 512 nibbles. [OBSERVED lle:flagctl; DOC ymfm ymfm_adpcm.h:348 (end + 1) << 8, minus one] - REPEAT restarts from the start address at the end; without it the channel stops and raises flag B. [DOC AM "Control 1", "ADPCM-B Synthesis Process"; ymfm ymfm_adpcm.cpp:480-496] Repeat was not measured: **U3**. - Writing $10 = $01 forces a stop; $10 = $00 ends playback. [DOC AM "ADPCM-B Synthesis Process"] - Addresses are 24 bits, a full 16 MiB without page limits. [DOC AM §3(B)] - ADPCM-B's ROM bus (PMPX, /POE, the address on PAD/PA) was not measured: **U4**.