comparison src/xs_sidplay2.cc @ 359:b1a858b8cb1a

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