diff options
Diffstat (limited to 'apps/codecs/libgme/ym2413_emu.h')
-rw-r--r-- | apps/codecs/libgme/ym2413_emu.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/apps/codecs/libgme/ym2413_emu.h b/apps/codecs/libgme/ym2413_emu.h new file mode 100644 index 0000000000..71369e9c88 --- /dev/null +++ b/apps/codecs/libgme/ym2413_emu.h | |||
@@ -0,0 +1,61 @@ | |||
1 | // YM2413 FM sound chip emulator interface | ||
2 | |||
3 | // Game_Music_Emu 0.6-pre | ||
4 | #ifndef YM2413_EMU_H | ||
5 | #define YM2413_EMU_H | ||
6 | |||
7 | #include "blargg_common.h" | ||
8 | #include "emu2413.h" | ||
9 | |||
10 | enum { out_chan_count = 2 }; // stereo | ||
11 | enum { channel_count = 14 }; | ||
12 | enum { disabled_time = -1 }; | ||
13 | |||
14 | struct Ym2413_Emu { | ||
15 | OPLL opll; | ||
16 | |||
17 | // Impl | ||
18 | int last_time; | ||
19 | short* out; | ||
20 | }; | ||
21 | |||
22 | void Ym2413_init( struct Ym2413_Emu* this ); | ||
23 | |||
24 | static inline bool Ym2413_supported( void ) { return true; } | ||
25 | |||
26 | // Sets output sample rate and chip clock rates, in Hz. Returns non-zero | ||
27 | // if error. | ||
28 | int Ym2413_set_rate( struct Ym2413_Emu* this, double sample_rate, double clock_rate ); | ||
29 | |||
30 | // Resets to power-up state | ||
31 | void Ym2413_reset( struct Ym2413_Emu* this ); | ||
32 | |||
33 | // Mutes voice n if bit n (1 << n) of mask is set | ||
34 | void Ym2413_mute_voices( struct Ym2413_Emu* this, int mask ); | ||
35 | |||
36 | // Writes data to addr | ||
37 | void Ym2413_write( struct Ym2413_Emu* this, int addr, int data ) ICODE_ATTR; | ||
38 | |||
39 | // Runs and writes pair_count*2 samples to output | ||
40 | void Ym2413_run( struct Ym2413_Emu* this, int pair_count, short* out ) ICODE_ATTR; | ||
41 | |||
42 | static inline void Ym2413_enable( struct Ym2413_Emu* this, bool b ) { this->last_time = b ? 0 : disabled_time; } | ||
43 | static inline bool Ym2413_enabled( struct Ym2413_Emu* this ) { return this->last_time != disabled_time; } | ||
44 | static inline void Ym2413_begin_frame( struct Ym2413_Emu* this, short* buf ) { this->out = buf; this->last_time = 0; } | ||
45 | |||
46 | static inline int Ym2413_run_until( struct Ym2413_Emu* this, int time ) | ||
47 | { | ||
48 | int count = time - this->last_time; | ||
49 | if ( count > 0 ) | ||
50 | { | ||
51 | if ( this->last_time < 0 ) | ||
52 | return false; | ||
53 | this->last_time = time; | ||
54 | short* p = this->out; | ||
55 | this->out += count * out_chan_count; | ||
56 | Ym2413_run( this, count, p ); | ||
57 | } | ||
58 | return true; | ||
59 | } | ||
60 | |||
61 | #endif | ||