summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libgme/ym2413_emu.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libgme/ym2413_emu.h')
-rw-r--r--lib/rbcodec/codecs/libgme/ym2413_emu.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/ym2413_emu.h b/lib/rbcodec/codecs/libgme/ym2413_emu.h
new file mode 100644
index 0000000000..8f52b04fbd
--- /dev/null
+++ b/lib/rbcodec/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
10enum { out_chan_count = 2 }; // stereo
11enum { channel_count = 14 };
12enum { disabled_time = -1 };
13
14struct Ym2413_Emu {
15 OPLL opll;
16
17 // Impl
18 int last_time;
19 short* out;
20};
21
22void Ym2413_init( struct Ym2413_Emu* this );
23
24static 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.
28int Ym2413_set_rate( struct Ym2413_Emu* this, int sample_rate, int clock_rate );
29
30// Resets to power-up state
31void Ym2413_reset( struct Ym2413_Emu* this );
32
33// Mutes voice n if bit n (1 << n) of mask is set
34void Ym2413_mute_voices( struct Ym2413_Emu* this, int mask );
35
36// Writes data to addr
37void Ym2413_write( struct Ym2413_Emu* this, int addr, int data );
38
39// Runs and writes pair_count*2 samples to output
40void Ym2413_run( struct Ym2413_Emu* this, int pair_count, short* out );
41
42static inline void Ym2413_enable( struct Ym2413_Emu* this, bool b ) { this->last_time = b ? 0 : disabled_time; }
43static inline bool Ym2413_enabled( struct Ym2413_Emu* this ) { return this->last_time != disabled_time; }
44static inline void Ym2413_begin_frame( struct Ym2413_Emu* this, short* buf ) { this->out = buf; this->last_time = 0; }
45
46static 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