diff options
Diffstat (limited to 'apps/codecs/libgme/vgm_emu.h')
-rw-r--r-- | apps/codecs/libgme/vgm_emu.h | 103 |
1 files changed, 51 insertions, 52 deletions
diff --git a/apps/codecs/libgme/vgm_emu.h b/apps/codecs/libgme/vgm_emu.h index 773b850a09..8c39482008 100644 --- a/apps/codecs/libgme/vgm_emu.h +++ b/apps/codecs/libgme/vgm_emu.h | |||
@@ -1,11 +1,13 @@ | |||
1 | // Sega Master System/Mark III, Sega Genesis/Mega Drive, BBC Micro VGM music file emulator | 1 | // Sega Master System/Mark III, Sega Genesis/Mega Drive, BBC Micro VGM music file emulator |
2 | 2 | ||
3 | // Game_Music_Emu 0.5.5 | 3 | // Game_Music_Emu 0.6-pre |
4 | #ifndef VGM_EMU_H | 4 | #ifndef VGM_EMU_H |
5 | #define VGM_EMU_H | 5 | #define VGM_EMU_H |
6 | 6 | ||
7 | #include "blargg_common.h" | 7 | #include "blargg_common.h" |
8 | #include "blargg_source.h" | 8 | #include "blargg_source.h" |
9 | |||
10 | #include "track_filter.h" | ||
9 | #include "resampler.h" | 11 | #include "resampler.h" |
10 | #include "multi_buffer.h" | 12 | #include "multi_buffer.h" |
11 | #include "ym2413_emu.h" | 13 | #include "ym2413_emu.h" |
@@ -17,7 +19,6 @@ typedef int fm_time_t; | |||
17 | 19 | ||
18 | enum { fm_time_bits = 12 }; | 20 | enum { fm_time_bits = 12 }; |
19 | enum { blip_time_bits = 12 }; | 21 | enum { blip_time_bits = 12 }; |
20 | enum { buf_size = 2048 }; | ||
21 | 22 | ||
22 | // VGM header format | 23 | // VGM header format |
23 | enum { header_size = 0x40 }; | 24 | enum { header_size = 0x40 }; |
@@ -46,9 +47,9 @@ enum { gme_max_field = 63 }; | |||
46 | struct track_info_t | 47 | struct track_info_t |
47 | { | 48 | { |
48 | /* times in milliseconds; -1 if unknown */ | 49 | /* times in milliseconds; -1 if unknown */ |
49 | long length; | 50 | int length; |
50 | long intro_length; | 51 | int intro_length; |
51 | long loop_length; | 52 | int loop_length; |
52 | 53 | ||
53 | /* empty string if not available */ | 54 | /* empty string if not available */ |
54 | char game [64]; | 55 | char game [64]; |
@@ -63,11 +64,11 @@ struct track_info_t | |||
63 | // YM2413 sound chip emulator. I can provide one I've modified to work with the library. | 64 | // YM2413 sound chip emulator. I can provide one I've modified to work with the library. |
64 | struct Vgm_Emu { | 65 | struct Vgm_Emu { |
65 | int fm_rate; | 66 | int fm_rate; |
66 | long psg_rate; | 67 | int psg_rate; |
67 | long vgm_rate; | 68 | int vgm_rate; |
68 | bool disable_oversampling; | 69 | bool disable_oversampling; |
69 | 70 | ||
70 | long fm_time_offset; | 71 | int fm_time_offset; |
71 | int fm_time_factor; | 72 | int fm_time_factor; |
72 | 73 | ||
73 | int blip_time_factor; | 74 | int blip_time_factor; |
@@ -84,47 +85,34 @@ struct Vgm_Emu { | |||
84 | int dac_amp; | 85 | int dac_amp; |
85 | int dac_disabled; // -1 if disabled | 86 | int dac_disabled; // -1 if disabled |
86 | 87 | ||
87 | struct Blip_Buffer blip_buf; | ||
88 | |||
89 | // general | 88 | // general |
90 | long clock_rate_; | 89 | int current_track; |
90 | int clock_rate_; | ||
91 | unsigned buf_changed_count; | 91 | unsigned buf_changed_count; |
92 | int max_initial_silence; | 92 | int max_initial_silence; |
93 | int voice_count; | 93 | int voice_count; |
94 | int const *voice_types; | ||
94 | int mute_mask_; | 95 | int mute_mask_; |
95 | int tempo; | 96 | int tempo; |
96 | int gain; | 97 | int gain; |
97 | 98 | ||
98 | long sample_rate; | 99 | int sample_rate; |
99 | |||
100 | // track-specific | ||
101 | blargg_long out_time; // number of samples played since start of track | ||
102 | blargg_long emu_time; // number of samples emulator has generated since start of track | ||
103 | bool emu_track_ended_; // emulator has reached end of track | ||
104 | volatile bool track_ended; | ||
105 | |||
106 | // fading | ||
107 | blargg_long fade_start; | ||
108 | int fade_step; | ||
109 | |||
110 | // silence detection | ||
111 | int silence_lookahead; // speed to run emulator when looking ahead for silence | ||
112 | bool ignore_silence; | ||
113 | long silence_time; // number of samples where most recent silence began | ||
114 | long silence_count; // number of samples of silence to play before using buf | ||
115 | long buf_remain; // number of samples left in silence buffer | ||
116 | 100 | ||
117 | // larger items at the end | 101 | // larger items at the end |
118 | struct track_info_t info; | 102 | struct track_info_t info; |
119 | sample_t buf_ [buf_size]; | 103 | |
104 | struct setup_t tfilter; | ||
105 | struct Track_Filter track_filter; | ||
120 | 106 | ||
121 | struct Ym2612_Emu ym2612; | 107 | struct Ym2612_Emu ym2612; |
122 | struct Ym2413_Emu ym2413; | 108 | struct Ym2413_Emu ym2413; |
123 | 109 | ||
124 | struct Sms_Apu psg; | 110 | struct Sms_Apu psg; |
125 | struct Blip_Synth pcm; | 111 | struct Blip_Synth pcm; |
112 | struct Blip_Buffer blip_buf; | ||
113 | |||
126 | struct Resampler resampler; | 114 | struct Resampler resampler; |
127 | struct Stereo_Buffer buf; | 115 | struct Multi_Buffer stereo_buf; |
128 | }; | 116 | }; |
129 | 117 | ||
130 | void Vgm_init( struct Vgm_Emu* this ); | 118 | void Vgm_init( struct Vgm_Emu* this ); |
@@ -135,7 +123,7 @@ static inline void Vgm_disable_oversampling( struct Vgm_Emu* this, bool disable | |||
135 | 123 | ||
136 | // Header for currently loaded file | 124 | // Header for currently loaded file |
137 | static inline struct header_t *header( struct Vgm_Emu* this ) { return (struct header_t*) this->file_begin; } | 125 | static inline struct header_t *header( struct Vgm_Emu* this ) { return (struct header_t*) this->file_begin; } |
138 | 126 | ||
139 | // Basic functionality (see Gme_File.h for file loading/track info functions) | 127 | // Basic functionality (see Gme_File.h for file loading/track info functions) |
140 | blargg_err_t Vgm_load_mem( struct Vgm_Emu* this, byte const* new_data, long new_size, bool parse_info ); | 128 | blargg_err_t Vgm_load_mem( struct Vgm_Emu* this, byte const* new_data, long new_size, bool parse_info ); |
141 | 129 | ||
@@ -144,34 +132,46 @@ blargg_err_t Vgm_load_mem( struct Vgm_Emu* this, byte const* new_data, long new_ | |||
144 | static inline bool uses_fm( struct Vgm_Emu* this ) { return Ym2612_enabled( &this->ym2612 ) || Ym2413_enabled( &this->ym2413 ); } | 132 | static inline bool uses_fm( struct Vgm_Emu* this ) { return Ym2612_enabled( &this->ym2612 ) || Ym2413_enabled( &this->ym2413 ); } |
145 | 133 | ||
146 | // Set output sample rate. Must be called only once before loading file. | 134 | // Set output sample rate. Must be called only once before loading file. |
147 | blargg_err_t Vgm_set_sample_rate( struct Vgm_Emu* this, long sample_rate ); | 135 | blargg_err_t Vgm_set_sample_rate( struct Vgm_Emu* this, int sample_rate ); |
148 | 136 | ||
149 | // Start a track, where 0 is the first track. Also clears warning string. | 137 | // Start a track, where 0 is the first track. Also clears warning string. |
150 | blargg_err_t Vgm_start_track( struct Vgm_Emu* this ); | 138 | blargg_err_t Vgm_start_track( struct Vgm_Emu* this ); |
151 | 139 | ||
152 | // Generate 'count' samples info 'buf'. Output is in stereo. Any emulation | 140 | // Generate 'count' samples info 'buf'. Output is in stereo. Any emulation |
153 | // errors set warning string, and major errors also end track. | 141 | // errors set warning string, and major errors also end track. |
154 | blargg_err_t Vgm_play( struct Vgm_Emu* this, long count, sample_t* buf ); | 142 | blargg_err_t Vgm_play( struct Vgm_Emu* this, int count, sample_t* buf ); |
155 | 143 | ||
156 | // Track status/control | 144 | // Track status/control |
157 | 145 | ||
158 | // Number of milliseconds (1000 msec = 1 second) played since beginning of track | 146 | // Number of milliseconds (1000 msec = 1 second) played since beginning of track |
159 | long Track_tell( struct Vgm_Emu* this ); | 147 | int Track_tell( struct Vgm_Emu* this ); |
160 | 148 | ||
161 | // Seek to new time in track. Seeking backwards or far forward can take a while. | 149 | // Seek to new time in track. Seeking backwards or far forward can take a while. |
162 | blargg_err_t Track_seek( struct Vgm_Emu* this, long msec ); | 150 | blargg_err_t Track_seek( struct Vgm_Emu* this, int msec ); |
163 | 151 | ||
164 | // Skip n samples | 152 | // Skip n samples |
165 | blargg_err_t Track_skip( struct Vgm_Emu* this, long n ); | 153 | blargg_err_t Track_skip( struct Vgm_Emu* this, int n ); |
166 | 154 | ||
167 | // Set start time and length of track fade out. Once fade ends track_ended() returns | 155 | // Set start time and length of track fade out. Once fade ends track_ended() returns |
168 | // true. Fade time can be changed while track is playing. | 156 | // true. Fade time can be changed while track is playing. |
169 | void Track_set_fade( struct Vgm_Emu* this, long start_msec, long length_msec ); | 157 | void Track_set_fade( struct Vgm_Emu* this, int start_msec, int length_msec ); |
158 | |||
159 | // True if a track has reached its end | ||
160 | static inline bool Track_ended( struct Vgm_Emu* this ) | ||
161 | { | ||
162 | return track_ended( &this->track_filter ); | ||
163 | } | ||
164 | |||
165 | // Disables automatic end-of-track detection and skipping of silence at beginning | ||
166 | static inline void Track_ignore_silence( struct Vgm_Emu* this, bool disable ) | ||
167 | { | ||
168 | this->track_filter.silence_ignored_ = disable; | ||
169 | } | ||
170 | 170 | ||
171 | // Get track length in milliseconds | 171 | // Get track length in milliseconds |
172 | static inline long Track_get_length( struct Vgm_Emu* this ) | 172 | static inline int Track_get_length( struct Vgm_Emu* this ) |
173 | { | 173 | { |
174 | long length = this->info.length; | 174 | int length = this->info.length; |
175 | if ( length <= 0 ) | 175 | if ( length <= 0 ) |
176 | { | 176 | { |
177 | length = this->info.intro_length + 2 * this->info.loop_length; // intro + 2 loops | 177 | length = this->info.intro_length + 2 * this->info.loop_length; // intro + 2 loops |
@@ -181,20 +181,20 @@ static inline long Track_get_length( struct Vgm_Emu* this ) | |||
181 | 181 | ||
182 | return length; | 182 | return length; |
183 | } | 183 | } |
184 | 184 | ||
185 | // Sound customization | 185 | // Sound customization |
186 | 186 | ||
187 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. | 187 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. |
188 | // Track length as returned by track_info() assumes a tempo of 1.0. | 188 | // Track length as returned by track_info() assumes a tempo of 1.0. |
189 | void Sound_set_tempo( struct Vgm_Emu* this, int t ); | 189 | void Sound_set_tempo( struct Vgm_Emu* this, int t ); |
190 | 190 | ||
191 | // Mute/unmute voice i, where voice 0 is first voice | 191 | // Mute/unmute voice i, where voice 0 is first voice |
192 | void Sound_mute_voice( struct Vgm_Emu* this, int index, bool mute ); | 192 | void Sound_mute_voice( struct Vgm_Emu* this, int index, bool mute ); |
193 | 193 | ||
194 | // Set muting state of all voices at once using a bit mask, where -1 mutes them all, | 194 | // Set muting state of all voices at once using a bit mask, where -1 mutes them all, |
195 | // 0 unmutes them all, 0x01 mutes just the first voice, etc. | 195 | // 0 unmutes them all, 0x01 mutes just the first voice, etc. |
196 | void Sound_mute_voices( struct Vgm_Emu* this, int mask ); | 196 | void Sound_mute_voices( struct Vgm_Emu* this, int mask ); |
197 | 197 | ||
198 | // Change overall output amplitude, where 1.0 results in minimal clamping. | 198 | // Change overall output amplitude, where 1.0 results in minimal clamping. |
199 | // Must be called before set_sample_rate(). | 199 | // Must be called before set_sample_rate(). |
200 | static inline void Sound_set_gain( struct Vgm_Emu* this, int g ) | 200 | static inline void Sound_set_gain( struct Vgm_Emu* this, int g ) |
@@ -203,5 +203,4 @@ static inline void Sound_set_gain( struct Vgm_Emu* this, int g ) | |||
203 | this->gain = g; | 203 | this->gain = g; |
204 | } | 204 | } |
205 | 205 | ||
206 | |||
207 | #endif | 206 | #endif |