diff options
Diffstat (limited to 'apps/codecs/libgme/sgc_emu.h')
-rw-r--r-- | apps/codecs/libgme/sgc_emu.h | 76 |
1 files changed, 36 insertions, 40 deletions
diff --git a/apps/codecs/libgme/sgc_emu.h b/apps/codecs/libgme/sgc_emu.h index 779ef2d923..6595c02daf 100644 --- a/apps/codecs/libgme/sgc_emu.h +++ b/apps/codecs/libgme/sgc_emu.h | |||
@@ -12,16 +12,14 @@ | |||
12 | #include "sms_fm_apu.h" | 12 | #include "sms_fm_apu.h" |
13 | #include "sms_apu.h" | 13 | #include "sms_apu.h" |
14 | #include "m3u_playlist.h" | 14 | #include "m3u_playlist.h" |
15 | #include "track_filter.h" | ||
15 | 16 | ||
16 | typedef short sample_t; | ||
17 | typedef struct Z80_Cpu Sgc_Cpu; | 17 | typedef struct Z80_Cpu Sgc_Cpu; |
18 | 18 | ||
19 | enum { buf_size = 2048 }; | ||
20 | |||
21 | // SGC file header | 19 | // SGC file header |
22 | enum { header_size = 0xA0 }; | 20 | enum { header_size = 0xA0 }; |
23 | struct header_t | 21 | struct header_t |
24 | { | 22 | { |
25 | char tag [4]; // "SGC\x1A" | 23 | char tag [4]; // "SGC\x1A" |
26 | byte vers; // 0x01 | 24 | byte vers; // 0x01 |
27 | byte rate; // 0=NTSC 1=PAL | 25 | byte rate; // 0=NTSC 1=PAL |
@@ -48,12 +46,11 @@ struct header_t | |||
48 | static inline bool valid_tag( struct header_t* h ) | 46 | static inline bool valid_tag( struct header_t* h ) |
49 | { | 47 | { |
50 | return 0 == memcmp( h->tag, "SGC\x1A", 4 ); | 48 | return 0 == memcmp( h->tag, "SGC\x1A", 4 ); |
51 | } | 49 | } |
52 | |||
53 | static inline int effect_count( struct header_t* h ) { return h->last_effect ? h->last_effect - h->first_effect + 1 : 0; } | ||
54 | 50 | ||
51 | static inline int effect_count( struct header_t* h ) { return h->last_effect ? h->last_effect - h->first_effect + 1 : 0; } | ||
55 | 52 | ||
56 | struct Sgc_Emu { | 53 | struct Sgc_Emu { |
57 | bool fm_accessed; | 54 | bool fm_accessed; |
58 | 55 | ||
59 | cpu_time_t play_period; | 56 | cpu_time_t play_period; |
@@ -65,40 +62,28 @@ struct Sgc_Emu { | |||
65 | 62 | ||
66 | // general | 63 | // general |
67 | int voice_count; | 64 | int voice_count; |
65 | int const* voice_types; | ||
68 | int mute_mask_; | 66 | int mute_mask_; |
69 | int tempo; | 67 | int tempo; |
70 | int gain; | 68 | int gain; |
71 | 69 | ||
72 | long sample_rate; | 70 | int sample_rate; |
73 | 71 | ||
74 | // track-specific | 72 | // track-specific |
75 | volatile bool track_ended; | ||
76 | int current_track; | 73 | int current_track; |
77 | int track_count; | 74 | int track_count; |
78 | blargg_long out_time; // number of samples played since start of track | 75 | |
79 | blargg_long emu_time; // number of samples emulator has generated since start of track | 76 | int clock_rate_; |
80 | bool emu_track_ended_; // emulator has reached end of track | ||
81 | |||
82 | // fading | ||
83 | blargg_long fade_start; | ||
84 | int fade_step; | ||
85 | |||
86 | // silence detection | ||
87 | bool ignore_silence; | ||
88 | int max_initial_silence; | ||
89 | int silence_lookahead; // speed to run emulator when looking ahead for silence | ||
90 | long silence_time; // number of samples where most recent silence began | ||
91 | long silence_count; // number of samples of silence to play before using buf | ||
92 | long buf_remain; // number of samples left in silence buffer | ||
93 | |||
94 | long clock_rate_; | ||
95 | unsigned buf_changed_count; | 77 | unsigned buf_changed_count; |
96 | 78 | ||
97 | // M3u Playlist | 79 | // M3u Playlist |
98 | struct M3u_Playlist m3u; | 80 | struct M3u_Playlist m3u; |
81 | struct header_t header; | ||
99 | 82 | ||
100 | sample_t buf [buf_size]; | 83 | struct setup_t tfilter; |
101 | struct Stereo_Buffer stereo_buf; | 84 | struct Track_Filter track_filter; |
85 | |||
86 | struct Multi_Buffer stereo_buf; | ||
102 | 87 | ||
103 | struct Sms_Apu apu; | 88 | struct Sms_Apu apu; |
104 | struct Sms_Fm_Apu fm_apu; | 89 | struct Sms_Fm_Apu fm_apu; |
@@ -106,12 +91,11 @@ struct Sgc_Emu { | |||
106 | Sgc_Cpu cpu; | 91 | Sgc_Cpu cpu; |
107 | 92 | ||
108 | // large items | 93 | // large items |
109 | struct header_t header; | ||
110 | struct Rom_Data rom; | 94 | struct Rom_Data rom; |
111 | byte vectors [page_size + page_padding]; | 95 | byte vectors [page_size + page_padding]; |
96 | byte unmapped_write [0x4000]; | ||
112 | byte ram [0x2000 + page_padding]; | 97 | byte ram [0x2000 + page_padding]; |
113 | byte ram2 [0x4000 + page_padding]; | 98 | byte ram2 [0x4000 + page_padding]; |
114 | byte unmapped_write [0x4000]; | ||
115 | }; | 99 | }; |
116 | 100 | ||
117 | // Basic functionality (see Gme_File.h for file loading/track info functions) | 101 | // Basic functionality (see Gme_File.h for file loading/track info functions) |
@@ -119,41 +103,53 @@ struct Sgc_Emu { | |||
119 | void Sgc_init( struct Sgc_Emu* this ); | 103 | void Sgc_init( struct Sgc_Emu* this ); |
120 | 104 | ||
121 | blargg_err_t Sgc_load_mem( struct Sgc_Emu* this, const void* data, long size ); | 105 | blargg_err_t Sgc_load_mem( struct Sgc_Emu* this, const void* data, long size ); |
122 | 106 | ||
123 | static inline int clock_rate( struct Sgc_Emu* this ) { return this->header.rate ? 3546893 : 3579545; } | 107 | static inline int clock_rate( struct Sgc_Emu* this ) { return this->header.rate ? 3546893 : 3579545; } |
124 | 108 | ||
125 | // 0x2000 bytes | 109 | // 0x2000 bytes |
126 | static inline void set_coleco_bios( struct Sgc_Emu* this, void* p ) { this->coleco_bios = p; } | 110 | static inline void set_coleco_bios( struct Sgc_Emu* this, void* p ) { this->coleco_bios = p; } |
127 | 111 | ||
128 | // Set output sample rate. Must be called only once before loading file. | 112 | // Set output sample rate. Must be called only once before loading file. |
129 | blargg_err_t Sgc_set_sample_rate( struct Sgc_Emu* this, long sample_rate ); | 113 | blargg_err_t Sgc_set_sample_rate( struct Sgc_Emu* this, int sample_rate ); |
130 | 114 | ||
131 | // Start a track, where 0 is the first track. Also clears warning string. | 115 | // Start a track, where 0 is the first track. Also clears warning string. |
132 | blargg_err_t Sgc_start_track( struct Sgc_Emu* this, int track ); | 116 | blargg_err_t Sgc_start_track( struct Sgc_Emu* this, int track ); |
133 | 117 | ||
134 | // Generate 'count' samples info 'buf'. Output is in stereo. Any emulation | 118 | // Generate 'count' samples info 'buf'. Output is in stereo. Any emulation |
135 | // errors set warning string, and major errors also end track. | 119 | // errors set warning string, and major errors also end track. |
136 | blargg_err_t Sgc_play( struct Sgc_Emu* this, long count, sample_t* buf ); | 120 | blargg_err_t Sgc_play( struct Sgc_Emu* this, int count, sample_t* buf ); |
137 | 121 | ||
138 | // Track status/control | 122 | // Track status/control |
139 | 123 | ||
140 | // Number of milliseconds (1000 msec = 1 second) played since beginning of track | 124 | // Number of milliseconds (1000 msec = 1 second) played since beginning of track |
141 | long Track_tell( struct Sgc_Emu* this ); | 125 | int Track_tell( struct Sgc_Emu* this ); |
142 | 126 | ||
143 | // Seek to new time in track. Seeking backwards or far forward can take a while. | 127 | // Seek to new time in track. Seeking backwards or far forward can take a while. |
144 | blargg_err_t Track_seek( struct Sgc_Emu* this, long msec ); | 128 | blargg_err_t Track_seek( struct Sgc_Emu* this, int msec ); |
145 | 129 | ||
146 | // Skip n samples | 130 | // Skip n samples |
147 | blargg_err_t Track_skip( struct Sgc_Emu* this, long n ); | 131 | blargg_err_t Track_skip( struct Sgc_Emu* this, int n ); |
148 | 132 | ||
149 | // Set start time and length of track fade out. Once fade ends track_ended() returns | 133 | // Set start time and length of track fade out. Once fade ends track_ended() returns |
150 | // true. Fade time can be changed while track is playing. | 134 | // true. Fade time can be changed while track is playing. |
151 | void Track_set_fade( struct Sgc_Emu* this, long start_msec, long length_msec ); | 135 | void Track_set_fade( struct Sgc_Emu* this, int start_msec, int length_msec ); |
136 | |||
137 | // True if a track has reached its end | ||
138 | static inline bool Track_ended( struct Sgc_Emu* this ) | ||
139 | { | ||
140 | return track_ended( &this->track_filter ); | ||
141 | } | ||
142 | |||
143 | // Disables automatic end-of-track detection and skipping of silence at beginning | ||
144 | static inline void Track_ignore_silence( struct Sgc_Emu* this, bool disable ) | ||
145 | { | ||
146 | this->track_filter.silence_ignored_ = disable; | ||
147 | } | ||
152 | 148 | ||
153 | // Get track length in milliseconds | 149 | // Get track length in milliseconds |
154 | static inline long Track_get_length( struct Sgc_Emu* this, int n ) | 150 | static inline int Track_get_length( struct Sgc_Emu* this, int n ) |
155 | { | 151 | { |
156 | long length = 120 * 1000; /* 2 minutes */ | 152 | int length = 120 * 1000; /* 2 minutes */ |
157 | if ( (this->m3u.size > 0) && (n < this->m3u.size) ) { | 153 | if ( (this->m3u.size > 0) && (n < this->m3u.size) ) { |
158 | struct entry_t* entry = &this->m3u.entries [n]; | 154 | struct entry_t* entry = &this->m3u.entries [n]; |
159 | length = entry->length; | 155 | length = entry->length; |