Vibrato — HLE reconstruction and DSP bytecode

DSPHLE selector 0x07 · program image prog50_vibrato · Intervention-pinned (a panel control was driven and the moving C-RAM cell identified).

LFO-swept pitch modulation; rate=0x02 (~4 Hz), depth=0x05.

This page pairs the bytecode the effect runs on the NEC µPD6383GF with the high-level reconstruction that makes it audible in MAME. The reconstruction is not the chip’s microcode — it is a textbook DSP block built from the decoded meaning of that microcode, and reading the two together is how the bytecode is understood (and, in time, driven toward a faithful low-level emulation). See also the signal-flow flowchart.

The bytecode below is the source of truth; the HLE reconstruction is not. The HLE is our best current interpretation and may contain mistakes — where the two disagree, the bytecode wins, and a better HLE should be updated here. This page is the permanent archive of the reference HLE: it is kept here even after the code is eventually removed from the MAME sources.

DSP bytecode (reverse-engineered microprogram)

The disassembled image the chip executes for this effect. Source (regenerable): dsp/disasm/prog50_vibrato.dsm.

; Reverse-engineered disassembly of the KN5000 effects-DSP microcode
; (NEC uPD6383GF), recovered from the original firmware.  The microcode is the
; work of its original authors; this is a disassembly for preservation and
; interoperability, and no claim of copyright is made over the disassembled program.
; KN5000 effects-DSP program -- VIBRATO
; image rep algo 50  |  slots 50  |  unit 0 (I-RAM load 84)
; family modulation  |  confidence high  |  53 words, 12 class-A multiplies (2 named)
; role: vibrato: wet-only modulated delay
; coefficient cursor base 0x00
;
; GENERATED by dsp/tools/gen_dsp_disasm.py -- DO NOT EDIT.
; Put labels/comments in the matching dsp/sym/*.sym; analysis in dsp/algorithms/.

  w0    00400008BC   ?word   0x00400008BC   ; 040.0.00.8BC  hi12{?6 res=040}  [SPECULATIVE: lo12 bit-11 modifier word + pointer-mode (bit11-family); the base selector/register is OPEN]
  w1    088013000B   ?word   0x088013000B   ; 880.1.30.00B  hi12{ESC ?7 res=080}  [external delay-DRAM READ (FORCED, adjudication-round5 sect. 3 -- addr8 bit 6 is the direction field and 0x60 is the WRITE; this REVERSES R1 F1, which bounded the read latency to one repetition when the descriptors need twenty words); this end moves with the user's DELAY (ms) knob, and the delay is READ_CELL - WRITE_CELL; addr8 0x30 also marks the FIRST DRAM access of a body, 37 of 38 distinct images (R3 sect. 6.2). external delay-DRAM access; address = DESCRIPTOR_CELL[k] + G, from the host bank behind pointer ...825 / tag 0x4C (R3, PROVEN BY CONSTRUCTION) -- the k-th class-1 escape word of a body takes the k-th cell of that body's own descriptor block (the IDENTITY map, FORCED in adjudication-round5 sect. 1), so the address is NOT in this word]
  w2    000020B1CD   ld      (p),(p)+11
  w3    000020040E   ld      acc,(p)+0
  w4    0212200000   mac.b   (p)0,(p)+0 ; mem[p]<-acc, acc=0
  w5    09001601D5   dly.w  dsc[k],p+96
  w6    0192A40000   mac.b   (p)0,c+,(p)+64 ; store SUPPRESSED (bit7)
        ; C-RAM[0x00] (coeff, base 0x00 MEASURED)
  w7    00822001C0   mac.b   (p),(p)+0
  w8    0C4032044C   ldreg   r4C,#25          ; immediate -> the register lo12 selects
  w9    0A00000041   ?word   0x0A00000041   ; A00.0.00.041  hi12{ESC f98=2}  [head of a fixed 3-word template (S-5); operands SRC 0x01/ACT 0x01 dark]
  w10   08801202C7   dly.r  dsc[k],p+32
  w11   0102ABD4C8   ?word   0x0102ABD4C8   ; 102.A.BD.4C8  hi12{f98=1 f31=1} cur+  [gain multiply (same op in phaser all-pass and reverb diffuser)]
        ; C-RAM[0x01] (coeff, base 0x00 MEASURED)
  w12   0000204407   ld.st   acc,(p)+4
  w13   0092A00200   mac.b   c,c+,(p)+0 ; store SUPPRESSED (bit7)
        ; C-RAM[0x02] (coeff, base 0x00 MEASURED)
  w14   00822001C0   mac.b   (p),(p)+0
  w15   0094A00200   wrap    acc,c+          ; acc <- datum(acc) & coef  (LFO modulus)
        ; C-RAM[0x03] (coeff, base 0x00 MEASURED)
  w16   0000200447   ?word   0x0000200447   ; 000.2.00.447  hi12{-}  [SPECULATIVE (prospective, not measured): SRC 0x11 = ACCB (2nd accumulator)]
  w17   0092200700   ?word   0x0092200700   ; 092.2.00.700  hi12{ST f31=1 ?7 res=080}  [SPECULATIVE (prospective, not measured): SRC 0x1C = control/mod source into MAC (100% MAC-consumed; LFO in mod fx, envelope/AGC in dynamics) -- NOT LFO-only: present in 19 non-LFO programs (dsp_datapath_fingerprint)]
  w18   0000A001D5   ld      (p),c+,(p)+0
        ; C-RAM[0x04] (coeff, base 0x00 MEASURED)
  w19   0182200000   mac.b   (p)0,(p)+0
  w20   0040000C63   ?word   0x0040000C63   ; 040.0.00.C63  hi12{?6 res=040}  [SPECULATIVE (prospective, not measured): SRC 0x11 = ACCB (2nd accumulator)]
  w21   00006184CD   ?word   0x00006184CD   ; 000.6.18.4CD  hi12{-}  [table-lookup idiom, class-6 addr8 = table selector (INFERRED)]
  w22   00124011CE   ?word   0x00124011CE   ; 012.4.01.1CE  hi12{ST f31=1}  [table-lookup idiom, third word (INFERRED)]
  w23   01042FE1CE   post    (p),(p)-2
  w24   0102200000   mac.b   (p)0,(p)+0
  w25   0000A00415   ld      acc,c+,(p)+0
        ; C-RAM[0x05] (coeff, base 0x00 MEASURED)
        ; coeff C-RAM[0x05] = op0x66[0] (role mix/tap, INFERRED)
  w26   0212200000   mac.b   (p)0,(p)+0 ; mem[p]<-acc, acc=0
  w27   0000203407   ld.st   acc,(p)+3
  w28   0092A00200   mac.b   c,c+,(p)+0 ; store SUPPRESSED (bit7)
        ; C-RAM[0x06] (coeff, base 0x00 MEASURED)
  w29   00822001C0   mac.b   (p),(p)+0
  w30   0094A00200   wrap    acc,c+          ; acc <- datum(acc) & coef  (LFO modulus)
        ; C-RAM[0x07] (coeff, base 0x00 MEASURED)
  w31   0000200447   ?word   0x0000200447   ; 000.2.00.447  hi12{-}  [SPECULATIVE (prospective, not measured): SRC 0x11 = ACCB (2nd accumulator)]
  w32   0092200700   ?word   0x0092200700   ; 092.2.00.700  hi12{ST f31=1 ?7 res=080}  [SPECULATIVE (prospective, not measured): SRC 0x1C = control/mod source into MAC (100% MAC-consumed; LFO in mod fx, envelope/AGC in dynamics) -- NOT LFO-only: present in 19 non-LFO programs (dsp_datapath_fingerprint)]
  w33   0000A001D5   ld      (p),c+,(p)+0
        ; C-RAM[0x08] (coeff, base 0x00 MEASURED)
  w34   0182200000   mac.b   (p)0,(p)+0
  w35   0040000C63   ?word   0x0040000C63   ; 040.0.00.C63  hi12{?6 res=040}  [SPECULATIVE (prospective, not measured): SRC 0x11 = ACCB (2nd accumulator)]
  w36   00006184CD   ?word   0x00006184CD   ; 000.6.18.4CD  hi12{-}  [table-lookup idiom, class-6 addr8 = table selector (INFERRED)]
  w37   00124011CE   ?word   0x00124011CE   ; 012.4.01.1CE  hi12{ST f31=1}  [table-lookup idiom, third word (INFERRED)]
  w38   01042FE1CE   post    (p),(p)-2
  w39   0102200000   mac.b   (p)0,(p)+0
  w40   0000AF4415   ld      acc,c+,(p)-12
        ; C-RAM[0x09] (coeff, base 0x00 MEASURED)
        ; coeff C-RAM[0x09] = op0x66[1] (role mix/tap, INFERRED)
  w41   021220A1CD   mac     (p),(p)+10 ; mem[p]<-acc, acc=0
  w42   00002021CE   ld      (p),(p)+2
  w43   0212200407   mac.st  acc,(p)+0 ; mem[p]<-acc, acc=0
  w44   09001601D5   dly.w  dsc[k],p+96
  w45   0192A41000   mac.b   (p)0,c+,(p)+65 ; store SUPPRESSED (bit7)
        ; C-RAM[0x0A] (coeff, base 0x00 MEASURED)
  w46   00822001C0   mac.b   (p),(p)+0
  w47   0C4032044C   ldreg   r4C,#25          ; immediate -> the register lo12 selects
  w48   0A00000041   ?word   0x0A00000041   ; A00.0.00.041  hi12{ESC f98=2}  [head of a fixed 3-word template (S-5); operands SRC 0x01/ACT 0x01 dark]
  w49   08801202C7   dly.r  dsc[k],p+32
  w50   0102AAD4C8   ?word   0x0102AAD4C8   ; 102.A.AD.4C8  hi12{f98=1 f31=1} cur+  [gain multiply (same op in phaser all-pass and reverb diffuser)]
        ; C-RAM[0x0B] (coeff, base 0x00 MEASURED)
  w51   0880160000   dly.w  dsc[k],p+96
  w52   040010E000   endblk  #0E             ; END OF BLOCK -- the last word of a block

HLE reconstruction (MAME, kn5000_tonegen.cpp)

The decode of the bytecode above, rebuilt as audible DSP. Two parts: the parameter refresh (reads the decoded C-RAM coefficient cells once per update) and the per-sample insert (the signal processing). Default OFF, behind the DSPHLE research port. Source: src/mame/matsushita/kn5000_tonegen.cpp.

Parameter refresh (decode the C-RAM coefficients):

	const bool vib_hle = (dsphle == 7);
	double ens_inc = 0.0, ens_tap[3] = { 0, 0, 0 };
	double vib_inc = 0.0, vib_depth = 0.0, vib_wet = 0.0;
	if (ens_hle || vib_hle)
	{
		auto q22m = [](u32 v) -> double {
			int32_t s = (v & 0x800000) ? int32_t(v) - 0x1000000 : int32_t(v);
			return double(s) / 4194304.0; };
		const bool bit1 = (dspcfg & 2) != 0;
		const double cs = bit1 ? 1.0 : 2.0;
		const double sr48 = double(STREAM_RATE) / 44100.0;
		if (ens_hle)
		{
			const double inc = double(m_dsp1->cram_read(0x00) & 0xffffff) * cs;
			ens_inc = std::clamp(inc * 44100.0 / 8388608.0, 0.02, 12.0) / double(STREAM_RATE);
			// three per-channel voice tap delays (L cells 0x02/0x04/0x06), in 44.1k samples
			ens_tap[0] = std::clamp(double(m_dsp1->cram_read(0x02) & 0xffffff) * cs, 2.0, 1500.0) * sr48;
			ens_tap[1] = std::clamp(double(m_dsp1->cram_read(0x04) & 0xffffff) * cs, 2.0, 1500.0) * sr48;
			ens_tap[2] = std::clamp(double(m_dsp1->cram_read(0x06) & 0xffffff) * cs, 2.0, 1500.0) * sr48;
		}
		if (vib_hle)
		{
			const double inc = double(m_dsp1->cram_read(0x02) & 0xffffff) * cs;
			vib_inc = std::clamp(inc * 44100.0 / 8388608.0, 0.02, 12.0) / double(STREAM_RATE);
			vib_depth = std::clamp(q22m(m_dsp1->cram_read(0x05)) * cs, 0.0, 1.0) * 240.0 * sr48;  // sweep
			vib_wet   = std::clamp(q22m(m_dsp1->cram_read(0x0C)) * cs, 0.0, 1.0);                  // mix
		}

Per-sample insert (the reconstructed signal path):

		if (vib_hle)
		{
			m_vib_phase += vib_inc;
			if (m_vib_phase >= 1.0) m_vib_phase -= 1.0;
			const double sl = double(mix_l) / 32768.0, sr = double(mix_r) / 32768.0;
			m_vib_l.write(sl); m_vib_r.write(sr);
			const double d = vib_depth + vib_depth * (0.5 + 0.5 * std::sin(2.0 * M_PI * m_vib_phase));
			const double tl = m_vib_l.read(std::max(2.0, d)), tr = m_vib_r.read(std::max(2.0, d));
			const double w = std::max(vib_wet, 0.5);               // vibrato is mostly wet
			mix_l = int32_t(((1.0 - w) * sl + w * tl) * 32768.0);
			mix_r = int32_t(((1.0 - w) * sr + w * tr) * 32768.0);
		}