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