comparison src/audio/mint/SDL_mintaudio_xbios.c @ 1107:856f76a099c7

Can use both clocks of FDI interface on Falcon, plus digital output
author Patrice Mandin <patmandin@gmail.com>
date Sun, 07 Aug 2005 12:17:28 +0000
parents 524fd51f5d2c
children 12c49532be00
comparison
equal deleted inserted replaced
1106:524fd51f5d2c 1107:856f76a099c7
261 DMAAUDIO_IO.sync_div = sync_div; 261 DMAAUDIO_IO.sync_div = sync_div;
262 262
263 Super(oldstack); 263 Super(oldstack);
264 } 264 }
265 265
266 static Uint32 Mint_CheckExternalClock(void) 266 static void Mint_CheckExternalClock(_THIS)
267 { 267 {
268 #define SIZE_BUF_CLOCK_MEASURE (44100/10) 268 #define SIZE_BUF_CLOCK_MEASURE (44100/10)
269 269
270 unsigned long cookie_snd; 270 unsigned long cookie_snd;
271 Uint32 masterclock;
272 char *buffer; 271 char *buffer;
273 int i; 272 int i, j;
274 273
275 /* DSP present with its GPIO port ? */ 274 /* DSP present with its GPIO port ? */
276 if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { 275 if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
277 return 0; 276 return;
278 } 277 }
279 if ((cookie_snd & SND_DSP)==0) { 278 if ((cookie_snd & SND_DSP)==0) {
280 return 0; 279 return;
281 } 280 }
282 281
283 buffer = Atari_SysMalloc(SIZE_BUF_CLOCK_MEASURE, MX_STRAM); 282 buffer = Atari_SysMalloc(SIZE_BUF_CLOCK_MEASURE, MX_STRAM);
284 if (buffer==NULL) { 283 if (buffer==NULL) {
285 DEBUG_PRINT((DEBUG_NAME "Not enough memory for the measure\n")); 284 DEBUG_PRINT((DEBUG_NAME "Not enough memory for the measure\n"));
286 return 0; 285 return;
287 } 286 }
288 memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE); 287 memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE);
289
290 masterclock=0;
291 288
292 Buffoper(0); 289 Buffoper(0);
293 Settracks(0,0); 290 Settracks(0,0);
294 Setmontracks(0); 291 Setmontracks(0);
295 Setmode(MONO8); 292 Setmode(MONO8);
311 unsigned long khz; 308 unsigned long khz;
312 309
313 khz = ((SIZE_BUF_CLOCK_MEASURE/SDL_MintAudio_clocktics) +1) & 0xFFFFFFFE; 310 khz = ((SIZE_BUF_CLOCK_MEASURE/SDL_MintAudio_clocktics) +1) & 0xFFFFFFFE;
314 DEBUG_PRINT((DEBUG_NAME "measure %d: freq=%lu KHz\n", i+1, khz)); 311 DEBUG_PRINT((DEBUG_NAME "measure %d: freq=%lu KHz\n", i+1, khz));
315 312
316 if (i==0) { 313 if(khz==44) {
317 if(khz==44) { 314 for (j=1; j<4; j++) {
318 masterclock = MASTERCLOCK_44K; 315 SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_44K, (1<<j)-1, 2+i);
319 } 316 }
320 } else { 317 } else if (khz==48) {
321 if(khz==48) { 318 for (j=1; j<4; j++) {
322 masterclock = MASTERCLOCK_48K; 319 SDL_MintAudio_AddFrequency(this, MASTERCLOCK_48K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_48K, (1<<j)-1, 2+i);
323 } 320 }
324 } 321 }
325 } else { 322 } else {
326 DEBUG_PRINT((DEBUG_NAME "No measure\n")); 323 DEBUG_PRINT((DEBUG_NAME "No measure\n"));
327 } 324 }
329 DEBUG_PRINT((DEBUG_NAME "No SDMA clock\n")); 326 DEBUG_PRINT((DEBUG_NAME "No SDMA clock\n"));
330 } 327 }
331 328
332 Buffoper(0); /* stop */ 329 Buffoper(0); /* stop */
333 Jdisint(MFP_TIMERA); /* Uninstall interrupt */ 330 Jdisint(MFP_TIMERA); /* Uninstall interrupt */
334 if (masterclock == 0)
335 break;
336 } 331 }
337 332
338 Mfree(buffer); 333 Mfree(buffer);
339 return masterclock;
340 } 334 }
341 335
342 static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) 336 static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
343 { 337 {
344 int i; 338 int i;
354 if ((spec->format & 0x00ff)==16) { 348 if ((spec->format & 0x00ff)==16) {
355 spec->format |= 0x1000; /* Audio is always big endian */ 349 spec->format |= 0x1000; /* Audio is always big endian */
356 spec->channels=2; /* 16 bits always stereo */ 350 spec->channels=2; /* 16 bits always stereo */
357 } 351 }
358 352
359 extclock=Mint_CheckExternalClock(); 353 MINTAUDIO_freqcount=0;
354
355 /* Add external clocks if present */
356 Mint_CheckExternalClock(this);
360 357
361 /* Standard clocks */ 358 /* Standard clocks */
362 MINTAUDIO_freqcount=0;
363 for (i=1;i<12;i++) { 359 for (i=1;i<12;i++) {
364 /* Remove unusable Falcon codec predivisors */ 360 /* Remove unusable Falcon codec predivisors */
365 if ((i==6) || (i==8) || (i==10)) { 361 if ((i==6) || (i==8) || (i==10)) {
366 continue; 362 continue;
367 } 363 }
368 SDL_MintAudio_AddFrequency(this, MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1)), MASTERCLOCK_FALCON1, i); 364 SDL_MintAudio_AddFrequency(this, MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1)), MASTERCLOCK_FALCON1, i, -1);
369 }
370
371 if (extclock>0) {
372 for (i=1; i<4; i++) {
373 SDL_MintAudio_AddFrequency(this, extclock/(MASTERPREDIV_FALCON*(1<<i)), extclock, (1<<i)-1);
374 }
375 } 365 }
376 366
377 #if 1 367 #if 1
378 for (i=0; i<MINTAUDIO_freqcount; i++) { 368 for (i=0; i<MINTAUDIO_freqcount; i++) {
379 DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", 369 DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n",
422 DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n")); 412 DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n"));
423 } 413 }
424 414
425 dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock; 415 dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock;
426 prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; 416 prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor;
427 if (dmaclock != MASTERCLOCK_FALCON1) { 417 if (MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits != -1) {
428 Gpio(GPIO_SET,7); /* DSP port gpio outputs */ 418 Gpio(GPIO_SET,7); /* DSP port gpio outputs */
429 if (dmaclock == MASTERCLOCK_44K) { 419 Gpio(GPIO_WRITE, MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits);
430 Gpio(GPIO_WRITE,2); /* 22.5792 MHz for 44.1KHz */ 420 Devconnect2(DMAPLAY, DAC|EXTOUT, CLKEXT, prediv);
431 } else {
432 Gpio(GPIO_WRITE,3); /* 24.576 MHz for 48KHz */
433 }
434 Devconnect2(DMAPLAY, DAC, CLKEXT, prediv);
435 } else { 421 } else {
436 Devconnect2(DMAPLAY, DAC, CLK25M, prediv); 422 Devconnect2(DMAPLAY, DAC, CLK25M, prediv);
437 } 423 }
438 424
439 /* Set buffer */ 425 /* Set buffer */