Mercurial > sdl-ios-xcode
comparison src/audio/mint/SDL_mintaudio_mcsn.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | a8181c4040b8 |
children | 45af7d69f8eb |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
65 static cookie_mcsn_t *cookie_mcsn; | 65 static cookie_mcsn_t *cookie_mcsn; |
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 _MCH present ? if not, assume ST machine */ | 98 |
99 if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) { | 99 /* Cookie _MCH present ? if not, assume ST machine */ |
100 cookie_mch = MCH_ST; | 100 if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) { |
101 } | 101 cookie_mch = MCH_ST; |
102 | 102 } |
103 /* Cookie _SND present ? if not, assume ST machine */ | 103 |
104 if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { | 104 /* Cookie _SND present ? if not, assume ST machine */ |
105 cookie_snd = SND_PSG; | 105 if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { |
106 } | 106 cookie_snd = SND_PSG; |
107 | 107 } |
108 /* Check if we have 16 bits audio */ | 108 |
109 if ((cookie_snd & SND_16BIT)==0) { | 109 /* Check if we have 16 bits audio */ |
110 DEBUG_PRINT((DEBUG_NAME "no 16 bits sound\n")); | 110 if ((cookie_snd & SND_16BIT) == 0) { |
111 return(0); | 111 DEBUG_PRINT((DEBUG_NAME "no 16 bits sound\n")); |
112 } | 112 return (0); |
113 | 113 } |
114 /* Cookie MCSN present ? */ | 114 |
115 if (Getcookie(C_McSn, (long *) &cookie_mcsn) != C_FOUND) { | 115 /* Cookie MCSN present ? */ |
116 DEBUG_PRINT((DEBUG_NAME "no MCSN audio\n")); | 116 if (Getcookie(C_McSn, (long *) &cookie_mcsn) != C_FOUND) { |
117 return(0); | 117 DEBUG_PRINT((DEBUG_NAME "no MCSN audio\n")); |
118 } | 118 return (0); |
119 | 119 } |
120 /* Check if interrupt at end of replay */ | 120 |
121 if (cookie_mcsn->pint == 0) { | 121 /* Check if interrupt at end of replay */ |
122 DEBUG_PRINT((DEBUG_NAME "no interrupt at end of replay\n")); | 122 if (cookie_mcsn->pint == 0) { |
123 return(0); | 123 DEBUG_PRINT((DEBUG_NAME "no interrupt at end of replay\n")); |
124 } | 124 return (0); |
125 | 125 } |
126 /* Check if audio is lockable */ | 126 |
127 if (Locksnd()!=1) { | 127 /* Check if audio is lockable */ |
128 DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n")); | 128 if (Locksnd() != 1) { |
129 return(0); | 129 DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n")); |
130 } | 130 return (0); |
131 | 131 } |
132 Unlocksnd(); | 132 |
133 | 133 Unlocksnd(); |
134 DEBUG_PRINT((DEBUG_NAME "MCSN audio available!\n")); | 134 |
135 return(1); | 135 DEBUG_PRINT((DEBUG_NAME "MCSN audio available!\n")); |
136 } | 136 return (1); |
137 | 137 } |
138 static void Audio_DeleteDevice(SDL_AudioDevice *device) | 138 |
139 static void | |
140 Audio_DeleteDevice(SDL_AudioDevice * device) | |
139 { | 141 { |
140 SDL_free(device->hidden); | 142 SDL_free(device->hidden); |
141 SDL_free(device); | 143 SDL_free(device); |
142 } | 144 } |
143 | 145 |
144 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | 146 static SDL_AudioDevice * |
145 { | 147 Audio_CreateDevice(int devindex) |
146 SDL_AudioDevice *this; | 148 { |
147 | 149 SDL_AudioDevice *this; |
148 /* Initialize all variables that we clean on shutdown */ | 150 |
149 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); | 151 /* Initialize all variables that we clean on shutdown */ |
150 if ( this ) { | 152 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); |
153 if (this) { | |
151 SDL_memset(this, 0, (sizeof *this)); | 154 SDL_memset(this, 0, (sizeof *this)); |
152 this->hidden = (struct SDL_PrivateAudioData *) | 155 this->hidden = (struct SDL_PrivateAudioData *) |
153 SDL_malloc((sizeof *this->hidden)); | 156 SDL_malloc((sizeof *this->hidden)); |
154 } | 157 } |
155 if ( (this == NULL) || (this->hidden == NULL) ) { | 158 if ((this == NULL) || (this->hidden == NULL)) { |
156 SDL_OutOfMemory(); | 159 SDL_OutOfMemory(); |
157 if ( this ) { | 160 if (this) { |
158 SDL_free(this); | 161 SDL_free(this); |
159 } | 162 } |
160 return(0); | 163 return (0); |
161 } | 164 } |
162 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); | 165 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
163 | 166 |
164 /* Set the function pointers */ | 167 /* Set the function pointers */ |
165 this->OpenAudio = Mint_OpenAudio; | 168 this->OpenAudio = Mint_OpenAudio; |
166 this->CloseAudio = Mint_CloseAudio; | 169 this->CloseAudio = Mint_CloseAudio; |
167 this->LockAudio = Mint_LockAudio; | 170 this->LockAudio = Mint_LockAudio; |
168 this->UnlockAudio = Mint_UnlockAudio; | 171 this->UnlockAudio = Mint_UnlockAudio; |
169 this->free = Audio_DeleteDevice; | 172 this->free = Audio_DeleteDevice; |
170 | 173 |
171 return this; | 174 return this; |
172 } | 175 } |
173 | 176 |
174 AudioBootStrap MINTAUDIO_MCSN_bootstrap = { | 177 AudioBootStrap MINTAUDIO_MCSN_bootstrap = { |
175 MINT_AUDIO_DRIVER_NAME, "MiNT MCSN audio driver", | 178 MINT_AUDIO_DRIVER_NAME, "MiNT MCSN audio driver", |
176 Audio_Available, Audio_CreateDevice | 179 Audio_Available, Audio_CreateDevice |
177 }; | 180 }; |
178 | 181 |
179 static void Mint_LockAudio(_THIS) | 182 static void |
180 { | 183 Mint_LockAudio(_THIS) |
181 /* Stop replay */ | 184 { |
182 Buffoper(0); | 185 /* Stop replay */ |
183 } | 186 Buffoper(0); |
184 | 187 } |
185 static void Mint_UnlockAudio(_THIS) | 188 |
186 { | 189 static void |
187 /* Restart replay */ | 190 Mint_UnlockAudio(_THIS) |
188 Buffoper(SB_PLA_ENA|SB_PLA_RPT); | 191 { |
189 } | 192 /* Restart replay */ |
190 | 193 Buffoper(SB_PLA_ENA | SB_PLA_RPT); |
191 static void Mint_CloseAudio(_THIS) | 194 } |
192 { | 195 |
193 /* Stop replay */ | 196 static void |
194 SDL_MintAudio_WaitThread(); | 197 Mint_CloseAudio(_THIS) |
195 Buffoper(0); | 198 { |
196 | 199 /* Stop replay */ |
197 if (!SDL_MintAudio_mint_present) { | 200 SDL_MintAudio_WaitThread(); |
198 /* Uninstall interrupt */ | 201 Buffoper(0); |
199 Jdisint(MFP_DMASOUND); | 202 |
200 } | 203 if (!SDL_MintAudio_mint_present) { |
201 | 204 /* Uninstall interrupt */ |
202 /* Wait if currently playing sound */ | 205 Jdisint(MFP_DMASOUND); |
203 while (SDL_MintAudio_mutex != 0) { | 206 } |
204 } | 207 |
205 | 208 /* Wait if currently playing sound */ |
206 /* Clear buffers */ | 209 while (SDL_MintAudio_mutex != 0) { |
207 if (SDL_MintAudio_audiobuf[0]) { | 210 } |
208 Mfree(SDL_MintAudio_audiobuf[0]); | 211 |
209 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; | 212 /* Clear buffers */ |
210 } | 213 if (SDL_MintAudio_audiobuf[0]) { |
211 | 214 Mfree(SDL_MintAudio_audiobuf[0]); |
212 /* Unlock sound system */ | 215 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; |
213 Unlocksnd(); | 216 } |
214 } | 217 |
215 | 218 /* Unlock sound system */ |
216 static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) | 219 Unlocksnd(); |
217 { | 220 } |
218 int i; | 221 |
219 unsigned long masterclock, masterprediv; | 222 static int |
220 | 223 Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) |
221 DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); | 224 { |
222 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); | 225 int i; |
223 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); | 226 unsigned long masterclock, masterprediv; |
224 DEBUG_PRINT(("channels=%d, ", spec->channels)); | 227 |
225 DEBUG_PRINT(("freq=%d\n", spec->freq)); | 228 DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); |
226 | 229 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); |
227 /* Check formats available */ | 230 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); |
228 MINTAUDIO_freqcount=0; | 231 DEBUG_PRINT(("channels=%d, ", spec->channels)); |
229 switch(cookie_mcsn->play) { | 232 DEBUG_PRINT(("freq=%d\n", spec->freq)); |
230 case MCSN_ST: | 233 |
231 spec->channels=1; | 234 /* Check formats available */ |
232 spec->format=8; /* FIXME: is it signed or unsigned ? */ | 235 MINTAUDIO_freqcount = 0; |
233 SDL_MintAudio_AddFrequency(this, 12500, 0, 0, -1); | 236 switch (cookie_mcsn->play) { |
234 break; | 237 case MCSN_ST: |
235 case MCSN_TT: /* Also STE, Mega STE */ | 238 spec->channels = 1; |
236 spec->format=AUDIO_S8; | 239 spec->format = 8; /* FIXME: is it signed or unsigned ? */ |
237 masterclock=MASTERCLOCK_STE; | 240 SDL_MintAudio_AddFrequency(this, 12500, 0, 0, -1); |
238 masterprediv=MASTERPREDIV_STE; | 241 break; |
239 if ((cookie_mch>>16)==MCH_TT) { | 242 case MCSN_TT: /* Also STE, Mega STE */ |
240 masterclock=MASTERCLOCK_TT; | 243 spec->format = AUDIO_S8; |
241 masterprediv=MASTERPREDIV_TT; | 244 masterclock = MASTERCLOCK_STE; |
242 } | 245 masterprediv = MASTERPREDIV_STE; |
243 for (i=0; i<4; i++) { | 246 if ((cookie_mch >> 16) == MCH_TT) { |
244 SDL_MintAudio_AddFrequency(this, masterclock/(masterprediv*(1<<i)), | 247 masterclock = MASTERCLOCK_TT; |
245 masterclock, 3-i, -1); | 248 masterprediv = MASTERPREDIV_TT; |
246 } | 249 } |
247 break; | 250 for (i = 0; i < 4; i++) { |
248 case MCSN_FALCON: /* Also Mac */ | 251 SDL_MintAudio_AddFrequency(this, |
249 for (i=1; i<12; i++) { | 252 masterclock / (masterprediv * |
250 /* Remove unusable Falcon codec predivisors */ | 253 (1 << i)), |
251 if ((i==6) || (i==8) || (i==10)) { | 254 masterclock, 3 - i, -1); |
252 continue; | 255 } |
253 } | 256 break; |
254 SDL_MintAudio_AddFrequency(this, MASTERCLOCK_FALCON1/(MASTERPREDIV_FALCON*(i+1)), | 257 case MCSN_FALCON: /* Also Mac */ |
255 CLK25M, i+1, -1); | 258 for (i = 1; i < 12; i++) { |
256 } | 259 /* Remove unusable Falcon codec predivisors */ |
257 if (cookie_mcsn->res1 != 0) { | 260 if ((i == 6) || (i == 8) || (i == 10)) { |
258 for (i=1; i<4; i++) { | 261 continue; |
259 SDL_MintAudio_AddFrequency(this, (cookie_mcsn->res1)/(MASTERPREDIV_FALCON*(1<<i)), | 262 } |
260 CLKEXT, (1<<i)-1, -1); | 263 SDL_MintAudio_AddFrequency(this, |
261 } | 264 MASTERCLOCK_FALCON1 / |
262 } | 265 (MASTERPREDIV_FALCON * (i + 1)), |
263 spec->format |= 0x8000; /* Audio is always signed */ | 266 CLK25M, i + 1, -1); |
264 if ((spec->format & 0x00ff)==16) { | 267 } |
265 spec->format |= 0x1000; /* Audio is always big endian */ | 268 if (cookie_mcsn->res1 != 0) { |
266 spec->channels=2; /* 16 bits always stereo */ | 269 for (i = 1; i < 4; i++) { |
267 } | 270 SDL_MintAudio_AddFrequency(this, |
268 break; | 271 (cookie_mcsn->res1) / |
269 } | 272 (MASTERPREDIV_FALCON * |
273 (1 << i)), CLKEXT, | |
274 (1 << i) - 1, -1); | |
275 } | |
276 } | |
277 spec->format |= 0x8000; /* Audio is always signed */ | |
278 if ((spec->format & 0x00ff) == 16) { | |
279 spec->format |= 0x1000; /* Audio is always big endian */ | |
280 spec->channels = 2; /* 16 bits always stereo */ | |
281 } | |
282 break; | |
283 } | |
270 | 284 |
271 #if 1 | 285 #if 1 |
272 for (i=0; i<MINTAUDIO_freqcount; i++) { | 286 for (i = 0; i < MINTAUDIO_freqcount; i++) { |
273 DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", | 287 DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", |
274 i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock, | 288 i, MINTAUDIO_frequencies[i].frequency, |
275 MINTAUDIO_frequencies[i].predivisor | 289 MINTAUDIO_frequencies[i].masterclock, |
276 )); | 290 MINTAUDIO_frequencies[i].predivisor)); |
277 } | 291 } |
278 #endif | 292 #endif |
279 | 293 |
280 MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq); | 294 MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq); |
281 spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; | 295 spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; |
282 | 296 |
283 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); | 297 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); |
284 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); | 298 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); |
285 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); | 299 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); |
286 DEBUG_PRINT(("channels=%d, ", spec->channels)); | 300 DEBUG_PRINT(("channels=%d, ", spec->channels)); |
287 DEBUG_PRINT(("freq=%d\n", spec->freq)); | 301 DEBUG_PRINT(("freq=%d\n", spec->freq)); |
288 | 302 |
289 return 0; | 303 return 0; |
290 } | 304 } |
291 | 305 |
292 static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec) | 306 static void |
293 { | 307 Mint_InitAudio(_THIS, SDL_AudioSpec * spec) |
294 int channels_mode, prediv, dmaclock; | 308 { |
295 void *buffer; | 309 int channels_mode, prediv, dmaclock; |
296 | 310 void *buffer; |
297 /* Stop currently playing sound */ | 311 |
298 SDL_MintAudio_quit_thread = SDL_FALSE; | 312 /* Stop currently playing sound */ |
299 SDL_MintAudio_thread_finished = SDL_TRUE; | 313 SDL_MintAudio_quit_thread = SDL_FALSE; |
300 SDL_MintAudio_WaitThread(); | 314 SDL_MintAudio_thread_finished = SDL_TRUE; |
301 Buffoper(0); | 315 SDL_MintAudio_WaitThread(); |
302 | 316 Buffoper(0); |
303 /* Set replay tracks */ | 317 |
304 Settracks(0,0); | 318 /* Set replay tracks */ |
305 Setmontracks(0); | 319 Settracks(0, 0); |
306 | 320 Setmontracks(0); |
307 /* Select replay format */ | 321 |
308 channels_mode=STEREO16; | 322 /* Select replay format */ |
309 switch (spec->format & 0xff) { | 323 channels_mode = STEREO16; |
310 case 8: | 324 switch (spec->format & 0xff) { |
311 if (spec->channels==2) { | 325 case 8: |
312 channels_mode=STEREO8; | 326 if (spec->channels == 2) { |
313 } else { | 327 channels_mode = STEREO8; |
314 channels_mode=MONO8; | 328 } else { |
315 } | 329 channels_mode = MONO8; |
316 break; | 330 } |
317 } | 331 break; |
318 if (Setmode(channels_mode)<0) { | 332 } |
319 DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n")); | 333 if (Setmode(channels_mode) < 0) { |
320 } | 334 DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n")); |
321 | 335 } |
322 dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock; | 336 |
323 prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; | 337 dmaclock = MINTAUDIO_frequencies[MINTAUDIO_numfreq].masterclock; |
324 switch(cookie_mcsn->play) { | 338 prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; |
325 case MCSN_TT: | 339 switch (cookie_mcsn->play) { |
326 Devconnect(DMAPLAY, DAC, CLK25M, CLKOLD, 1); | 340 case MCSN_TT: |
327 Soundcmd(SETPRESCALE, prediv); | 341 Devconnect(DMAPLAY, DAC, CLK25M, CLKOLD, 1); |
328 DEBUG_PRINT((DEBUG_NAME "STE/TT prescaler selected\n")); | 342 Soundcmd(SETPRESCALE, prediv); |
329 break; | 343 DEBUG_PRINT((DEBUG_NAME "STE/TT prescaler selected\n")); |
330 case MCSN_FALCON: | 344 break; |
331 Devconnect(DMAPLAY, DAC, dmaclock, prediv, 1); | 345 case MCSN_FALCON: |
332 DEBUG_PRINT((DEBUG_NAME "Falcon prescaler selected\n")); | 346 Devconnect(DMAPLAY, DAC, dmaclock, prediv, 1); |
333 break; | 347 DEBUG_PRINT((DEBUG_NAME "Falcon prescaler selected\n")); |
334 } | 348 break; |
335 | 349 } |
336 /* Set buffer */ | 350 |
337 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; | 351 /* Set buffer */ |
338 if (Setbuffer(0, buffer, buffer + spec->size)<0) { | 352 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; |
339 DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n")); | 353 if (Setbuffer(0, buffer, buffer + spec->size) < 0) { |
340 } | 354 DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n")); |
341 | 355 } |
342 if (SDL_MintAudio_mint_present) { | 356 |
343 SDL_MintAudio_thread_pid = tfork(SDL_MintAudio_Thread, 0); | 357 if (SDL_MintAudio_mint_present) { |
344 } else { | 358 SDL_MintAudio_thread_pid = tfork(SDL_MintAudio_Thread, 0); |
345 /* Install interrupt */ | 359 } else { |
346 Jdisint(MFP_DMASOUND); | 360 /* Install interrupt */ |
347 Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_XbiosInterrupt); | 361 Jdisint(MFP_DMASOUND); |
348 Jenabint(MFP_DMASOUND); | 362 Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_XbiosInterrupt); |
349 | 363 Jenabint(MFP_DMASOUND); |
350 if (Setinterrupt(SI_TIMERA, SI_PLAY)<0) { | 364 |
351 DEBUG_PRINT((DEBUG_NAME "Setinterrupt() failed\n")); | 365 if (Setinterrupt(SI_TIMERA, SI_PLAY) < 0) { |
352 } | 366 DEBUG_PRINT((DEBUG_NAME "Setinterrupt() failed\n")); |
353 } | 367 } |
354 | 368 } |
355 /* Go */ | 369 |
356 Buffoper(SB_PLA_ENA|SB_PLA_RPT); | 370 /* Go */ |
357 DEBUG_PRINT((DEBUG_NAME "hardware initialized\n")); | 371 Buffoper(SB_PLA_ENA | SB_PLA_RPT); |
358 } | 372 DEBUG_PRINT((DEBUG_NAME "hardware initialized\n")); |
359 | 373 } |
360 static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec) | 374 |
361 { | 375 static int |
362 /* Lock sound system */ | 376 Mint_OpenAudio(_THIS, SDL_AudioSpec * spec) |
363 if (Locksnd()!=1) { | 377 { |
364 SDL_SetError("Mint_OpenAudio: Audio system already in use"); | 378 /* Lock sound system */ |
365 return(-1); | 379 if (Locksnd() != 1) { |
366 } | 380 SDL_SetError("Mint_OpenAudio: Audio system already in use"); |
367 | 381 return (-1); |
368 SDL_MintAudio_device = this; | 382 } |
369 | 383 |
370 /* Check audio capabilities */ | 384 SDL_MintAudio_device = this; |
371 if (Mint_CheckAudio(this, spec)==-1) { | 385 |
372 return -1; | 386 /* Check audio capabilities */ |
373 } | 387 if (Mint_CheckAudio(this, spec) == -1) { |
374 | 388 return -1; |
375 SDL_CalculateAudioSpec(spec); | 389 } |
376 | 390 |
377 /* Allocate memory for audio buffers in DMA-able RAM */ | 391 SDL_CalculateAudioSpec(spec); |
378 DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); | 392 |
379 | 393 /* Allocate memory for audio buffers in DMA-able RAM */ |
380 SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM); | 394 DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); |
381 if (SDL_MintAudio_audiobuf[0]==NULL) { | 395 |
382 SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); | 396 SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM); |
383 return (-1); | 397 if (SDL_MintAudio_audiobuf[0] == NULL) { |
384 } | 398 SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); |
385 SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ; | 399 return (-1); |
386 SDL_MintAudio_numbuf=0; | 400 } |
387 SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2); | 401 SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; |
388 SDL_MintAudio_audiosize = spec->size; | 402 SDL_MintAudio_numbuf = 0; |
389 SDL_MintAudio_mutex = 0; | 403 SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); |
390 | 404 SDL_MintAudio_audiosize = spec->size; |
391 DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0])); | 405 SDL_MintAudio_mutex = 0; |
392 DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1])); | 406 |
393 | 407 DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", |
394 /* Setup audio hardware */ | 408 SDL_MintAudio_audiobuf[0])); |
395 Mint_InitAudio(this, spec); | 409 DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", |
396 | 410 SDL_MintAudio_audiobuf[1])); |
397 return(1); /* We don't use SDL threaded audio */ | 411 |
398 } | 412 /* Setup audio hardware */ |
413 Mint_InitAudio(this, spec); | |
414 | |
415 return (1); /* We don't use SDL threaded audio */ | |
416 } | |
417 | |
418 /* vi: set ts=4 sw=4 expandtab: */ |