summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libgme/ay_emu.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libgme/ay_emu.h')
-rw-r--r--lib/rbcodec/codecs/libgme/ay_emu.h169
1 files changed, 169 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/ay_emu.h b/lib/rbcodec/codecs/libgme/ay_emu.h
new file mode 100644
index 0000000000..7334167876
--- /dev/null
+++ b/lib/rbcodec/codecs/libgme/ay_emu.h
@@ -0,0 +1,169 @@
1// Sinclair Spectrum AY music file emulator
2
3// Game_Music_Emu 0.6-pre
4#ifndef AY_EMU_H
5#define AY_EMU_H
6
7#include "blargg_source.h"
8
9#include "multi_buffer.h"
10#include "z80_cpu.h"
11#include "ay_apu.h"
12#include "m3u_playlist.h"
13#include "track_filter.h"
14
15// 64K memory to load code and data into before starting track. Caller
16// must parse the AY file.
17enum { mem_size = 0x10000 };
18enum { ram_addr = 0x4000 }; // where official RAM starts
19
20// AY file header
21enum { header_size = 0x14 };
22struct header_t
23{
24 byte tag [8];
25 byte vers;
26 byte player;
27 byte unused [2];
28 byte author [2];
29 byte comment [2];
30 byte max_track;
31 byte first_track;
32 byte track_info [2];
33};
34
35struct file_t {
36 struct header_t const* header;
37 byte const* tracks;
38 byte const* end; // end of file data
39};
40
41struct mem_t {
42 uint8_t padding1 [0x100];
43 uint8_t ram [mem_size + 0x100];
44};
45
46struct Ay_Emu {
47 struct file_t file;
48
49 struct Blip_Buffer* beeper_output;
50 int beeper_delta;
51 int last_beeper;
52 int beeper_mask;
53
54 addr_t play_addr;
55 cpu_time_t play_period;
56 cpu_time_t next_play;
57
58 int cpc_latch;
59 bool spectrum_mode;
60 bool cpc_mode;
61
62 // general
63 int voice_count;
64 int const* voice_types;
65 int mute_mask_;
66 int tempo;
67 int gain;
68
69 int sample_rate;
70
71 // track-specific
72 int current_track;
73 int track_count;
74
75 int clock_rate_;
76 unsigned buf_changed_count;
77
78 // M3u Playlist
79 struct M3u_Playlist m3u;
80
81 // large items
82 struct setup_t tfilter;
83 struct Track_Filter track_filter;
84
85 struct Ay_Apu apu;
86 struct Multi_Buffer stereo_buf; // NULL if using custom buffer
87 struct Z80_Cpu cpu;
88 struct mem_t mem;
89};
90
91// Basic functionality (see Gme_File.h for file loading/track info functions)
92void Ay_init( struct Ay_Emu* this );
93
94blargg_err_t Ay_load_mem( struct Ay_Emu* this, byte const in [], long size );
95
96// Set output sample rate. Must be called only once before loading file.
97blargg_err_t Ay_set_sample_rate( struct Ay_Emu* this, int sample_rate );
98
99// Start a track, where 0 is the first track. Also clears warning string.
100blargg_err_t Ay_start_track( struct Ay_Emu* this, int track );
101
102// Generate 'count' samples info 'buf'. Output is in stereo. Any emulation
103// errors set warning string, and major errors also end track.
104blargg_err_t Ay_play( struct Ay_Emu* this, int count, sample_t* buf );
105
106
107// Track status/control
108
109// Number of milliseconds (1000 msec = 1 second) played since beginning of track
110int Track_tell( struct Ay_Emu* this );
111
112// Seek to new time in track. Seeking backwards or far forward can take a while.
113blargg_err_t Track_seek( struct Ay_Emu* this, int msec );
114
115// Skip n samples
116blargg_err_t Track_skip( struct Ay_Emu* this, int n );
117
118// Set start time and length of track fade out. Once fade ends track_ended() returns
119// true. Fade time can be changed while track is playing.
120void Track_set_fade( struct Ay_Emu* this, int start_msec, int length_msec );
121
122// True if a track has reached its end
123static inline bool Track_ended( struct Ay_Emu* this )
124{
125 return track_ended( &this->track_filter );
126}
127
128// Disables automatic end-of-track detection and skipping of silence at beginning
129static inline void Track_ignore_silence( struct Ay_Emu* this, bool disable )
130{
131 this->track_filter.silence_ignored_ = disable;
132}
133
134// Get track length in milliseconds
135int Track_get_length( struct Ay_Emu* this, int n );
136
137// Sound customization
138
139// Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed.
140// Track length as returned by track_info() assumes a tempo of 1.0.
141void Sound_set_tempo( struct Ay_Emu* this, int t );
142
143// Mute/unmute voice i, where voice 0 is first voice
144void Sound_mute_voice( struct Ay_Emu* this, int index, bool mute );
145
146// Set muting state of all voices at once using a bit mask, where -1 mutes them all,
147// 0 unmutes them all, 0x01 mutes just the first voice, etc.
148void Sound_mute_voices( struct Ay_Emu* this, int mask );
149
150// Change overall output amplitude, where 1.0 results in minimal clamping.
151// Must be called before set_sample_rate().
152static inline void Sound_set_gain( struct Ay_Emu* this, int g )
153{
154 assert( !this->sample_rate ); // you must set gain before setting sample rate
155 this->gain = g;
156}
157
158// Emulation (You shouldn't touch these)
159void cpu_out( struct Ay_Emu* this, cpu_time_t, addr_t, int data );
160void cpu_out_( struct Ay_Emu* this, cpu_time_t, addr_t, int data );
161bool run_cpu( struct Ay_Emu* this, cpu_time_t end );
162
163static inline void disable_beeper( struct Ay_Emu *this )
164{
165 this->beeper_mask = 0;
166 this->last_beeper = 0;
167}
168
169#endif