fmopl.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef FMOPL_H
  2. #define FMOPL_H
  3. typedef void (*OPL_TIMERHANDLER)(void *param, int channel, double interval_Sec);
  4. /* !!!!! here is private section , do not access there member direct !!!!! */
  5. /* Saving is necessary for member of the 'R' mark for suspend/resume */
  6. /* ---------- OPL one of slot ---------- */
  7. typedef struct fm_opl_slot {
  8. int32_t TL; /* total level :TL << 8 */
  9. int32_t TLL; /* adjusted now TL */
  10. uint8_t KSR; /* key scale rate :(shift down bit) */
  11. int32_t *AR; /* attack rate :&AR_TABLE[AR<<2] */
  12. int32_t *DR; /* decay rate :&DR_TALBE[DR<<2] */
  13. int32_t SL; /* sustin level :SL_TALBE[SL] */
  14. int32_t *RR; /* release rate :&DR_TABLE[RR<<2] */
  15. uint8_t ksl; /* keyscale level :(shift down bits) */
  16. uint8_t ksr; /* key scale rate :kcode>>KSR */
  17. uint32_t mul; /* multiple :ML_TABLE[ML] */
  18. uint32_t Cnt; /* frequency count : */
  19. uint32_t Incr; /* frequency step : */
  20. /* envelope generator state */
  21. uint8_t eg_typ; /* envelope type flag */
  22. uint8_t evm; /* envelope phase */
  23. int32_t evc; /* envelope counter */
  24. int32_t eve; /* envelope counter end point */
  25. int32_t evs; /* envelope counter step */
  26. int32_t evsa; /* envelope step for AR :AR[ksr] */
  27. int32_t evsd; /* envelope step for DR :DR[ksr] */
  28. int32_t evsr; /* envelope step for RR :RR[ksr] */
  29. /* LFO */
  30. uint8_t ams; /* ams flag */
  31. uint8_t vib; /* vibrate flag */
  32. /* wave selector */
  33. int32_t **wavetable;
  34. }OPL_SLOT;
  35. /* ---------- OPL one of channel ---------- */
  36. typedef struct fm_opl_channel {
  37. OPL_SLOT SLOT[2];
  38. uint8_t CON; /* connection type */
  39. uint8_t FB; /* feed back :(shift down bit) */
  40. int32_t *connect1; /* slot1 output pointer */
  41. int32_t *connect2; /* slot2 output pointer */
  42. int32_t op1_out[2]; /* slot1 output for selfeedback */
  43. /* phase generator state */
  44. uint32_t block_fnum; /* block+fnum : */
  45. uint8_t kcode; /* key code : KeyScaleCode */
  46. uint32_t fc; /* Freq. Increment base */
  47. uint32_t ksl_base; /* KeyScaleLevel Base step */
  48. uint8_t keyon; /* key on/off flag */
  49. } OPL_CH;
  50. /* OPL state */
  51. typedef struct fm_opl_f {
  52. int clock; /* master clock (Hz) */
  53. int rate; /* sampling rate (Hz) */
  54. double freqbase; /* frequency base */
  55. double TimerBase; /* Timer base time (==sampling time) */
  56. uint8_t address; /* address register */
  57. uint8_t status; /* status flag */
  58. uint8_t statusmask; /* status mask */
  59. uint32_t mode; /* Reg.08 : CSM , notesel,etc. */
  60. /* Timer */
  61. int T[2]; /* timer counter */
  62. uint8_t st[2]; /* timer enable */
  63. /* FM channel slots */
  64. OPL_CH *P_CH; /* pointer of CH */
  65. int max_ch; /* maximum channel */
  66. /* Rhythm sention */
  67. uint8_t rhythm; /* Rhythm mode , key flag */
  68. /* time tables */
  69. int32_t AR_TABLE[76]; /* attack rate tables */
  70. int32_t DR_TABLE[76]; /* decay rate tables */
  71. uint32_t FN_TABLE[1024]; /* fnumber -> increment counter */
  72. /* LFO */
  73. int32_t *ams_table;
  74. int32_t *vib_table;
  75. int32_t amsCnt;
  76. int32_t amsIncr;
  77. int32_t vibCnt;
  78. int32_t vibIncr;
  79. /* wave selector enable flag */
  80. uint8_t wavesel;
  81. /* external event callback handler */
  82. OPL_TIMERHANDLER TimerHandler; /* TIMER handler */
  83. void *TimerParam; /* TIMER parameter */
  84. } FM_OPL;
  85. /* ---------- Generic interface section ---------- */
  86. FM_OPL *OPLCreate(int clock, int rate);
  87. void OPLDestroy(FM_OPL *OPL);
  88. void OPLSetTimerHandler(FM_OPL *OPL, OPL_TIMERHANDLER TimerHandler,
  89. void *param);
  90. int OPLWrite(FM_OPL *OPL,int a,int v);
  91. unsigned char OPLRead(FM_OPL *OPL,int a);
  92. int OPLTimerOver(FM_OPL *OPL,int c);
  93. void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int length);
  94. #endif