comparison src/audio/mint/SDL_mintaudio_mcsn.c @ 961:185acc07127a

Date: Fri, 29 Oct 2004 11:47:09 +0200 From: Patrice Mandin Subject: Reworked audio drivers for Atari platform These are reworked audio drivers for the Atari platform. Previous drivers were missing some features: - Test external clock plugged to DSP port on Atari Falcon 030. - Ability to select internal or external clock. So now, I generate a list of frequencies available, with the master clock and predivisor to use. One big caveat to this: I do not have an external clock, so I hope it works.
author Patrice Mandin <patmandin@gmail.com>
date Fri, 29 Oct 2004 09:56:53 +0000
parents b8d311d90021
children 176240cf4405
comparison
equal deleted inserted replaced
960:eec28a5278be 961:185acc07127a
51 51
52 #define MINT_AUDIO_DRIVER_NAME "mint_mcsn" 52 #define MINT_AUDIO_DRIVER_NAME "mint_mcsn"
53 53
54 /* Debug print info */ 54 /* Debug print info */
55 #define DEBUG_NAME "audio:mcsn: " 55 #define DEBUG_NAME "audio:mcsn: "
56 #if 0 56 #if 1
57 #define DEBUG_PRINT(what) \ 57 #define DEBUG_PRINT(what) \
58 { \ 58 { \
59 printf what; \ 59 printf what; \
60 } 60 }
61 #else 61 #else
215 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); 215 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0)));
216 DEBUG_PRINT(("channels=%d, ", spec->channels)); 216 DEBUG_PRINT(("channels=%d, ", spec->channels));
217 DEBUG_PRINT(("freq=%d\n", spec->freq)); 217 DEBUG_PRINT(("freq=%d\n", spec->freq));
218 218
219 /* Check formats available */ 219 /* Check formats available */
220 MINTAUDIO_nfreq=4; 220 MINTAUDIO_freqcount=0;
221 MINTAUDIO_sfreq=0;
222 switch(cookie_mcsn->play) { 221 switch(cookie_mcsn->play) {
223 case MCSN_ST: 222 case MCSN_ST:
224 spec->channels=1; 223 spec->channels=1;
225 spec->format=8; /* FIXME: is it signed or unsigned ? */ 224 spec->format=8; /* FIXME: is it signed or unsigned ? */
226 MINTAUDIO_nfreq=1; 225 SDL_MintAudio_AddFrequency(this, 12500, 0, 0);
227 MINTAUDIO_hardfreq[0]=12500;
228 break; 226 break;
229 case MCSN_TT: /* Also STE, Mega STE */ 227 case MCSN_TT: /* Also STE, Mega STE */
230 spec->format=AUDIO_S8; 228 spec->format=AUDIO_S8;
231 masterclock=MASTERCLOCK_STE; 229 masterclock=MASTERCLOCK_STE;
232 masterprediv=MASTERPREDIV_STE; 230 masterprediv=MASTERPREDIV_STE;
233 if ((cookie_mch>>16)==MCH_TT) { 231 if ((cookie_mch>>16)==MCH_TT) {
234 masterclock=MASTERCLOCK_TT; 232 masterclock=MASTERCLOCK_TT;
235 masterprediv=MASTERPREDIV_TT; 233 masterprediv=MASTERPREDIV_TT;
236 } 234 }
237 for (i=MINTAUDIO_sfreq;i<MINTAUDIO_nfreq;i++) { 235 for (i=0; i<4; i++) {
238 MINTAUDIO_hardfreq[i]=masterclock/(masterprediv*(1<<i)); 236 SDL_MintAudio_AddFrequency(this, masterclock/(masterprediv*(1<<i)), masterclock, 3-i);
239 DEBUG_PRINT((DEBUG_NAME "calc:freq(%d)=%lu\n", i, MINTAUDIO_hardfreq[i]));
240 } 237 }
241 break; 238 break;
242 case MCSN_FALCON: /* Also Mac */ 239 case MCSN_FALCON: /* Also Mac */
243 MINTAUDIO_nfreq=12; 240 for (i=1; i<12; i++) {
244 MINTAUDIO_sfreq=1; 241 /* Remove unusable Falcon codec predivisors */
245 masterclock=MASTERCLOCK_FALCON1; 242 if ((i==6) || (i==8) || (i==10)) {
243 continue;
244 }
245 SDL_MintAudio_AddFrequency(this, MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1)), CLK25M, i+1);
246 }
246 if (cookie_mcsn->res1 != 0) { 247 if (cookie_mcsn->res1 != 0) {
247 masterclock=cookie_mcsn->res1; 248 for (i=1; i<4; i++) {
248 } 249 SDL_MintAudio_AddFrequency(this, (cookie_mcsn->res1)/(MASTERPREDIV_FALCON*(1<<i)), CLKEXT, (1<<i)-1);
249 for (i=MINTAUDIO_sfreq;i<MINTAUDIO_nfreq;i++) { 250 }
250 MINTAUDIO_hardfreq[i]=masterclock/(MASTERPREDIV_FALCON*(i+1));
251 DEBUG_PRINT((DEBUG_NAME "calc:freq(%d)=%lu\n", i, MINTAUDIO_hardfreq[i]));
252 } 251 }
253 spec->format |= 0x8000; /* Audio is always signed */ 252 spec->format |= 0x8000; /* Audio is always signed */
254 if ((spec->format & 0x00ff)==16) { 253 if ((spec->format & 0x00ff)==16) {
255 spec->format |= 0x1000; /* Audio is always big endian */ 254 spec->format |= 0x1000; /* Audio is always big endian */
256 spec->channels=2; /* 16 bits always stereo */ 255 spec->channels=2; /* 16 bits always stereo */
257 } 256 }
258 break; 257 break;
259 } 258 }
260 259
261 MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, (cookie_mch>>16)==MCH_F30, spec->freq); 260 #if 1
262 spec->freq=MINTAUDIO_hardfreq[MINTAUDIO_numfreq]; 261 for (i=0; i<MINTAUDIO_freqcount; i++) {
262 DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n",
263 i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock,
264 MINTAUDIO_frequencies[i].predivisor
265 ));
266 }
267 #endif
268
269 MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq);
270 spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
263 271
264 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); 272 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff));
265 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); 273 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
266 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); 274 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0)));
267 DEBUG_PRINT(("channels=%d, ", spec->channels)); 275 DEBUG_PRINT(("channels=%d, ", spec->channels));
270 return 0; 278 return 0;
271 } 279 }
272 280
273 static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec) 281 static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec)
274 { 282 {
275 int channels_mode; 283 int channels_mode, prediv, dmaclock;
276 void *buffer; 284 void *buffer;
277 285
278 /* Stop currently playing sound */ 286 /* Stop currently playing sound */
279 Buffoper(0); 287 Buffoper(0);
280 288
295 } 303 }
296 if (Setmode(channels_mode)<0) { 304 if (Setmode(channels_mode)<0) {
297 DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n")); 305 DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n"));
298 } 306 }
299 307
308 dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock;
309 prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor;
300 switch(cookie_mcsn->play) { 310 switch(cookie_mcsn->play) {
301 case MCSN_TT: 311 case MCSN_TT:
302 Devconnect(DMAPLAY, DAC, CLK25M, CLKOLD, 1); 312 Devconnect(DMAPLAY, DAC, CLK25M, CLKOLD, 1);
303 Soundcmd(SETPRESCALE, 3-MINTAUDIO_numfreq); 313 Soundcmd(SETPRESCALE, prediv);
304 DEBUG_PRINT((DEBUG_NAME "STE/TT prescaler selected\n")); 314 DEBUG_PRINT((DEBUG_NAME "STE/TT prescaler selected\n"));
305 break; 315 break;
306 case MCSN_FALCON: 316 case MCSN_FALCON:
307 if (cookie_mcsn->res1 != 0) { 317 Devconnect(DMAPLAY, DAC, dmaclock, prediv, 1);
308 Devconnect(DMAPLAY, DAC, CLKEXT, MINTAUDIO_numfreq, 1); 318 DEBUG_PRINT((DEBUG_NAME "Falcon prescaler selected\n"));
309 DEBUG_PRINT((DEBUG_NAME "External clock selected, prescaler %d\n", MINTAUDIO_numfreq));
310 } else {
311 Devconnect(DMAPLAY, DAC, CLK25M, MINTAUDIO_numfreq, 1);
312 DEBUG_PRINT((DEBUG_NAME "25.175 MHz clock selected, prescaler %d\n", MINTAUDIO_numfreq));
313 }
314 break; 319 break;
315 } 320 }
316 321
317 /* Set buffer */ 322 /* Set buffer */
318 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; 323 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];