comparison src/audio/mint/SDL_mintaudio_xbios.c @ 1662:782fd950bd46 SDL-1.3

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