1 /*************************************************************************** 2 Yamaha YM2151 driver (version 2.150 final beta) - May, 11th 2002 3 4 (c) 1997-2002 Jarek Burczynski (s0246@poczta.onet.pl, bujar@mame.net) 5 Some of the optimizing ideas by Tatsuyuki Satoh 6 7 This driver is based upon the MAME source code, with some minor 8 modifications to integrate it into the Cannonball framework. 9 10 See http://mamedev.org/source/docs/license.txt for more details. 11 ***************************************************************************/ 12 13 #pragma once 14 15 #include <stdint.h> 16 17 /* struct describing a single operator */ 18 typedef struct 19 { 20 uint32_t phase; /* accumulated operator phase */ 21 uint32_t freq; /* operator frequency count */ 22 int32_t dt1; /* current DT1 (detune 1 phase inc/decrement) value */ 23 uint32_t mul; /* frequency count multiply */ 24 uint32_t dt1_i; /* DT1 index * 32 */ 25 uint32_t dt2; /* current DT2 (detune 2) value */ 26 27 signed int *connects; /* operator output 'direction' */ 28 29 /* only M1 (operator 0) is filled with this data: */ 30 signed int *mem_connect; /* where to put the delayed sample (MEM) */ 31 int32_t mem_value; /* delayed sample (MEM) value */ 32 33 /* channel specific data; note: each operator number 0 contains channel specific data */ 34 uint32_t fb_shift; /* feedback shift value for operators 0 in each channel */ 35 int32_t fb_out_curr; /* operator feedback value (used only by operators 0) */ 36 int32_t fb_out_prev; /* previous feedback value (used only by operators 0) */ 37 uint32_t kc; /* channel KC (copied to all operators) */ 38 uint32_t kc_i; /* just for speedup */ 39 uint32_t pms; /* channel PMS */ 40 uint32_t ams; /* channel AMS */ 41 /* end of channel specific data */ 42 43 uint32_t AMmask; /* LFO Amplitude Modulation enable mask */ 44 uint32_t state; /* Envelope state: 4-attack(AR) 3-decay(D1R) 2-sustain(D2R) 1-release(RR) 0-off */ 45 uint8_t eg_sh_ar; /* (attack state) */ 46 uint8_t eg_sel_ar; /* (attack state) */ 47 uint32_t tl; /* Total attenuation Level */ 48 int32_t volume; /* current envelope attenuation level */ 49 uint8_t eg_sh_d1r; /* (decay state) */ 50 uint8_t eg_sel_d1r; /* (decay state) */ 51 uint32_t d1l; /* envelope switches to sustain state after reaching this level */ 52 uint8_t eg_sh_d2r; /* (sustain state) */ 53 uint8_t eg_sel_d2r; /* (sustain state) */ 54 uint8_t eg_sh_rr; /* (release state) */ 55 uint8_t eg_sel_rr; /* (release state) */ 56 57 uint32_t key; /* 0=last key was KEY OFF, 1=last key was KEY ON */ 58 59 uint32_t ks; /* key scale */ 60 uint32_t ar; /* attack rate */ 61 uint32_t d1r; /* decay rate */ 62 uint32_t d2r; /* sustain rate */ 63 uint32_t rr; /* release rate */ 64 65 uint32_t reserved0; /**/ 66 uint32_t reserved1; /**/ 67 68 } YM2151Operator; 69 70 71 void YM_Create(uint32_t clock); 72 73 void YM_init(int rate, int fps); 74 void YM_stream_update(uint16_t* stream, int samples); 75 76 void YM_write_reg(int r, int v); 77 uint32_t YM_read_status(); 78 79