comparison src/audio/mint/SDL_mintaudio_dma8.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
61 61
62 static unsigned long cookie_snd, cookie_mch; 62 static unsigned long cookie_snd, cookie_mch;
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 /*--- Audio driver bootstrap functions ---*/ 75 /*--- Audio driver bootstrap functions ---*/
76 76
77 static int 77 static int
78 Audio_Available (void) 78 Audio_Available(void)
79 { 79 {
80 const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); 80 const char *envr = SDL_getenv("SDL_AUDIODRIVER");
81 81
82 /* Check if user asked a different audio driver */ 82 /* Check if user asked a different audio driver */
83 if ((envr) && (SDL_strcmp (envr, MINT_AUDIO_DRIVER_NAME) != 0)) { 83 if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) {
84 DEBUG_PRINT ((DEBUG_NAME "user asked a different audio driver\n")); 84 DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
85 return 0; 85 return 0;
86 } 86 }
87 87
88 /* Cookie _MCH present ? if not, assume ST machine */ 88 /* Cookie _MCH present ? if not, assume ST machine */
89 if (Getcookie (C__MCH, &cookie_mch) == C_NOTFOUND) { 89 if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
90 cookie_mch = MCH_ST; 90 cookie_mch = MCH_ST;
91 } 91 }
92 92
93 /* Cookie _SND present ? if not, assume ST machine */ 93 /* Cookie _SND present ? if not, assume ST machine */
94 if (Getcookie (C__SND, &cookie_snd) == C_NOTFOUND) { 94 if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
95 cookie_snd = SND_PSG; 95 cookie_snd = SND_PSG;
96 } 96 }
97 97
98 /* Check if we have 8 bits audio */ 98 /* Check if we have 8 bits audio */
99 if ((cookie_snd & SND_8BIT) == 0) { 99 if ((cookie_snd & SND_8BIT) == 0) {
100 DEBUG_PRINT ((DEBUG_NAME "no 8 bits sound\n")); 100 DEBUG_PRINT((DEBUG_NAME "no 8 bits sound\n"));
101 return (0); 101 return (0);
102 } 102 }
103 103
104 /* Check if audio is lockable */ 104 /* Check if audio is lockable */
105 if (cookie_snd & SND_16BIT) { 105 if (cookie_snd & SND_16BIT) {
106 if (Locksnd () != 1) { 106 if (Locksnd() != 1) {
107 DEBUG_PRINT ((DEBUG_NAME "audio locked by other application\n")); 107 DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n"));
108 return (0); 108 return (0);
109 } 109 }
110 110
111 Unlocksnd (); 111 Unlocksnd();
112 } 112 }
113 113
114 DEBUG_PRINT ((DEBUG_NAME "8 bits audio available!\n")); 114 DEBUG_PRINT((DEBUG_NAME "8 bits 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 DMA 8 bits audio driver", 157 MINT_AUDIO_DRIVER_NAME, "MiNT DMA 8 bits 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 DMAAUDIO_IO.control = 0; 168 DMAAUDIO_IO.control = 0;
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 DMAAUDIO_IO.control = 3; 179 DMAAUDIO_IO.control = 3;
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 DMAAUDIO_IO.control = 0; 190 DMAAUDIO_IO.control = 0;
191 Super (oldpile); 191 Super(oldpile);
192 192
193 DEBUG_PRINT ((DEBUG_NAME "closeaudio: replay stopped\n")); 193 DEBUG_PRINT((DEBUG_NAME "closeaudio: replay stopped\n"));
194 194
195 /* Disable interrupt */ 195 /* Disable interrupt */
196 Jdisint (MFP_DMASOUND); 196 Jdisint(MFP_DMASOUND);
197 197
198 DEBUG_PRINT ((DEBUG_NAME "closeaudio: interrupt disabled\n")); 198 DEBUG_PRINT((DEBUG_NAME "closeaudio: interrupt disabled\n"));
199 199
200 /* Wait if currently playing sound */ 200 /* Wait if currently playing sound */
201 while (SDL_MintAudio_mutex != 0) { 201 while (SDL_MintAudio_mutex != 0) {
202 } 202 }
203 203
204 DEBUG_PRINT ((DEBUG_NAME "closeaudio: no more interrupt running\n")); 204 DEBUG_PRINT((DEBUG_NAME "closeaudio: no more interrupt running\n"));
205 205
206 /* Clear buffers */ 206 /* Clear buffers */
207 if (SDL_MintAudio_audiobuf[0]) { 207 if (SDL_MintAudio_audiobuf[0]) {
208 Mfree (SDL_MintAudio_audiobuf[0]); 208 Mfree(SDL_MintAudio_audiobuf[0]);
209 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; 209 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
210 } 210 }
211 211
212 DEBUG_PRINT ((DEBUG_NAME "closeaudio: buffers freed\n")); 212 DEBUG_PRINT((DEBUG_NAME "closeaudio: buffers freed\n"));
213 } 213 }
214 214
215 static int 215 static int
216 Mint_CheckAudio (_THIS, SDL_AudioSpec * spec) 216 Mint_CheckAudio(_THIS, SDL_AudioSpec * spec)
217 { 217 {
218 int i, masterprediv, sfreq; 218 int i, masterprediv, sfreq;
219 unsigned long masterclock; 219 unsigned long masterclock;
220 220
221 DEBUG_PRINT ((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); 221 DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff));
222 DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); 222 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0)));
223 DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); 223 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0)));
224 DEBUG_PRINT (("channels=%d, ", spec->channels)); 224 DEBUG_PRINT(("channels=%d, ", spec->channels));
225 DEBUG_PRINT (("freq=%d\n", spec->freq)); 225 DEBUG_PRINT(("freq=%d\n", spec->freq));
226 226
227 /* Check formats available */ 227 /* Check formats available */
228 spec->format = AUDIO_S8; 228 spec->format = AUDIO_S8;
229 229
230 /* Calculate and select the closest frequency */ 230 /* Calculate and select the closest frequency */
250 break; 250 break;
251 } 251 }
252 252
253 MINTAUDIO_freqcount = 0; 253 MINTAUDIO_freqcount = 0;
254 for (i = sfreq; i < 4; i++) { 254 for (i = sfreq; i < 4; i++) {
255 SDL_MintAudio_AddFrequency (this, 255 SDL_MintAudio_AddFrequency(this,
256 masterclock / (masterprediv * (1 << i)), 256 masterclock / (masterprediv * (1 << i)),
257 masterclock, i - sfreq, -1); 257 masterclock, i - sfreq, -1);
258 } 258 }
259 259
260 #if 1 260 #if 1
261 for (i = 0; i < MINTAUDIO_freqcount; i++) { 261 for (i = 0; i < MINTAUDIO_freqcount; i++) {
262 DEBUG_PRINT ((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", 262 DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n",
263 i, MINTAUDIO_frequencies[i].frequency, 263 i, MINTAUDIO_frequencies[i].frequency,
264 MINTAUDIO_frequencies[i].masterclock, 264 MINTAUDIO_frequencies[i].masterclock,
265 MINTAUDIO_frequencies[i].predivisor)); 265 MINTAUDIO_frequencies[i].predivisor));
266 } 266 }
267 #endif 267 #endif
268 268
269 MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency (this, spec->freq); 269 MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq);
270 spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; 270 spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
271 271
272 DEBUG_PRINT ((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); 272 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff));
273 DEBUG_PRINT (("signed=%d, ", ((spec->format & 0x8000) != 0))); 273 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0)));
274 DEBUG_PRINT (("big endian=%d, ", ((spec->format & 0x1000) != 0))); 274 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0)));
275 DEBUG_PRINT (("channels=%d, ", spec->channels)); 275 DEBUG_PRINT(("channels=%d, ", spec->channels));
276 DEBUG_PRINT (("freq=%d\n", spec->freq)); 276 DEBUG_PRINT(("freq=%d\n", spec->freq));
277 277
278 return 0; 278 return 0;
279 } 279 }
280 280
281 static void 281 static void
282 Mint_InitAudio (_THIS, SDL_AudioSpec * spec) 282 Mint_InitAudio(_THIS, SDL_AudioSpec * spec)
283 { 283 {
284 void *oldpile; 284 void *oldpile;
285 unsigned long buffer; 285 unsigned long buffer;
286 unsigned char mode; 286 unsigned char mode;
287 287
288 /* Set replay tracks */ 288 /* Set replay tracks */
289 if (cookie_snd & SND_16BIT) { 289 if (cookie_snd & SND_16BIT) {
290 Settracks (0, 0); 290 Settracks(0, 0);
291 Setmontracks (0); 291 Setmontracks(0);
292 } 292 }
293 293
294 oldpile = (void *) Super (0); 294 oldpile = (void *) Super(0);
295 295
296 /* Stop currently playing sound */ 296 /* Stop currently playing sound */
297 DMAAUDIO_IO.control = 0; 297 DMAAUDIO_IO.control = 0;
298 298
299 /* Set buffer */ 299 /* Set buffer */
312 mode |= 1 << 7; 312 mode |= 1 << 7;
313 } 313 }
314 DMAAUDIO_IO.sound_ctrl = mode; 314 DMAAUDIO_IO.sound_ctrl = mode;
315 315
316 /* Set interrupt */ 316 /* Set interrupt */
317 Jdisint (MFP_DMASOUND); 317 Jdisint(MFP_DMASOUND);
318 Xbtimer (XB_TIMERA, 8, 1, SDL_MintAudio_Dma8Interrupt); 318 Xbtimer(XB_TIMERA, 8, 1, SDL_MintAudio_Dma8Interrupt);
319 Jenabint (MFP_DMASOUND); 319 Jenabint(MFP_DMASOUND);
320 320
321 if (cookie_snd & SND_16BIT) { 321 if (cookie_snd & SND_16BIT) {
322 if (Setinterrupt (SI_TIMERA, SI_PLAY) < 0) { 322 if (Setinterrupt(SI_TIMERA, SI_PLAY) < 0) {
323 DEBUG_PRINT ((DEBUG_NAME "Setinterrupt() failed\n")); 323 DEBUG_PRINT((DEBUG_NAME "Setinterrupt() failed\n"));
324 } 324 }
325 } 325 }
326 326
327 /* Go */ 327 /* Go */
328 DMAAUDIO_IO.control = 3; /* playback + repeat */ 328 DMAAUDIO_IO.control = 3; /* playback + repeat */
329 329
330 Super (oldpile); 330 Super(oldpile);
331 } 331 }
332 332
333 static int 333 static int
334 Mint_OpenAudio (_THIS, SDL_AudioSpec * spec) 334 Mint_OpenAudio(_THIS, SDL_AudioSpec * spec)
335 { 335 {
336 SDL_MintAudio_device = this; 336 SDL_MintAudio_device = this;
337 337
338 /* Check audio capabilities */ 338 /* Check audio capabilities */
339 if (Mint_CheckAudio (this, spec) == -1) { 339 if (Mint_CheckAudio(this, spec) == -1) {
340 return -1; 340 return -1;
341 } 341 }
342 342
343 SDL_CalculateAudioSpec (spec); 343 SDL_CalculateAudioSpec(spec);
344 344
345 /* Allocate memory for audio buffers in DMA-able RAM */ 345 /* Allocate memory for audio buffers in DMA-able RAM */
346 DEBUG_PRINT ((DEBUG_NAME "buffer size=%d\n", spec->size)); 346 DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
347 347
348 SDL_MintAudio_audiobuf[0] = Atari_SysMalloc (spec->size * 2, MX_STRAM); 348 SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM);
349 if (SDL_MintAudio_audiobuf[0] == NULL) { 349 if (SDL_MintAudio_audiobuf[0] == NULL) {
350 SDL_SetError ("MINT_OpenAudio: Not enough memory for audio buffer"); 350 SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
351 return (-1); 351 return (-1);
352 } 352 }
353 SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size; 353 SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size;
354 SDL_MintAudio_numbuf = 0; 354 SDL_MintAudio_numbuf = 0;
355 SDL_memset (SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2); 355 SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2);
356 SDL_MintAudio_audiosize = spec->size; 356 SDL_MintAudio_audiosize = spec->size;
357 SDL_MintAudio_mutex = 0; 357 SDL_MintAudio_mutex = 0;
358 358
359 DEBUG_PRINT ((DEBUG_NAME "buffer 0 at 0x%08x\n", 359 DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n",
360 SDL_MintAudio_audiobuf[0])); 360 SDL_MintAudio_audiobuf[0]));
361 DEBUG_PRINT ((DEBUG_NAME "buffer 1 at 0x%08x\n", 361 DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n",
362 SDL_MintAudio_audiobuf[1])); 362 SDL_MintAudio_audiobuf[1]));
363 363
364 /* Setup audio hardware */ 364 /* Setup audio hardware */
365 Mint_InitAudio (this, spec); 365 Mint_InitAudio(this, spec);
366 366
367 return (1); /* We don't use threaded audio */ 367 return (1); /* We don't use threaded audio */
368 } 368 }
369 369
370 /* vi: set ts=4 sw=4 expandtab: */ 370 /* vi: set ts=4 sw=4 expandtab: */