Commit 0a4aca52 authored by Patrice Mandin's avatar Patrice Mandin

Can use both clocks of FDI interface on Falcon, plus digital output

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401108
parent 3bcb730b
...@@ -76,7 +76,8 @@ void SDL_MintAudio_Callback(void) ...@@ -76,7 +76,8 @@ void SDL_MintAudio_Callback(void)
} }
/* Add a new frequency/clock/predivisor to the current list */ /* Add a new frequency/clock/predivisor to the current list */
void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock, Uint32 prediv) void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock,
Uint32 prediv, int gpio_bits)
{ {
int i, p; int i, p;
...@@ -94,9 +95,7 @@ void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock, Uint32 pr ...@@ -94,9 +95,7 @@ void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock, Uint32 pr
/* Put all following ones farer */ /* Put all following ones farer */
if (MINTAUDIO_freqcount>0) { if (MINTAUDIO_freqcount>0) {
for (i=MINTAUDIO_freqcount; i>p; i--) { for (i=MINTAUDIO_freqcount; i>p; i--) {
MINTAUDIO_frequencies[i].frequency = MINTAUDIO_frequencies[i-1].frequency; memcpy(&MINTAUDIO_frequencies[i], &MINTAUDIO_frequencies[i-1], sizeof(mint_frequency_t));
MINTAUDIO_frequencies[i].masterclock = MINTAUDIO_frequencies[i-1].masterclock;
MINTAUDIO_frequencies[i].predivisor = MINTAUDIO_frequencies[i-1].predivisor;
} }
} }
...@@ -104,6 +103,7 @@ void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock, Uint32 pr ...@@ -104,6 +103,7 @@ void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock, Uint32 pr
MINTAUDIO_frequencies[p].frequency = frequency; MINTAUDIO_frequencies[p].frequency = frequency;
MINTAUDIO_frequencies[p].masterclock = clock; MINTAUDIO_frequencies[p].masterclock = clock;
MINTAUDIO_frequencies[p].predivisor = prediv; MINTAUDIO_frequencies[p].predivisor = prediv;
MINTAUDIO_frequencies[p].gpio_bits = gpio_bits;
MINTAUDIO_freqcount++; MINTAUDIO_freqcount++;
} }
......
...@@ -42,6 +42,7 @@ typedef struct { ...@@ -42,6 +42,7 @@ typedef struct {
Uint32 frequency; Uint32 frequency;
Uint32 masterclock; Uint32 masterclock;
Uint32 predivisor; Uint32 predivisor;
int gpio_bits; /* in case of external clock */
} mint_frequency_t; } mint_frequency_t;
struct SDL_PrivateAudioData { struct SDL_PrivateAudioData {
...@@ -124,7 +125,8 @@ extern unsigned long SDL_MintAudio_clocktics; ...@@ -124,7 +125,8 @@ extern unsigned long SDL_MintAudio_clocktics;
/* Functions */ /* Functions */
void SDL_MintAudio_Callback(void); void SDL_MintAudio_Callback(void);
void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock, Uint32 prediv); void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock,
Uint32 prediv, int gpio_bits);
int SDL_MintAudio_SearchFrequency(_THIS, int desired_freq); int SDL_MintAudio_SearchFrequency(_THIS, int desired_freq);
/* ASM interrupt functions */ /* ASM interrupt functions */
......
...@@ -250,7 +250,8 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) ...@@ -250,7 +250,8 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
MINTAUDIO_freqcount=0; MINTAUDIO_freqcount=0;
for (i=sfreq;i<4;i++) { for (i=sfreq;i<4;i++) {
SDL_MintAudio_AddFrequency(this, masterclock/(masterprediv*(1<<i)), masterclock, i-sfreq); SDL_MintAudio_AddFrequency(this, masterclock/(masterprediv*(1<<i)),
masterclock, i-sfreq, -1);
} }
#if 1 #if 1
......
...@@ -276,7 +276,9 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) ...@@ -276,7 +276,9 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
/* Calculate and select the closest frequency */ /* Calculate and select the closest frequency */
MINTAUDIO_freqcount=0; MINTAUDIO_freqcount=0;
for (i=1;i<4;i++) { for (i=1;i<4;i++) {
SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(1<<i)), MASTERCLOCK_44K, (1<<i)-1); SDL_MintAudio_AddFrequency(this,
MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(1<<i)), MASTERCLOCK_44K,
(1<<i)-1, -1);
} }
#if 1 #if 1
......
...@@ -233,7 +233,7 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) ...@@ -233,7 +233,7 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
case MCSN_ST: case MCSN_ST:
spec->channels=1; spec->channels=1;
spec->format=8; /* FIXME: is it signed or unsigned ? */ spec->format=8; /* FIXME: is it signed or unsigned ? */
SDL_MintAudio_AddFrequency(this, 12500, 0, 0); SDL_MintAudio_AddFrequency(this, 12500, 0, 0, -1);
break; break;
case MCSN_TT: /* Also STE, Mega STE */ case MCSN_TT: /* Also STE, Mega STE */
spec->format=AUDIO_S8; spec->format=AUDIO_S8;
...@@ -244,7 +244,8 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) ...@@ -244,7 +244,8 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
masterprediv=MASTERPREDIV_TT; masterprediv=MASTERPREDIV_TT;
} }
for (i=0; i<4; i++) { for (i=0; i<4; i++) {
SDL_MintAudio_AddFrequency(this, masterclock/(masterprediv*(1<<i)), masterclock, 3-i); SDL_MintAudio_AddFrequency(this, masterclock/(masterprediv*(1<<i)),
masterclock, 3-i, -1);
} }
break; break;
case MCSN_FALCON: /* Also Mac */ case MCSN_FALCON: /* Also Mac */
...@@ -253,11 +254,13 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) ...@@ -253,11 +254,13 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
if ((i==6) || (i==8) || (i==10)) { if ((i==6) || (i==8) || (i==10)) {
continue; continue;
} }
SDL_MintAudio_AddFrequency(this, MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1)), CLK25M, i+1); SDL_MintAudio_AddFrequency(this, MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1)),
CLK25M, i+1, -1);
} }
if (cookie_mcsn->res1 != 0) { if (cookie_mcsn->res1 != 0) {
for (i=1; i<4; i++) { for (i=1; i<4; i++) {
SDL_MintAudio_AddFrequency(this, (cookie_mcsn->res1)/(MASTERPREDIV_FALCON*(1<<i)), CLKEXT, (1<<i)-1); SDL_MintAudio_AddFrequency(this, (cookie_mcsn->res1)/(MASTERPREDIV_FALCON*(1<<i)),
CLKEXT, (1<<i)-1, -1);
} }
} }
spec->format |= 0x8000; /* Audio is always signed */ spec->format |= 0x8000; /* Audio is always signed */
......
...@@ -213,7 +213,7 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) ...@@ -213,7 +213,7 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
/* Check formats available */ /* Check formats available */
MINTAUDIO_freqcount=0; MINTAUDIO_freqcount=0;
for (i=0;i<16;i++) { for (i=0;i<16;i++) {
SDL_MintAudio_AddFrequency(this, freqs[i], 0, i); SDL_MintAudio_AddFrequency(this, freqs[i], 0, i, -1);
} }
#if 1 #if 1
......
...@@ -263,32 +263,29 @@ static void Devconnect2(int src, int dst, int sclk, int pre) ...@@ -263,32 +263,29 @@ static void Devconnect2(int src, int dst, int sclk, int pre)
Super(oldstack); Super(oldstack);
} }
static Uint32 Mint_CheckExternalClock(void) static void Mint_CheckExternalClock(_THIS)
{ {
#define SIZE_BUF_CLOCK_MEASURE (44100/10) #define SIZE_BUF_CLOCK_MEASURE (44100/10)
unsigned long cookie_snd; unsigned long cookie_snd;
Uint32 masterclock;
char *buffer; char *buffer;
int i; int i, j;
/* DSP present with its GPIO port ? */ /* DSP present with its GPIO port ? */
if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
return 0; return;
} }
if ((cookie_snd & SND_DSP)==0) { if ((cookie_snd & SND_DSP)==0) {
return 0; return;
} }
buffer = Atari_SysMalloc(SIZE_BUF_CLOCK_MEASURE, MX_STRAM); buffer = Atari_SysMalloc(SIZE_BUF_CLOCK_MEASURE, MX_STRAM);
if (buffer==NULL) { if (buffer==NULL) {
DEBUG_PRINT((DEBUG_NAME "Not enough memory for the measure\n")); DEBUG_PRINT((DEBUG_NAME "Not enough memory for the measure\n"));
return 0; return;
} }
memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE); memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE);
masterclock=0;
Buffoper(0); Buffoper(0);
Settracks(0,0); Settracks(0,0);
Setmontracks(0); Setmontracks(0);
...@@ -313,13 +310,13 @@ static Uint32 Mint_CheckExternalClock(void) ...@@ -313,13 +310,13 @@ static Uint32 Mint_CheckExternalClock(void)
khz = ((SIZE_BUF_CLOCK_MEASURE/SDL_MintAudio_clocktics) +1) & 0xFFFFFFFE; khz = ((SIZE_BUF_CLOCK_MEASURE/SDL_MintAudio_clocktics) +1) & 0xFFFFFFFE;
DEBUG_PRINT((DEBUG_NAME "measure %d: freq=%lu KHz\n", i+1, khz)); DEBUG_PRINT((DEBUG_NAME "measure %d: freq=%lu KHz\n", i+1, khz));
if (i==0) { if(khz==44) {
if(khz==44) { for (j=1; j<4; j++) {
masterclock = MASTERCLOCK_44K; SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_44K, (1<<j)-1, 2+i);
} }
} else { } else if (khz==48) {
if(khz==48) { for (j=1; j<4; j++) {
masterclock = MASTERCLOCK_48K; SDL_MintAudio_AddFrequency(this, MASTERCLOCK_48K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_48K, (1<<j)-1, 2+i);
} }
} }
} else { } else {
...@@ -331,12 +328,9 @@ static Uint32 Mint_CheckExternalClock(void) ...@@ -331,12 +328,9 @@ static Uint32 Mint_CheckExternalClock(void)
Buffoper(0); /* stop */ Buffoper(0); /* stop */
Jdisint(MFP_TIMERA); /* Uninstall interrupt */ Jdisint(MFP_TIMERA); /* Uninstall interrupt */
if (masterclock == 0)
break;
} }
Mfree(buffer); Mfree(buffer);
return masterclock;
} }
static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
...@@ -356,22 +350,18 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) ...@@ -356,22 +350,18 @@ static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
spec->channels=2; /* 16 bits always stereo */ spec->channels=2; /* 16 bits always stereo */
} }
extclock=Mint_CheckExternalClock(); MINTAUDIO_freqcount=0;
/* Add external clocks if present */
Mint_CheckExternalClock(this);
/* Standard clocks */ /* Standard clocks */
MINTAUDIO_freqcount=0;
for (i=1;i<12;i++) { for (i=1;i<12;i++) {
/* Remove unusable Falcon codec predivisors */ /* Remove unusable Falcon codec predivisors */
if ((i==6) || (i==8) || (i==10)) { if ((i==6) || (i==8) || (i==10)) {
continue; continue;
} }
SDL_MintAudio_AddFrequency(this, MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1)), MASTERCLOCK_FALCON1, i); SDL_MintAudio_AddFrequency(this, MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1)), MASTERCLOCK_FALCON1, i, -1);
}
if (extclock>0) {
for (i=1; i<4; i++) {
SDL_MintAudio_AddFrequency(this, extclock/(MASTERPREDIV_FALCON*(1<<i)), extclock, (1<<i)-1);
}
} }
#if 1 #if 1
...@@ -424,14 +414,10 @@ static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec) ...@@ -424,14 +414,10 @@ static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec)
dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock; dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock;
prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor;
if (dmaclock != MASTERCLOCK_FALCON1) { if (MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits != -1) {
Gpio(GPIO_SET,7); /* DSP port gpio outputs */ Gpio(GPIO_SET,7); /* DSP port gpio outputs */
if (dmaclock == MASTERCLOCK_44K) { Gpio(GPIO_WRITE, MINTAUDIO_frequencies[MINTAUDIO_numfreq].gpio_bits);
Gpio(GPIO_WRITE,2); /* 22.5792 MHz for 44.1KHz */ Devconnect2(DMAPLAY, DAC|EXTOUT, CLKEXT, prediv);
} else {
Gpio(GPIO_WRITE,3); /* 24.576 MHz for 48KHz */
}
Devconnect2(DMAPLAY, DAC, CLKEXT, prediv);
} else { } else {
Devconnect2(DMAPLAY, DAC, CLK25M, prediv); Devconnect2(DMAPLAY, DAC, CLK25M, prediv);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment