-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneric.cpp
205 lines (169 loc) · 5.96 KB
/
generic.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "config.h"
#include "base.h"
#include "reader.h"
#include "coleco.h"
#include <gme/blargg_endian.h>
#include <gme/Gym_Emu.h>
#include <gme/Sgc_Emu.h>
#undef HEADER_STRING
#define HEADER_STRING(i,n,f) meta_add((i), (n), (f), sizeof(f))
static gme_type_t const gme_type_list_ [] = { gme_ay_type, gme_gbs_type, gme_gym_type, gme_hes_type, gme_kss_type, gme_sap_type, gme_sgc_type };
static unsigned identify_header( void const* header )
{
switch ( get_be32( header ) )
{
case BLARGG_4CHAR('Z','X','A','Y'): return 1;
case BLARGG_4CHAR('G','B','S',0x01): return 2;
case BLARGG_4CHAR('G','Y','M','X'): return 3;
case BLARGG_4CHAR('H','E','S','M'): return 4;
case BLARGG_4CHAR('K','S','C','C'):
case BLARGG_4CHAR('K','S','S','X'): return 5;
case BLARGG_4CHAR('S','A','P',0x0D): return 6;
case BLARGG_4CHAR('S','G','C',0x1A): return 7;
}
return 0;
}
static struct coleco_setup
{
coleco_setup()
{
for ( unsigned i = 0; i < 0x2000; i++ )
{
image [i] *= 820109;
}
Sgc_Emu::set_coleco_bios( image );
}
} setup_stuff;
class input_generic : public input_gep
{
unsigned type;
public:
static bool g_is_our_path( const char * p_path, const char * p_extension )
{
for ( unsigned i = 0, j = tabsize( gme_type_list_ ); i < j; ++i )
{
if ( ! ( cfg_format_enable & ( 1 << ( i + 3 ) ) ) ) continue;
if ( ! stricmp( p_extension, gme_type_list_[ i ]->extension_ ) )
return 1;
}
return 0;
}
void open( service_ptr_t<file> p_filehint, const char * p_path, t_input_open_reason p_reason, abort_callback & p_abort )
{
if ( p_reason == input_open_info_write ) throw exception_io_data();
input_gep::open( p_filehint, p_path, p_reason, p_abort );
char header [4];
m_file->read_object_t( header, p_abort );
type = identify_header( header );
if ( !type ) throw exception_io_data();
gme_type_t const gtype = gme_type_list_[ type - 1 ];
// Disallow type / extension overlap
if ( stricmp( gtype->extension_, pfc::string_extension( p_path ) ) ) throw exception_io_data();
m_file->seek( 0, p_abort );
foobar_Data_Reader rdr( m_file, p_abort );
if ( p_reason == input_open_info_read )
emu = gtype->new_info();
else if ( p_reason == input_open_decode )
emu = gtype->new_emu();
if ( !emu ) throw std::bad_alloc();
if ( p_reason == input_open_decode )
{
if ( gtype == gme_gym_type )
{
static_cast<Gym_Emu *>( emu )->disable_oversampling();
setup_effects( false );
}
else
setup_effects();
}
ERRCHK( emu->set_sample_rate( sample_rate ) );
ERRCHK( emu->load( rdr ) );
handle_warning();
if ( p_reason == input_open_decode && gtype != gme_gym_type )
setup_effects_2();
m_file.release();
if ( gtype != gme_gym_type )
{
pfc::string_replace_extension list( p_path, "m3u" );
if ( filesystem::g_exists( list, p_abort ) )
{
filesystem::g_open( p_filehint, list, filesystem::open_mode_read, p_abort );
foobar_Data_Reader rdr( p_filehint, p_abort );
ERRCHK( emu->load_m3u( rdr ) );
handle_warning();
}
}
}
unsigned get_subsong_count()
{
return emu->track_count();
}
t_uint32 get_subsong( unsigned p_subsong )
{
return p_subsong;
}
void get_info( t_uint32 p_subsong, file_info & p_info, abort_callback & p_abort )
{
p_info.info_set("codec", gme_type_list_[ type - 1 ]->extension_ );
p_info.info_set( "encoding", "synthesized" );
//p_info.info_set_int("samplerate", sample_rate);
p_info.info_set_int("channels", 2);
p_info.info_set_int("bitspersample", 16);
track_info_t i;
ERRCHK( emu->track_info( &i, p_subsong ) );
int length = 0;
double dlength = double(tag_song_ms + tag_fade_ms) * .001;
if ( i.intro_length != -1 && i.loop_length != -1 )
length = i.intro_length + i.loop_length * ( i.repeat_count > 0 ? i.repeat_count : 2 );
else if ( i.length != -1 )
length = i.length;
if ( length )
{
tag_song_ms = length;
tag_fade_ms = i.fade_length;
dlength = double(tag_song_ms + tag_fade_ms) * .001;
}
HEADER_STRING( p_info, "system", i.system );
HEADER_STRING( p_info, "album", i.game );
HEADER_STRING( p_info, "title", i.song );
HEADER_STRING( p_info, "artist", i.author );
HEADER_STRING( p_info, "date", i.date );
HEADER_STRING( p_info, "engineer", i.engineer );
HEADER_STRING( p_info, "composer", i.composer );
HEADER_STRING( p_info, "sequencer", i.sequencer );
HEADER_STRING( p_info, "copyright", i.copyright );
HEADER_STRING( p_info, "comment", i.comment );
HEADER_STRING( p_info, "dumper", i.dumper );
HEADER_STRING( p_info, "tagger", i.tagger );
p_info.set_length(dlength);
}
void decode_initialize( t_uint32 p_subsong, unsigned p_flags, abort_callback & p_abort )
{
track_info_t i;
ERRCHK( emu->track_info( &i, p_subsong ) );
int length = 0;
double dlength = double(tag_song_ms + tag_fade_ms) * .001;
if ( i.intro_length != -1 && i.loop_length != -1 )
length = i.intro_length + i.loop_length * ( i.repeat_count > 0 ? i.repeat_count : 2 );
else if ( i.length != -1 )
length = i.length;
if ( length )
{
tag_song_ms = length;
tag_fade_ms = i.fade_length;
dlength = double(tag_song_ms + tag_fade_ms) * .001;
}
input_gep::decode_initialize( p_subsong, p_flags, p_abort );
}
};
#define DECLARE_FILE_TYPE_n(NS,NAME,MASK) \
namespace NS { static input_file_type_impl g_filetype_instance(NAME,MASK,true); \
static service_factory_single_ref_t<input_file_type_impl> g_filetype_service(g_filetype_instance); }
DECLARE_FILE_TYPE_n( a, "AY files", "*.AY" );
DECLARE_FILE_TYPE_n( b, "GBS files", "*.GBS" );
DECLARE_FILE_TYPE_n( c, "GYM files", "*.GYM" );
DECLARE_FILE_TYPE_n( d, "HES files", "*.HES" );
DECLARE_FILE_TYPE_n( e, "KSS files", "*.KSS" );
DECLARE_FILE_TYPE_n( f, "SAP files", "*.SAP" );
DECLARE_FILE_TYPE_n( g, "SGC files", "*.SGC" );
static input_factory_t <input_generic> g_input_factory_generic;