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