comparison src/xs_sidplay1.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 3e55874170eb
comparison
equal deleted inserted replaced
363:a89064a9c3ba 364:421e4fc13bce
32 32
33 #include <sidplay/player.h> 33 #include <sidplay/player.h>
34 #include <sidplay/myendian.h> 34 #include <sidplay/myendian.h>
35 #include <sidplay/fformat.h> 35 #include <sidplay/fformat.h>
36 36
37 /* Maximum audio frequency supported by libSIDPlay v1 */
38 #define SIDPLAY1_MAX_FREQ (48000)
39 37
40 typedef struct 38 typedef struct
41 { 39 {
42 emuEngine *currEng; 40 emuEngine *currEng;
43 emuConfig currConfig; 41 emuConfig currConfig;
50 { 48 {
51 49
52 50
53 /* Check if we can play the given file 51 /* Check if we can play the given file
54 */ 52 */
55 gboolean xs_sidplay1_isourfile(gchar * pcFilename) 53 gboolean xs_sidplay1_isourfile(gchar * pcFilename)
56 { 54 {
57 sidTune *testTune = new sidTune(pcFilename); 55 sidTune *testTune = new sidTune(pcFilename);
58 56
59 if (!testTune) 57 if (!testTune) return FALSE;
60 return FALSE; 58
61 if (!testTune->getStatus()) 59 if (!testTune->getStatus()) {
62 { 60 delete testTune;
63 delete testTune; 61 return FALSE;
64 return FALSE; 62 }
63
64 delete testTune;
65 return TRUE;
66 }
67
68
69 /* Initialize SIDPlay1
70 */
71 gboolean xs_sidplay1_init(t_xs_status * myStatus)
72 {
73 gint tmpFreq;
74 t_xs_sidplay1 *myEngine;
75 assert(myStatus);
76
77 /* Allocate internal structures */
78 myEngine = (t_xs_sidplay1 *) g_malloc0(sizeof(t_xs_sidplay1));
79 if (!myEngine) return FALSE;
80
81 /* Initialize engine */
82 myEngine->currEng = new emuEngine();
83 if (!myEngine->currEng) {
84 XSERR("Could not initialize libSIDPlay1 emulation engine\n");
85 g_free(myEngine);
86 return FALSE;
87 }
88
89 /* Verify endianess */
90 if (!myEngine->currEng->verifyEndianess()) {
91 XSERR("Endianess verification failed\n");
92 delete myEngine->currEng;
93 g_free(myEngine);
94 return FALSE;
95 }
96
97 myStatus->sidEngine = myEngine;
98
99 /* Get current configuration */
100 myEngine->currEng->getConfig(myEngine->currConfig);
101
102 /* Configure channel parameters */
103 switch (myStatus->audioChannels) {
104
105 case XS_CHN_AUTOPAN:
106 myEngine->currConfig.channels = SIDEMU_STEREO;
107 myEngine->currConfig.autoPanning = SIDEMU_CENTEREDAUTOPANNING;
108 myEngine->currConfig.volumeControl = SIDEMU_FULLPANNING;
109 break;
110
111 case XS_CHN_STEREO:
112 myEngine->currConfig.channels = SIDEMU_STEREO;
113 myEngine->currConfig.autoPanning = SIDEMU_NONE;
114 myEngine->currConfig.volumeControl = SIDEMU_NONE;
115 break;
116
117 case XS_CHN_MONO:
118 default:
119 myEngine->currConfig.channels = SIDEMU_MONO;
120 myEngine->currConfig.autoPanning = SIDEMU_NONE;
121 myEngine->currConfig.volumeControl = SIDEMU_NONE;
122 myStatus->audioChannels = XS_CHN_MONO;
123 break;
124 }
125
126
127 /* Memory mode settings */
128 switch (xs_cfg.memoryMode) {
129 case XS_MPU_TRANSPARENT_ROM:
130 myEngine->currConfig.memoryMode = MPU_TRANSPARENT_ROM;
131 break;
132
133 case XS_MPU_PLAYSID_ENVIRONMENT:
134 myEngine->currConfig.memoryMode = MPU_PLAYSID_ENVIRONMENT;
135 break;
136
137 case XS_MPU_BANK_SWITCHING:
138 default:
139 myEngine->currConfig.memoryMode = MPU_BANK_SWITCHING;
140 xs_cfg.memoryMode = XS_MPU_BANK_SWITCHING;
141 break;
142 }
143
144
145 /* Clockspeed settings */
146 switch (xs_cfg.clockSpeed) {
147 case XS_CLOCK_NTSC:
148 myEngine->currConfig.clockSpeed = SIDTUNE_CLOCK_NTSC;
149 break;
150
151 case XS_CLOCK_PAL:
152 default:
153 myEngine->currConfig.clockSpeed = SIDTUNE_CLOCK_PAL;
154 xs_cfg.clockSpeed = XS_CLOCK_PAL;
155 break;
156 }
157
158
159 /* Configure rest of the emulation */
160 myEngine->currConfig.mos8580 = xs_cfg.mos8580;
161 myEngine->currConfig.emulateFilter = xs_cfg.emulateFilters;
162 myEngine->currConfig.filterFs = xs_cfg.filterFs;
163 myEngine->currConfig.filterFm = xs_cfg.filterFm;
164 myEngine->currConfig.filterFt = xs_cfg.filterFt;
165
166
167 /* Audio parameters sanity checking and setup */
168 myEngine->currConfig.bitsPerSample = myStatus->audioBitsPerSample;
169 tmpFreq = myStatus->audioFrequency;
170
171 if (myStatus->oversampleEnable) {
172 if ((tmpFreq * myStatus->oversampleFactor) > SIDPLAY1_MAX_FREQ) {
173 myStatus->oversampleEnable = FALSE;
174 } else {
175 tmpFreq = (tmpFreq * myStatus->oversampleFactor);
65 } 176 }
66 177 } else {
67 delete testTune; 178 if (tmpFreq > SIDPLAY1_MAX_FREQ)
68 return TRUE; 179 tmpFreq = SIDPLAY1_MAX_FREQ;
69 } 180 }
70 181
71 182 myEngine->currConfig.frequency = tmpFreq;
72 /* Initialize SIDPlay1 183
73 */ 184 switch (myStatus->audioBitsPerSample) {
74 gboolean xs_sidplay1_init(t_xs_status * myStatus) 185 case XS_RES_8BIT:
75 { 186 switch (myStatus->audioFormat) {
76 gint tmpFreq; 187 case FMT_S8:
77 t_xs_sidplay1 *myEngine; 188 myStatus->audioFormat = FMT_S8;
78 assert(myStatus); 189 myEngine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM;
79
80 /* Allocate internal structures */
81 myEngine = (t_xs_sidplay1 *) g_malloc0(sizeof(t_xs_sidplay1));
82 if (!myEngine)
83 return FALSE;
84
85 /* Initialize engine */
86 myEngine->currEng = new emuEngine();
87 if (!myEngine->currEng) {
88 XSERR("Could not initialize libSIDPlay1 emulation engine\n");
89 g_free(myEngine);
90 return FALSE;
91 }
92
93 /* Verify endianess */
94 if (!myEngine->currEng->verifyEndianess()) {
95 XSERR("Endianess verification failed\n");
96 delete myEngine->currEng;
97 g_free(myEngine);
98 return FALSE;
99 }
100
101 myStatus->sidEngine = myEngine;
102
103 /* Get current configuration */
104 myEngine->currEng->getConfig(myEngine->currConfig);
105
106 /* Configure channel parameters */
107 switch (myStatus->audioChannels) {
108
109 case XS_CHN_AUTOPAN:
110 myEngine->currConfig.channels = SIDEMU_STEREO;
111 myEngine->currConfig.autoPanning = SIDEMU_CENTEREDAUTOPANNING;
112 myEngine->currConfig.volumeControl = SIDEMU_FULLPANNING;
113 break; 190 break;
114 191
115 case XS_CHN_STEREO: 192 case FMT_U8:
116 myEngine->currConfig.channels = SIDEMU_STEREO;
117 myEngine->currConfig.autoPanning = SIDEMU_NONE;
118 myEngine->currConfig.volumeControl = SIDEMU_NONE;
119 break;
120
121 case XS_CHN_MONO:
122 default: 193 default:
123 myEngine->currConfig.channels = SIDEMU_MONO; 194 myStatus->audioFormat = FMT_U8;
124 myEngine->currConfig.autoPanning = SIDEMU_NONE; 195 myEngine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM;
125 myEngine->currConfig.volumeControl = SIDEMU_NONE;
126 myStatus->audioChannels = XS_CHN_MONO;
127 break; 196 break;
128 } 197 }
129 198 break;
130 199
131 /* Memory mode settings */ 200 case XS_RES_16BIT:
132 switch (xs_cfg.memoryMode) { 201 default:
133 case XS_MPU_TRANSPARENT_ROM: 202 switch (myStatus->audioFormat) {
134 myEngine->currConfig.memoryMode = MPU_TRANSPARENT_ROM; 203 case FMT_U16_NE:
204 case FMT_U16_LE:
205 case FMT_U16_BE:
206 myStatus->audioFormat = FMT_U16_NE;
207 myEngine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM;
135 break; 208 break;
136 209
137 case XS_MPU_PLAYSID_ENVIRONMENT: 210 case FMT_S16_NE:
138 myEngine->currConfig.memoryMode = MPU_PLAYSID_ENVIRONMENT; 211 case FMT_S16_LE:
139 break; 212 case FMT_S16_BE:
140
141 case XS_MPU_BANK_SWITCHING:
142 default: 213 default:
143 myEngine->currConfig.memoryMode = MPU_BANK_SWITCHING; 214 myStatus->audioFormat = FMT_S16_NE;
144 xs_cfg.memoryMode = XS_MPU_BANK_SWITCHING; 215 myEngine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM;
145 break; 216 break;
146 } 217 }
147 218 break;
148 219 }
149 /* Clockspeed settings */ 220
150 switch (xs_cfg.clockSpeed) { 221 /* Now set the emulator configuration */
151 case XS_CLOCK_NTSC: 222 if (!myEngine->currEng->setConfig(myEngine->currConfig)) {
152 myEngine->currConfig.clockSpeed = SIDTUNE_CLOCK_NTSC; 223 XSERR("Emulator engine configuration failed!\n");
153 break; 224 return FALSE;
154 225 }
155 case XS_CLOCK_PAL: 226
156 default: 227 return TRUE;
157 myEngine->currConfig.clockSpeed = SIDTUNE_CLOCK_PAL; 228 }
158 xs_cfg.clockSpeed = XS_CLOCK_PAL;
159 break;
160 }
161
162
163 /* Configure rest of the emulation */
164 myEngine->currConfig.mos8580 = xs_cfg.mos8580;
165 myEngine->currConfig.emulateFilter = xs_cfg.emulateFilters;
166 myEngine->currConfig.filterFs = xs_cfg.filterFs;
167 myEngine->currConfig.filterFm = xs_cfg.filterFm;
168 myEngine->currConfig.filterFt = xs_cfg.filterFt;
169
170
171 /* Audio parameters sanity checking and setup */
172 myEngine->currConfig.bitsPerSample = myStatus->audioBitsPerSample;
173 tmpFreq = myStatus->audioFrequency;
174
175 if (myStatus->oversampleEnable) {
176 if ((tmpFreq * myStatus->oversampleFactor) > SIDPLAY1_MAX_FREQ) {
177 myStatus->oversampleEnable = FALSE;
178 } else {
179 tmpFreq = (tmpFreq * myStatus->oversampleFactor);
180 }
181 } else {
182 if (tmpFreq > SIDPLAY1_MAX_FREQ)
183 tmpFreq = SIDPLAY1_MAX_FREQ;
184 }
185
186 myEngine->currConfig.frequency = tmpFreq;
187
188 switch (myStatus->audioBitsPerSample) {
189 case XS_RES_8BIT:
190 switch (myStatus->audioFormat) {
191 case FMT_S8:
192 myStatus->audioFormat = FMT_S8;
193 myEngine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM;
194 break;
195
196 case FMT_U8:
197 default:
198 myStatus->audioFormat = FMT_U8;
199 myEngine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM;
200 break;
201 }
202 break;
203
204 case XS_RES_16BIT:
205 default:
206 switch (myStatus->audioFormat) {
207 case FMT_U16_NE:
208 case FMT_U16_LE:
209 case FMT_U16_BE:
210 myStatus->audioFormat = FMT_U16_NE;
211 myEngine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM;
212 break;
213
214 case FMT_S16_NE:
215 case FMT_S16_LE:
216 case FMT_S16_BE:
217 default:
218 myStatus->audioFormat = FMT_S16_NE;
219 myEngine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM;
220 break;
221 }
222 break;
223 }
224
225 /* Now set the emulator configuration */
226 if (!myEngine->currEng->setConfig(myEngine->currConfig)) {
227 XSERR("Emulator engine configuration failed!\n");
228 return FALSE;
229 }
230
231 return TRUE;
232 }
233 229
234 230
235 /* Close SIDPlay1 engine 231 /* Close SIDPlay1 engine
236 */ 232 */
237 void xs_sidplay1_close(t_xs_status * myStatus) 233 void xs_sidplay1_close(t_xs_status * myStatus)
238 { 234 {
239 t_xs_sidplay1 *myEngine; 235 t_xs_sidplay1 *myEngine;
240 assert(myStatus); 236 assert(myStatus);
241 237
242 myEngine = (t_xs_sidplay1 *) myStatus->sidEngine; 238 myEngine = (t_xs_sidplay1 *) myStatus->sidEngine;
243 239
244 /* Free internals */ 240 /* Free internals */
245 if (myEngine->currEng) { 241 if (myEngine->currEng) {
246 delete myEngine->currEng; 242 delete myEngine->currEng;
247 myEngine->currEng = NULL; 243 myEngine->currEng = NULL;
248 } 244 }
249 245
250 g_free(myEngine); 246 g_free(myEngine);
251 myStatus->sidEngine = NULL; 247 myStatus->sidEngine = NULL;
252 } 248 }
253 249
254 250
255 /* Initialize current song and sub-tune 251 /* Initialize current song and sub-tune
256 */ 252 */
257 gboolean xs_sidplay1_initsong(t_xs_status * myStatus) 253 gboolean xs_sidplay1_initsong(t_xs_status * myStatus)
258 { 254 {
259 t_xs_sidplay1 *myEngine; 255 t_xs_sidplay1 *myEngine;
260 assert(myStatus); 256 assert(myStatus);
261 257
262 myEngine = (t_xs_sidplay1 *) myStatus->sidEngine; 258 myEngine = (t_xs_sidplay1 *) myStatus->sidEngine;
263 if (!myEngine) 259 if (!myEngine) return FALSE;
264 return FALSE; 260
265 261 if (!myEngine->currTune) {
266 if (!myEngine->currTune) { 262 XSERR("Tune was NULL\n");
267 XSERR("Tune was NULL\n"); 263 return FALSE;
268 return FALSE; 264 }
269 } 265
270 266 if (!myEngine->currTune->getStatus()) {
271 if (!myEngine->currTune->getStatus()) { 267 XSERR("Tune status check failed\n");
272 XSERR("Tune status check failed\n"); 268 return FALSE;
273 return FALSE; 269 }
274 } 270
275 271 return sidEmuInitializeSong(*myEngine->currEng, *myEngine->currTune, myStatus->currSong);
276 return sidEmuInitializeSong(*myEngine->currEng, *myEngine->currTune, myStatus->currSong); 272 }
277 }
278 273
279 274
280 /* Emulate and render audio data to given buffer 275 /* Emulate and render audio data to given buffer
281 */ 276 */
282 guint xs_sidplay1_fillbuffer(t_xs_status * myStatus, gchar * audioBuffer, guint audioBufSize) 277 guint xs_sidplay1_fillbuffer(t_xs_status * myStatus, gchar * audioBuffer, guint audioBufSize)
283 { 278 {
284 t_xs_sidplay1 *myEngine; 279 t_xs_sidplay1 *myEngine;
285 assert(myStatus); 280 assert(myStatus);
286 281
287 myEngine = (t_xs_sidplay1 *) myStatus->sidEngine; 282 myEngine = (t_xs_sidplay1 *) myStatus->sidEngine;
288 if (!myEngine) 283 if (!myEngine) return 0;
289 return 0; 284
290 285 sidEmuFillBuffer(*myEngine->currEng, *myEngine->currTune, audioBuffer, audioBufSize);
291 sidEmuFillBuffer(*myEngine->currEng, *myEngine->currTune, audioBuffer, audioBufSize); 286
292 287 return audioBufSize;
293 return audioBufSize; 288 }
294 }
295 289
296 290
297 /* Load a given SID-tune file 291 /* Load a given SID-tune file
298 */ 292 */
299 gboolean xs_sidplay1_loadsid(t_xs_status * myStatus, gchar * pcFilename) 293 gboolean xs_sidplay1_loadsid(t_xs_status * myStatus, gchar * pcFilename)
300 { 294 {
301 t_xs_sidplay1 *myEngine; 295 t_xs_sidplay1 *myEngine;
302 sidTune *newTune; 296 sidTune *newTune;
303 assert(myStatus); 297 assert(myStatus);
304 298
305 myEngine = (t_xs_sidplay1 *) myStatus->sidEngine; 299 myEngine = (t_xs_sidplay1 *) myStatus->sidEngine;
306 300
307 /* Try to get the tune */ 301 /* Try to get the tune */
308 if (!pcFilename) 302 if (!pcFilename) return FALSE;
309 return FALSE; 303
310 304 newTune = new sidTune(pcFilename);
311 newTune = new sidTune(pcFilename); 305 if (!newTune) return FALSE;
312 if (!newTune) 306
313 return FALSE; 307 myEngine->currTune = newTune;
314 308
315 myEngine->currTune = newTune; 309 return TRUE;
316 310 }
317 return TRUE;
318 }
319 311
320 312
321 /* Delete INTERNAL information 313 /* Delete INTERNAL information
322 */ 314 */
323 void xs_sidplay1_deletesid(t_xs_status * myStatus) 315 void xs_sidplay1_deletesid(t_xs_status * myStatus)
324 { 316 {
325 t_xs_sidplay1 *myEngine; 317 t_xs_sidplay1 *myEngine;
326 assert(myStatus); 318 assert(myStatus);
327 319
328 myEngine = (t_xs_sidplay1 *) myStatus->sidEngine; 320 myEngine = (t_xs_sidplay1 *) myStatus->sidEngine;
329 if (!myEngine) 321 if (!myEngine)
330 return; 322 return;
331 323
332 if (myEngine->currTune) { 324 if (myEngine->currTune) {
333 delete myEngine->currTune; 325 delete myEngine->currTune;
334 myEngine->currTune = NULL; 326 myEngine->currTune = NULL;
335 } 327 }
336 } 328 }
337 329
338 330
339 /* Return song information 331 /* Return song information
340 */ 332 */
341 #define TFUNCTION xs_sidplay1_getsidinfo 333 #define TFUNCTION xs_sidplay1_getsidinfo