1 // ---------------------------------------------------------------------------
2 // OPM-like Sound Generator
3 // Copyright (C) cisc 1998, 2003.
4 // ---------------------------------------------------------------------------
5 // $Id: opm.h,v 1.14 2003/06/07 08:25:53 cisc Exp $
15 // ---------------------------------------------------------------------------
17 // OPM に良く似た(?)音を生成する音源ユニット
20 // bool Init(uint clock, uint rate, bool);
21 // 初期化.このクラスを使用する前にかならず呼んでおくこと.
22 // 注意: 線形補完モードは廃止されました
24 // clock: OPM のクロック周波数(Hz)
26 // rate: 生成する PCM の標本周波数(Hz)
31 // bool SetRate(uint clock, uint rate, bool)
35 // void Mix(Sample* dest, int nsamples)
36 // Stereo PCM データを nsamples 分合成し, dest で始まる配列に
38 // ・dest には sample*2 個分の領域が必要
39 // ・格納形式は L, R, L, R... となる.
40 // ・あくまで加算なので,あらかじめ配列をゼロクリアする必要がある
41 // ・FM_SAMPLETYPE が short 型の場合クリッピングが行われる.
42 // ・この関数は音源内部のタイマーとは独立している.
43 // Timer は Count と GetNextEvent で操作する必要がある.
48 // void SetReg(uint reg, uint data)
49 // 音源のレジスタ reg に data を書き込む
58 // bool Count(uint32 t)
59 // 音源のタイマーを t [clock] 進める.
60 // 音源の内部状態に変化があった時(timer オーバーフロー)
63 // uint32 GetNextEvent()
64 // 音源のタイマーのどちらかがオーバーフローするまでに必要な
66 // タイマーが停止している場合は 0 を返す.
68 // void SetVolume(int db_l, int db_r)
69 // 各音源の音量を+−方向に調節する.標準値は 0.
70 // 単位は約 1/2 dB,有効範囲の上限は 20 (10dB)
74 // YM2151(OPM) ----------------------------------------------------
75 class DLL_PREFIX OPM : public Timer
83 bool Init(uint c, uint r, bool=false);
84 bool SetRate(uint c, uint r, bool);
85 void SetLPFCutoff(uint freq);
89 void SetReg(uint addr, uint data);
90 uint GetReg(uint addr);
91 uint ReadStatus() { return status & 0x03; }
93 void Mix(Sample* buffer, int nsamples);
95 void SetVolume(int db_l, int db_r);
96 void SetChannelMask(uint mask);
98 bool ProcessState(void *f, bool loading);
101 void Intr(bool value);
109 void SetStatus(uint bit);
110 void ResetStatus(uint bit);
111 void SetParameter(uint addr, uint data);
113 void RebuildTimeTable();
114 void MixSub(int activech, ISample**);
115 void MixSubL(int activech, ISample**);
132 uint lfo_count_diff_;
134 uint lfo_count_prev_;
155 static void BuildLFOTable();
156 static int amtable[4][OPM_LFOENTS];
157 static int pmtable[4][OPM_LFOENTS];
160 int dbgGetOpOut(int c, int s) { return ch[c].op[s].dbgopout_; }
161 Channel4* dbgGetCh(int c) { return &ch[c]; }