comparison src/xs_sidplay1.cpp @ 837:5b3e2116408f

Cosmetic cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 08 Nov 2012 20:58:45 +0200
parents a7ee5dc23e78
children 5b93bd8c7814
comparison
equal deleted inserted replaced
836:ccfe44f567c0 837:5b3e2116408f
1 /* 1 /*
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) 2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
3 3
4 libSIDPlay v1 support 4 libSIDPlay1 support
5 5
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> 6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
7 (C) Copyright 1999-2007 Tecnic Software productions (TNSP) 7 (C) Copyright 1999-2007 Tecnic Software productions (TNSP)
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
90 engine = (XSSIDPlay1 *) g_malloc0(sizeof(XSSIDPlay1)); 90 engine = (XSSIDPlay1 *) g_malloc0(sizeof(XSSIDPlay1));
91 if (!engine) return FALSE; 91 if (!engine) return FALSE;
92 92
93 /* Initialize engine */ 93 /* Initialize engine */
94 engine->emu = new emuEngine(); 94 engine->emu = new emuEngine();
95 if (!engine->emu) { 95 if (!engine->emu)
96 {
96 xs_error("[SIDPlay1] Could not initialize emulation engine.\n"); 97 xs_error("[SIDPlay1] Could not initialize emulation engine.\n");
97 g_free(engine); 98 g_free(engine);
98 return FALSE; 99 return FALSE;
99 } 100 }
100 101
101 /* Verify endianess */ 102 /* Verify endianess */
102 if (!engine->emu->verifyEndianess()) { 103 if (!engine->emu->verifyEndianess())
104 {
103 xs_error("[SIDPlay1] Endianess verification failed.\n"); 105 xs_error("[SIDPlay1] Endianess verification failed.\n");
104 delete engine->emu; 106 delete engine->emu;
105 g_free(engine); 107 g_free(engine);
106 return FALSE; 108 return FALSE;
107 } 109 }
110 112
111 /* Get current configuration */ 113 /* Get current configuration */
112 engine->emu->getConfig(engine->currConfig); 114 engine->emu->getConfig(engine->currConfig);
113 115
114 /* Configure channel parameters */ 116 /* Configure channel parameters */
115 switch (state->audioChannels) { 117 switch (state->audioChannels)
116 118 {
117 case XS_CHN_AUTOPAN: 119 case XS_CHN_AUTOPAN:
118 engine->currConfig.channels = SIDEMU_STEREO; 120 engine->currConfig.channels = SIDEMU_STEREO;
119 engine->currConfig.autoPanning = SIDEMU_CENTEREDAUTOPANNING; 121 engine->currConfig.autoPanning = SIDEMU_CENTEREDAUTOPANNING;
120 engine->currConfig.volumeControl = SIDEMU_FULLPANNING; 122 engine->currConfig.volumeControl = SIDEMU_FULLPANNING;
121 break; 123 break;
122 124
123 case XS_CHN_STEREO: 125 case XS_CHN_STEREO:
124 engine->currConfig.channels = SIDEMU_STEREO; 126 engine->currConfig.channels = SIDEMU_STEREO;
125 engine->currConfig.autoPanning = SIDEMU_NONE; 127 engine->currConfig.autoPanning = SIDEMU_NONE;
126 engine->currConfig.volumeControl = SIDEMU_NONE; 128 engine->currConfig.volumeControl = SIDEMU_NONE;
127 break; 129 break;
128 130
129 case XS_CHN_MONO: 131 case XS_CHN_MONO:
130 default: 132 default:
131 engine->currConfig.channels = SIDEMU_MONO; 133 engine->currConfig.channels = SIDEMU_MONO;
132 engine->currConfig.autoPanning = SIDEMU_NONE; 134 engine->currConfig.autoPanning = SIDEMU_NONE;
133 engine->currConfig.volumeControl = SIDEMU_NONE; 135 engine->currConfig.volumeControl = SIDEMU_NONE;
134 state->audioChannels = XS_CHN_MONO; 136 state->audioChannels = XS_CHN_MONO;
135 break; 137 break;
136 } 138 }
137 139
138 140
139 /* Memory mode settings */ 141 /* Memory mode settings */
140 switch (xs_cfg.memoryMode) { 142 switch (xs_cfg.memoryMode)
141 case XS_MPU_TRANSPARENT_ROM: 143 {
142 engine->currConfig.memoryMode = MPU_TRANSPARENT_ROM; 144 case XS_MPU_TRANSPARENT_ROM:
143 break; 145 engine->currConfig.memoryMode = MPU_TRANSPARENT_ROM;
144 146 break;
145 case XS_MPU_PLAYSID_ENVIRONMENT: 147
146 engine->currConfig.memoryMode = MPU_PLAYSID_ENVIRONMENT; 148 case XS_MPU_PLAYSID_ENVIRONMENT:
147 break; 149 engine->currConfig.memoryMode = MPU_PLAYSID_ENVIRONMENT;
148 150 break;
149 case XS_MPU_BANK_SWITCHING: 151
150 default: 152 case XS_MPU_BANK_SWITCHING:
151 engine->currConfig.memoryMode = MPU_BANK_SWITCHING; 153 default:
152 xs_cfg.memoryMode = XS_MPU_BANK_SWITCHING; 154 engine->currConfig.memoryMode = MPU_BANK_SWITCHING;
153 break; 155 xs_cfg.memoryMode = XS_MPU_BANK_SWITCHING;
156 break;
154 } 157 }
155 158
156 159
157 /* Audio parameters sanity checking and setup */ 160 /* Audio parameters sanity checking and setup */
158 engine->currConfig.bitsPerSample = state->audioBitsPerSample; 161 engine->currConfig.bitsPerSample = state->audioBitsPerSample;
161 if (tmpFreq > SIDPLAY1_MAX_FREQ) 164 if (tmpFreq > SIDPLAY1_MAX_FREQ)
162 tmpFreq = SIDPLAY1_MAX_FREQ; 165 tmpFreq = SIDPLAY1_MAX_FREQ;
163 166
164 engine->currConfig.frequency = tmpFreq; 167 engine->currConfig.frequency = tmpFreq;
165 168
166 switch (state->audioBitsPerSample) { 169 switch (state->audioBitsPerSample)
167 case XS_RES_8BIT: 170 {
168 switch (state->audioFormat) { 171 case XS_RES_8BIT:
169 case FMT_S8: 172 switch (state->audioFormat)
170 state->audioFormat = FMT_S8; 173 {
171 engine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM; 174 case FMT_S8:
172 break; 175 state->audioFormat = FMT_S8;
173 176 engine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM;
174 case FMT_U8: 177 break;
178
179 case FMT_U8:
180 default:
181 state->audioFormat = FMT_U8;
182 engine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM;
183 break;
184 }
185 break;
186
187 case XS_RES_16BIT:
175 default: 188 default:
176 state->audioFormat = FMT_U8; 189 switch (state->audioFormat)
177 engine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM; 190 {
178 break; 191 case FMT_U16_NE:
179 } 192 case FMT_U16_LE:
180 break; 193 case FMT_U16_BE:
181 194 state->audioFormat = FMT_U16_NE;
182 case XS_RES_16BIT: 195 engine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM;
183 default: 196 break;
184 switch (state->audioFormat) { 197
185 case FMT_U16_NE: 198 case FMT_S16_NE:
186 case FMT_U16_LE: 199 case FMT_S16_LE:
187 case FMT_U16_BE: 200 case FMT_S16_BE:
188 state->audioFormat = FMT_U16_NE; 201 default:
189 engine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM; 202 state->audioFormat = FMT_S16_NE;
190 break; 203 engine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM;
191 204 break;
192 case FMT_S16_NE: 205 }
193 case FMT_S16_LE: 206 break;
194 case FMT_S16_BE: 207 }
208
209 /* Clockspeed settings */
210 switch (xs_cfg.clockSpeed)
211 {
212 case XS_CLOCK_NTSC:
213 engine->currConfig.clockSpeed = SIDTUNE_CLOCK_NTSC;
214 break;
215
216 case XS_CLOCK_PAL:
195 default: 217 default:
196 state->audioFormat = FMT_S16_NE; 218 engine->currConfig.clockSpeed = SIDTUNE_CLOCK_PAL;
197 engine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM; 219 xs_cfg.clockSpeed = XS_CLOCK_PAL;
198 break; 220 break;
199 }
200 break;
201 }
202
203 /* Clockspeed settings */
204 switch (xs_cfg.clockSpeed) {
205 case XS_CLOCK_NTSC:
206 engine->currConfig.clockSpeed = SIDTUNE_CLOCK_NTSC;
207 break;
208
209 case XS_CLOCK_PAL:
210 default:
211 engine->currConfig.clockSpeed = SIDTUNE_CLOCK_PAL;
212 xs_cfg.clockSpeed = XS_CLOCK_PAL;
213 break;
214 } 221 }
215 222
216 engine->currConfig.forceSongSpeed = xs_cfg.forceSpeed; 223 engine->currConfig.forceSongSpeed = xs_cfg.forceSpeed;
217 224
218 225
224 engine->currConfig.filterFm = xs_cfg.sid1Filter.fm; 231 engine->currConfig.filterFm = xs_cfg.sid1Filter.fm;
225 engine->currConfig.filterFt = xs_cfg.sid1Filter.ft; 232 engine->currConfig.filterFt = xs_cfg.sid1Filter.ft;
226 233
227 234
228 /* Now set the emulator configuration */ 235 /* Now set the emulator configuration */
229 if (!engine->emu->setConfig(engine->currConfig)) { 236 if (!engine->emu->setConfig(engine->currConfig))
237 {
230 xs_error("[SIDPlay1] Emulator engine configuration failed!\n"); 238 xs_error("[SIDPlay1] Emulator engine configuration failed!\n");
231 return FALSE; 239 return FALSE;
232 } 240 }
233 241
234 /* Create sidtune object */ 242 /* Create sidtune object */
235 engine->tune = new sidTune(0); 243 engine->tune = new sidTune(0);
236 if (!engine->tune) { 244 if (!engine->tune)
245 {
237 xs_error("[SIDPlay1] Could not initialize SIDTune object.\n"); 246 xs_error("[SIDPlay1] Could not initialize SIDTune object.\n");
238 return FALSE; 247 return FALSE;
239 } 248 }
240 249
241 return TRUE; 250 return TRUE;
250 assert(state); 259 assert(state);
251 260
252 engine = (XSSIDPlay1 *) state->internal; 261 engine = (XSSIDPlay1 *) state->internal;
253 262
254 /* Free internals */ 263 /* Free internals */
255 if (engine->emu) { 264 if (engine->emu)
265 {
256 delete engine->emu; 266 delete engine->emu;
257 engine->emu = NULL; 267 engine->emu = NULL;
258 } 268 }
259 269
260 if (engine->tune) { 270 if (engine->tune)
271 {
261 delete engine->tune; 272 delete engine->tune;
262 engine->tune = NULL; 273 engine->tune = NULL;
263 } 274 }
264 275
265 xs_sidplay1_delete(state); 276 xs_sidplay1_delete(state);
277 assert(state); 288 assert(state);
278 289
279 engine = (XSSIDPlay1 *) state->internal; 290 engine = (XSSIDPlay1 *) state->internal;
280 if (!engine) return FALSE; 291 if (!engine) return FALSE;
281 292
282 if (!engine->tune) { 293 if (!engine->tune)
294 {
283 xs_error("[SIDPlay1] SID-tune struct pointer was NULL. This should not happen, report to XMMS-SID author.\n"); 295 xs_error("[SIDPlay1] SID-tune struct pointer was NULL. This should not happen, report to XMMS-SID author.\n");
284 return FALSE; 296 return FALSE;
285 } 297 }
286 298
287 if (!engine->tune->getStatus()) { 299 if (!engine->tune->getStatus())
300 {
288 xs_error("[SIDPlay1] SID-tune status check failed. This should not happen, report to XMMS-SID author.\n"); 301 xs_error("[SIDPlay1] SID-tune status check failed. This should not happen, report to XMMS-SID author.\n");
289 return FALSE; 302 return FALSE;
290 } 303 }
291 304
292 return sidEmuInitializeSong(*engine->emu, *engine->tune, state->currSong); 305 return sidEmuInitializeSong(*engine->emu, *engine->tune, state->currSong);