comparison src/audio/amigaos/SDL_ahiaudio.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
26 #include "SDL_audio.h" 26 #include "SDL_audio.h"
27 #include "../SDL_audio_c.h" 27 #include "../SDL_audio_c.h"
28 #include "SDL_ahiaudio.h" 28 #include "SDL_ahiaudio.h"
29 29
30 /* Audio driver functions */ 30 /* Audio driver functions */
31 static int AHI_OpenAudio (_THIS, SDL_AudioSpec * spec); 31 static int AHI_OpenAudio(_THIS, SDL_AudioSpec * spec);
32 static void AHI_WaitAudio (_THIS); 32 static void AHI_WaitAudio(_THIS);
33 static void AHI_PlayAudio (_THIS); 33 static void AHI_PlayAudio(_THIS);
34 static Uint8 *AHI_GetAudioBuf (_THIS); 34 static Uint8 *AHI_GetAudioBuf(_THIS);
35 static void AHI_CloseAudio (_THIS); 35 static void AHI_CloseAudio(_THIS);
36 36
37 #ifndef __SASC 37 #ifndef __SASC
38 #define mymalloc(x) AllocVec(x,MEMF_PUBLIC) 38 #define mymalloc(x) AllocVec(x,MEMF_PUBLIC)
39 #define myfree FreeVec 39 #define myfree FreeVec
40 #else 40 #else
43 #endif 43 #endif
44 44
45 /* Audio driver bootstrap functions */ 45 /* Audio driver bootstrap functions */
46 46
47 static int 47 static int
48 Audio_Available (void) 48 Audio_Available(void)
49 { 49 {
50 int ok = 0; 50 int ok = 0;
51 struct MsgPort *p; 51 struct MsgPort *p;
52 struct AHIRequest *req; 52 struct AHIRequest *req;
53 53
54 if (p = CreateMsgPort ()) { 54 if (p = CreateMsgPort()) {
55 if (req = 55 if (req =
56 (struct AHIRequest *) CreateIORequest (p, 56 (struct AHIRequest *) CreateIORequest(p,
57 sizeof (struct 57 sizeof(struct
58 AHIRequest))) { 58 AHIRequest))) {
59 req->ahir_Version = 4; 59 req->ahir_Version = 4;
60 60
61 if (!OpenDevice (AHINAME, 0, (struct IORequest *) req, NULL)) { 61 if (!OpenDevice(AHINAME, 0, (struct IORequest *) req, NULL)) {
62 D (bug ("AHI available.\n")); 62 D(bug("AHI available.\n"));
63 ok = 1; 63 ok = 1;
64 CloseDevice ((struct IORequest *) req); 64 CloseDevice((struct IORequest *) req);
65 } 65 }
66 DeleteIORequest ((struct IORequest *) req); 66 DeleteIORequest((struct IORequest *) req);
67 } 67 }
68 DeleteMsgPort (p); 68 DeleteMsgPort(p);
69 } 69 }
70 70
71 D (if (!ok) bug ("AHI not available\n")); 71 D(if (!ok) bug("AHI not available\n"));
72 return ok; 72 return ok;
73 } 73 }
74 74
75 static void 75 static void
76 Audio_DeleteDevice (SDL_AudioDevice * device) 76 Audio_DeleteDevice(SDL_AudioDevice * device)
77 { 77 {
78 SDL_free (device->hidden); 78 SDL_free(device->hidden);
79 SDL_free (device); 79 SDL_free(device);
80 } 80 }
81 81
82 static SDL_AudioDevice * 82 static SDL_AudioDevice *
83 Audio_CreateDevice (int devindex) 83 Audio_CreateDevice(int devindex)
84 { 84 {
85 SDL_AudioDevice *this; 85 SDL_AudioDevice *this;
86 86
87 #ifndef NO_AMIGADEBUG 87 #ifndef NO_AMIGADEBUG
88 D (bug ("AHI created...\n")); 88 D(bug("AHI created...\n"));
89 #endif 89 #endif
90 90
91 /* Initialize all variables that we clean on shutdown */ 91 /* Initialize all variables that we clean on shutdown */
92 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); 92 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
93 if (this) { 93 if (this) {
94 SDL_memset (this, 0, (sizeof *this)); 94 SDL_memset(this, 0, (sizeof *this));
95 this->hidden = (struct SDL_PrivateAudioData *) 95 this->hidden = (struct SDL_PrivateAudioData *)
96 SDL_malloc ((sizeof *this->hidden)); 96 SDL_malloc((sizeof *this->hidden));
97 } 97 }
98 if ((this == NULL) || (this->hidden == NULL)) { 98 if ((this == NULL) || (this->hidden == NULL)) {
99 SDL_OutOfMemory (); 99 SDL_OutOfMemory();
100 if (this) { 100 if (this) {
101 SDL_free (this); 101 SDL_free(this);
102 } 102 }
103 return (0); 103 return (0);
104 } 104 }
105 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); 105 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
106 106
107 /* Set the function pointers */ 107 /* Set the function pointers */
108 this->OpenAudio = AHI_OpenAudio; 108 this->OpenAudio = AHI_OpenAudio;
109 this->WaitAudio = AHI_WaitAudio; 109 this->WaitAudio = AHI_WaitAudio;
110 this->PlayAudio = AHI_PlayAudio; 110 this->PlayAudio = AHI_PlayAudio;
120 "AHI", Audio_Available, Audio_CreateDevice 120 "AHI", Audio_Available, Audio_CreateDevice
121 }; 121 };
122 122
123 123
124 void static 124 void static
125 AHI_WaitAudio (_THIS) 125 AHI_WaitAudio(_THIS)
126 { 126 {
127 if (!CheckIO ((struct IORequest *) audio_req[current_buffer])) { 127 if (!CheckIO((struct IORequest *) audio_req[current_buffer])) {
128 WaitIO ((struct IORequest *) audio_req[current_buffer]); 128 WaitIO((struct IORequest *) audio_req[current_buffer]);
129 // AbortIO((struct IORequest *)audio_req[current_buffer]); 129 // AbortIO((struct IORequest *)audio_req[current_buffer]);
130 } 130 }
131 } 131 }
132 132
133 static void 133 static void
134 AHI_PlayAudio (_THIS) 134 AHI_PlayAudio(_THIS)
135 { 135 {
136 if (playing > 1) 136 if (playing > 1)
137 WaitIO ((struct IORequest *) audio_req[current_buffer]); 137 WaitIO((struct IORequest *) audio_req[current_buffer]);
138 138
139 /* Write the audio data out */ 139 /* Write the audio data out */
140 audio_req[current_buffer]->ahir_Std.io_Message.mn_Node.ln_Pri = 60; 140 audio_req[current_buffer]->ahir_Std.io_Message.mn_Node.ln_Pri = 60;
141 audio_req[current_buffer]->ahir_Std.io_Data = mixbuf[current_buffer]; 141 audio_req[current_buffer]->ahir_Std.io_Data = mixbuf[current_buffer];
142 audio_req[current_buffer]->ahir_Std.io_Length = this->hidden->size; 142 audio_req[current_buffer]->ahir_Std.io_Length = this->hidden->size;
147 audio_req[current_buffer]->ahir_Type = this->hidden->type; 147 audio_req[current_buffer]->ahir_Type = this->hidden->type;
148 audio_req[current_buffer]->ahir_Position = 0x8000; 148 audio_req[current_buffer]->ahir_Position = 0x8000;
149 audio_req[current_buffer]->ahir_Link = 149 audio_req[current_buffer]->ahir_Link =
150 (playing > 0 ? audio_req[current_buffer ^ 1] : NULL); 150 (playing > 0 ? audio_req[current_buffer ^ 1] : NULL);
151 151
152 SendIO ((struct IORequest *) audio_req[current_buffer]); 152 SendIO((struct IORequest *) audio_req[current_buffer]);
153 current_buffer ^= 1; 153 current_buffer ^= 1;
154 154
155 playing++; 155 playing++;
156 } 156 }
157 157
158 static Uint8 * 158 static Uint8 *
159 AHI_GetAudioBuf (_THIS) 159 AHI_GetAudioBuf(_THIS)
160 { 160 {
161 return (mixbuf[current_buffer]); 161 return (mixbuf[current_buffer]);
162 } 162 }
163 163
164 static void 164 static void
165 AHI_CloseAudio (_THIS) 165 AHI_CloseAudio(_THIS)
166 { 166 {
167 D (bug ("Closing audio...\n")); 167 D(bug("Closing audio...\n"));
168 168
169 playing = 0; 169 playing = 0;
170 170
171 if (audio_req[0]) { 171 if (audio_req[0]) {
172 if (audio_req[1]) { 172 if (audio_req[1]) {
173 D (bug ("Break req[1]...\n")); 173 D(bug("Break req[1]...\n"));
174 174
175 AbortIO ((struct IORequest *) audio_req[1]); 175 AbortIO((struct IORequest *) audio_req[1]);
176 WaitIO ((struct IORequest *) audio_req[1]); 176 WaitIO((struct IORequest *) audio_req[1]);
177 } 177 }
178 178
179 D (bug ("Break req[0]...\n")); 179 D(bug("Break req[0]...\n"));
180 180
181 AbortIO ((struct IORequest *) audio_req[0]); 181 AbortIO((struct IORequest *) audio_req[0]);
182 WaitIO ((struct IORequest *) audio_req[0]); 182 WaitIO((struct IORequest *) audio_req[0]);
183 183
184 if (audio_req[1]) { 184 if (audio_req[1]) {
185 D (bug ("Break AGAIN req[1]...\n")); 185 D(bug("Break AGAIN req[1]...\n"));
186 AbortIO ((struct IORequest *) audio_req[1]); 186 AbortIO((struct IORequest *) audio_req[1]);
187 WaitIO ((struct IORequest *) audio_req[1]); 187 WaitIO((struct IORequest *) audio_req[1]);
188 } 188 }
189 // Double abort to be sure to break the dbuffering process. 189 // Double abort to be sure to break the dbuffering process.
190 190
191 SDL_Delay (200); 191 SDL_Delay(200);
192 192
193 D (bug ("Reqs breaked, closing device...\n")); 193 D(bug("Reqs breaked, closing device...\n"));
194 CloseDevice ((struct IORequest *) audio_req[0]); 194 CloseDevice((struct IORequest *) audio_req[0]);
195 D (bug ("Device closed, freeing memory...\n")); 195 D(bug("Device closed, freeing memory...\n"));
196 myfree (audio_req[1]); 196 myfree(audio_req[1]);
197 D (bug ("Memory freed, deleting IOReq...\n")); 197 D(bug("Memory freed, deleting IOReq...\n"));
198 DeleteIORequest ((struct IORequest *) audio_req[0]); 198 DeleteIORequest((struct IORequest *) audio_req[0]);
199 audio_req[0] = audio_req[1] = NULL; 199 audio_req[0] = audio_req[1] = NULL;
200 } 200 }
201 201
202 D (bug ("Freeing mixbuf[0]...\n")); 202 D(bug("Freeing mixbuf[0]...\n"));
203 if (mixbuf[0] != NULL) { 203 if (mixbuf[0] != NULL) {
204 myfree (mixbuf[0]); 204 myfree(mixbuf[0]);
205 // SDL_FreeAudioMem(mixbuf[0]); 205 // SDL_FreeAudioMem(mixbuf[0]);
206 mixbuf[0] = NULL; 206 mixbuf[0] = NULL;
207 } 207 }
208 208
209 D (bug ("Freeing mixbuf[1]...\n")); 209 D(bug("Freeing mixbuf[1]...\n"));
210 if (mixbuf[1] != NULL) { 210 if (mixbuf[1] != NULL) {
211 myfree (mixbuf[1]); 211 myfree(mixbuf[1]);
212 // SDL_FreeAudioMem(mixbuf[1]); 212 // SDL_FreeAudioMem(mixbuf[1]);
213 mixbuf[1] = NULL; 213 mixbuf[1] = NULL;
214 } 214 }
215 215
216 D (bug ("Freeing audio_port...\n")); 216 D(bug("Freeing audio_port...\n"));
217 217
218 if (audio_port != NULL) { 218 if (audio_port != NULL) {
219 DeleteMsgPort (audio_port); 219 DeleteMsgPort(audio_port);
220 audio_port = NULL; 220 audio_port = NULL;
221 } 221 }
222 D (bug ("...done!\n")); 222 D(bug("...done!\n"));
223 } 223 }
224 224
225 static int 225 static int
226 AHI_OpenAudio (_THIS, SDL_AudioSpec * spec) 226 AHI_OpenAudio(_THIS, SDL_AudioSpec * spec)
227 { 227 {
228 // int width; 228 // int width;
229 229
230 D (bug ("AHI opening...\n")); 230 D(bug("AHI opening...\n"));
231 231
232 /* Determine the audio parameters from the AudioSpec */ 232 /* Determine the audio parameters from the AudioSpec */
233 switch (spec->format & 0xFF) { 233 switch (spec->format & 0xFF) {
234 234
235 case 8: 235 case 8:
236 { /* Signed 8 bit audio data */ 236 { /* Signed 8 bit audio data */
237 D (bug ("Samples a 8 bit...\n")); 237 D(bug("Samples a 8 bit...\n"));
238 spec->format = AUDIO_S8; 238 spec->format = AUDIO_S8;
239 this->hidden->bytespersample = 1; 239 this->hidden->bytespersample = 1;
240 if (spec->channels < 2) 240 if (spec->channels < 2)
241 this->hidden->type = AHIST_M8S; 241 this->hidden->type = AHIST_M8S;
242 else 242 else
244 } 244 }
245 break; 245 break;
246 246
247 case 16: 247 case 16:
248 { /* Signed 16 bit audio data */ 248 { /* Signed 16 bit audio data */
249 D (bug ("Samples a 16 bit...\n")); 249 D(bug("Samples a 16 bit...\n"));
250 spec->format = AUDIO_S16MSB; 250 spec->format = AUDIO_S16MSB;
251 this->hidden->bytespersample = 2; 251 this->hidden->bytespersample = 2;
252 if (spec->channels < 2) 252 if (spec->channels < 2)
253 this->hidden->type = AHIST_M16S; 253 this->hidden->type = AHIST_M16S;
254 else 254 else
256 } 256 }
257 break; 257 break;
258 258
259 default: 259 default:
260 { 260 {
261 SDL_SetError ("Unsupported audio format"); 261 SDL_SetError("Unsupported audio format");
262 return (-1); 262 return (-1);
263 } 263 }
264 } 264 }
265 265
266 if (spec->channels != 1 && spec->channels != 2) { 266 if (spec->channels != 1 && spec->channels != 2) {
267 D (bug ("Wrong channel number!\n")); 267 D(bug("Wrong channel number!\n"));
268 SDL_SetError ("Channel number non supported"); 268 SDL_SetError("Channel number non supported");
269 return -1; 269 return -1;
270 } 270 }
271 271
272 D (bug ("Before CalculateAudioSpec\n")); 272 D(bug("Before CalculateAudioSpec\n"));
273 /* Update the fragment size as size in bytes */ 273 /* Update the fragment size as size in bytes */
274 SDL_CalculateAudioSpec (spec); 274 SDL_CalculateAudioSpec(spec);
275 275
276 D (bug ("Before CreateMsgPort\n")); 276 D(bug("Before CreateMsgPort\n"));
277 277
278 if (!(audio_port = CreateMsgPort ())) { 278 if (!(audio_port = CreateMsgPort())) {
279 SDL_SetError ("Unable to create a MsgPort"); 279 SDL_SetError("Unable to create a MsgPort");
280 return -1; 280 return -1;
281 } 281 }
282 282
283 D (bug ("Before CreateIORequest\n")); 283 D(bug("Before CreateIORequest\n"));
284 284
285 if (! 285 if (!
286 (audio_req[0] = 286 (audio_req[0] =
287 (struct AHIRequest *) CreateIORequest (audio_port, 287 (struct AHIRequest *) CreateIORequest(audio_port,
288 sizeof (struct AHIRequest)))) 288 sizeof(struct AHIRequest)))) {
289 { 289 SDL_SetError("Unable to create an AHIRequest");
290 SDL_SetError ("Unable to create an AHIRequest"); 290 DeleteMsgPort(audio_port);
291 DeleteMsgPort (audio_port);
292 return -1; 291 return -1;
293 } 292 }
294 293
295 audio_req[0]->ahir_Version = 4; 294 audio_req[0]->ahir_Version = 4;
296 295
297 if (OpenDevice (AHINAME, 0, (struct IORequest *) audio_req[0], NULL)) { 296 if (OpenDevice(AHINAME, 0, (struct IORequest *) audio_req[0], NULL)) {
298 SDL_SetError ("Unable to open AHI device!\n"); 297 SDL_SetError("Unable to open AHI device!\n");
299 DeleteIORequest ((struct IORequest *) audio_req[0]); 298 DeleteIORequest((struct IORequest *) audio_req[0]);
300 DeleteMsgPort (audio_port); 299 DeleteMsgPort(audio_port);
301 return -1; 300 return -1;
302 } 301 }
303 302
304 D (bug ("AFTER opendevice\n")); 303 D(bug("AFTER opendevice\n"));
305 304
306 /* Set output frequency and size */ 305 /* Set output frequency and size */
307 this->hidden->freq = spec->freq; 306 this->hidden->freq = spec->freq;
308 this->hidden->size = spec->size; 307 this->hidden->size = spec->size;
309 308
310 D (bug ("Before buffer allocation\n")); 309 D(bug("Before buffer allocation\n"));
311 310
312 /* Allocate mixing buffer */ 311 /* Allocate mixing buffer */
313 mixbuf[0] = (Uint8 *) mymalloc (spec->size); 312 mixbuf[0] = (Uint8 *) mymalloc(spec->size);
314 mixbuf[1] = (Uint8 *) mymalloc (spec->size); 313 mixbuf[1] = (Uint8 *) mymalloc(spec->size);
315 314
316 D (bug ("Before audio_req allocation\n")); 315 D(bug("Before audio_req allocation\n"));
317 316
318 if (!(audio_req[1] = mymalloc (sizeof (struct AHIRequest)))) { 317 if (!(audio_req[1] = mymalloc(sizeof(struct AHIRequest)))) {
319 SDL_OutOfMemory (); 318 SDL_OutOfMemory();
320 return (-1); 319 return (-1);
321 } 320 }
322 321
323 D (bug ("Before audio_req memcpy\n")); 322 D(bug("Before audio_req memcpy\n"));
324 323
325 SDL_memcpy (audio_req[1], audio_req[0], sizeof (struct AHIRequest)); 324 SDL_memcpy(audio_req[1], audio_req[0], sizeof(struct AHIRequest));
326 325
327 if (mixbuf[0] == NULL || mixbuf[1] == NULL) { 326 if (mixbuf[0] == NULL || mixbuf[1] == NULL) {
328 SDL_OutOfMemory (); 327 SDL_OutOfMemory();
329 return (-1); 328 return (-1);
330 } 329 }
331 330
332 D (bug ("Before mixbuf memset\n")); 331 D(bug("Before mixbuf memset\n"));
333 332
334 SDL_memset (mixbuf[0], spec->silence, spec->size); 333 SDL_memset(mixbuf[0], spec->silence, spec->size);
335 SDL_memset (mixbuf[1], spec->silence, spec->size); 334 SDL_memset(mixbuf[1], spec->silence, spec->size);
336 335
337 current_buffer = 0; 336 current_buffer = 0;
338 playing = 0; 337 playing = 0;
339 338
340 D (bug 339 D(bug
341 ("AHI opened: freq:%ld mixbuf:%lx/%lx buflen:%ld bits:%ld channels:%ld\n", 340 ("AHI opened: freq:%ld mixbuf:%lx/%lx buflen:%ld bits:%ld channels:%ld\n",
342 spec->freq, mixbuf[0], mixbuf[1], spec->size, 341 spec->freq, mixbuf[0], mixbuf[1], spec->size,
343 this->hidden->bytespersample * 8, spec->channels)); 342 this->hidden->bytespersample * 8, spec->channels));
344 343
345 /* We're ready to rock and roll. :-) */ 344 /* We're ready to rock and roll. :-) */
346 return (0); 345 return (0);
347 } 346 }
348 347