Mercurial > sdl-ios-xcode
comparison src/audio/mint/SDL_mintaudio_gsxb.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 |
---|---|
61 | 61 |
62 static unsigned long cookie_snd, cookie_gsxb; | 62 static unsigned long cookie_snd, cookie_gsxb; |
63 | 63 |
64 /*--- Audio driver functions ---*/ | 64 /*--- Audio driver functions ---*/ |
65 | 65 |
66 static void Mint_CloseAudio(_THIS); | 66 static void Mint_CloseAudio (_THIS); |
67 static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec); | 67 static int Mint_OpenAudio (_THIS, SDL_AudioSpec * spec); |
68 static void Mint_LockAudio(_THIS); | 68 static void Mint_LockAudio (_THIS); |
69 static void Mint_UnlockAudio(_THIS); | 69 static void Mint_UnlockAudio (_THIS); |
70 | 70 |
71 /* To check/init hardware audio */ | 71 /* To check/init hardware audio */ |
72 static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec); | 72 static int Mint_CheckAudio (_THIS, SDL_AudioSpec * spec); |
73 static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec); | 73 static void Mint_InitAudio (_THIS, SDL_AudioSpec * spec); |
74 | 74 |
75 /* GSXB callbacks */ | 75 /* GSXB callbacks */ |
76 static void Mint_GsxbInterrupt(void); | 76 static void Mint_GsxbInterrupt (void); |
77 static void Mint_GsxbNullInterrupt(void); | 77 static void Mint_GsxbNullInterrupt (void); |
78 | 78 |
79 /*--- Audio driver bootstrap functions ---*/ | 79 /*--- Audio driver bootstrap functions ---*/ |
80 | 80 |
81 static int Audio_Available(void) | 81 static int |
82 { | 82 Audio_Available (void) |
83 const char *envr = SDL_getenv("SDL_AUDIODRIVER"); | 83 { |
84 | 84 const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); |
85 /* Check if user asked a different audio driver */ | 85 |
86 if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) { | 86 /* Check if user asked a different audio driver */ |
87 DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n")); | 87 if ((envr) && (SDL_strcmp (envr, MINT_AUDIO_DRIVER_NAME) != 0)) { |
88 return(0); | 88 DEBUG_PRINT ((DEBUG_NAME "user asked a different audio driver\n")); |
89 } | 89 return (0); |
90 | 90 } |
91 /* Cookie _SND present ? if not, assume ST machine */ | 91 |
92 if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { | 92 /* Cookie _SND present ? if not, assume ST machine */ |
93 cookie_snd = SND_PSG; | 93 if (Getcookie (C__SND, &cookie_snd) == C_NOTFOUND) { |
94 } | 94 cookie_snd = SND_PSG; |
95 | 95 } |
96 /* Check if we have 16 bits audio */ | 96 |
97 if ((cookie_snd & SND_16BIT)==0) { | 97 /* Check if we have 16 bits audio */ |
98 DEBUG_PRINT((DEBUG_NAME "no 16 bits sound\n")); | 98 if ((cookie_snd & SND_16BIT) == 0) { |
99 return(0); | 99 DEBUG_PRINT ((DEBUG_NAME "no 16 bits sound\n")); |
100 } | 100 return (0); |
101 | 101 } |
102 /* Cookie GSXB present ? */ | 102 |
103 cookie_gsxb = (Getcookie(C_GSXB, &cookie_gsxb) == C_FOUND); | 103 /* Cookie GSXB present ? */ |
104 | 104 cookie_gsxb = (Getcookie (C_GSXB, &cookie_gsxb) == C_FOUND); |
105 /* Is it GSXB ? */ | 105 |
106 if (((cookie_snd & SND_GSXB)==0) || (cookie_gsxb==0)) { | 106 /* Is it GSXB ? */ |
107 DEBUG_PRINT((DEBUG_NAME "no GSXB audio\n")); | 107 if (((cookie_snd & SND_GSXB) == 0) || (cookie_gsxb == 0)) { |
108 return(0); | 108 DEBUG_PRINT ((DEBUG_NAME "no GSXB audio\n")); |
109 } | 109 return (0); |
110 | 110 } |
111 /* Check if audio is lockable */ | 111 |
112 if (Locksnd()!=1) { | 112 /* Check if audio is lockable */ |
113 DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n")); | 113 if (Locksnd () != 1) { |
114 return(0); | 114 DEBUG_PRINT ((DEBUG_NAME "audio locked by other application\n")); |
115 } | 115 return (0); |
116 | 116 } |
117 Unlocksnd(); | 117 |
118 | 118 Unlocksnd (); |
119 DEBUG_PRINT((DEBUG_NAME "GSXB audio available!\n")); | 119 |
120 return(1); | 120 DEBUG_PRINT ((DEBUG_NAME "GSXB audio available!\n")); |
121 } | 121 return (1); |
122 | 122 } |
123 static void Audio_DeleteDevice(SDL_AudioDevice *device) | 123 |
124 { | 124 static void |
125 SDL_free(device->hidden); | 125 Audio_DeleteDevice (SDL_AudioDevice * device) |
126 SDL_free(device); | 126 { |
127 } | 127 SDL_free (device->hidden); |
128 | 128 SDL_free (device); |
129 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | 129 } |
130 { | 130 |
131 SDL_AudioDevice *this; | 131 static SDL_AudioDevice * |
132 | 132 Audio_CreateDevice (int devindex) |
133 /* Initialize all variables that we clean on shutdown */ | 133 { |
134 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); | 134 SDL_AudioDevice *this; |
135 if ( this ) { | 135 |
136 SDL_memset(this, 0, (sizeof *this)); | 136 /* Initialize all variables that we clean on shutdown */ |
137 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); | |
138 if (this) { | |
139 SDL_memset (this, 0, (sizeof *this)); | |
137 this->hidden = (struct SDL_PrivateAudioData *) | 140 this->hidden = (struct SDL_PrivateAudioData *) |
138 SDL_malloc((sizeof *this->hidden)); | 141 SDL_malloc ((sizeof *this->hidden)); |
139 } | 142 } |
140 if ( (this == NULL) || (this->hidden == NULL) ) { | 143 if ((this == NULL) || (this->hidden == NULL)) { |
141 SDL_OutOfMemory(); | 144 SDL_OutOfMemory (); |
142 if ( this ) { | 145 if (this) { |
143 SDL_free(this); | 146 SDL_free (this); |
144 } | 147 } |
145 return(0); | 148 return (0); |
146 } | 149 } |
147 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); | 150 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); |
148 | 151 |
149 /* Set the function pointers */ | 152 /* Set the function pointers */ |
150 this->OpenAudio = Mint_OpenAudio; | 153 this->OpenAudio = Mint_OpenAudio; |
151 this->CloseAudio = Mint_CloseAudio; | 154 this->CloseAudio = Mint_CloseAudio; |
152 this->LockAudio = Mint_LockAudio; | 155 this->LockAudio = Mint_LockAudio; |
153 this->UnlockAudio = Mint_UnlockAudio; | 156 this->UnlockAudio = Mint_UnlockAudio; |
154 this->free = Audio_DeleteDevice; | 157 this->free = Audio_DeleteDevice; |
155 | 158 |
156 return this; | 159 return this; |
157 } | 160 } |
158 | 161 |
159 AudioBootStrap MINTAUDIO_GSXB_bootstrap = { | 162 AudioBootStrap MINTAUDIO_GSXB_bootstrap = { |
160 MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver", | 163 MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver", |
161 Audio_Available, Audio_CreateDevice | 164 Audio_Available, Audio_CreateDevice |
162 }; | 165 }; |
163 | 166 |
164 static void Mint_LockAudio(_THIS) | 167 static void |
165 { | 168 Mint_LockAudio (_THIS) |
166 /* Stop replay */ | 169 { |
167 Buffoper(0); | 170 /* Stop replay */ |
168 } | 171 Buffoper (0); |
169 | 172 } |
170 static void Mint_UnlockAudio(_THIS) | 173 |
171 { | 174 static void |
172 /* Restart replay */ | 175 Mint_UnlockAudio (_THIS) |
173 Buffoper(SB_PLA_ENA|SB_PLA_RPT); | 176 { |
174 } | 177 /* Restart replay */ |
175 | 178 Buffoper (SB_PLA_ENA | SB_PLA_RPT); |
176 static void Mint_CloseAudio(_THIS) | 179 } |
177 { | 180 |
178 /* Stop replay */ | 181 static void |
179 Buffoper(0); | 182 Mint_CloseAudio (_THIS) |
180 | 183 { |
181 /* Uninstall interrupt */ | 184 /* Stop replay */ |
182 if (NSetinterrupt(2, SI_NONE, Mint_GsxbNullInterrupt)<0) { | 185 Buffoper (0); |
183 DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n")); | 186 |
184 } | 187 /* Uninstall interrupt */ |
185 | 188 if (NSetinterrupt (2, SI_NONE, Mint_GsxbNullInterrupt) < 0) { |
186 /* Wait if currently playing sound */ | 189 DEBUG_PRINT ((DEBUG_NAME "NSetinterrupt() failed in close\n")); |
187 while (SDL_MintAudio_mutex != 0) { | 190 } |
188 } | 191 |
189 | 192 /* Wait if currently playing sound */ |
190 /* Clear buffers */ | 193 while (SDL_MintAudio_mutex != 0) { |
191 if (SDL_MintAudio_audiobuf[0]) { | 194 } |
192 Mfree(SDL_MintAudio_audiobuf[0]); | 195 |
193 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; | 196 /* Clear buffers */ |
194 } | 197 if (SDL_MintAudio_audiobuf[0]) { |
195 | 198 Mfree (SDL_MintAudio_audiobuf[0]); |
196 /* Unlock sound system */ | 199 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; |
197 Unlocksnd(); | 200 } |
198 } | 201 |
199 | 202 /* Unlock sound system */ |
200 static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec) | 203 Unlocksnd (); |
201 { | 204 } |
202 long snd_format; | 205 |
203 int i, resolution, format_signed, format_bigendian; | 206 static int |
204 | 207 Mint_CheckAudio (_THIS, SDL_AudioSpec * spec) |
205 resolution = spec->format & 0x00ff; | 208 { |
206 format_signed = ((spec->format & 0x8000)!=0); | 209 long snd_format; |
207 format_bigendian = ((spec->format & 0x1000)!=0); | 210 int i, resolution, format_signed, format_bigendian; |
208 | 211 |
209 DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff)); | 212 resolution = spec->format & 0x00ff; |
210 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); | 213 format_signed = ((spec->format & 0x8000) != 0); |
211 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); | 214 format_bigendian = ((spec->format & 0x1000) != 0); |
212 DEBUG_PRINT(("channels=%d, ", spec->channels)); | 215 |
213 DEBUG_PRINT(("freq=%d\n", spec->freq)); | 216 DEBUG_PRINT ((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); |
214 | 217 DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); |
215 /* Check formats available */ | 218 DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); |
216 snd_format = Sndstatus(SND_QUERYFORMATS); | 219 DEBUG_PRINT (("channels=%d, ", spec->channels)); |
217 switch (resolution) { | 220 DEBUG_PRINT (("freq=%d\n", spec->freq)); |
218 case 8: | 221 |
219 if ((snd_format & SND_FORMAT8)==0) { | 222 /* Check formats available */ |
220 SDL_SetError("Mint_CheckAudio: 8 bits samples not supported"); | 223 snd_format = Sndstatus (SND_QUERYFORMATS); |
221 return -1; | 224 switch (resolution) { |
222 } | 225 case 8: |
223 snd_format = Sndstatus(SND_QUERY8BIT); | 226 if ((snd_format & SND_FORMAT8) == 0) { |
224 break; | 227 SDL_SetError ("Mint_CheckAudio: 8 bits samples not supported"); |
225 case 16: | 228 return -1; |
226 if ((snd_format & SND_FORMAT16)==0) { | 229 } |
227 SDL_SetError("Mint_CheckAudio: 16 bits samples not supported"); | 230 snd_format = Sndstatus (SND_QUERY8BIT); |
228 return -1; | 231 break; |
229 } | 232 case 16: |
230 snd_format = Sndstatus(SND_QUERY16BIT); | 233 if ((snd_format & SND_FORMAT16) == 0) { |
231 break; | 234 SDL_SetError ("Mint_CheckAudio: 16 bits samples not supported"); |
232 default: | 235 return -1; |
233 SDL_SetError("Mint_CheckAudio: Unsupported sample resolution"); | 236 } |
234 return -1; | 237 snd_format = Sndstatus (SND_QUERY16BIT); |
235 break; | 238 break; |
236 } | 239 default: |
237 | 240 SDL_SetError ("Mint_CheckAudio: Unsupported sample resolution"); |
238 /* Check signed/unsigned format */ | 241 return -1; |
239 if (format_signed) { | 242 break; |
240 if (snd_format & SND_FORMATSIGNED) { | 243 } |
241 /* Ok */ | 244 |
242 } else if (snd_format & SND_FORMATUNSIGNED) { | 245 /* Check signed/unsigned format */ |
243 /* Give unsigned format */ | 246 if (format_signed) { |
244 spec->format = spec->format & (~0x8000); | 247 if (snd_format & SND_FORMATSIGNED) { |
245 } | 248 /* Ok */ |
246 } else { | 249 } else if (snd_format & SND_FORMATUNSIGNED) { |
247 if (snd_format & SND_FORMATUNSIGNED) { | 250 /* Give unsigned format */ |
248 /* Ok */ | 251 spec->format = spec->format & (~0x8000); |
249 } else if (snd_format & SND_FORMATSIGNED) { | 252 } |
250 /* Give signed format */ | 253 } else { |
251 spec->format |= 0x8000; | 254 if (snd_format & SND_FORMATUNSIGNED) { |
252 } | 255 /* Ok */ |
253 } | 256 } else if (snd_format & SND_FORMATSIGNED) { |
254 | 257 /* Give signed format */ |
255 if (format_bigendian) { | 258 spec->format |= 0x8000; |
256 if (snd_format & SND_FORMATBIGENDIAN) { | 259 } |
257 /* Ok */ | 260 } |
258 } else if (snd_format & SND_FORMATLITTLEENDIAN) { | 261 |
259 /* Give little endian format */ | 262 if (format_bigendian) { |
260 spec->format = spec->format & (~0x1000); | 263 if (snd_format & SND_FORMATBIGENDIAN) { |
261 } | 264 /* Ok */ |
262 } else { | 265 } else if (snd_format & SND_FORMATLITTLEENDIAN) { |
263 if (snd_format & SND_FORMATLITTLEENDIAN) { | 266 /* Give little endian format */ |
264 /* Ok */ | 267 spec->format = spec->format & (~0x1000); |
265 } else if (snd_format & SND_FORMATBIGENDIAN) { | 268 } |
266 /* Give big endian format */ | 269 } else { |
267 spec->format |= 0x1000; | 270 if (snd_format & SND_FORMATLITTLEENDIAN) { |
268 } | 271 /* Ok */ |
269 } | 272 } else if (snd_format & SND_FORMATBIGENDIAN) { |
270 | 273 /* Give big endian format */ |
271 /* Calculate and select the closest frequency */ | 274 spec->format |= 0x1000; |
272 MINTAUDIO_freqcount=0; | 275 } |
273 for (i=1;i<4;i++) { | 276 } |
274 SDL_MintAudio_AddFrequency(this, | 277 |
275 MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(1<<i)), MASTERCLOCK_44K, | 278 /* Calculate and select the closest frequency */ |
276 (1<<i)-1, -1); | 279 MINTAUDIO_freqcount = 0; |
277 } | 280 for (i = 1; i < 4; i++) { |
281 SDL_MintAudio_AddFrequency (this, | |
282 MASTERCLOCK_44K / (MASTERPREDIV_MILAN * | |
283 (1 << i)), | |
284 MASTERCLOCK_44K, (1 << i) - 1, -1); | |
285 } | |
278 | 286 |
279 #if 1 | 287 #if 1 |
280 for (i=0; i<MINTAUDIO_freqcount; i++) { | 288 for (i = 0; i < MINTAUDIO_freqcount; i++) { |
281 DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", | 289 DEBUG_PRINT ((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", |
282 i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock, | 290 i, MINTAUDIO_frequencies[i].frequency, |
283 MINTAUDIO_frequencies[i].predivisor | 291 MINTAUDIO_frequencies[i].masterclock, |
284 )); | 292 MINTAUDIO_frequencies[i].predivisor)); |
285 } | 293 } |
286 #endif | 294 #endif |
287 | 295 |
288 MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq); | 296 MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency (this, spec->freq); |
289 spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; | 297 spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; |
290 | 298 |
291 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); | 299 DEBUG_PRINT ((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); |
292 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); | 300 DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); |
293 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); | 301 DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); |
294 DEBUG_PRINT(("channels=%d, ", spec->channels)); | 302 DEBUG_PRINT (("channels=%d, ", spec->channels)); |
295 DEBUG_PRINT(("freq=%d\n", spec->freq)); | 303 DEBUG_PRINT (("freq=%d\n", spec->freq)); |
296 | 304 |
297 return 0; | 305 return 0; |
298 } | 306 } |
299 | 307 |
300 static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec) | 308 static void |
301 { | 309 Mint_InitAudio (_THIS, SDL_AudioSpec * spec) |
302 int channels_mode, prediv; | 310 { |
303 void *buffer; | 311 int channels_mode, prediv; |
304 | 312 void *buffer; |
305 /* Stop currently playing sound */ | 313 |
306 Buffoper(0); | 314 /* Stop currently playing sound */ |
307 | 315 Buffoper (0); |
308 /* Set replay tracks */ | 316 |
309 Settracks(0,0); | 317 /* Set replay tracks */ |
310 Setmontracks(0); | 318 Settracks (0, 0); |
311 | 319 Setmontracks (0); |
312 /* Select replay format */ | 320 |
313 switch (spec->format & 0xff) { | 321 /* Select replay format */ |
314 case 8: | 322 switch (spec->format & 0xff) { |
315 if (spec->channels==2) { | 323 case 8: |
316 channels_mode=STEREO8; | 324 if (spec->channels == 2) { |
317 } else { | 325 channels_mode = STEREO8; |
318 channels_mode=MONO8; | 326 } else { |
319 } | 327 channels_mode = MONO8; |
320 break; | 328 } |
321 case 16: | 329 break; |
322 if (spec->channels==2) { | 330 case 16: |
323 channels_mode=STEREO16; | 331 if (spec->channels == 2) { |
324 } else { | 332 channels_mode = STEREO16; |
325 channels_mode=MONO16; | 333 } else { |
326 } | 334 channels_mode = MONO16; |
327 break; | 335 } |
328 default: | 336 break; |
329 channels_mode=STEREO16; | 337 default: |
330 break; | 338 channels_mode = STEREO16; |
331 } | 339 break; |
332 if (Setmode(channels_mode)<0) { | 340 } |
333 DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n")); | 341 if (Setmode (channels_mode) < 0) { |
334 } | 342 DEBUG_PRINT ((DEBUG_NAME "Setmode() failed\n")); |
335 | 343 } |
336 prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; | 344 |
337 Devconnect(DMAPLAY, DAC, CLKEXT, prediv, 1); | 345 prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; |
338 | 346 Devconnect (DMAPLAY, DAC, CLKEXT, prediv, 1); |
339 /* Set buffer */ | 347 |
340 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; | 348 /* Set buffer */ |
341 if (Setbuffer(0, buffer, buffer + spec->size)<0) { | 349 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; |
342 DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n")); | 350 if (Setbuffer (0, buffer, buffer + spec->size) < 0) { |
343 } | 351 DEBUG_PRINT ((DEBUG_NAME "Setbuffer() failed\n")); |
344 | 352 } |
345 /* Install interrupt */ | 353 |
346 if (NSetinterrupt(2, SI_PLAY, Mint_GsxbInterrupt)<0) { | 354 /* Install interrupt */ |
347 DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed\n")); | 355 if (NSetinterrupt (2, SI_PLAY, Mint_GsxbInterrupt) < 0) { |
348 } | 356 DEBUG_PRINT ((DEBUG_NAME "NSetinterrupt() failed\n")); |
349 | 357 } |
350 /* Go */ | 358 |
351 Buffoper(SB_PLA_ENA|SB_PLA_RPT); | 359 /* Go */ |
352 DEBUG_PRINT((DEBUG_NAME "hardware initialized\n")); | 360 Buffoper (SB_PLA_ENA | SB_PLA_RPT); |
353 } | 361 DEBUG_PRINT ((DEBUG_NAME "hardware initialized\n")); |
354 | 362 } |
355 static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec) | 363 |
356 { | 364 static int |
357 /* Lock sound system */ | 365 Mint_OpenAudio (_THIS, SDL_AudioSpec * spec) |
358 if (Locksnd()!=1) { | 366 { |
359 SDL_SetError("Mint_OpenAudio: Audio system already in use"); | 367 /* Lock sound system */ |
360 return(-1); | 368 if (Locksnd () != 1) { |
361 } | 369 SDL_SetError ("Mint_OpenAudio: Audio system already in use"); |
362 | 370 return (-1); |
363 SDL_MintAudio_device = this; | 371 } |
364 | 372 |
365 /* Check audio capabilities */ | 373 SDL_MintAudio_device = this; |
366 if (Mint_CheckAudio(this, spec)==-1) { | 374 |
367 return -1; | 375 /* Check audio capabilities */ |
368 } | 376 if (Mint_CheckAudio (this, spec) == -1) { |
369 | 377 return -1; |
370 SDL_CalculateAudioSpec(spec); | 378 } |
371 | 379 |
372 /* Allocate memory for audio buffers in DMA-able RAM */ | 380 SDL_CalculateAudioSpec (spec); |
373 DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); | 381 |
374 | 382 /* Allocate memory for audio buffers in DMA-able RAM */ |
375 SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM); | 383 DEBUG_PRINT ((DEBUG_NAME "buffer size=%d\n", spec->size)); |
376 if (SDL_MintAudio_audiobuf[0]==NULL) { | 384 |
377 SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); | 385 SDL_MintAudio_audiobuf[0] = Atari_SysMalloc (spec->size * 2, MX_STRAM); |
378 return (-1); | 386 if (SDL_MintAudio_audiobuf[0] == NULL) { |
379 } | 387 SDL_SetError ("MINT_OpenAudio: Not enough memory for audio buffer"); |
380 SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ; | 388 return (-1); |
381 SDL_MintAudio_numbuf=0; | 389 } |
382 SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2); | 390 SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; |
383 SDL_MintAudio_audiosize = spec->size; | 391 SDL_MintAudio_numbuf = 0; |
384 SDL_MintAudio_mutex = 0; | 392 SDL_memset (SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); |
385 | 393 SDL_MintAudio_audiosize = spec->size; |
386 DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0])); | 394 SDL_MintAudio_mutex = 0; |
387 DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1])); | 395 |
388 | 396 DEBUG_PRINT ((DEBUG_NAME "buffer 0 at 0x%08x\n", |
389 /* Setup audio hardware */ | 397 SDL_MintAudio_audiobuf[0])); |
390 Mint_InitAudio(this, spec); | 398 DEBUG_PRINT ((DEBUG_NAME "buffer 1 at 0x%08x\n", |
391 | 399 SDL_MintAudio_audiobuf[1])); |
392 return(1); /* We don't use threaded audio */ | 400 |
393 } | 401 /* Setup audio hardware */ |
394 | 402 Mint_InitAudio (this, spec); |
395 static void Mint_GsxbInterrupt(void) | 403 |
396 { | 404 return (1); /* We don't use threaded audio */ |
397 Uint8 *newbuf; | 405 } |
398 | 406 |
399 if (SDL_MintAudio_mutex) | 407 static void |
400 return; | 408 Mint_GsxbInterrupt (void) |
401 | 409 { |
402 SDL_MintAudio_mutex=1; | 410 Uint8 *newbuf; |
403 | 411 |
404 SDL_MintAudio_numbuf ^= 1; | 412 if (SDL_MintAudio_mutex) |
405 SDL_MintAudio_Callback(); | 413 return; |
406 newbuf = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; | 414 |
407 Setbuffer(0, newbuf, newbuf + SDL_MintAudio_audiosize); | 415 SDL_MintAudio_mutex = 1; |
408 | 416 |
409 SDL_MintAudio_mutex=0; | 417 SDL_MintAudio_numbuf ^= 1; |
410 } | 418 SDL_MintAudio_Callback (); |
411 | 419 newbuf = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; |
412 static void Mint_GsxbNullInterrupt(void) | 420 Setbuffer (0, newbuf, newbuf + SDL_MintAudio_audiosize); |
413 { | 421 |
414 } | 422 SDL_MintAudio_mutex = 0; |
423 } | |
424 | |
425 static void | |
426 Mint_GsxbNullInterrupt (void) | |
427 { | |
428 } | |
429 | |
430 /* vi: set ts=4 sw=4 expandtab: */ |