Mercurial > sdl-ios-xcode
annotate src/audio/amigaos/SDL_ahiaudio.c @ 1336:3692456e7b0f
Use SDL_ prefixed versions of C library functions.
FIXME:
Change #include <stdlib.h> to #include "SDL_stdlib.h"
Change #include <string.h> to #include "SDL_string.h"
Make sure nothing else broke because of this...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 06:59:48 +0000 |
parents | c9b51268668f |
children | d02b552e5304 |
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_endian.h" |
26 #include "SDL_audio.h" | |
27 #include "SDL_audiomem.h" | |
28 #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
|
29 #include "SDL_ahiaudio.h" |
0 | 30 |
31 /* Audio driver functions */ | |
32 static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
33 static void AHI_WaitAudio(_THIS); | |
34 static void AHI_PlayAudio(_THIS); | |
35 static Uint8 *AHI_GetAudioBuf(_THIS); | |
36 static void AHI_CloseAudio(_THIS); | |
37 | |
38 #ifndef __SASC | |
39 #define mymalloc(x) AllocVec(x,MEMF_PUBLIC) | |
40 #define myfree FreeVec | |
41 #else | |
42 #define mymalloc malloc | |
43 #define myfree free | |
44 #endif | |
45 | |
46 /* Audio driver bootstrap functions */ | |
47 | |
48 static int Audio_Available(void) | |
49 { | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
50 int ok=0; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
51 struct MsgPort *p; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
52 struct AHIRequest *req; |
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(p=CreateMsgPort()) |
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 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
|
57 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
58 req->ahir_Version=4; |
0 | 59 |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
60 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
|
61 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
62 D(bug("AHI available.\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
63 ok=1; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
64 CloseDevice((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 DeleteIORequest((struct IORequest *)req); |
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 DeleteMsgPort(p); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
69 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
70 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
71 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
|
72 return ok; |
0 | 73 } |
74 | |
75 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
76 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
77 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
78 SDL_free(device); |
0 | 79 } |
80 | |
81 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
82 { | |
83 SDL_AudioDevice *this; | |
84 | |
85 #ifndef NO_AMIGADEBUG | |
86 D(bug("AHI created...\n")); | |
87 #endif | |
88 | |
89 /* 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
|
90 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
0 | 91 if ( this ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
92 SDL_memset(this, 0, (sizeof *this)); |
0 | 93 this->hidden = (struct SDL_PrivateAudioData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
94 SDL_malloc((sizeof *this->hidden)); |
0 | 95 } |
96 if ( (this == NULL) || (this->hidden == NULL) ) { | |
97 SDL_OutOfMemory(); | |
98 if ( this ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
99 SDL_free(this); |
0 | 100 } |
101 return(0); | |
102 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
103 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 104 |
105 /* Set the function pointers */ | |
106 this->OpenAudio = AHI_OpenAudio; | |
107 this->WaitAudio = AHI_WaitAudio; | |
108 this->PlayAudio = AHI_PlayAudio; | |
109 this->GetAudioBuf = AHI_GetAudioBuf; | |
110 this->CloseAudio = AHI_CloseAudio; | |
111 | |
112 this->free = Audio_DeleteDevice; | |
113 | |
114 return this; | |
115 } | |
116 | |
117 AudioBootStrap AHI_bootstrap = { | |
118 "AHI", Audio_Available, Audio_CreateDevice | |
119 }; | |
120 | |
121 | |
122 void static AHI_WaitAudio(_THIS) | |
123 { | |
124 if(!CheckIO((struct IORequest *)audio_req[current_buffer])) | |
125 { | |
126 WaitIO((struct IORequest *)audio_req[current_buffer]); | |
127 // AbortIO((struct IORequest *)audio_req[current_buffer]); | |
128 } | |
129 } | |
130 | |
131 static void AHI_PlayAudio(_THIS) | |
132 { | |
133 if(playing>1) | |
134 WaitIO((struct IORequest *)audio_req[current_buffer]); | |
135 | |
136 /* Write the audio data out */ | |
137 audio_req[current_buffer] -> ahir_Std. io_Message.mn_Node.ln_Pri = 60; | |
138 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
|
139 audio_req[current_buffer] -> ahir_Std. io_Length = this->hidden->size; |
0 | 140 audio_req[current_buffer] -> ahir_Std. io_Offset = 0; |
141 audio_req[current_buffer] -> ahir_Std . io_Command = CMD_WRITE; | |
142 audio_req[current_buffer] -> ahir_Frequency = this->hidden->freq; | |
143 audio_req[current_buffer] -> ahir_Volume = 0x10000; | |
144 audio_req[current_buffer] -> ahir_Type = this->hidden->type; | |
145 audio_req[current_buffer] -> ahir_Position = 0x8000; | |
146 audio_req[current_buffer] -> ahir_Link = (playing>0 ? audio_req[current_buffer^1] : NULL); | |
147 | |
148 SendIO((struct IORequest *)audio_req[current_buffer]); | |
149 current_buffer^=1; | |
150 | |
151 playing++; | |
152 } | |
153 | |
154 static Uint8 *AHI_GetAudioBuf(_THIS) | |
155 { | |
156 return(mixbuf[current_buffer]); | |
157 } | |
158 | |
159 static void AHI_CloseAudio(_THIS) | |
160 { | |
161 D(bug("Closing audio...\n")); | |
162 | |
163 playing=0; | |
164 | |
165 if(audio_req[0]) | |
166 { | |
167 if(audio_req[1]) | |
168 { | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
169 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
|
170 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
171 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
|
172 WaitIO((struct IORequest *)audio_req[1]); |
0 | 173 } |
174 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
175 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
|
176 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
177 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
|
178 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
|
179 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
180 if(audio_req[1]) |
0 | 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 AGAIN req[1]...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
183 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
|
184 WaitIO((struct IORequest *)audio_req[1]); |
0 | 185 } |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
186 // Double abort to be sure to break the dbuffering process. |
0 | 187 |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
188 SDL_Delay(200); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
189 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
190 D(bug("Reqs breaked, closing device...\n")); |
0 | 191 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
|
192 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
|
193 myfree(audio_req[1]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
194 D(bug("Memory freed, deleting IOReq...\n")); |
0 | 195 DeleteIORequest((struct IORequest *)audio_req[0]); |
196 audio_req[0]=audio_req[1]=NULL; | |
197 } | |
198 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
199 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
|
200 if ( mixbuf[0] != NULL ) { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
201 myfree(mixbuf[0]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
202 // SDL_FreeAudioMem(mixbuf[0]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
203 mixbuf[0] = NULL; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
204 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
205 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
206 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
|
207 if ( mixbuf[1] != NULL ) { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
208 myfree(mixbuf[1]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
209 // SDL_FreeAudioMem(mixbuf[1]); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
210 mixbuf[1] = 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 audio_port...\n")); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
214 |
0 | 215 if ( audio_port != NULL ) { |
216 DeleteMsgPort(audio_port); | |
217 audio_port = NULL; | |
218 } | |
219 D(bug("...done!\n")); | |
220 } | |
221 | |
222 static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
223 { | |
224 // int width; | |
225 | |
226 D(bug("AHI opening...\n")); | |
227 | |
228 /* Determine the audio parameters from the AudioSpec */ | |
229 switch ( spec->format & 0xFF ) { | |
230 | |
231 case 8: { /* Signed 8 bit audio data */ | |
232 D(bug("Samples a 8 bit...\n")); | |
233 spec->format = AUDIO_S8; | |
234 this->hidden->bytespersample=1; | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
235 if(spec->channels<2) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
236 this->hidden->type = AHIST_M8S; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
237 else |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
238 this->hidden->type = AHIST_S8S; |
0 | 239 } |
240 break; | |
241 | |
242 case 16: { /* Signed 16 bit audio data */ | |
243 D(bug("Samples a 16 bit...\n")); | |
244 spec->format = AUDIO_S16MSB; | |
245 this->hidden->bytespersample=2; | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
246 if(spec->channels<2) |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
247 this->hidden->type = AHIST_M16S; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
248 else |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
249 this->hidden->type = AHIST_S16S; |
0 | 250 } |
251 break; | |
252 | |
253 default: { | |
254 SDL_SetError("Unsupported audio format"); | |
255 return(-1); | |
256 } | |
257 } | |
258 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
259 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
|
260 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
261 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
|
262 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
|
263 return -1; |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
264 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
265 |
0 | 266 D(bug("Before CalculateAudioSpec\n")); |
267 /* Update the fragment size as size in bytes */ | |
268 SDL_CalculateAudioSpec(spec); | |
269 | |
270 D(bug("Before CreateMsgPort\n")); | |
271 | |
272 if(!(audio_port=CreateMsgPort())) | |
273 { | |
274 SDL_SetError("Unable to create a MsgPort"); | |
275 return -1; | |
276 } | |
277 | |
278 D(bug("Before CreateIORequest\n")); | |
279 | |
280 if(!(audio_req[0]=(struct AHIRequest *)CreateIORequest(audio_port,sizeof(struct AHIRequest)))) | |
281 { | |
282 SDL_SetError("Unable to create an AHIRequest"); | |
283 DeleteMsgPort(audio_port); | |
284 return -1; | |
285 } | |
286 | |
287 audio_req[0]->ahir_Version = 4; | |
288 | |
289 if(OpenDevice(AHINAME,0,(struct IORequest *)audio_req[0],NULL)) | |
290 { | |
291 SDL_SetError("Unable to open AHI device!\n"); | |
292 DeleteIORequest((struct IORequest *)audio_req[0]); | |
293 DeleteMsgPort(audio_port); | |
294 return -1; | |
295 } | |
296 | |
297 D(bug("AFTER opendevice\n")); | |
298 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
299 /* Set output frequency and size */ |
0 | 300 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
|
301 this->hidden->size = spec->size; |
0 | 302 |
303 D(bug("Before buffer allocation\n")); | |
304 | |
305 /* Allocate mixing buffer */ | |
306 mixbuf[0] = (Uint8 *)mymalloc(spec->size); | |
307 mixbuf[1] = (Uint8 *)mymalloc(spec->size); | |
308 | |
309 D(bug("Before audio_req allocation\n")); | |
310 | |
311 if(!(audio_req[1]=mymalloc(sizeof(struct AHIRequest)))) | |
312 { | |
313 SDL_OutOfMemory(); | |
314 return(-1); | |
315 } | |
316 | |
317 D(bug("Before audio_req memcpy\n")); | |
318 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
319 SDL_memcpy(audio_req[1],audio_req[0],sizeof(struct AHIRequest)); |
0 | 320 |
321 if ( mixbuf[0] == NULL || mixbuf[1] == NULL ) { | |
322 SDL_OutOfMemory(); | |
323 return(-1); | |
324 } | |
325 | |
326 D(bug("Before mixbuf memset\n")); | |
327 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
328 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
|
329 SDL_memset(mixbuf[1], spec->silence, spec->size); |
0 | 330 |
331 current_buffer=0; | |
332 playing=0; | |
333 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
334 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 | 335 |
336 /* We're ready to rock and roll. :-) */ | |
337 return(0); | |
338 } |