comparison src/xs_sidplay2.cc @ 364:421e4fc13bce

More and more of indentation fixes.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 08 Nov 2005 08:31:01 +0000
parents b1a858b8cb1a
children 29c4484f1de2
comparison
equal deleted inserted replaced
363:a89064a9c3ba 364:421e4fc13bce
54 { 54 {
55 55
56 56
57 /* Check if we can play the given file 57 /* Check if we can play the given file
58 */ 58 */
59 gboolean xs_sidplay2_isourfile(gchar * pcFilename) 59 gboolean xs_sidplay2_isourfile(gchar * pcFilename)
60 { 60 {
61 SidTune *testTune = new SidTune(pcFilename); 61 SidTune *testTune = new SidTune(pcFilename);
62 62
63 if (!testTune) 63 if (!testTune) return FALSE;
64 return FALSE; 64
65 if (!testTune->getStatus()) 65 if (!testTune->getStatus()) {
66 { 66 delete testTune;
67 delete testTune; 67 return FALSE;
68 return FALSE; 68 }
69
70 delete testTune;
71 return TRUE;
72 }
73
74
75
76 /* Initialize SIDPlay2
77 */
78 gboolean xs_sidplay2_init(t_xs_status * myStatus)
79 {
80 gint tmpFreq;
81 t_xs_sidplay2 *myEngine;
82 assert(myStatus);
83
84 /* Allocate internal structures */
85 myEngine = (t_xs_sidplay2 *) g_malloc0(sizeof(t_xs_sidplay2));
86 myStatus->sidEngine = myEngine;
87 if (!myEngine) return FALSE;
88
89 /* Initialize the engine */
90 myEngine->currEng = new sidplay2;
91 if (!myEngine->currEng) {
92 XSERR("Could not initialize libSIDPlay2 emulation engine\n");
93 return FALSE;
94 }
95
96 /* Get current configuration */
97 myEngine->currConfig = myEngine->currEng->config();
98
99 /* Configure channels and stuff */
100 switch (myStatus->audioChannels) {
101
102 case XS_CHN_AUTOPAN:
103 myEngine->currConfig.playback = sid2_stereo;
104 break;
105
106 case XS_CHN_STEREO:
107 myEngine->currConfig.playback = sid2_stereo;
108 break;
109
110 case XS_CHN_MONO:
111 default:
112 myEngine->currConfig.playback = sid2_mono;
113 myStatus->audioChannels = XS_CHN_MONO;
114 break;
115 }
116
117
118 /* Memory mode settings */
119 switch (xs_cfg.memoryMode) {
120 case XS_MPU_BANK_SWITCHING:
121 myEngine->currConfig.environment = sid2_envBS;
122 break;
123
124 case XS_MPU_TRANSPARENT_ROM:
125 myEngine->currConfig.environment = sid2_envTP;
126 break;
127
128 case XS_MPU_PLAYSID_ENVIRONMENT:
129 myEngine->currConfig.environment = sid2_envPS;
130 break;
131
132 case XS_MPU_REAL:
133 default:
134 myEngine->currConfig.environment = sid2_envR;
135 xs_cfg.memoryMode = XS_MPU_REAL;
136 break;
137 }
138
139
140 /* Clockspeed settings */
141 switch (xs_cfg.clockSpeed) {
142 case XS_CLOCK_NTSC:
143 myEngine->currConfig.clockSpeed = myEngine->currConfig.clockDefault = SID2_CLOCK_NTSC;
144 break;
145
146 case XS_CLOCK_PAL:
147 default:
148 myEngine->currConfig.clockSpeed = myEngine->currConfig.clockDefault = SID2_CLOCK_PAL;
149 xs_cfg.clockSpeed = XS_CLOCK_PAL;
150 break;
151 }
152
153
154 /* Audio parameters sanity checking and setup */
155 myEngine->currConfig.precision = myStatus->audioBitsPerSample;
156 tmpFreq = myStatus->audioFrequency;
157
158 if (myStatus->oversampleEnable)
159 tmpFreq = (tmpFreq * myStatus->oversampleFactor);
160
161 myEngine->currConfig.frequency = tmpFreq;
162
163 switch (myStatus->audioBitsPerSample) {
164 case XS_RES_8BIT:
165 myStatus->audioFormat = FMT_U8;
166 myEngine->currConfig.sampleFormat = SID2_LITTLE_UNSIGNED;
167 break;
168
169 case XS_RES_16BIT:
170 default:
171 switch (myStatus->audioFormat) {
172 case FMT_U16_LE:
173 myEngine->currConfig.sampleFormat = SID2_LITTLE_UNSIGNED;
174 break;
175
176 case FMT_U16_BE:
177 myEngine->currConfig.sampleFormat = SID2_BIG_UNSIGNED;
178 break;
179
180 case FMT_U16_NE:
181 #ifdef WORDS_BIGENDIAN
182 myEngine->currConfig.sampleFormat = SID2_BIG_UNSIGNED;
183 #else
184 myEngine->currConfig.sampleFormat = SID2_LITTLE_UNSIGNED;
185 #endif
186 break;
187
188 case FMT_S16_LE:
189 myEngine->currConfig.sampleFormat = SID2_LITTLE_SIGNED;
190 break;
191
192 case FMT_S16_BE:
193 myEngine->currConfig.sampleFormat = SID2_BIG_SIGNED;
194 break;
195
196 default:
197 myStatus->audioFormat = FMT_S16_NE;
198 #ifdef WORDS_BIGENDIAN
199 myEngine->currConfig.sampleFormat = SID2_BIG_SIGNED;
200 #else
201 myEngine->currConfig.sampleFormat = SID2_LITTLE_SIGNED;
202 #endif
203 break;
204
69 } 205 }
70 206 break;
71 delete testTune; 207 }
72 return TRUE; 208
73 } 209 /* Initialize builder object */
74 210 XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (myEngine->currEng->info()).maxsids);
75 211 #ifdef HAVE_RESID_BUILDER
76 212 if (xs_cfg.sid2Builder == XS_BLD_RESID) {
77 /* Initialize SIDPlay2 213 ReSIDBuilder *rs = new ReSIDBuilder("ReSID builder");
78 */ 214 myEngine->currBuilder = (sidbuilder *) rs;
79 gboolean xs_sidplay2_init(t_xs_status * myStatus) 215 if (rs) {
80 { 216 /* Builder object created, initialize it */
81 gint tmpFreq; 217 rs->create((myEngine->currEng->info()).maxsids);
82 t_xs_sidplay2 *myEngine; 218 if (!*rs) {
83 assert(myStatus); 219 XSERR("rs->create() failed. SIDPlay2 suxx again.\n");
84 220 return FALSE;
85 /* Allocate internal structures */ 221 }
86 myEngine = (t_xs_sidplay2 *) g_malloc0(sizeof(t_xs_sidplay2)); 222
87 myStatus->sidEngine = myEngine; 223 rs->filter(xs_cfg.emulateFilters);
88 if (!myEngine) 224 if (!*rs) {
89 return FALSE; 225 XSERR("rs->filter(%d) failed.\n", xs_cfg.emulateFilters);
90 226 return FALSE;
91 227 }
92 /* Initialize the engine */ 228
93 myEngine->currEng = new sidplay2; 229 rs->sampling(tmpFreq);
94 if (!myEngine->currEng) { 230 if (!*rs) {
95 XSERR("Could not initialize libSIDPlay2 emulation engine\n"); 231 XSERR("rs->sampling(%d) failed.\n", tmpFreq);
96 return FALSE; 232 return FALSE;
233 }
234
235 rs->filter((sid_filter_t *) NULL);
236 if (!*rs) {
237 XSERR("rs->filter(NULL) failed.\n");
238 return FALSE;
239 }
97 } 240 }
98 241 }
99 /* Get current configuration */ 242 #endif
100 myEngine->currConfig = myEngine->currEng->config(); 243 #ifdef HAVE_HARDSID_BUILDER
101 244 if (xs_cfg.sid2Builder == XS_BLD_HARDSID) {
102 /* Configure channels and stuff */ 245 HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder");
103 switch (myStatus->audioChannels) { 246 myEngine->currBuilder = (sidbuilder *) hs;
104 247 if (hs) {
105 case XS_CHN_AUTOPAN: 248 /* Builder object created, initialize it */
106 myEngine->currConfig.playback = sid2_stereo; 249 hs->create((myEngine->currEng->info()).maxsids);
107 break; 250 if (!*hs) {
108 251 XSERR("hs->create() failed. SIDPlay2 suxx again.\n");
109 case XS_CHN_STEREO: 252 return FALSE;
110 myEngine->currConfig.playback = sid2_stereo; 253 }
111 break; 254
112 255 hs->filter(xs_cfg.emulateFilters);
113 case XS_CHN_MONO: 256 if (!*hs) {
114 default: 257 XSERR("hs->filter(%d) failed.\n", xs_cfg.emulateFilters);
115 myEngine->currConfig.playback = sid2_mono; 258 return FALSE;
116 myStatus->audioChannels = XS_CHN_MONO; 259 }
117 break;
118 } 260 }
119 261 }
120 262 #endif
121 /* Memory mode settings */ 263
122 switch (xs_cfg.memoryMode) { 264 if (!myEngine->currBuilder) {
123 case XS_MPU_BANK_SWITCHING: 265 XSERR("Could not initialize SIDBuilder object.\n");
124 myEngine->currConfig.environment = sid2_envBS; 266 return FALSE;
125 break; 267 }
126 268
127 case XS_MPU_TRANSPARENT_ROM: 269 XSDEBUG("%s\n", myEngine->currBuilder->credits());
128 myEngine->currConfig.environment = sid2_envTP; 270
129 break; 271
130 272 /* Configure rest of the emulation */
131 case XS_MPU_PLAYSID_ENVIRONMENT: 273 myEngine->currConfig.sidEmulation = myEngine->currBuilder;
132 myEngine->currConfig.environment = sid2_envPS; 274 myEngine->currConfig.clockForced = xs_cfg.forceSpeed;
133 break; 275 myEngine->currConfig.optimisation = (xs_cfg.sid2OptLevel) ? 1 : 0;
134 276 if (xs_cfg.mos8580)
135 case XS_MPU_REAL: 277 myEngine->currConfig.sidDefault = SID2_MOS8580;
136 default: 278 else
137 myEngine->currConfig.environment = sid2_envR; 279 myEngine->currConfig.sidDefault = SID2_MOS6581;
138 xs_cfg.memoryMode = XS_MPU_REAL; 280
139 break; 281 myEngine->currConfig.sidModel = myEngine->currConfig.sidDefault;
140 } 282 myEngine->currConfig.sidSamples = TRUE; // FIXME FIX ME, make configurable!
141 283
142 284
143 /* Clockspeed settings */ 285 /* Now set the emulator configuration */
144 switch (xs_cfg.clockSpeed) { 286 if (myEngine->currEng->config(myEngine->currConfig) < 0) {
145 case XS_CLOCK_NTSC: 287 XSERR("Emulator engine configuration failed!\n");
146 myEngine->currConfig.clockSpeed = myEngine->currConfig.clockDefault = SID2_CLOCK_NTSC; 288 return FALSE;
147 break; 289 }
148 290
149 case XS_CLOCK_PAL: 291 /* Create the sidtune */
150 default: 292 myEngine->currTune = new SidTune(0);
151 myEngine->currConfig.clockSpeed = myEngine->currConfig.clockDefault = SID2_CLOCK_PAL; 293 if (!myEngine->currTune) {
152 xs_cfg.clockSpeed = XS_CLOCK_PAL; 294 XSERR("Could not initialize SIDTune object.\n");
153 break; 295 return FALSE;
154 } 296 }
155 297
156 298 return TRUE;
157 /* Audio parameters sanity checking and setup */ 299 }
158 myEngine->currConfig.precision = myStatus->audioBitsPerSample;
159 tmpFreq = myStatus->audioFrequency;
160
161 if (myStatus->oversampleEnable)
162 tmpFreq = (tmpFreq * myStatus->oversampleFactor);
163
164 myEngine->currConfig.frequency = tmpFreq;
165
166 switch (myStatus->audioBitsPerSample) {
167 case XS_RES_8BIT:
168 myStatus->audioFormat = FMT_U8;
169 myEngine->currConfig.sampleFormat = SID2_LITTLE_UNSIGNED;
170 break;
171
172 case XS_RES_16BIT:
173 default:
174 switch (myStatus->audioFormat) {
175 case FMT_U16_LE:
176 myEngine->currConfig.sampleFormat = SID2_LITTLE_UNSIGNED;
177 break;
178
179 case FMT_U16_BE:
180 myEngine->currConfig.sampleFormat = SID2_BIG_UNSIGNED;
181 break;
182
183 case FMT_U16_NE:
184 #ifdef WORDS_BIGENDIAN
185 myEngine->currConfig.sampleFormat = SID2_BIG_UNSIGNED;
186 #else
187 myEngine->currConfig.sampleFormat = SID2_LITTLE_UNSIGNED;
188 #endif
189 break;
190
191 case FMT_S16_LE:
192 myEngine->currConfig.sampleFormat = SID2_LITTLE_SIGNED;
193 break;
194
195 case FMT_S16_BE:
196 myEngine->currConfig.sampleFormat = SID2_BIG_SIGNED;
197 break;
198
199 default:
200 myStatus->audioFormat = FMT_S16_NE;
201 #ifdef WORDS_BIGENDIAN
202 myEngine->currConfig.sampleFormat = SID2_BIG_SIGNED;
203 #else
204 myEngine->currConfig.sampleFormat = SID2_LITTLE_SIGNED;
205 #endif
206 break;
207
208 }
209 break;
210 }
211
212 /* Initialize builder object */
213 XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (myEngine->currEng->info()).maxsids);
214 #ifdef HAVE_RESID_BUILDER
215 if (xs_cfg.sid2Builder == XS_BLD_RESID) {
216 ReSIDBuilder *rs = new ReSIDBuilder("ReSID builder");
217 myEngine->currBuilder = (sidbuilder *) rs;
218 if (rs) {
219 /* Builder object created, initialize it */
220 rs->create((myEngine->currEng->info()).maxsids);
221 if (!*rs) {
222 XSERR("rs->create() failed. SIDPlay2 suxx again.\n");
223 return FALSE;
224 }
225
226 rs->filter(xs_cfg.emulateFilters);
227 if (!*rs) {
228 XSERR("rs->filter(%d) failed.\n", xs_cfg.emulateFilters);
229 return FALSE;
230 }
231
232 rs->sampling(tmpFreq);
233 if (!*rs) {
234 XSERR("rs->sampling(%d) failed.\n", tmpFreq);
235 return FALSE;
236 }
237
238 rs->filter((sid_filter_t *) NULL);
239 if (!*rs) {
240 XSERR("rs->filter(NULL) failed.\n");
241 return FALSE;
242 }
243 }
244 }
245 #endif
246 #ifdef HAVE_HARDSID_BUILDER
247 if (xs_cfg.sid2Builder == XS_BLD_HARDSID) {
248 HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder");
249 myEngine->currBuilder = (sidbuilder *) hs;
250 if (hs) {
251 /* Builder object created, initialize it */
252 hs->create((myEngine->currEng->info()).maxsids);
253 if (!*hs) {
254 XSERR("hs->create() failed. SIDPlay2 suxx again.\n");
255 return FALSE;
256 }
257
258 hs->filter(xs_cfg.emulateFilters);
259 if (!*hs) {
260 XSERR("hs->filter(%d) failed.\n", xs_cfg.emulateFilters);
261 return FALSE;
262 }
263 }
264 }
265 #endif
266
267 if (!myEngine->currBuilder) {
268 XSERR("Could not initialize SIDBuilder object.\n");
269 return FALSE;
270 }
271
272 XSDEBUG("%s\n", myEngine->currBuilder->credits());
273
274
275 /* Configure rest of the emulation */
276 myEngine->currConfig.sidEmulation = myEngine->currBuilder;
277 myEngine->currConfig.clockForced = xs_cfg.forceSpeed;
278 myEngine->currConfig.optimisation = (xs_cfg.sid2OptLevel) ? 1 : 0;
279 if (xs_cfg.mos8580)
280 myEngine->currConfig.sidDefault = SID2_MOS8580;
281 else
282 myEngine->currConfig.sidDefault = SID2_MOS6581;
283
284 myEngine->currConfig.sidModel = myEngine->currConfig.sidDefault;
285 myEngine->currConfig.sidSamples = TRUE; // FIXME FIX ME, make configurable!
286
287
288 /* Now set the emulator configuration */
289 if (myEngine->currEng->config(myEngine->currConfig) < 0) {
290 XSERR("Emulator engine configuration failed!\n");
291 return FALSE;
292 }
293
294 /* Create the sidtune */
295 myEngine->currTune = new SidTune(0);
296 if (!myEngine->currTune) {
297 XSERR("Could not initialize SIDTune object.\n");
298 return FALSE;
299 }
300
301 return TRUE;
302 }
303 300
304 301
305 /* Close SIDPlay2 engine 302 /* Close SIDPlay2 engine
306 */ 303 */
307 void xs_sidplay2_close(t_xs_status * myStatus) 304 void xs_sidplay2_close(t_xs_status * myStatus)
308 { 305 {
309 t_xs_sidplay2 *myEngine; 306 t_xs_sidplay2 *myEngine;
310 assert(myStatus); 307 assert(myStatus);
311 308
312 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine; 309 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine;
313 310
314 /* Free internals */ 311 /* Free internals */
315 if (myEngine->currBuilder) { 312 if (myEngine->currBuilder) {
316 delete myEngine->currBuilder; 313 delete myEngine->currBuilder;
317 myEngine->currBuilder = NULL; 314 myEngine->currBuilder = NULL;
318 } 315 }
319 316
320 if (myEngine->currEng) { 317 if (myEngine->currEng) {
321 delete myEngine->currEng; 318 delete myEngine->currEng;
322 myEngine->currEng = NULL; 319 myEngine->currEng = NULL;
323 } 320 }
324 321
325 if (myEngine->currTune) { 322 if (myEngine->currTune) {
326 delete myEngine->currTune; 323 delete myEngine->currTune;
327 myEngine->currTune = NULL; 324 myEngine->currTune = NULL;
328 } 325 }
329 326
330 xs_sidplay2_deletesid(myStatus); 327 xs_sidplay2_deletesid(myStatus);
331 328
332 g_free(myEngine); 329 g_free(myEngine);
333 myStatus->sidEngine = NULL; 330 myStatus->sidEngine = NULL;
334 } 331 }
335 332
336 333
337 /* Initialize current song and sub-tune 334 /* Initialize current song and sub-tune
338 */ 335 */
339 gboolean xs_sidplay2_initsong(t_xs_status * myStatus) 336 gboolean xs_sidplay2_initsong(t_xs_status * myStatus)
340 { 337 {
341 t_xs_sidplay2 *myEngine; 338 t_xs_sidplay2 *myEngine;
342 assert(myStatus); 339 assert(myStatus);
343 340
344 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine; 341 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine;
345 if (!myEngine) 342 if (!myEngine) return FALSE;
346 return FALSE; 343
347 344 if (!myEngine->currTune->selectSong(myStatus->currSong)) {
348 if (!myEngine->currTune->selectSong(myStatus->currSong)) { 345 XSERR("currTune->selectSong() failed\n");
349 XSERR("currTune->selectSong() failed\n"); 346 return FALSE;
350 return FALSE; 347 }
351 } 348
352 349 if (myEngine->currEng->load(myEngine->currTune) < 0) {
353 if (myEngine->currEng->load(myEngine->currTune) < 0) { 350 XSERR("currEng->load() failed\n");
354 XSERR("currEng->load() failed\n"); 351 return FALSE;
355 return FALSE; 352 }
356 } 353
357 354 return TRUE;
358 return TRUE; 355 }
359 }
360 356
361 357
362 /* Emulate and render audio data to given buffer 358 /* Emulate and render audio data to given buffer
363 */ 359 */
364 guint xs_sidplay2_fillbuffer(t_xs_status * myStatus, gchar * audioBuffer, guint audioBufSize) 360 guint xs_sidplay2_fillbuffer(t_xs_status * myStatus, gchar * audioBuffer, guint audioBufSize)
365 { 361 {
366 t_xs_sidplay2 *myEngine; 362 t_xs_sidplay2 *myEngine;
367 assert(myStatus); 363 assert(myStatus);
368 364
369 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine; 365 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine;
370 if (!myEngine) 366 if (!myEngine) return 0;
371 return 0; 367
372 368 return myEngine->currEng->play(audioBuffer, audioBufSize);
373 return myEngine->currEng->play(audioBuffer, audioBufSize); 369 }
374 }
375 370
376 371
377 /* Load a given SID-tune file 372 /* Load a given SID-tune file
378 */ 373 */
379 gboolean xs_sidplay2_loadsid(t_xs_status * myStatus, gchar * pcFilename) 374 gboolean xs_sidplay2_loadsid(t_xs_status * myStatus, gchar * pcFilename)
380 { 375 {
381 t_xs_sidplay2 *myEngine; 376 t_xs_sidplay2 *myEngine;
382 assert(myStatus); 377 assert(myStatus);
383 378
384 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine; 379 myEngine = (t_xs_sidplay2 *) myStatus->sidEngine;
385 380
386 /* Try to get the tune */ 381 /* Try to get the tune */
387 if (!pcFilename) 382 if (!pcFilename) return FALSE;
388 return FALSE; 383 if (!myEngine->currTune->load(pcFilename))
389 if (!myEngine->currTune->load(pcFilename)) 384 return FALSE;
390 return FALSE; 385
391 386 return TRUE;
392 return TRUE; 387 }
393 }
394 388
395 389
396 /* Delete INTERNAL information 390 /* Delete INTERNAL information
397 */ 391 */
398 void xs_sidplay2_deletesid(t_xs_status * myStatus) 392 void xs_sidplay2_deletesid(t_xs_status * myStatus)
399 { 393 {
400 assert(myStatus); 394 assert(myStatus);
401 395
402 /* With the current scheme of handling sidtune-loading, we don't do anything here. */ 396 /* With the current scheme of handling sidtune-loading, we don't do anything here. */
403 } 397 }
404 398
405 399
406 /* Return song information 400 /* Return song information
407 */ 401 */
408 #define TFUNCTION xs_sidplay2_getsidinfo 402 #define TFUNCTION xs_sidplay2_getsidinfo