# ADPCM-A Six channels of fixed-rate 4-bit ADPCM from the ADPCM-A ROM bus. Citations as in [registers.md](registers.md); `lle:adpcma` runs feed the chip a constant ROM byte (every byte the bus reads is the same), which fixes the nibble stream without serving a ROM. ## Registers (part II) | Address | Bits | Function | Evidence | | --- | --- | --- | --- | | $00 | D7 DM, D5-D0 channels 6-1 | write with DM = 0 keys the set channels on, DM = 1 off | DOC AM "DUMP/ADPCM-A ON" | | $01 | D5-D0 ATL | total level, 0 to -47.25 dB in 0.75 dB steps, $3F = 0 dB | DOC AM "ADPCM-A Total Level" | | $02 | test | write 0 | DOC AM "TEST ($02)" | | $08-$0D | D7 L, D6 R, D4-D0 ACL | per channel: outputs, level 0 to -23.25 dB in 0.75 dB steps, $1F = 0 dB | DOC AM "Output Select/Channel Level" | | $10-$15, $18-$1D | start address bits 15-8, 23-16 | per channel, 256-byte units | DOC AM "Start Addr. L/H" | | $20-$25, $28-$2D | end address bits 15-8, 23-16 | per channel, 256-byte units | DOC AM "End Addr. L/H" | - The start and end high registers must have equal top nibbles: a sample may not cross a 1 MiB page. [DOC AM note under "End Addr."] - /IC clears them all to $00. [DOC AM §9(b)] (C5: ymfm resets $08-$0D to $DF.) ## Rate and order - One decoded sample per channel every **432 clocks** (18.52 kHz at 8 MHz): each new value holds for 3 output samples. [OBSERVED lle:adpcma; DOC AM §3(c) "18.5 kHz"] ymfm clocks ADPCM-A on every third FM sample (its envelope cycle). [DOC ymfm ymfm_opn.cpp:2167-2169] - After key-on the first decoded value reached the word 8 samples later. [OBSERVED lle:adpcma] The latency's dependence on the key-on's phase and on the channel number is not measured: **U4**. - Each byte gives two nibbles, high nibble first. [DOC ymfm ymfm_adpcm.cpp:160-189; DOC OPNA p. 49 for the OPNA's ADPCM] The closed box's alternating streams (byte $80: nibbles 8 then 0) began with the negative step, which fits high first. [OBSERVED lle:adpcma] ## The decoder The closed box's output for ten constant bytes ($11 ... $FF) matches, in all ten, exactly one of four candidate decoders (`python3 -I validation/fit_adpcma.py`): [OBSERVED lle:adpcma] - **Steps**: ss = floor(16 x 1.1^n), n = 0..48 (16 ... 1552). The list is Dialogic's [DOC Dialogic, *ADPCM Algorithm*, 00-1366-001, 1988, as cited in msm6295-python docs/decoder.md] and ymfm's [DOC ymfm ymfm_adpcm.cpp:192-201]; `validation/check_tables.py` checks both against the formula in exact arithmetic. Rung 0 computes it. - **Delta**: (2L + 1) x ss / 8 with one truncation, L the three magnitude bits, negated when bit 3 is set. [OBSERVED; DOC ymfm ymfm_adpcm.cpp:202-204] Dialogic's term-by-term form (ss B2 + ss/2 B1 + ss/4 B0 + ss/8) truncates differently and does not match (6 of 10 streams). [DOC Dialogic] - **Index**: n += -1, -1, -1, -1, **+2, +5, +7, +9** for L = 0..7, clamped to 0..48. [OBSERVED; DOC ymfm ymfm_adpcm.cpp:210-211] Dialogic's +2, +4, +6, +8 does not match. [DOC Dialogic] Contradiction **C4**: the YM2610 is not the OKI/Dialogic decoder in this respect; the core follows the closed box and ymfm, provisional (no hardware recording settles it). - **Accumulator**: 12 bits, **wrapping** (3767 became -329 in the $77 stream), starting at 0 with n = 0 on key-on. [OBSERVED; DOC ymfm ymfm_adpcm.cpp:128-132, 206-207] (Dialogic: "nothing about overflow". [DOC Dialogic]) - The YM2610 manual's only word on this decoder is second-hand: "it seems to be the YM2608's rhythm part with external ROM addressing". [DOC AM "Additional Information from Others"] ## Level and output - Attenuation v = (ATL ^ $3F) + (ACL ^ $1F) in 0.75 dB steps; v >= 63 is silent; otherwise the word gets ((acc << 4) x (15 - (v & 7))) >> (5 + (v >> 3)), low two bits cleared, added to L and/or R. [DOC ymfm ymfm_adpcm.cpp:226-245] The closed box gave exactly this for 13 ATL/ACL pairs (v = 0, 1, 2, 7, 8, 15, 31, 63, 94). [OBSERVED lle:adpcma] The steps are 0.75 dB as the manual says, realised as a 3-bit mantissa and a shift. [DOC AM] - Full level and accumulator +2047 give +15,352 in the word. (From the formula.) ## End of a sample - The channel stops after the last nibble of the end address's 256-byte block (end inclusive): start = end = $0000 plays 512 nibbles; $0000-$0001, 1,024. [OBSERVED lle:pages; DOC ymfm ymfm_adpcm.cpp:169-177] - Only the low 20 address bits are compared: start $1000 (address $100000) with end $0000 stops after one block. [OBSERVED lle:pages; DOC ymfm ymfm_adpcm.cpp:164-173, which says a game (twinspri) depends on it] - The end raises the channel's status 1 flag (unless masked by $1C, see [registers.md](registers.md)) and silences the channel. [DOC AM "ADPCM-A Synthesis Process"; OBSERVED lle:flagctl] - Keying a channel on again while its end flag is still set **plays** it. [OBSERVED lle:flagctl] That the channel then stays silent until the flag is cleared is [HYPOTHESIS: was NGD *ADPCM*], which cited no test. Contradiction **C6** (its other side now a set-aside source's); the core follows the closed box, provisional. A hardware recording or a test ROM would settle it. - Key-on while a channel plays restarts it from its start address (ymfm's "QUESTION: repeated key ons restart the sample?") [DOC ymfm ymfm_adpcm.cpp:122-132]: not measured, **U4**.