static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) { int i, masterprediv, sfreq; unsigned long masterclock; DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); if (spec->channels > 2) spec->channels = 2; /* Check formats available */ spec->format = AUDIO_S8; /* Calculate and select the closest frequency */ sfreq=0; masterclock=MASTERCLOCK_STE; masterprediv=MASTERPREDIV_STE; switch(cookie_mch>>16) { case MCH_TT: masterclock=MASTERCLOCK_TT; masterprediv=MASTERPREDIV_TT; break; case MCH_F30: case MCH_ARANYM: masterclock=MASTERCLOCK_FALCON1; masterprediv=MASTERPREDIV_FALCON; sfreq=1; break; } MINTAUDIO_freqcount=0; for (i=sfreq;i<4;i++) { SDL_MintAudio_AddFrequency(this, masterclock/(masterprediv*(1<<i)), masterclock, i-sfreq, -1); } #if 1 for (i=0; i<MINTAUDIO_freqcount; i++) { DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock, MINTAUDIO_frequencies[i].predivisor )); } #endif MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq); spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); return 0; }
static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) { int i; Uint32 extclock; DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); if (spec->channels > 2) { spec->channels = 2; /* no more than stereo! */ } spec->format |= 0x8000; /* Audio is always signed */ if ((spec->format & 0x00ff)==16) { spec->format |= 0x1000; /* Audio is always big endian */ spec->channels=2; /* 16 bits always stereo */ } MINTAUDIO_freqcount=0; /* Add external clocks if present */ Mint_CheckExternalClock(this); /* Standard clocks */ for (i=1;i<12;i++) { /* Remove unusable Falcon codec predivisors */ if ((i==6) || (i==8) || (i==10)) { continue; } SDL_MintAudio_AddFrequency(this, MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1)), MASTERCLOCK_FALCON1, i, -1); } #if 1 for (i=0; i<MINTAUDIO_freqcount; i++) { DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock, MINTAUDIO_frequencies[i].predivisor )); } #endif MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq); spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); return 0; }
static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) { int i; DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); if (spec->channels > 2) { spec->channels = 2; } spec->format |= 0x8000; if ((spec->format & 0x00ff)==16) { spec->format |= 0x1000; spec->channels=2; } MINTAUDIO_freqcount=0; Mint_CheckExternalClock(this); for (i=1;i<12;i++) { if ((i==6) || (i==8) || (i==10)) { continue; } SDL_MintAudio_AddFrequency(this, MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1)), MASTERCLOCK_FALCON1, i, -1); } #if 1 for (i=0; i<MINTAUDIO_freqcount; i++) { DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock, MINTAUDIO_frequencies[i].predivisor )); } #endif MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq); spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); return 0; }
static int MINTSTFA_CheckAudio(_THIS) { int i; DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", SDL_AUDIO_BITSIZE(this->spec.format))); DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format))); DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format))); DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format))); DEBUG_PRINT(("channels=%d, ", this->spec.channels)); DEBUG_PRINT(("freq=%d\n", this->spec.freq)); if (SDL_AUDIO_BITSIZE(this->spec.format) > 16) { this->spec.format = AUDIO_S16SYS; /* clamp out int32/float32 ... */ } if (this->spec.channels > 2) { this->spec.channels = 2; /* no more than stereo! */ } /* Check formats available */ MINTAUDIO_freqcount = 0; for (i = 0; i < 16; i++) { SDL_MintAudio_AddFrequency(this, freqs[i], 0, i, -1); } #if 1 for (i = 0; i < MINTAUDIO_freqcount; i++) { DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock, MINTAUDIO_frequencies[i].predivisor)); } #endif MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, this->spec.freq); this->spec.freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", SDL_AUDIO_BITSIZE(this->spec.format))); DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format))); DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format))); DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format))); DEBUG_PRINT(("channels=%d, ", this->spec.channels)); DEBUG_PRINT(("freq=%d\n", this->spec.freq)); return 0; }
static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) { int i; DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); if (spec->channels > 2) { spec->channels = 2; /* no more than stereo! */ } /* Check formats available */ MINTAUDIO_freqcount=0; for (i=0;i<16;i++) { SDL_MintAudio_AddFrequency(this, freqs[i], 0, i, -1); } #if 1 for (i=0; i<MINTAUDIO_freqcount; i++) { DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock, MINTAUDIO_frequencies[i].predivisor )); } #endif MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq); spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); return 0; }
static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) { long snd_format = 0; int i, resolution, format_signed, format_bigendian; Uint16 test_format = SDL_FirstAudioFormat(spec->format); int valid_datatype = 0; resolution = spec->format & 0x00ff; format_signed = ((spec->format & 0x8000)!=0); format_bigendian = ((spec->format & 0x1000)!=0); DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); if (spec->channels > 2) { spec->channels = 2; } while ((!valid_datatype) && (test_format)) { snd_format = Sndstatus(SND_QUERYFORMATS); spec->format = test_format; resolution = spec->format & 0xff; format_signed = (spec->format & (1<<15)); format_bigendian = (spec->format & (1<<12)); switch (test_format) { case AUDIO_U8: case AUDIO_S8: if (snd_format & SND_FORMAT8) { valid_datatype = 1; snd_format = Sndstatus(SND_QUERY8BIT); } break; case AUDIO_U16LSB: case AUDIO_S16LSB: case AUDIO_U16MSB: case AUDIO_S16MSB: if (snd_format & SND_FORMAT16) { valid_datatype = 1; snd_format = Sndstatus(SND_QUERY16BIT); } break; default: test_format = SDL_NextAudioFormat(); break; } } if (!valid_datatype) { SDL_SetError("Unsupported audio format"); return (-1); } if (format_signed) { if (snd_format & SND_FORMATSIGNED) { } else if (snd_format & SND_FORMATUNSIGNED) { spec->format = spec->format & (~0x8000); } } else { if (snd_format & SND_FORMATUNSIGNED) { } else if (snd_format & SND_FORMATSIGNED) { spec->format |= 0x8000; } } if (format_bigendian) { if (snd_format & SND_FORMATBIGENDIAN) { } else if (snd_format & SND_FORMATLITTLEENDIAN) { spec->format = spec->format & (~0x1000); } } else { if (snd_format & SND_FORMATLITTLEENDIAN) { } else if (snd_format & SND_FORMATBIGENDIAN) { spec->format |= 0x1000; } } MINTAUDIO_freqcount=0; for (i=1;i<4;i++) { SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(1<<i)), MASTERCLOCK_44K, (1<<i)-1, -1); } #if 1 for (i=0; i<MINTAUDIO_freqcount; i++) { DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock, MINTAUDIO_frequencies[i].predivisor )); } #endif MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq); spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); return 0; }
static void Mint_CheckExternalClock(_THIS) { #define SIZE_BUF_CLOCK_MEASURE (44100/10) char *buffer; int i, j; if ((cookie_snd & SND_DSP)==0) { return; } buffer = Atari_SysMalloc(SIZE_BUF_CLOCK_MEASURE, MX_STRAM); if (buffer==NULL) { DEBUG_PRINT((DEBUG_NAME "Not enough memory for the measure\n")); return; } SDL_memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE); Buffoper(0); Settracks(0,0); Setmontracks(0); Setmode(MONO8); Jdisint(MFP_TIMERA); for (i=0; i<2; i++) { Gpio(GPIO_SET,7); Gpio(GPIO_WRITE,2+i); Devconnect2(DMAPLAY, DAC, CLKEXT, CLK50K); Setbuffer(0, buffer, buffer + SIZE_BUF_CLOCK_MEASURE); Xbtimer(XB_TIMERA, 5, 38, SDL_MintAudio_XbiosInterruptMeasureClock); Jenabint(MFP_TIMERA); SDL_MintAudio_clocktics = 0; Buffoper(SB_PLA_ENA); usleep(110000); if((Buffoper(-1) & 1)==0) { if (SDL_MintAudio_clocktics) { unsigned long khz; khz = ((SIZE_BUF_CLOCK_MEASURE/SDL_MintAudio_clocktics) +1) & 0xFFFFFFFE; DEBUG_PRINT((DEBUG_NAME "measure %d: freq=%lu KHz\n", i+1, khz)); if(khz==44) { for (j=1; j<4; j++) { SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_44K, (1<<j)-1, 2+i); } } else if (khz==48) { for (j=1; j<4; j++) { SDL_MintAudio_AddFrequency(this, MASTERCLOCK_48K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_48K, (1<<j)-1, 2+i); } } } else { DEBUG_PRINT((DEBUG_NAME "No measure\n")); } } else { DEBUG_PRINT((DEBUG_NAME "No SDMA clock\n")); } Buffoper(0); Jdisint(MFP_TIMERA); } Mfree(buffer); }
static void Mint_CheckExternalClock(_THIS) { #define SIZE_BUF_CLOCK_MEASURE (44100/10) unsigned long cookie_snd; char *buffer; int i, j; /* DSP present with its GPIO port ? */ if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { return; } if ((cookie_snd & SND_DSP)==0) { return; } buffer = Atari_SysMalloc(SIZE_BUF_CLOCK_MEASURE, MX_STRAM); if (buffer==NULL) { DEBUG_PRINT((DEBUG_NAME "Not enough memory for the measure\n")); return; } SDL_memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE); Buffoper(0); Settracks(0,0); Setmontracks(0); Setmode(MONO8); Jdisint(MFP_TIMERA); for (i=0; i<2; i++) { Gpio(GPIO_SET,7); /* DSP port gpio outputs */ Gpio(GPIO_WRITE,2+i); /* 22.5792/24.576 MHz for 44.1/48KHz */ Devconnect2(DMAPLAY, DAC, CLKEXT, CLK50K); /* Matrix and clock source */ Setbuffer(0, buffer, buffer + SIZE_BUF_CLOCK_MEASURE); /* Set buffer */ Xbtimer(XB_TIMERA, 5, 38, SDL_MintAudio_XbiosInterruptMeasureClock); /* delay mode timer A, prediv /64, 1KHz */ Jenabint(MFP_TIMERA); SDL_MintAudio_clocktics = 0; Buffoper(SB_PLA_ENA); usleep(110000); if((Buffoper(-1) & 1)==0) { if (SDL_MintAudio_clocktics) { unsigned long khz; khz = ((SIZE_BUF_CLOCK_MEASURE/SDL_MintAudio_clocktics) +1) & 0xFFFFFFFE; DEBUG_PRINT((DEBUG_NAME "measure %d: freq=%lu KHz\n", i+1, khz)); if(khz==44) { for (j=1; j<4; j++) { SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_44K, (1<<j)-1, 2+i); } } else if (khz==48) { for (j=1; j<4; j++) { SDL_MintAudio_AddFrequency(this, MASTERCLOCK_48K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_48K, (1<<j)-1, 2+i); } } } else { DEBUG_PRINT((DEBUG_NAME "No measure\n")); } } else { DEBUG_PRINT((DEBUG_NAME "No SDMA clock\n")); } Buffoper(0); /* stop */ Jdisint(MFP_TIMERA); /* Uninstall interrupt */ } Mfree(buffer); }
static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) { long snd_format; int i, resolution, format_signed, format_bigendian; resolution = spec->format & 0x00ff; format_signed = ((spec->format & 0x8000)!=0); format_bigendian = ((spec->format & 0x1000)!=0); DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); /* Check formats available */ snd_format = Sndstatus(SND_QUERYFORMATS); switch (resolution) { case 8: if ((snd_format & SND_FORMAT8)==0) { SDL_SetError("Mint_CheckAudio: 8 bits samples not supported"); return -1; } snd_format = Sndstatus(SND_QUERY8BIT); break; case 16: if ((snd_format & SND_FORMAT16)==0) { SDL_SetError("Mint_CheckAudio: 16 bits samples not supported"); return -1; } snd_format = Sndstatus(SND_QUERY16BIT); break; default: SDL_SetError("Mint_CheckAudio: Unsupported sample resolution"); return -1; break; } /* Check signed/unsigned format */ if (format_signed) { if (snd_format & SND_FORMATSIGNED) { /* Ok */ } else if (snd_format & SND_FORMATUNSIGNED) { /* Give unsigned format */ spec->format = spec->format & (~0x8000); } } else { if (snd_format & SND_FORMATUNSIGNED) { /* Ok */ } else if (snd_format & SND_FORMATSIGNED) { /* Give signed format */ spec->format |= 0x8000; } } if (format_bigendian) { if (snd_format & SND_FORMATBIGENDIAN) { /* Ok */ } else if (snd_format & SND_FORMATLITTLEENDIAN) { /* Give little endian format */ spec->format = spec->format & (~0x1000); } } else { if (snd_format & SND_FORMATLITTLEENDIAN) { /* Ok */ } else if (snd_format & SND_FORMATBIGENDIAN) { /* Give big endian format */ spec->format |= 0x1000; } } /* Calculate and select the closest frequency */ MINTAUDIO_freqcount=0; for (i=1;i<4;i++) { SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(1<<i)), MASTERCLOCK_44K, (1<<i)-1); } #if 1 for (i=0; i<MINTAUDIO_freqcount; i++) { DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock, MINTAUDIO_frequencies[i].predivisor )); } #endif MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq); spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); DEBUG_PRINT(("channels=%d, ", spec->channels)); DEBUG_PRINT(("freq=%d\n", spec->freq)); return 0; }