Mercurial > sdl-ios-xcode
annotate src/audio/amigaos/SDL_ahiaudio.c @ 302:8a86bdf34f0f
Added Atari joystick support (thanks Patrice!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 07 Mar 2002 20:23:11 +0000 |
parents | dcb5e869f8b5 |
children | c9b51268668f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 5635-34 Springhouse Dr. | |
21 Pleasanton, CA 94588 (USA) | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
22 slouken@libsdl.org |
0 | 23 */ |
24 | |
25 #ifdef SAVE_RCSID | |
26 static char rcsid = | |
27 "@(#) $Id$"; | |
28 #endif | |
29 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
30 /* Allow access to a raw mixing buffer (for AmigaOS) */ |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
31 |
0 | 32 #include "SDL_endian.h" |
33 #include "SDL_audio.h" | |
34 #include "SDL_audiomem.h" | |
35 #include "SDL_audio_c.h" | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
36 #include "SDL_ahiaudio.h" |
0 | 37 |
38 /* Audio driver functions */ | |
39 static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
40 static void AHI_WaitAudio(_THIS); | |
41 static void AHI_PlayAudio(_THIS); | |
42 static Uint8 *AHI_GetAudioBuf(_THIS); | |
43 static void AHI_CloseAudio(_THIS); | |
44 | |
45 #ifndef __SASC | |
46 #define mymalloc(x) AllocVec(x,MEMF_PUBLIC) | |
47 #define myfree FreeVec | |
48 #else | |
49 #define mymalloc malloc | |
50 #define myfree free | |
51 #endif | |
52 | |
53 /* Audio driver bootstrap functions */ | |
54 | |
55 static int Audio_Available(void) | |
56 { | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
57 int ok=0; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
58 struct MsgPort *p; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
59 struct AHIRequest *req; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
60 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
61 if(p=CreateMsgPort()) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
62 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
63 if(req=(struct AHIRequest *)CreateIORequest(p,sizeof(struct AHIRequest))) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
64 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
65 req->ahir_Version=4; |
0 | 66 |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
67 if(!OpenDevice(AHINAME,0,(struct IORequest *)req,NULL)) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
68 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
69 D(bug("AHI available.\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
70 ok=1; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
71 CloseDevice((struct IORequest *)req); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
72 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
73 DeleteIORequest((struct IORequest *)req); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
74 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
75 DeleteMsgPort(p); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
76 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
77 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
78 D(if(!ok) bug("AHI not available\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
79 return ok; |
0 | 80 } |
81 | |
82 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
83 { | |
84 free(device->hidden); | |
85 free(device); | |
86 } | |
87 | |
88 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
89 { | |
90 SDL_AudioDevice *this; | |
91 | |
92 #ifndef NO_AMIGADEBUG | |
93 D(bug("AHI created...\n")); | |
94 #endif | |
95 | |
96 /* Initialize all variables that we clean on shutdown */ | |
97 this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); | |
98 if ( this ) { | |
99 memset(this, 0, (sizeof *this)); | |
100 this->hidden = (struct SDL_PrivateAudioData *) | |
101 malloc((sizeof *this->hidden)); | |
102 } | |
103 if ( (this == NULL) || (this->hidden == NULL) ) { | |
104 SDL_OutOfMemory(); | |
105 if ( this ) { | |
106 free(this); | |
107 } | |
108 return(0); | |
109 } | |
110 memset(this->hidden, 0, (sizeof *this->hidden)); | |
111 | |
112 /* Set the function pointers */ | |
113 this->OpenAudio = AHI_OpenAudio; | |
114 this->WaitAudio = AHI_WaitAudio; | |
115 this->PlayAudio = AHI_PlayAudio; | |
116 this->GetAudioBuf = AHI_GetAudioBuf; | |
117 this->CloseAudio = AHI_CloseAudio; | |
118 | |
119 this->free = Audio_DeleteDevice; | |
120 | |
121 return this; | |
122 } | |
123 | |
124 AudioBootStrap AHI_bootstrap = { | |
125 "AHI", Audio_Available, Audio_CreateDevice | |
126 }; | |
127 | |
128 | |
129 void static AHI_WaitAudio(_THIS) | |
130 { | |
131 if(!CheckIO((struct IORequest *)audio_req[current_buffer])) | |
132 { | |
133 WaitIO((struct IORequest *)audio_req[current_buffer]); | |
134 // AbortIO((struct IORequest *)audio_req[current_buffer]); | |
135 } | |
136 } | |
137 | |
138 static void AHI_PlayAudio(_THIS) | |
139 { | |
140 if(playing>1) | |
141 WaitIO((struct IORequest *)audio_req[current_buffer]); | |
142 | |
143 /* Write the audio data out */ | |
144 audio_req[current_buffer] -> ahir_Std. io_Message.mn_Node.ln_Pri = 60; | |
145 audio_req[current_buffer] -> ahir_Std. io_Data = mixbuf[current_buffer]; | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
146 audio_req[current_buffer] -> ahir_Std. io_Length = this->hidden->size; |
0 | 147 audio_req[current_buffer] -> ahir_Std. io_Offset = 0; |
148 audio_req[current_buffer] -> ahir_Std . io_Command = CMD_WRITE; | |
149 audio_req[current_buffer] -> ahir_Frequency = this->hidden->freq; | |
150 audio_req[current_buffer] -> ahir_Volume = 0x10000; | |
151 audio_req[current_buffer] -> ahir_Type = this->hidden->type; | |
152 audio_req[current_buffer] -> ahir_Position = 0x8000; | |
153 audio_req[current_buffer] -> ahir_Link = (playing>0 ? audio_req[current_buffer^1] : NULL); | |
154 | |
155 SendIO((struct IORequest *)audio_req[current_buffer]); | |
156 current_buffer^=1; | |
157 | |
158 playing++; | |
159 } | |
160 | |
161 static Uint8 *AHI_GetAudioBuf(_THIS) | |
162 { | |
163 return(mixbuf[current_buffer]); | |
164 } | |
165 | |
166 static void AHI_CloseAudio(_THIS) | |
167 { | |
168 D(bug("Closing audio...\n")); | |
169 | |
170 playing=0; | |
171 | |
172 if(audio_req[0]) | |
173 { | |
174 if(audio_req[1]) | |
175 { | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
176 D(bug("Break req[1]...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
177 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
178 AbortIO((struct IORequest *)audio_req[1]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
179 WaitIO((struct IORequest *)audio_req[1]); |
0 | 180 } |
181 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
182 D(bug("Break req[0]...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
183 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
184 AbortIO((struct IORequest *)audio_req[0]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
185 WaitIO((struct IORequest *)audio_req[0]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
186 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
187 if(audio_req[1]) |
0 | 188 { |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
189 D(bug("Break AGAIN req[1]...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
190 AbortIO((struct IORequest *)audio_req[1]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
191 WaitIO((struct IORequest *)audio_req[1]); |
0 | 192 } |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
193 // Double abort to be sure to break the dbuffering process. |
0 | 194 |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
195 SDL_Delay(200); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
196 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
197 D(bug("Reqs breaked, closing device...\n")); |
0 | 198 CloseDevice((struct IORequest *)audio_req[0]); |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
199 D(bug("Device closed, freeing memory...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
200 myfree(audio_req[1]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
201 D(bug("Memory freed, deleting IOReq...\n")); |
0 | 202 DeleteIORequest((struct IORequest *)audio_req[0]); |
203 audio_req[0]=audio_req[1]=NULL; | |
204 } | |
205 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
206 D(bug("Freeing mixbuf[0]...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
207 if ( mixbuf[0] != NULL ) { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
208 myfree(mixbuf[0]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
209 // SDL_FreeAudioMem(mixbuf[0]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
210 mixbuf[0] = NULL; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
211 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
212 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
213 D(bug("Freeing mixbuf[1]...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
214 if ( mixbuf[1] != NULL ) { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
215 myfree(mixbuf[1]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
216 // SDL_FreeAudioMem(mixbuf[1]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
217 mixbuf[1] = NULL; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
218 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
219 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
220 D(bug("Freeing audio_port...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
221 |
0 | 222 if ( audio_port != NULL ) { |
223 DeleteMsgPort(audio_port); | |
224 audio_port = NULL; | |
225 } | |
226 D(bug("...done!\n")); | |
227 } | |
228 | |
229 static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
230 { | |
231 // int width; | |
232 | |
233 D(bug("AHI opening...\n")); | |
234 | |
235 /* Determine the audio parameters from the AudioSpec */ | |
236 switch ( spec->format & 0xFF ) { | |
237 | |
238 case 8: { /* Signed 8 bit audio data */ | |
239 D(bug("Samples a 8 bit...\n")); | |
240 spec->format = AUDIO_S8; | |
241 this->hidden->bytespersample=1; | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
242 if(spec->channels<2) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
243 this->hidden->type = AHIST_M8S; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
244 else |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
245 this->hidden->type = AHIST_S8S; |
0 | 246 } |
247 break; | |
248 | |
249 case 16: { /* Signed 16 bit audio data */ | |
250 D(bug("Samples a 16 bit...\n")); | |
251 spec->format = AUDIO_S16MSB; | |
252 this->hidden->bytespersample=2; | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
253 if(spec->channels<2) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
254 this->hidden->type = AHIST_M16S; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
255 else |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
256 this->hidden->type = AHIST_S16S; |
0 | 257 } |
258 break; | |
259 | |
260 default: { | |
261 SDL_SetError("Unsupported audio format"); | |
262 return(-1); | |
263 } | |
264 } | |
265 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
266 if(spec->channels!=1 && spec->channels!=2) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
267 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
268 D(bug("Wrong channel number!\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
269 SDL_SetError("Channel number non supported"); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
270 return -1; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
271 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
272 |
0 | 273 D(bug("Before CalculateAudioSpec\n")); |
274 /* Update the fragment size as size in bytes */ | |
275 SDL_CalculateAudioSpec(spec); | |
276 | |
277 D(bug("Before CreateMsgPort\n")); | |
278 | |
279 if(!(audio_port=CreateMsgPort())) | |
280 { | |
281 SDL_SetError("Unable to create a MsgPort"); | |
282 return -1; | |
283 } | |
284 | |
285 D(bug("Before CreateIORequest\n")); | |
286 | |
287 if(!(audio_req[0]=(struct AHIRequest *)CreateIORequest(audio_port,sizeof(struct AHIRequest)))) | |
288 { | |
289 SDL_SetError("Unable to create an AHIRequest"); | |
290 DeleteMsgPort(audio_port); | |
291 return -1; | |
292 } | |
293 | |
294 audio_req[0]->ahir_Version = 4; | |
295 | |
296 if(OpenDevice(AHINAME,0,(struct IORequest *)audio_req[0],NULL)) | |
297 { | |
298 SDL_SetError("Unable to open AHI device!\n"); | |
299 DeleteIORequest((struct IORequest *)audio_req[0]); | |
300 DeleteMsgPort(audio_port); | |
301 return -1; | |
302 } | |
303 | |
304 D(bug("AFTER opendevice\n")); | |
305 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
306 /* Set output frequency and size */ |
0 | 307 this->hidden->freq = spec->freq; |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
308 this->hidden->size = spec->size; |
0 | 309 |
310 D(bug("Before buffer allocation\n")); | |
311 | |
312 /* Allocate mixing buffer */ | |
313 mixbuf[0] = (Uint8 *)mymalloc(spec->size); | |
314 mixbuf[1] = (Uint8 *)mymalloc(spec->size); | |
315 | |
316 D(bug("Before audio_req allocation\n")); | |
317 | |
318 if(!(audio_req[1]=mymalloc(sizeof(struct AHIRequest)))) | |
319 { | |
320 SDL_OutOfMemory(); | |
321 return(-1); | |
322 } | |
323 | |
324 D(bug("Before audio_req memcpy\n")); | |
325 | |
326 memcpy(audio_req[1],audio_req[0],sizeof(struct AHIRequest)); | |
327 | |
328 if ( mixbuf[0] == NULL || mixbuf[1] == NULL ) { | |
329 SDL_OutOfMemory(); | |
330 return(-1); | |
331 } | |
332 | |
333 D(bug("Before mixbuf memset\n")); | |
334 | |
335 memset(mixbuf[0], spec->silence, spec->size); | |
336 memset(mixbuf[1], spec->silence, spec->size); | |
337 | |
338 current_buffer=0; | |
339 playing=0; | |
340 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
341 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)); |
0 | 342 |
343 /* We're ready to rock and roll. :-) */ | |
344 return(0); | |
345 } |