Mercurial > sdl-ios-xcode
comparison src/audio/mint/SDL_mintaudio_xbios.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
64 | 64 |
65 static unsigned long cookie_snd; | 65 static unsigned long cookie_snd; |
66 | 66 |
67 /*--- Audio driver functions ---*/ | 67 /*--- Audio driver functions ---*/ |
68 | 68 |
69 static void Mint_CloseAudio (_THIS); | 69 static void Mint_CloseAudio(_THIS); |
70 static int Mint_OpenAudio (_THIS, SDL_AudioSpec * spec); | 70 static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec); |
71 static void Mint_LockAudio (_THIS); | 71 static void Mint_LockAudio(_THIS); |
72 static void Mint_UnlockAudio (_THIS); | 72 static void Mint_UnlockAudio(_THIS); |
73 | 73 |
74 /* To check/init hardware audio */ | 74 /* To check/init hardware audio */ |
75 static int Mint_CheckAudio (_THIS, SDL_AudioSpec * spec); | 75 static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec); |
76 static void Mint_InitAudio (_THIS, SDL_AudioSpec * spec); | 76 static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec); |
77 | 77 |
78 /*--- Audio driver bootstrap functions ---*/ | 78 /*--- Audio driver bootstrap functions ---*/ |
79 | 79 |
80 static int | 80 static int |
81 Audio_Available (void) | 81 Audio_Available(void) |
82 { | 82 { |
83 unsigned long dummy; | 83 unsigned long dummy; |
84 const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); | 84 const char *envr = SDL_getenv("SDL_AUDIODRIVER"); |
85 | 85 |
86 SDL_MintAudio_mint_present = (Getcookie (C_MiNT, &dummy) == C_FOUND); | 86 SDL_MintAudio_mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND); |
87 | 87 |
88 /* We can't use XBIOS in interrupt with Magic, don't know about thread */ | 88 /* We can't use XBIOS in interrupt with Magic, don't know about thread */ |
89 if (Getcookie (C_MagX, &dummy) == C_FOUND) { | 89 if (Getcookie(C_MagX, &dummy) == C_FOUND) { |
90 return (0); | 90 return (0); |
91 } | 91 } |
92 | 92 |
93 /* Check if user asked a different audio driver */ | 93 /* Check if user asked a different audio driver */ |
94 if ((envr) && (SDL_strcmp (envr, MINT_AUDIO_DRIVER_NAME) != 0)) { | 94 if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) { |
95 DEBUG_PRINT ((DEBUG_NAME "user asked a different audio driver\n")); | 95 DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n")); |
96 return (0); | 96 return (0); |
97 } | 97 } |
98 | 98 |
99 /* Cookie _SND present ? if not, assume ST machine */ | 99 /* Cookie _SND present ? if not, assume ST machine */ |
100 if (Getcookie (C__SND, &cookie_snd) == C_NOTFOUND) { | 100 if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { |
101 cookie_snd = SND_PSG; | 101 cookie_snd = SND_PSG; |
102 } | 102 } |
103 | 103 |
104 /* Check if we have 16 bits audio */ | 104 /* Check if we have 16 bits audio */ |
105 if ((cookie_snd & SND_16BIT) == 0) { | 105 if ((cookie_snd & SND_16BIT) == 0) { |
106 DEBUG_PRINT ((DEBUG_NAME "no 16 bits sound\n")); | 106 DEBUG_PRINT((DEBUG_NAME "no 16 bits sound\n")); |
107 return (0); | 107 return (0); |
108 } | 108 } |
109 | 109 |
110 /* Check if audio is lockable */ | 110 /* Check if audio is lockable */ |
111 if (Locksnd () != 1) { | 111 if (Locksnd() != 1) { |
112 DEBUG_PRINT ((DEBUG_NAME "audio locked by other application\n")); | 112 DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n")); |
113 return (0); | 113 return (0); |
114 } | 114 } |
115 | 115 |
116 Unlocksnd (); | 116 Unlocksnd(); |
117 | 117 |
118 DEBUG_PRINT ((DEBUG_NAME "XBIOS audio available!\n")); | 118 DEBUG_PRINT((DEBUG_NAME "XBIOS audio available!\n")); |
119 return (1); | 119 return (1); |
120 } | 120 } |
121 | 121 |
122 static void | 122 static void |
123 Audio_DeleteDevice (SDL_AudioDevice * device) | 123 Audio_DeleteDevice(SDL_AudioDevice * device) |
124 { | 124 { |
125 SDL_free (device->hidden); | 125 SDL_free(device->hidden); |
126 SDL_free (device); | 126 SDL_free(device); |
127 } | 127 } |
128 | 128 |
129 static SDL_AudioDevice * | 129 static SDL_AudioDevice * |
130 Audio_CreateDevice (int devindex) | 130 Audio_CreateDevice(int devindex) |
131 { | 131 { |
132 SDL_AudioDevice *this; | 132 SDL_AudioDevice *this; |
133 | 133 |
134 /* Initialize all variables that we clean on shutdown */ | 134 /* Initialize all variables that we clean on shutdown */ |
135 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); | 135 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); |
136 if (this) { | 136 if (this) { |
137 SDL_memset (this, 0, (sizeof *this)); | 137 SDL_memset(this, 0, (sizeof *this)); |
138 this->hidden = (struct SDL_PrivateAudioData *) | 138 this->hidden = (struct SDL_PrivateAudioData *) |
139 SDL_malloc ((sizeof *this->hidden)); | 139 SDL_malloc((sizeof *this->hidden)); |
140 } | 140 } |
141 if ((this == NULL) || (this->hidden == NULL)) { | 141 if ((this == NULL) || (this->hidden == NULL)) { |
142 SDL_OutOfMemory (); | 142 SDL_OutOfMemory(); |
143 if (this) { | 143 if (this) { |
144 SDL_free (this); | 144 SDL_free(this); |
145 } | 145 } |
146 return (0); | 146 return (0); |
147 } | 147 } |
148 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); | 148 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
149 | 149 |
150 /* Set the function pointers */ | 150 /* Set the function pointers */ |
151 this->OpenAudio = Mint_OpenAudio; | 151 this->OpenAudio = Mint_OpenAudio; |
152 this->CloseAudio = Mint_CloseAudio; | 152 this->CloseAudio = Mint_CloseAudio; |
153 this->LockAudio = Mint_LockAudio; | 153 this->LockAudio = Mint_LockAudio; |
161 MINT_AUDIO_DRIVER_NAME, "MiNT XBIOS audio driver", | 161 MINT_AUDIO_DRIVER_NAME, "MiNT XBIOS audio driver", |
162 Audio_Available, Audio_CreateDevice | 162 Audio_Available, Audio_CreateDevice |
163 }; | 163 }; |
164 | 164 |
165 static void | 165 static void |
166 Mint_LockAudio (_THIS) | 166 Mint_LockAudio(_THIS) |
167 { | 167 { |
168 /* Stop replay */ | 168 /* Stop replay */ |
169 Buffoper (0); | 169 Buffoper(0); |
170 } | 170 } |
171 | 171 |
172 static void | 172 static void |
173 Mint_UnlockAudio (_THIS) | 173 Mint_UnlockAudio(_THIS) |
174 { | 174 { |
175 /* Restart replay */ | 175 /* Restart replay */ |
176 Buffoper (SB_PLA_ENA | SB_PLA_RPT); | 176 Buffoper(SB_PLA_ENA | SB_PLA_RPT); |
177 } | 177 } |
178 | 178 |
179 static void | 179 static void |
180 Mint_CloseAudio (_THIS) | 180 Mint_CloseAudio(_THIS) |
181 { | 181 { |
182 /* Stop replay */ | 182 /* Stop replay */ |
183 SDL_MintAudio_WaitThread (); | 183 SDL_MintAudio_WaitThread(); |
184 Buffoper (0); | 184 Buffoper(0); |
185 | 185 |
186 if (!SDL_MintAudio_mint_present) { | 186 if (!SDL_MintAudio_mint_present) { |
187 /* Uninstall interrupt */ | 187 /* Uninstall interrupt */ |
188 Jdisint (MFP_DMASOUND); | 188 Jdisint(MFP_DMASOUND); |
189 } | 189 } |
190 | 190 |
191 /* Wait if currently playing sound */ | 191 /* Wait if currently playing sound */ |
192 while (SDL_MintAudio_mutex != 0) { | 192 while (SDL_MintAudio_mutex != 0) { |
193 } | 193 } |
194 | 194 |
195 /* Clear buffers */ | 195 /* Clear buffers */ |
196 if (SDL_MintAudio_audiobuf[0]) { | 196 if (SDL_MintAudio_audiobuf[0]) { |
197 Mfree (SDL_MintAudio_audiobuf[0]); | 197 Mfree(SDL_MintAudio_audiobuf[0]); |
198 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; | 198 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; |
199 } | 199 } |
200 | 200 |
201 /* Unlock sound system */ | 201 /* Unlock sound system */ |
202 Unlocksnd (); | 202 Unlocksnd(); |
203 } | 203 } |
204 | 204 |
205 /* Falcon XBIOS implementation of Devconnect() is buggy with external clock */ | 205 /* Falcon XBIOS implementation of Devconnect() is buggy with external clock */ |
206 static void | 206 static void |
207 Devconnect2 (int src, int dst, int sclk, int pre) | 207 Devconnect2(int src, int dst, int sclk, int pre) |
208 { | 208 { |
209 static const unsigned short MASK1[3] = { 0, 0x6000, 0 }; | 209 static const unsigned short MASK1[3] = { 0, 0x6000, 0 }; |
210 static const unsigned short MASK2[4] = { 0xFFF0, 0xFF8F, 0xF0FF, 0x0FFF }; | 210 static const unsigned short MASK2[4] = { 0xFFF0, 0xFF8F, 0xF0FF, 0x0FFF }; |
211 static const unsigned short INDEX1[4] = { 1, 3, 5, 7 }; | 211 static const unsigned short INDEX1[4] = { 1, 3, 5, 7 }; |
212 static const unsigned short INDEX2[4] = { 0, 2, 4, 6 }; | 212 static const unsigned short INDEX2[4] = { 0, 2, 4, 6 }; |
215 | 215 |
216 if (dst == 0) { | 216 if (dst == 0) { |
217 return; | 217 return; |
218 } | 218 } |
219 | 219 |
220 oldstack = (void *) Super (0); | 220 oldstack = (void *) Super(0); |
221 | 221 |
222 dev_ctrl = DMAAUDIO_IO.dev_ctrl; | 222 dev_ctrl = DMAAUDIO_IO.dev_ctrl; |
223 dest_ctrl = DMAAUDIO_IO.dest_ctrl; | 223 dest_ctrl = DMAAUDIO_IO.dest_ctrl; |
224 dev_ctrl &= MASK2[src]; | 224 dev_ctrl &= MASK2[src]; |
225 | 225 |
262 | 262 |
263 DMAAUDIO_IO.dev_ctrl = dev_ctrl; | 263 DMAAUDIO_IO.dev_ctrl = dev_ctrl; |
264 DMAAUDIO_IO.dest_ctrl = dest_ctrl; | 264 DMAAUDIO_IO.dest_ctrl = dest_ctrl; |
265 DMAAUDIO_IO.sync_div = sync_div; | 265 DMAAUDIO_IO.sync_div = sync_div; |
266 | 266 |
267 Super (oldstack); | 267 Super(oldstack); |
268 } | 268 } |
269 | 269 |
270 static void | 270 static void |
271 Mint_CheckExternalClock (_THIS) | 271 Mint_CheckExternalClock(_THIS) |
272 { | 272 { |
273 #define SIZE_BUF_CLOCK_MEASURE (44100/10) | 273 #define SIZE_BUF_CLOCK_MEASURE (44100/10) |
274 | 274 |
275 unsigned long cookie_snd; | 275 unsigned long cookie_snd; |
276 char *buffer; | 276 char *buffer; |
277 int i, j; | 277 int i, j; |
278 | 278 |
279 /* DSP present with its GPIO port ? */ | 279 /* DSP present with its GPIO port ? */ |
280 if (Getcookie (C__SND, &cookie_snd) == C_NOTFOUND) { | 280 if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { |
281 return; | 281 return; |
282 } | 282 } |
283 if ((cookie_snd & SND_DSP) == 0) { | 283 if ((cookie_snd & SND_DSP) == 0) { |
284 return; | 284 return; |
285 } | 285 } |
286 | 286 |
287 buffer = Atari_SysMalloc (SIZE_BUF_CLOCK_MEASURE, MX_STRAM); | 287 buffer = Atari_SysMalloc(SIZE_BUF_CLOCK_MEASURE, MX_STRAM); |
288 if (buffer == NULL) { | 288 if (buffer == NULL) { |
289 DEBUG_PRINT ((DEBUG_NAME "Not enough memory for the measure\n")); | 289 DEBUG_PRINT((DEBUG_NAME "Not enough memory for the measure\n")); |
290 return; | 290 return; |
291 } | 291 } |
292 SDL_memset (buffer, 0, SIZE_BUF_CLOCK_MEASURE); | 292 SDL_memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE); |
293 | 293 |
294 Buffoper (0); | 294 Buffoper(0); |
295 Settracks (0, 0); | 295 Settracks(0, 0); |
296 Setmontracks (0); | 296 Setmontracks(0); |
297 Setmode (MONO8); | 297 Setmode(MONO8); |
298 Jdisint (MFP_TIMERA); | 298 Jdisint(MFP_TIMERA); |
299 | 299 |
300 for (i = 0; i < 2; i++) { | 300 for (i = 0; i < 2; i++) { |
301 Gpio (GPIO_SET, 7); /* DSP port gpio outputs */ | 301 Gpio(GPIO_SET, 7); /* DSP port gpio outputs */ |
302 Gpio (GPIO_WRITE, 2 + i); /* 22.5792/24.576 MHz for 44.1/48KHz */ | 302 Gpio(GPIO_WRITE, 2 + i); /* 22.5792/24.576 MHz for 44.1/48KHz */ |
303 Devconnect2 (DMAPLAY, DAC, CLKEXT, CLK50K); /* Matrix and clock source */ | 303 Devconnect2(DMAPLAY, DAC, CLKEXT, CLK50K); /* Matrix and clock source */ |
304 Setbuffer (0, buffer, buffer + SIZE_BUF_CLOCK_MEASURE); /* Set buffer */ | 304 Setbuffer(0, buffer, buffer + SIZE_BUF_CLOCK_MEASURE); /* Set buffer */ |
305 Xbtimer (XB_TIMERA, 5, 38, SDL_MintAudio_XbiosInterruptMeasureClock); /* delay mode timer A, prediv /64, 1KHz */ | 305 Xbtimer(XB_TIMERA, 5, 38, SDL_MintAudio_XbiosInterruptMeasureClock); /* delay mode timer A, prediv /64, 1KHz */ |
306 Jenabint (MFP_TIMERA); | 306 Jenabint(MFP_TIMERA); |
307 SDL_MintAudio_clocktics = 0; | 307 SDL_MintAudio_clocktics = 0; |
308 Buffoper (SB_PLA_ENA); | 308 Buffoper(SB_PLA_ENA); |
309 usleep (110000); | 309 usleep(110000); |
310 | 310 |
311 if ((Buffoper (-1) & 1) == 0) { | 311 if ((Buffoper(-1) & 1) == 0) { |
312 if (SDL_MintAudio_clocktics) { | 312 if (SDL_MintAudio_clocktics) { |
313 unsigned long khz; | 313 unsigned long khz; |
314 | 314 |
315 khz = | 315 khz = |
316 ((SIZE_BUF_CLOCK_MEASURE / | 316 ((SIZE_BUF_CLOCK_MEASURE / |
317 SDL_MintAudio_clocktics) + 1) & 0xFFFFFFFE; | 317 SDL_MintAudio_clocktics) + 1) & 0xFFFFFFFE; |
318 DEBUG_PRINT ((DEBUG_NAME "measure %d: freq=%lu KHz\n", | 318 DEBUG_PRINT((DEBUG_NAME "measure %d: freq=%lu KHz\n", |
319 i + 1, khz)); | 319 i + 1, khz)); |
320 | 320 |
321 if (khz == 44) { | 321 if (khz == 44) { |
322 for (j = 1; j < 4; j++) { | 322 for (j = 1; j < 4; j++) { |
323 SDL_MintAudio_AddFrequency (this, | 323 SDL_MintAudio_AddFrequency(this, |
324 MASTERCLOCK_44K | 324 MASTERCLOCK_44K |
325 / | 325 / |
326 (MASTERPREDIV_FALCON | 326 (MASTERPREDIV_FALCON |
327 * (1 << j)), | 327 * (1 << j)), |
328 MASTERCLOCK_44K, | 328 MASTERCLOCK_44K, |
329 (1 << j) - 1, 2 + i); | 329 (1 << j) - 1, 2 + i); |
330 } | 330 } |
331 } else if (khz == 48) { | 331 } else if (khz == 48) { |
332 for (j = 1; j < 4; j++) { | 332 for (j = 1; j < 4; j++) { |
333 SDL_MintAudio_AddFrequency (this, | 333 SDL_MintAudio_AddFrequency(this, |
334 MASTERCLOCK_48K | 334 MASTERCLOCK_48K |
335 / | 335 / |
336 (MASTERPREDIV_FALCON | 336 (MASTERPREDIV_FALCON |
337 * (1 << j)), | 337 * (1 << j)), |
338 MASTERCLOCK_48K, | 338 MASTERCLOCK_48K, |
339 (1 << j) - 1, 2 + i); | 339 (1 << j) - 1, 2 + i); |
340 } | 340 } |
341 } | 341 } |
342 } else { | 342 } else { |
343 DEBUG_PRINT ((DEBUG_NAME "No measure\n")); | 343 DEBUG_PRINT((DEBUG_NAME "No measure\n")); |
344 } | 344 } |
345 } else { | 345 } else { |
346 DEBUG_PRINT ((DEBUG_NAME "No SDMA clock\n")); | 346 DEBUG_PRINT((DEBUG_NAME "No SDMA clock\n")); |
347 } | 347 } |
348 | 348 |
349 Buffoper (0); /* stop */ | 349 Buffoper(0); /* stop */ |
350 Jdisint (MFP_TIMERA); /* Uninstall interrupt */ | 350 Jdisint(MFP_TIMERA); /* Uninstall interrupt */ |
351 } | 351 } |
352 | 352 |
353 Mfree (buffer); | 353 Mfree(buffer); |
354 } | 354 } |
355 | 355 |
356 static int | 356 static int |
357 Mint_CheckAudio (_THIS, SDL_AudioSpec * spec) | 357 Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) |
358 { | 358 { |
359 int i; | 359 int i; |
360 Uint32 extclock; | 360 Uint32 extclock; |
361 | 361 |
362 DEBUG_PRINT ((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); | 362 DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); |
363 DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); | 363 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); |
364 DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); | 364 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); |
365 DEBUG_PRINT (("channels=%d, ", spec->channels)); | 365 DEBUG_PRINT(("channels=%d, ", spec->channels)); |
366 DEBUG_PRINT (("freq=%d\n", spec->freq)); | 366 DEBUG_PRINT(("freq=%d\n", spec->freq)); |
367 | 367 |
368 spec->format |= 0x8000; /* Audio is always signed */ | 368 spec->format |= 0x8000; /* Audio is always signed */ |
369 if ((spec->format & 0x00ff) == 16) { | 369 if ((spec->format & 0x00ff) == 16) { |
370 spec->format |= 0x1000; /* Audio is always big endian */ | 370 spec->format |= 0x1000; /* Audio is always big endian */ |
371 spec->channels = 2; /* 16 bits always stereo */ | 371 spec->channels = 2; /* 16 bits always stereo */ |
372 } | 372 } |
373 | 373 |
374 MINTAUDIO_freqcount = 0; | 374 MINTAUDIO_freqcount = 0; |
375 | 375 |
376 /* Add external clocks if present */ | 376 /* Add external clocks if present */ |
377 Mint_CheckExternalClock (this); | 377 Mint_CheckExternalClock(this); |
378 | 378 |
379 /* Standard clocks */ | 379 /* Standard clocks */ |
380 for (i = 1; i < 12; i++) { | 380 for (i = 1; i < 12; i++) { |
381 /* Remove unusable Falcon codec predivisors */ | 381 /* Remove unusable Falcon codec predivisors */ |
382 if ((i == 6) || (i == 8) || (i == 10)) { | 382 if ((i == 6) || (i == 8) || (i == 10)) { |
383 continue; | 383 continue; |
384 } | 384 } |
385 SDL_MintAudio_AddFrequency (this, | 385 SDL_MintAudio_AddFrequency(this, |
386 MASTERCLOCK_FALCON1 / | 386 MASTERCLOCK_FALCON1 / |
387 (MASTERPREDIV_FALCON * (i + 1)), | 387 (MASTERPREDIV_FALCON * (i + 1)), |
388 MASTERCLOCK_FALCON1, i, -1); | 388 MASTERCLOCK_FALCON1, i, -1); |
389 } | 389 } |
390 | 390 |
391 #if 1 | 391 #if 1 |
392 for (i = 0; i < MINTAUDIO_freqcount; i++) { | 392 for (i = 0; i < MINTAUDIO_freqcount; i++) { |
393 DEBUG_PRINT ((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", | 393 DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", |
394 i, MINTAUDIO_frequencies[i].frequency, | 394 i, MINTAUDIO_frequencies[i].frequency, |
395 MINTAUDIO_frequencies[i].masterclock, | 395 MINTAUDIO_frequencies[i].masterclock, |
396 MINTAUDIO_frequencies[i].predivisor)); | 396 MINTAUDIO_frequencies[i].predivisor)); |
397 } | 397 } |
398 #endif | 398 #endif |
399 | 399 |
400 MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency (this, spec->freq); | 400 MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq); |
401 spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; | 401 spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; |
402 | 402 |
403 DEBUG_PRINT ((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); | 403 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); |
404 DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); | 404 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); |
405 DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); | 405 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); |
406 DEBUG_PRINT (("channels=%d, ", spec->channels)); | 406 DEBUG_PRINT(("channels=%d, ", spec->channels)); |
407 DEBUG_PRINT (("freq=%d\n", spec->freq)); | 407 DEBUG_PRINT(("freq=%d\n", spec->freq)); |
408 | 408 |
409 return 0; | 409 return 0; |
410 } | 410 } |
411 | 411 |
412 static void | 412 static void |
413 Mint_InitAudio (_THIS, SDL_AudioSpec * spec) | 413 Mint_InitAudio(_THIS, SDL_AudioSpec * spec) |
414 { | 414 { |
415 int channels_mode, dmaclock, prediv; | 415 int channels_mode, dmaclock, prediv; |
416 void *buffer; | 416 void *buffer; |
417 | 417 |
418 /* Stop currently playing sound */ | 418 /* Stop currently playing sound */ |
419 SDL_MintAudio_quit_thread = SDL_FALSE; | 419 SDL_MintAudio_quit_thread = SDL_FALSE; |
420 SDL_MintAudio_thread_finished = SDL_TRUE; | 420 SDL_MintAudio_thread_finished = SDL_TRUE; |
421 SDL_MintAudio_WaitThread (); | 421 SDL_MintAudio_WaitThread(); |
422 Buffoper (0); | 422 Buffoper(0); |
423 | 423 |
424 /* Set replay tracks */ | 424 /* Set replay tracks */ |
425 Settracks (0, 0); | 425 Settracks(0, 0); |
426 Setmontracks (0); | 426 Setmontracks(0); |
427 | 427 |
428 /* Select replay format */ | 428 /* Select replay format */ |
429 channels_mode = STEREO16; | 429 channels_mode = STEREO16; |
430 switch (spec->format & 0xff) { | 430 switch (spec->format & 0xff) { |
431 case 8: | 431 case 8: |
434 } else { | 434 } else { |
435 channels_mode = MONO8; | 435 channels_mode = MONO8; |
436 } | 436 } |
437 break; | 437 break; |
438 } | 438 } |
439 if (Setmode (channels_mode) < 0) { | 439 if (Setmode(channels_mode) < 0) { |
440 DEBUG_PRINT ((DEBUG_NAME "Setmode() failed\n")); | 440 DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n")); |
441 } | 441 } |
442 | 442 |
443 dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock; | 443 dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock; |
444 prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; | 444 prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; |
445 if (MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits != -1) { | 445 if (MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits != -1) { |
446 Gpio (GPIO_SET, 7); /* DSP port gpio outputs */ | 446 Gpio(GPIO_SET, 7); /* DSP port gpio outputs */ |
447 Gpio (GPIO_WRITE, MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits); | 447 Gpio(GPIO_WRITE, MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits); |
448 Devconnect2 (DMAPLAY, DAC | EXTOUT, CLKEXT, prediv); | 448 Devconnect2(DMAPLAY, DAC | EXTOUT, CLKEXT, prediv); |
449 } else { | 449 } else { |
450 Devconnect2 (DMAPLAY, DAC, CLK25M, prediv); | 450 Devconnect2(DMAPLAY, DAC, CLK25M, prediv); |
451 } | 451 } |
452 | 452 |
453 /* Set buffer */ | 453 /* Set buffer */ |
454 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; | 454 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; |
455 if (Setbuffer (0, buffer, buffer + spec->size) < 0) { | 455 if (Setbuffer(0, buffer, buffer + spec->size) < 0) { |
456 DEBUG_PRINT ((DEBUG_NAME "Setbuffer() failed\n")); | 456 DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n")); |
457 } | 457 } |
458 | 458 |
459 if (SDL_MintAudio_mint_present) { | 459 if (SDL_MintAudio_mint_present) { |
460 SDL_MintAudio_thread_pid = tfork (SDL_MintAudio_Thread, 0); | 460 SDL_MintAudio_thread_pid = tfork(SDL_MintAudio_Thread, 0); |
461 } else { | 461 } else { |
462 /* Install interrupt */ | 462 /* Install interrupt */ |
463 Jdisint (MFP_DMASOUND); | 463 Jdisint(MFP_DMASOUND); |
464 Xbtimer (XB_TIMERA, 8, 1, SDL_MintAudio_XbiosInterrupt); | 464 Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_XbiosInterrupt); |
465 Jenabint (MFP_DMASOUND); | 465 Jenabint(MFP_DMASOUND); |
466 | 466 |
467 if (Setinterrupt (SI_TIMERA, SI_PLAY) < 0) { | 467 if (Setinterrupt(SI_TIMERA, SI_PLAY) < 0) { |
468 DEBUG_PRINT ((DEBUG_NAME "Setinterrupt() failed\n")); | 468 DEBUG_PRINT((DEBUG_NAME "Setinterrupt() failed\n")); |
469 } | 469 } |
470 } | 470 } |
471 | 471 |
472 /* Go */ | 472 /* Go */ |
473 Buffoper (SB_PLA_ENA | SB_PLA_RPT); | 473 Buffoper(SB_PLA_ENA | SB_PLA_RPT); |
474 DEBUG_PRINT ((DEBUG_NAME "hardware initialized\n")); | 474 DEBUG_PRINT((DEBUG_NAME "hardware initialized\n")); |
475 } | 475 } |
476 | 476 |
477 static int | 477 static int |
478 Mint_OpenAudio (_THIS, SDL_AudioSpec * spec) | 478 Mint_OpenAudio(_THIS, SDL_AudioSpec * spec) |
479 { | 479 { |
480 /* Lock sound system */ | 480 /* Lock sound system */ |
481 if (Locksnd () != 1) { | 481 if (Locksnd() != 1) { |
482 SDL_SetError ("Mint_OpenAudio: Audio system already in use"); | 482 SDL_SetError("Mint_OpenAudio: Audio system already in use"); |
483 return (-1); | 483 return (-1); |
484 } | 484 } |
485 | 485 |
486 SDL_MintAudio_device = this; | 486 SDL_MintAudio_device = this; |
487 | 487 |
488 /* Check audio capabilities */ | 488 /* Check audio capabilities */ |
489 if (Mint_CheckAudio (this, spec) == -1) { | 489 if (Mint_CheckAudio(this, spec) == -1) { |
490 return -1; | 490 return -1; |
491 } | 491 } |
492 | 492 |
493 SDL_CalculateAudioSpec (spec); | 493 SDL_CalculateAudioSpec(spec); |
494 | 494 |
495 /* Allocate memory for audio buffers in DMA-able RAM */ | 495 /* Allocate memory for audio buffers in DMA-able RAM */ |
496 DEBUG_PRINT ((DEBUG_NAME "buffer size=%d\n", spec->size)); | 496 DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); |
497 | 497 |
498 SDL_MintAudio_audiobuf[0] = Atari_SysMalloc (spec->size * 2, MX_STRAM); | 498 SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM); |
499 if (SDL_MintAudio_audiobuf[0] == NULL) { | 499 if (SDL_MintAudio_audiobuf[0] == NULL) { |
500 SDL_SetError ("MINT_OpenAudio: Not enough memory for audio buffer"); | 500 SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); |
501 return (-1); | 501 return (-1); |
502 } | 502 } |
503 SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; | 503 SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; |
504 SDL_MintAudio_numbuf = 0; | 504 SDL_MintAudio_numbuf = 0; |
505 SDL_memset (SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); | 505 SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); |
506 SDL_MintAudio_audiosize = spec->size; | 506 SDL_MintAudio_audiosize = spec->size; |
507 SDL_MintAudio_mutex = 0; | 507 SDL_MintAudio_mutex = 0; |
508 | 508 |
509 DEBUG_PRINT ((DEBUG_NAME "buffer 0 at 0x%08x\n", | 509 DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", |
510 SDL_MintAudio_audiobuf[0])); | 510 SDL_MintAudio_audiobuf[0])); |
511 DEBUG_PRINT ((DEBUG_NAME "buffer 1 at 0x%08x\n", | 511 DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", |
512 SDL_MintAudio_audiobuf[1])); | 512 SDL_MintAudio_audiobuf[1])); |
513 | 513 |
514 /* Setup audio hardware */ | 514 /* Setup audio hardware */ |
515 Mint_InitAudio (this, spec); | 515 Mint_InitAudio(this, spec); |
516 | 516 |
517 return (1); /* We don't use SDL threaded audio */ | 517 return (1); /* We don't use SDL threaded audio */ |
518 } | 518 } |
519 | 519 |
520 /* vi: set ts=4 sw=4 expandtab: */ | 520 /* vi: set ts=4 sw=4 expandtab: */ |