Mercurial > sdl-ios-xcode
comparison src/audio/mint/SDL_mintaudio_stfa.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
69 30720, 32336, 43885, 49152 | 69 30720, 32336, 43885, 49152 |
70 }; | 70 }; |
71 | 71 |
72 /*--- Audio driver functions ---*/ | 72 /*--- Audio driver functions ---*/ |
73 | 73 |
74 static void Mint_CloseAudio (_THIS); | 74 static void Mint_CloseAudio(_THIS); |
75 static int Mint_OpenAudio (_THIS, SDL_AudioSpec * spec); | 75 static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec); |
76 static void Mint_LockAudio (_THIS); | 76 static void Mint_LockAudio(_THIS); |
77 static void Mint_UnlockAudio (_THIS); | 77 static void Mint_UnlockAudio(_THIS); |
78 | 78 |
79 /* To check/init hardware audio */ | 79 /* To check/init hardware audio */ |
80 static int Mint_CheckAudio (_THIS, SDL_AudioSpec * spec); | 80 static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec); |
81 static void Mint_InitAudio (_THIS, SDL_AudioSpec * spec); | 81 static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec); |
82 | 82 |
83 /*--- Audio driver bootstrap functions ---*/ | 83 /*--- Audio driver bootstrap functions ---*/ |
84 | 84 |
85 static int | 85 static int |
86 Audio_Available (void) | 86 Audio_Available(void) |
87 { | 87 { |
88 const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); | 88 const char *envr = SDL_getenv("SDL_AUDIODRIVER"); |
89 | 89 |
90 /* Check if user asked a different audio driver */ | 90 /* Check if user asked a different audio driver */ |
91 if ((envr) && (SDL_strcmp (envr, MINT_AUDIO_DRIVER_NAME) != 0)) { | 91 if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) { |
92 DEBUG_PRINT ((DEBUG_NAME "user asked a different audio driver\n")); | 92 DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n")); |
93 return (0); | 93 return (0); |
94 } | 94 } |
95 | 95 |
96 /* Cookie _MCH present ? if not, assume ST machine */ | 96 /* Cookie _MCH present ? if not, assume ST machine */ |
97 if (Getcookie (C__MCH, &cookie_mch) == C_NOTFOUND) { | 97 if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) { |
98 cookie_mch = MCH_ST; | 98 cookie_mch = MCH_ST; |
99 } | 99 } |
100 | 100 |
101 /* Cookie _SND present ? if not, assume ST machine */ | 101 /* Cookie _SND present ? if not, assume ST machine */ |
102 if (Getcookie (C__SND, &cookie_snd) == C_NOTFOUND) { | 102 if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { |
103 cookie_snd = SND_PSG; | 103 cookie_snd = SND_PSG; |
104 } | 104 } |
105 | 105 |
106 /* Cookie STFA present ? */ | 106 /* Cookie STFA present ? */ |
107 if (Getcookie (C_STFA, (long *) &cookie_stfa) != C_FOUND) { | 107 if (Getcookie(C_STFA, (long *) &cookie_stfa) != C_FOUND) { |
108 DEBUG_PRINT ((DEBUG_NAME "no STFA audio\n")); | 108 DEBUG_PRINT((DEBUG_NAME "no STFA audio\n")); |
109 return (0); | 109 return (0); |
110 } | 110 } |
111 | 111 |
112 SDL_MintAudio_stfa = cookie_stfa; | 112 SDL_MintAudio_stfa = cookie_stfa; |
113 | 113 |
114 DEBUG_PRINT ((DEBUG_NAME "STFA audio available!\n")); | 114 DEBUG_PRINT((DEBUG_NAME "STFA audio available!\n")); |
115 return (1); | 115 return (1); |
116 } | 116 } |
117 | 117 |
118 static void | 118 static void |
119 Audio_DeleteDevice (SDL_AudioDevice * device) | 119 Audio_DeleteDevice(SDL_AudioDevice * device) |
120 { | 120 { |
121 SDL_free (device->hidden); | 121 SDL_free(device->hidden); |
122 SDL_free (device); | 122 SDL_free(device); |
123 } | 123 } |
124 | 124 |
125 static SDL_AudioDevice * | 125 static SDL_AudioDevice * |
126 Audio_CreateDevice (int devindex) | 126 Audio_CreateDevice(int devindex) |
127 { | 127 { |
128 SDL_AudioDevice *this; | 128 SDL_AudioDevice *this; |
129 | 129 |
130 /* Initialize all variables that we clean on shutdown */ | 130 /* Initialize all variables that we clean on shutdown */ |
131 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); | 131 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); |
132 if (this) { | 132 if (this) { |
133 SDL_memset (this, 0, (sizeof *this)); | 133 SDL_memset(this, 0, (sizeof *this)); |
134 this->hidden = (struct SDL_PrivateAudioData *) | 134 this->hidden = (struct SDL_PrivateAudioData *) |
135 SDL_malloc ((sizeof *this->hidden)); | 135 SDL_malloc((sizeof *this->hidden)); |
136 } | 136 } |
137 if ((this == NULL) || (this->hidden == NULL)) { | 137 if ((this == NULL) || (this->hidden == NULL)) { |
138 SDL_OutOfMemory (); | 138 SDL_OutOfMemory(); |
139 if (this) { | 139 if (this) { |
140 SDL_free (this); | 140 SDL_free(this); |
141 } | 141 } |
142 return (0); | 142 return (0); |
143 } | 143 } |
144 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); | 144 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
145 | 145 |
146 /* Set the function pointers */ | 146 /* Set the function pointers */ |
147 this->OpenAudio = Mint_OpenAudio; | 147 this->OpenAudio = Mint_OpenAudio; |
148 this->CloseAudio = Mint_CloseAudio; | 148 this->CloseAudio = Mint_CloseAudio; |
149 this->LockAudio = Mint_LockAudio; | 149 this->LockAudio = Mint_LockAudio; |
157 MINT_AUDIO_DRIVER_NAME, "MiNT STFA audio driver", | 157 MINT_AUDIO_DRIVER_NAME, "MiNT STFA audio driver", |
158 Audio_Available, Audio_CreateDevice | 158 Audio_Available, Audio_CreateDevice |
159 }; | 159 }; |
160 | 160 |
161 static void | 161 static void |
162 Mint_LockAudio (_THIS) | 162 Mint_LockAudio(_THIS) |
163 { | 163 { |
164 void *oldpile; | 164 void *oldpile; |
165 | 165 |
166 /* Stop replay */ | 166 /* Stop replay */ |
167 oldpile = (void *) Super (0); | 167 oldpile = (void *) Super(0); |
168 cookie_stfa->sound_enable = STFA_PLAY_DISABLE; | 168 cookie_stfa->sound_enable = STFA_PLAY_DISABLE; |
169 Super (oldpile); | 169 Super(oldpile); |
170 } | 170 } |
171 | 171 |
172 static void | 172 static void |
173 Mint_UnlockAudio (_THIS) | 173 Mint_UnlockAudio(_THIS) |
174 { | 174 { |
175 void *oldpile; | 175 void *oldpile; |
176 | 176 |
177 /* Restart replay */ | 177 /* Restart replay */ |
178 oldpile = (void *) Super (0); | 178 oldpile = (void *) Super(0); |
179 cookie_stfa->sound_enable = STFA_PLAY_ENABLE | STFA_PLAY_REPEAT; | 179 cookie_stfa->sound_enable = STFA_PLAY_ENABLE | STFA_PLAY_REPEAT; |
180 Super (oldpile); | 180 Super(oldpile); |
181 } | 181 } |
182 | 182 |
183 static void | 183 static void |
184 Mint_CloseAudio (_THIS) | 184 Mint_CloseAudio(_THIS) |
185 { | 185 { |
186 void *oldpile; | 186 void *oldpile; |
187 | 187 |
188 /* Stop replay */ | 188 /* Stop replay */ |
189 oldpile = (void *) Super (0); | 189 oldpile = (void *) Super(0); |
190 cookie_stfa->sound_enable = STFA_PLAY_DISABLE; | 190 cookie_stfa->sound_enable = STFA_PLAY_DISABLE; |
191 Super (oldpile); | 191 Super(oldpile); |
192 | 192 |
193 /* Wait if currently playing sound */ | 193 /* Wait if currently playing sound */ |
194 while (SDL_MintAudio_mutex != 0) { | 194 while (SDL_MintAudio_mutex != 0) { |
195 } | 195 } |
196 | 196 |
197 /* Clear buffers */ | 197 /* Clear buffers */ |
198 if (SDL_MintAudio_audiobuf[0]) { | 198 if (SDL_MintAudio_audiobuf[0]) { |
199 Mfree (SDL_MintAudio_audiobuf[0]); | 199 Mfree(SDL_MintAudio_audiobuf[0]); |
200 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; | 200 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 static int | 204 static int |
205 Mint_CheckAudio (_THIS, SDL_AudioSpec * spec) | 205 Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) |
206 { | 206 { |
207 int i; | 207 int i; |
208 | 208 |
209 DEBUG_PRINT ((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); | 209 DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); |
210 DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); | 210 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); |
211 DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); | 211 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); |
212 DEBUG_PRINT (("channels=%d, ", spec->channels)); | 212 DEBUG_PRINT(("channels=%d, ", spec->channels)); |
213 DEBUG_PRINT (("freq=%d\n", spec->freq)); | 213 DEBUG_PRINT(("freq=%d\n", spec->freq)); |
214 | 214 |
215 /* Check formats available */ | 215 /* Check formats available */ |
216 MINTAUDIO_freqcount = 0; | 216 MINTAUDIO_freqcount = 0; |
217 for (i = 0; i < 16; i++) { | 217 for (i = 0; i < 16; i++) { |
218 SDL_MintAudio_AddFrequency (this, freqs[i], 0, i, -1); | 218 SDL_MintAudio_AddFrequency(this, freqs[i], 0, i, -1); |
219 } | 219 } |
220 | 220 |
221 #if 1 | 221 #if 1 |
222 for (i = 0; i < MINTAUDIO_freqcount; i++) { | 222 for (i = 0; i < MINTAUDIO_freqcount; i++) { |
223 DEBUG_PRINT ((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", | 223 DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", |
224 i, MINTAUDIO_frequencies[i].frequency, | 224 i, MINTAUDIO_frequencies[i].frequency, |
225 MINTAUDIO_frequencies[i].masterclock, | 225 MINTAUDIO_frequencies[i].masterclock, |
226 MINTAUDIO_frequencies[i].predivisor)); | 226 MINTAUDIO_frequencies[i].predivisor)); |
227 } | 227 } |
228 #endif | 228 #endif |
229 | 229 |
230 MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency (this, spec->freq); | 230 MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq); |
231 spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; | 231 spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; |
232 | 232 |
233 DEBUG_PRINT ((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); | 233 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); |
234 DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); | 234 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); |
235 DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); | 235 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); |
236 DEBUG_PRINT (("channels=%d, ", spec->channels)); | 236 DEBUG_PRINT(("channels=%d, ", spec->channels)); |
237 DEBUG_PRINT (("freq=%d\n", spec->freq)); | 237 DEBUG_PRINT(("freq=%d\n", spec->freq)); |
238 | 238 |
239 return 0; | 239 return 0; |
240 } | 240 } |
241 | 241 |
242 static void | 242 static void |
243 Mint_InitAudio (_THIS, SDL_AudioSpec * spec) | 243 Mint_InitAudio(_THIS, SDL_AudioSpec * spec) |
244 { | 244 { |
245 void *buffer; | 245 void *buffer; |
246 void *oldpile; | 246 void *oldpile; |
247 | 247 |
248 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; | 248 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; |
249 | 249 |
250 oldpile = (void *) Super (0); | 250 oldpile = (void *) Super(0); |
251 | 251 |
252 /* Stop replay */ | 252 /* Stop replay */ |
253 cookie_stfa->sound_enable = STFA_PLAY_DISABLE; | 253 cookie_stfa->sound_enable = STFA_PLAY_DISABLE; |
254 | 254 |
255 /* Select replay format */ | 255 /* Select replay format */ |
284 cookie_stfa->stfa_it = SDL_MintAudio_StfaInterrupt; | 284 cookie_stfa->stfa_it = SDL_MintAudio_StfaInterrupt; |
285 | 285 |
286 /* Restart replay */ | 286 /* Restart replay */ |
287 cookie_stfa->sound_enable = STFA_PLAY_ENABLE | STFA_PLAY_REPEAT; | 287 cookie_stfa->sound_enable = STFA_PLAY_ENABLE | STFA_PLAY_REPEAT; |
288 | 288 |
289 Super (oldpile); | 289 Super(oldpile); |
290 | 290 |
291 DEBUG_PRINT ((DEBUG_NAME "hardware initialized\n")); | 291 DEBUG_PRINT((DEBUG_NAME "hardware initialized\n")); |
292 } | 292 } |
293 | 293 |
294 static int | 294 static int |
295 Mint_OpenAudio (_THIS, SDL_AudioSpec * spec) | 295 Mint_OpenAudio(_THIS, SDL_AudioSpec * spec) |
296 { | 296 { |
297 SDL_MintAudio_device = this; | 297 SDL_MintAudio_device = this; |
298 | 298 |
299 /* Check audio capabilities */ | 299 /* Check audio capabilities */ |
300 if (Mint_CheckAudio (this, spec) == -1) { | 300 if (Mint_CheckAudio(this, spec) == -1) { |
301 return -1; | 301 return -1; |
302 } | 302 } |
303 | 303 |
304 SDL_CalculateAudioSpec (spec); | 304 SDL_CalculateAudioSpec(spec); |
305 | 305 |
306 /* Allocate memory for audio buffers in DMA-able RAM */ | 306 /* Allocate memory for audio buffers in DMA-able RAM */ |
307 DEBUG_PRINT ((DEBUG_NAME "buffer size=%d\n", spec->size)); | 307 DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); |
308 | 308 |
309 SDL_MintAudio_audiobuf[0] = Atari_SysMalloc (spec->size * 2, MX_STRAM); | 309 SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM); |
310 if (SDL_MintAudio_audiobuf[0] == NULL) { | 310 if (SDL_MintAudio_audiobuf[0] == NULL) { |
311 SDL_SetError ("MINT_OpenAudio: Not enough memory for audio buffer"); | 311 SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); |
312 return (-1); | 312 return (-1); |
313 } | 313 } |
314 SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; | 314 SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; |
315 SDL_MintAudio_numbuf = 0; | 315 SDL_MintAudio_numbuf = 0; |
316 SDL_memset (SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); | 316 SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); |
317 SDL_MintAudio_audiosize = spec->size; | 317 SDL_MintAudio_audiosize = spec->size; |
318 SDL_MintAudio_mutex = 0; | 318 SDL_MintAudio_mutex = 0; |
319 | 319 |
320 DEBUG_PRINT ((DEBUG_NAME "buffer 0 at 0x%08x\n", | 320 DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", |
321 SDL_MintAudio_audiobuf[0])); | 321 SDL_MintAudio_audiobuf[0])); |
322 DEBUG_PRINT ((DEBUG_NAME "buffer 1 at 0x%08x\n", | 322 DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", |
323 SDL_MintAudio_audiobuf[1])); | 323 SDL_MintAudio_audiobuf[1])); |
324 | 324 |
325 /* Setup audio hardware */ | 325 /* Setup audio hardware */ |
326 Mint_InitAudio (this, spec); | 326 Mint_InitAudio(this, spec); |
327 | 327 |
328 return (1); /* We don't use threaded audio */ | 328 return (1); /* We don't use threaded audio */ |
329 } | 329 } |
330 | 330 |
331 /* vi: set ts=4 sw=4 expandtab: */ | 331 /* vi: set ts=4 sw=4 expandtab: */ |