summaryrefslogtreecommitdiff
path: root/apps/codecs/libgme/gbs_emu.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libgme/gbs_emu.h')
-rw-r--r--apps/codecs/libgme/gbs_emu.h82
1 files changed, 37 insertions, 45 deletions
diff --git a/apps/codecs/libgme/gbs_emu.h b/apps/codecs/libgme/gbs_emu.h
index 409cf2d6c2..72671b4658 100644
--- a/apps/codecs/libgme/gbs_emu.h
+++ b/apps/codecs/libgme/gbs_emu.h
@@ -9,15 +9,12 @@
9#include "gb_apu.h" 9#include "gb_apu.h"
10#include "gb_cpu.h" 10#include "gb_cpu.h"
11#include "m3u_playlist.h" 11#include "m3u_playlist.h"
12 12#include "track_filter.h"
13/* typedef uint8_t byte; */
14typedef short sample_t;
15 13
16enum { joypad_addr = 0xFF00 }; 14enum { joypad_addr = 0xFF00 };
17enum { ram_addr = 0xA000 }; 15enum { ram_addr = 0xA000 };
18enum { hi_page = 0xFF00 - ram_addr }; 16enum { hi_page = 0xFF00 - ram_addr };
19enum { io_base = 0xFF00 }; 17enum { io_base = 0xFF00 };
20enum { buf_size = 2048 };
21 18
22// Selects which sound hardware to use. AGB hardware is cleaner than the 19// Selects which sound hardware to use. AGB hardware is cleaner than the
23// others. Doesn't take effect until next start_track(). 20// others. Doesn't take effect until next start_track().
@@ -59,36 +56,19 @@ struct Gbs_Emu {
59 blip_time_t next_play; 56 blip_time_t next_play;
60 57
61 // Sound 58 // Sound
62 long clock_rate_; 59 int clock_rate_;
63 long sample_rate_; 60 int sample_rate_;
64 unsigned buf_changed_count; 61 unsigned buf_changed_count;
65 int voice_count_; 62 int voice_count_;
63 int const* voice_types_;
64 int mute_mask_;
66 int gain_; 65 int gain_;
67 int tempo_; 66 int tempo_;
68 67
69 // track-specific 68 // track-specific
70 byte track_count; 69 byte track_count;
71 volatile bool track_ended;
72 int current_track_; 70 int current_track_;
73 blargg_long out_time; // number of samples played since start of track
74 blargg_long emu_time; // number of samples emulator has generated since start of track
75 bool emu_track_ended_; // emulator has reached end of track
76
77 // fading
78 blargg_long fade_start;
79 int fade_step;
80
81 // silence detection
82 // Disable automatic end-of-track detection and skipping of silence at beginning
83 bool ignore_silence;
84 71
85 int max_initial_silence;
86 int mute_mask_;
87 int silence_lookahead; // speed to run emulator when looking ahead for silence
88 long silence_time; // number of samples where most recent silence began
89 long silence_count; // number of samples of silence to play before using buf
90 long buf_remain; // number of samples left in silence buffer
91
92 // Larger items at the end 72 // Larger items at the end
93 // Header for currently loaded file 73 // Header for currently loaded file
94 struct header_t header; 74 struct header_t header;
@@ -96,11 +76,12 @@ struct Gbs_Emu {
96 // M3u Playlist 76 // M3u Playlist
97 struct M3u_Playlist m3u; 77 struct M3u_Playlist m3u;
98 78
79 struct setup_t tfilter;
80 struct Track_Filter track_filter;
81
99 struct Gb_Apu apu; 82 struct Gb_Apu apu;
100 struct Gb_Cpu cpu; 83 struct Gb_Cpu cpu;
101 struct Stereo_Buffer stereo_buf; 84 struct Multi_Buffer stereo_buf;
102
103 sample_t buf [buf_size];
104 85
105 // rom & ram 86 // rom & ram
106 struct Rom_Data rom; 87 struct Rom_Data rom;
@@ -116,36 +97,48 @@ void Gbs_init( struct Gbs_Emu* this );
116void Gbs_stop( struct Gbs_Emu* this ); 97void Gbs_stop( struct Gbs_Emu* this );
117 98
118// Loads a file from memory 99// Loads a file from memory
119blargg_err_t Gbs_load( struct Gbs_Emu* this, void* data, long size ); 100blargg_err_t Gbs_load_mem( struct Gbs_Emu* this, void* data, long size );
120 101
121// Set output sample rate. Must be called only once before loading file. 102// Set output sample rate. Must be called only once before loading file.
122blargg_err_t Gbs_set_sample_rate( struct Gbs_Emu* this, long sample_rate ); 103blargg_err_t Gbs_set_sample_rate( struct Gbs_Emu* this, int sample_rate );
123 104
124// Start a track, where 0 is the first track. Also clears warning string. 105// Start a track, where 0 is the first track. Also clears warning string.
125blargg_err_t Gbs_start_track( struct Gbs_Emu* this, int ); 106blargg_err_t Gbs_start_track( struct Gbs_Emu* this, int );
126 107
127// Generate 'count' samples info 'buf'. Output is in stereo. Any emulation 108// Generate 'count' samples info 'buf'. Output is in stereo. Any emulation
128// errors set warning string, and major errors also end track. 109// errors set warning string, and major errors also end track.
129blargg_err_t Gbs_play( struct Gbs_Emu* this, long count, sample_t* buf ); 110blargg_err_t Gbs_play( struct Gbs_Emu* this, int count, sample_t* buf );
130 111
131// Track status/control 112// Track status/control
132// Number of milliseconds (1000 msec = 1 second) played since beginning of track 113// Number of milliseconds (1000 msec = 1 second) played since beginning of track
133long Track_tell( struct Gbs_Emu* this ); 114int Track_tell( struct Gbs_Emu* this );
134 115
135// Seek to new time in track. Seeking backwards or far forward can take a while. 116// Seek to new time in track. Seeking backwards or far forward can take a while.
136blargg_err_t Track_seek( struct Gbs_Emu* this, long msec ); 117blargg_err_t Track_seek( struct Gbs_Emu* this, int msec );
137 118
138// Skip n samples 119// Skip n samples
139blargg_err_t Track_skip( struct Gbs_Emu* this, long n ); 120blargg_err_t Track_skip( struct Gbs_Emu* this, int n );
140 121
141// Set start time and length of track fade out. Once fade ends track_ended() returns 122// Set start time and length of track fade out. Once fade ends track_ended() returns
142// true. Fade time can be changed while track is playing. 123// true. Fade time can be changed while track is playing.
143void Track_set_fade( struct Gbs_Emu* this, long start_msec, long length_msec ); 124void Track_set_fade( struct Gbs_Emu* this, int start_msec, int length_msec );
125
126// True if a track has reached its end
127static inline bool Track_ended( struct Gbs_Emu* this )
128{
129 return track_ended( &this->track_filter );
130}
131
132// Disables automatic end-of-track detection and skipping of silence at beginning
133static inline void Track_ignore_silence( struct Gbs_Emu* this, bool disable )
134{
135 this->track_filter.silence_ignored_ = disable;
136}
144 137
145// Get track length in milliseconds 138// Get track length in milliseconds
146static inline long Track_get_length( struct Gbs_Emu* this, int n ) 139static inline int Track_get_length( struct Gbs_Emu* this, int n )
147{ 140{
148 long length = 120 * 1000; /* 2 minutes */ 141 int length = 120 * 1000; /* 2 minutes */
149 if ( (this->m3u.size > 0) && (n < this->m3u.size) ) { 142 if ( (this->m3u.size > 0) && (n < this->m3u.size) ) {
150 struct entry_t* entry = &this->m3u.entries [n]; 143 struct entry_t* entry = &this->m3u.entries [n];
151 length = entry->length; 144 length = entry->length;
@@ -175,19 +168,18 @@ static inline void Sound_set_gain( struct Gbs_Emu* this, int g )
175 this->gain_ = g; 168 this->gain_ = g;
176} 169}
177 170
178
179// Emulation (You shouldn't touch these) 171// Emulation (You shouldn't touch these)
180 172
181blargg_err_t Run_clocks( struct Gbs_Emu* this, blip_time_t duration ); 173blargg_err_t run_clocks( struct Gbs_Emu* this, blip_time_t duration );
182void Set_bank( struct Gbs_Emu* this, int ); 174void set_bank( struct Gbs_Emu* this, int );
183void Update_timer( struct Gbs_Emu* this ); 175void update_timer( struct Gbs_Emu* this );
184 176
185// Runs CPU until time becomes >= 0 177// Runs CPU until time becomes >= 0
186void Run_cpu( struct Gbs_Emu* this ); 178void run_cpu( struct Gbs_Emu* this );
187 179
188// Reads/writes memory and I/O 180// Reads/writes memory and I/O
189int Read_mem( struct Gbs_Emu* this, addr_t addr ); 181int read_mem( struct Gbs_Emu* this, addr_t addr );
190void Write_mem( struct Gbs_Emu* this, addr_t addr, int data ); 182void write_mem( struct Gbs_Emu* this, addr_t addr, int data );
191 183
192// Current time 184// Current time
193static inline blip_time_t Time( struct Gbs_Emu* this ) 185static inline blip_time_t Time( struct Gbs_Emu* this )
@@ -195,6 +187,6 @@ static inline blip_time_t Time( struct Gbs_Emu* this )
195 return Cpu_time( &this->cpu ) + this->end_time; 187 return Cpu_time( &this->cpu ) + this->end_time;
196} 188}
197 189
198void Jsr_then_stop( struct Gbs_Emu* this, byte const [] ); 190void jsr_then_stop( struct Gbs_Emu* this, byte const [] );
199 191
200#endif 192#endif