Mercurial > sdl-ios-xcode
comparison src/audio/amigaos/SDL_ahiaudio.c @ 21:75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Thu, 10 May 2001 20:13:29 +0000 |
parents | 74212992fb08 |
children | e8157fcb3114 |
comparison
equal
deleted
inserted
replaced
20:3dc008dc229d | 21:75a95f82bc1f |
---|---|
25 #ifdef SAVE_RCSID | 25 #ifdef SAVE_RCSID |
26 static char rcsid = | 26 static char rcsid = |
27 "@(#) $Id$"; | 27 "@(#) $Id$"; |
28 #endif | 28 #endif |
29 | 29 |
30 /* Allow access to a raw mixing buffer (For IRIX 6.5 and higher) */ | 30 /* Allow access to a raw mixing buffer (for AmigaOS) */ |
31 | |
32 #include <stdio.h> | |
33 #include <stdlib.h> | |
34 #include <string.h> | |
31 | 35 |
32 #include "SDL_endian.h" | 36 #include "SDL_endian.h" |
33 #include "SDL_audio.h" | 37 #include "SDL_audio.h" |
34 #include "SDL_audiomem.h" | 38 #include "SDL_audiomem.h" |
35 #include "SDL_audio_c.h" | 39 #include "SDL_audio_c.h" |
36 #include "SDL_lowaudio.h" | 40 #include "SDL_ahiaudio.h" |
37 | 41 |
38 /* Audio driver functions */ | 42 /* Audio driver functions */ |
39 static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec); | 43 static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec); |
40 static void AHI_WaitAudio(_THIS); | 44 static void AHI_WaitAudio(_THIS); |
41 static void AHI_PlayAudio(_THIS); | 45 static void AHI_PlayAudio(_THIS); |
52 | 56 |
53 /* Audio driver bootstrap functions */ | 57 /* Audio driver bootstrap functions */ |
54 | 58 |
55 static int Audio_Available(void) | 59 static int Audio_Available(void) |
56 { | 60 { |
57 #ifndef NO_AMIGADEBUG | 61 int ok=0; |
58 D(bug("AHI available.\n")); | 62 struct MsgPort *p; |
59 #endif | 63 struct AHIRequest *req; |
60 | 64 |
61 return 1; | 65 if(p=CreateMsgPort()) |
66 { | |
67 if(req=(struct AHIRequest *)CreateIORequest(p,sizeof(struct AHIRequest))) | |
68 { | |
69 req->ahir_Version=4; | |
70 | |
71 if(!OpenDevice(AHINAME,0,(struct IORequest *)req,NULL)) | |
72 { | |
73 D(bug("AHI available.\n")); | |
74 ok=1; | |
75 CloseDevice((struct IORequest *)req); | |
76 } | |
77 DeleteIORequest((struct IORequest *)req); | |
78 } | |
79 DeleteMsgPort(p); | |
80 } | |
81 | |
82 D(if(!ok) bug("AHI not available\n")); | |
83 return ok; | |
62 } | 84 } |
63 | 85 |
64 static void Audio_DeleteDevice(SDL_AudioDevice *device) | 86 static void Audio_DeleteDevice(SDL_AudioDevice *device) |
65 { | 87 { |
66 free(device->hidden); | 88 free(device->hidden); |
123 WaitIO((struct IORequest *)audio_req[current_buffer]); | 145 WaitIO((struct IORequest *)audio_req[current_buffer]); |
124 | 146 |
125 /* Write the audio data out */ | 147 /* Write the audio data out */ |
126 audio_req[current_buffer] -> ahir_Std. io_Message.mn_Node.ln_Pri = 60; | 148 audio_req[current_buffer] -> ahir_Std. io_Message.mn_Node.ln_Pri = 60; |
127 audio_req[current_buffer] -> ahir_Std. io_Data = mixbuf[current_buffer]; | 149 audio_req[current_buffer] -> ahir_Std. io_Data = mixbuf[current_buffer]; |
128 audio_req[current_buffer] -> ahir_Std. io_Length = this->spec.samples*this->hidden->bytespersample; | 150 audio_req[current_buffer] -> ahir_Std. io_Length = this->hidden->size; |
129 audio_req[current_buffer] -> ahir_Std. io_Offset = 0; | 151 audio_req[current_buffer] -> ahir_Std. io_Offset = 0; |
130 audio_req[current_buffer] -> ahir_Std . io_Command = CMD_WRITE; | 152 audio_req[current_buffer] -> ahir_Std . io_Command = CMD_WRITE; |
131 audio_req[current_buffer] -> ahir_Frequency = this->hidden->freq; | 153 audio_req[current_buffer] -> ahir_Frequency = this->hidden->freq; |
132 audio_req[current_buffer] -> ahir_Volume = 0x10000; | 154 audio_req[current_buffer] -> ahir_Volume = 0x10000; |
133 audio_req[current_buffer] -> ahir_Type = this->hidden->type; | 155 audio_req[current_buffer] -> ahir_Type = this->hidden->type; |
147 | 169 |
148 static void AHI_CloseAudio(_THIS) | 170 static void AHI_CloseAudio(_THIS) |
149 { | 171 { |
150 D(bug("Closing audio...\n")); | 172 D(bug("Closing audio...\n")); |
151 | 173 |
174 playing=0; | |
175 | |
176 if(audio_req[0]) | |
177 { | |
178 if(audio_req[1]) | |
179 { | |
180 D(bug("Break req[1]...\n")); | |
181 | |
182 AbortIO((struct IORequest *)audio_req[1]); | |
183 WaitIO((struct IORequest *)audio_req[1]); | |
184 } | |
185 | |
186 D(bug("Break req[0]...\n")); | |
187 | |
188 AbortIO((struct IORequest *)audio_req[0]); | |
189 WaitIO((struct IORequest *)audio_req[0]); | |
190 | |
191 if(audio_req[1]) | |
192 { | |
193 D(bug("Break AGAIN req[1]...\n")); | |
194 AbortIO((struct IORequest *)audio_req[1]); | |
195 WaitIO((struct IORequest *)audio_req[1]); | |
196 } | |
197 // Double abort to be sure to break the dbuffering process. | |
198 | |
199 SDL_Delay(200); | |
200 | |
201 D(bug("Reqs breaked, closing device...\n")); | |
202 CloseDevice((struct IORequest *)audio_req[0]); | |
203 D(bug("Device closed, freeing memory...\n")); | |
204 myfree(audio_req[1]); | |
205 D(bug("Memory freed, deleting IOReq...\n")); | |
206 DeleteIORequest((struct IORequest *)audio_req[0]); | |
207 audio_req[0]=audio_req[1]=NULL; | |
208 } | |
209 | |
210 D(bug("Freeing mixbuf[0]...\n")); | |
152 if ( mixbuf[0] != NULL ) { | 211 if ( mixbuf[0] != NULL ) { |
153 myfree(mixbuf[0]); | 212 myfree(mixbuf[0]); |
154 // SDL_FreeAudioMem(mixbuf[0]); | 213 // SDL_FreeAudioMem(mixbuf[0]); |
155 mixbuf[0] = NULL; | 214 mixbuf[0] = NULL; |
156 } | 215 } |
157 | 216 |
217 D(bug("Freeing mixbuf[1]...\n")); | |
158 if ( mixbuf[1] != NULL ) { | 218 if ( mixbuf[1] != NULL ) { |
159 myfree(mixbuf[1]); | 219 myfree(mixbuf[1]); |
160 // SDL_FreeAudioMem(mixbuf[1]); | 220 // SDL_FreeAudioMem(mixbuf[1]); |
161 mixbuf[1] = NULL; | 221 mixbuf[1] = NULL; |
162 } | 222 } |
163 | 223 |
164 playing=0; | 224 D(bug("Freeing audio_port...\n")); |
165 | |
166 if(audio_req[0]) | |
167 { | |
168 if(audio_req[1]) | |
169 { | |
170 if(!CheckIO((struct IORequest *)audio_req[1])) | |
171 { | |
172 AbortIO((struct IORequest *)audio_req[1]); | |
173 WaitIO((struct IORequest *)audio_req[1]); | |
174 } | |
175 myfree(audio_req[1]); | |
176 } | |
177 | |
178 if(!CheckIO((struct IORequest *)audio_req[0])) | |
179 { | |
180 AbortIO((struct IORequest *)audio_req[0]); | |
181 WaitIO((struct IORequest *)audio_req[0]); | |
182 } | |
183 | |
184 CloseDevice((struct IORequest *)audio_req[0]); | |
185 DeleteIORequest((struct IORequest *)audio_req[0]); | |
186 audio_req[0]=audio_req[1]=NULL; | |
187 } | |
188 | 225 |
189 if ( audio_port != NULL ) { | 226 if ( audio_port != NULL ) { |
190 DeleteMsgPort(audio_port); | 227 DeleteMsgPort(audio_port); |
191 audio_port = NULL; | 228 audio_port = NULL; |
192 } | 229 } |
204 | 241 |
205 case 8: { /* Signed 8 bit audio data */ | 242 case 8: { /* Signed 8 bit audio data */ |
206 D(bug("Samples a 8 bit...\n")); | 243 D(bug("Samples a 8 bit...\n")); |
207 spec->format = AUDIO_S8; | 244 spec->format = AUDIO_S8; |
208 this->hidden->bytespersample=1; | 245 this->hidden->bytespersample=1; |
209 this->hidden->type = AHIST_M8S; | 246 if(spec->channels<2) |
210 | 247 this->hidden->type = AHIST_M8S; |
248 else | |
249 this->hidden->type = AHIST_S8S; | |
211 } | 250 } |
212 break; | 251 break; |
213 | 252 |
214 case 16: { /* Signed 16 bit audio data */ | 253 case 16: { /* Signed 16 bit audio data */ |
215 D(bug("Samples a 16 bit...\n")); | 254 D(bug("Samples a 16 bit...\n")); |
216 spec->format = AUDIO_S16MSB; | 255 spec->format = AUDIO_S16MSB; |
217 this->hidden->bytespersample=2; | 256 this->hidden->bytespersample=2; |
218 this->hidden->type = AHIST_M16S; | 257 if(spec->channels<2) |
258 this->hidden->type = AHIST_M16S; | |
259 else | |
260 this->hidden->type = AHIST_S16S; | |
219 } | 261 } |
220 break; | 262 break; |
221 | 263 |
222 default: { | 264 default: { |
223 SDL_SetError("Unsupported audio format"); | 265 SDL_SetError("Unsupported audio format"); |
224 return(-1); | 266 return(-1); |
225 } | 267 } |
268 } | |
269 | |
270 if(spec->channels!=1 && spec->channels!=2) | |
271 { | |
272 D(bug("Wrong channel number!\n")); | |
273 SDL_SetError("Channel number non supported"); | |
274 return -1; | |
226 } | 275 } |
227 | 276 |
228 D(bug("Before CalculateAudioSpec\n")); | 277 D(bug("Before CalculateAudioSpec\n")); |
229 /* Update the fragment size as size in bytes */ | 278 /* Update the fragment size as size in bytes */ |
230 SDL_CalculateAudioSpec(spec); | 279 SDL_CalculateAudioSpec(spec); |
256 return -1; | 305 return -1; |
257 } | 306 } |
258 | 307 |
259 D(bug("AFTER opendevice\n")); | 308 D(bug("AFTER opendevice\n")); |
260 | 309 |
261 /* Set output frequency */ | 310 /* Set output frequency and size */ |
262 this->hidden->freq = spec->freq; | 311 this->hidden->freq = spec->freq; |
312 this->hidden->size = spec->size; | |
263 | 313 |
264 D(bug("Before buffer allocation\n")); | 314 D(bug("Before buffer allocation\n")); |
265 | 315 |
266 /* Allocate mixing buffer */ | 316 /* Allocate mixing buffer */ |
267 mixbuf[0] = (Uint8 *)mymalloc(spec->size); | 317 mixbuf[0] = (Uint8 *)mymalloc(spec->size); |
290 memset(mixbuf[1], spec->silence, spec->size); | 340 memset(mixbuf[1], spec->silence, spec->size); |
291 | 341 |
292 current_buffer=0; | 342 current_buffer=0; |
293 playing=0; | 343 playing=0; |
294 | 344 |
295 D(bug("AHI opened: freq:%ld mixbuf:%lx/%lx buflen:%ld bits:%ld\n",spec->freq,mixbuf[0],mixbuf[1],spec->size,this->hidden->bytespersample*8)); | 345 D(bug("AHI opened: freq:%ld mixbuf:%lx/%lx buflen:%ld bits:%ld channels:%ld\n",spec->freq,mixbuf[0],mixbuf[1],spec->size,this->hidden->bytespersample*8,spec->channels)); |
296 | 346 |
297 /* We're ready to rock and roll. :-) */ | 347 /* We're ready to rock and roll. :-) */ |
298 return(0); | 348 return(0); |
299 } | 349 } |