Mercurial > sdl-ios-xcode
comparison src/audio/ums/SDL_umsaudio.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
43 #define UMS_DRIVER_NAME "ums" | 43 #define UMS_DRIVER_NAME "ums" |
44 | 44 |
45 #define DEBUG_AUDIO 1 | 45 #define DEBUG_AUDIO 1 |
46 | 46 |
47 /* Audio driver functions */ | 47 /* Audio driver functions */ |
48 static int UMS_OpenAudio (_THIS, SDL_AudioSpec * spec); | 48 static int UMS_OpenAudio(_THIS, SDL_AudioSpec * spec); |
49 static void UMS_PlayAudio (_THIS); | 49 static void UMS_PlayAudio(_THIS); |
50 static Uint8 *UMS_GetAudioBuf (_THIS); | 50 static Uint8 *UMS_GetAudioBuf(_THIS); |
51 static void UMS_CloseAudio (_THIS); | 51 static void UMS_CloseAudio(_THIS); |
52 | 52 |
53 static UMSAudioDevice_ReturnCode UADOpen (_THIS, string device, string mode, | 53 static UMSAudioDevice_ReturnCode UADOpen(_THIS, string device, string mode, |
54 long flags); | 54 long flags); |
55 static UMSAudioDevice_ReturnCode UADClose (_THIS); | 55 static UMSAudioDevice_ReturnCode UADClose(_THIS); |
56 static UMSAudioDevice_ReturnCode UADGetBitsPerSample (_THIS, long *bits); | 56 static UMSAudioDevice_ReturnCode UADGetBitsPerSample(_THIS, long *bits); |
57 static UMSAudioDevice_ReturnCode UADSetBitsPerSample (_THIS, long bits); | 57 static UMSAudioDevice_ReturnCode UADSetBitsPerSample(_THIS, long bits); |
58 static UMSAudioDevice_ReturnCode UADSetSampleRate (_THIS, long rate, | 58 static UMSAudioDevice_ReturnCode UADSetSampleRate(_THIS, long rate, |
59 long *set_rate); | 59 long *set_rate); |
60 static UMSAudioDevice_ReturnCode UADSetByteOrder (_THIS, string byte_order); | 60 static UMSAudioDevice_ReturnCode UADSetByteOrder(_THIS, string byte_order); |
61 static UMSAudioDevice_ReturnCode UADSetAudioFormatType (_THIS, string fmt); | 61 static UMSAudioDevice_ReturnCode UADSetAudioFormatType(_THIS, string fmt); |
62 static UMSAudioDevice_ReturnCode UADSetNumberFormat (_THIS, string fmt); | 62 static UMSAudioDevice_ReturnCode UADSetNumberFormat(_THIS, string fmt); |
63 static UMSAudioDevice_ReturnCode UADInitialize (_THIS); | 63 static UMSAudioDevice_ReturnCode UADInitialize(_THIS); |
64 static UMSAudioDevice_ReturnCode UADStart (_THIS); | 64 static UMSAudioDevice_ReturnCode UADStart(_THIS); |
65 static UMSAudioDevice_ReturnCode UADStop (_THIS); | 65 static UMSAudioDevice_ReturnCode UADStop(_THIS); |
66 static UMSAudioDevice_ReturnCode UADSetTimeFormat (_THIS, | 66 static UMSAudioDevice_ReturnCode UADSetTimeFormat(_THIS, |
67 UMSAudioTypes_TimeFormat | 67 UMSAudioTypes_TimeFormat |
68 fmt); | 68 fmt); |
69 static UMSAudioDevice_ReturnCode UADWriteBuffSize (_THIS, long *buff_size); | 69 static UMSAudioDevice_ReturnCode UADWriteBuffSize(_THIS, long *buff_size); |
70 static UMSAudioDevice_ReturnCode UADWriteBuffRemain (_THIS, long *buff_size); | 70 static UMSAudioDevice_ReturnCode UADWriteBuffRemain(_THIS, long *buff_size); |
71 static UMSAudioDevice_ReturnCode UADWriteBuffUsed (_THIS, long *buff_size); | 71 static UMSAudioDevice_ReturnCode UADWriteBuffUsed(_THIS, long *buff_size); |
72 static UMSAudioDevice_ReturnCode UADSetDMABufferSize (_THIS, long bytes, | 72 static UMSAudioDevice_ReturnCode UADSetDMABufferSize(_THIS, long bytes, |
73 long *bytes_ret); | 73 long *bytes_ret); |
74 static UMSAudioDevice_ReturnCode UADSetVolume (_THIS, long volume); | 74 static UMSAudioDevice_ReturnCode UADSetVolume(_THIS, long volume); |
75 static UMSAudioDevice_ReturnCode UADSetBalance (_THIS, long balance); | 75 static UMSAudioDevice_ReturnCode UADSetBalance(_THIS, long balance); |
76 static UMSAudioDevice_ReturnCode UADSetChannels (_THIS, long channels); | 76 static UMSAudioDevice_ReturnCode UADSetChannels(_THIS, long channels); |
77 static UMSAudioDevice_ReturnCode UADPlayRemainingData (_THIS, boolean block); | 77 static UMSAudioDevice_ReturnCode UADPlayRemainingData(_THIS, boolean block); |
78 static UMSAudioDevice_ReturnCode UADEnableOutput (_THIS, string output, | 78 static UMSAudioDevice_ReturnCode UADEnableOutput(_THIS, string output, |
79 long *left_gain, | 79 long *left_gain, |
80 long *right_gain); | 80 long *right_gain); |
81 static UMSAudioDevice_ReturnCode UADWrite (_THIS, UMSAudioTypes_Buffer * buff, | 81 static UMSAudioDevice_ReturnCode UADWrite(_THIS, UMSAudioTypes_Buffer * buff, |
82 long samples, | 82 long samples, |
83 long *samples_written); | 83 long *samples_written); |
84 | 84 |
85 /* Audio driver bootstrap functions */ | 85 /* Audio driver bootstrap functions */ |
86 static int | 86 static int |
87 Audio_Available (void) | 87 Audio_Available(void) |
88 { | 88 { |
89 return 1; | 89 return 1; |
90 } | 90 } |
91 | 91 |
92 static void | 92 static void |
93 Audio_DeleteDevice (_THIS) | 93 Audio_DeleteDevice(_THIS) |
94 { | 94 { |
95 if (this->hidden->playbuf._buffer) | 95 if (this->hidden->playbuf._buffer) |
96 SDL_free (this->hidden->playbuf._buffer); | 96 SDL_free(this->hidden->playbuf._buffer); |
97 if (this->hidden->fillbuf._buffer) | 97 if (this->hidden->fillbuf._buffer) |
98 SDL_free (this->hidden->fillbuf._buffer); | 98 SDL_free(this->hidden->fillbuf._buffer); |
99 _somFree (this->hidden->umsdev); | 99 _somFree(this->hidden->umsdev); |
100 SDL_free (this->hidden); | 100 SDL_free(this->hidden); |
101 SDL_free (this); | 101 SDL_free(this); |
102 } | 102 } |
103 | 103 |
104 static SDL_AudioDevice * | 104 static SDL_AudioDevice * |
105 Audio_CreateDevice (int devindex) | 105 Audio_CreateDevice(int devindex) |
106 { | 106 { |
107 SDL_AudioDevice *this; | 107 SDL_AudioDevice *this; |
108 | 108 |
109 /* | 109 /* |
110 * Allocate and initialize management storage and private management | 110 * Allocate and initialize management storage and private management |
111 * storage for this SDL-using library. | 111 * storage for this SDL-using library. |
112 */ | 112 */ |
113 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); | 113 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); |
114 if (this) { | 114 if (this) { |
115 SDL_memset (this, 0, (sizeof *this)); | 115 SDL_memset(this, 0, (sizeof *this)); |
116 this->hidden = (struct SDL_PrivateAudioData *) | 116 this->hidden = (struct SDL_PrivateAudioData *) |
117 SDL_malloc ((sizeof *this->hidden)); | 117 SDL_malloc((sizeof *this->hidden)); |
118 } | 118 } |
119 if ((this == NULL) || (this->hidden == NULL)) { | 119 if ((this == NULL) || (this->hidden == NULL)) { |
120 SDL_OutOfMemory (); | 120 SDL_OutOfMemory(); |
121 if (this) { | 121 if (this) { |
122 SDL_free (this); | 122 SDL_free(this); |
123 } | 123 } |
124 return (0); | 124 return (0); |
125 } | 125 } |
126 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); | 126 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
127 #ifdef DEBUG_AUDIO | 127 #ifdef DEBUG_AUDIO |
128 fprintf (stderr, "Creating UMS Audio device\n"); | 128 fprintf(stderr, "Creating UMS Audio device\n"); |
129 #endif | 129 #endif |
130 | 130 |
131 /* | 131 /* |
132 * Calls for UMS env initialization and audio object construction. | 132 * Calls for UMS env initialization and audio object construction. |
133 */ | 133 */ |
134 this->hidden->ev = somGetGlobalEnvironment (); | 134 this->hidden->ev = somGetGlobalEnvironment(); |
135 this->hidden->umsdev = UMSAudioDeviceNew (); | 135 this->hidden->umsdev = UMSAudioDeviceNew(); |
136 | 136 |
137 /* | 137 /* |
138 * Set the function pointers. | 138 * Set the function pointers. |
139 */ | 139 */ |
140 this->OpenAudio = UMS_OpenAudio; | 140 this->OpenAudio = UMS_OpenAudio; |
143 this->GetAudioBuf = UMS_GetAudioBuf; | 143 this->GetAudioBuf = UMS_GetAudioBuf; |
144 this->CloseAudio = UMS_CloseAudio; | 144 this->CloseAudio = UMS_CloseAudio; |
145 this->free = Audio_DeleteDevice; | 145 this->free = Audio_DeleteDevice; |
146 | 146 |
147 #ifdef DEBUG_AUDIO | 147 #ifdef DEBUG_AUDIO |
148 fprintf (stderr, "done\n"); | 148 fprintf(stderr, "done\n"); |
149 #endif | 149 #endif |
150 return this; | 150 return this; |
151 } | 151 } |
152 | 152 |
153 AudioBootStrap UMS_bootstrap = { | 153 AudioBootStrap UMS_bootstrap = { |
154 UMS_DRIVER_NAME, "AUX UMS audio", | 154 UMS_DRIVER_NAME, "AUX UMS audio", |
155 Audio_Available, Audio_CreateDevice | 155 Audio_Available, Audio_CreateDevice |
156 }; | 156 }; |
157 | 157 |
158 static Uint8 * | 158 static Uint8 * |
159 UMS_GetAudioBuf (_THIS) | 159 UMS_GetAudioBuf(_THIS) |
160 { | 160 { |
161 #ifdef DEBUG_AUDIO | 161 #ifdef DEBUG_AUDIO |
162 fprintf (stderr, "enter UMS_GetAudioBuf\n"); | 162 fprintf(stderr, "enter UMS_GetAudioBuf\n"); |
163 #endif | 163 #endif |
164 return this->hidden->fillbuf._buffer; | 164 return this->hidden->fillbuf._buffer; |
165 /* | 165 /* |
166 long bufSize; | 166 long bufSize; |
167 UMSAudioDevice_ReturnCode rc; | 167 UMSAudioDevice_ReturnCode rc; |
170 rc = UADWriteBuffSize(this, bufSize ); | 170 rc = UADWriteBuffSize(this, bufSize ); |
171 */ | 171 */ |
172 } | 172 } |
173 | 173 |
174 static void | 174 static void |
175 UMS_CloseAudio (_THIS) | 175 UMS_CloseAudio(_THIS) |
176 { | 176 { |
177 UMSAudioDevice_ReturnCode rc; | 177 UMSAudioDevice_ReturnCode rc; |
178 | 178 |
179 #ifdef DEBUG_AUDIO | 179 #ifdef DEBUG_AUDIO |
180 fprintf (stderr, "enter UMS_CloseAudio\n"); | 180 fprintf(stderr, "enter UMS_CloseAudio\n"); |
181 #endif | 181 #endif |
182 rc = UADPlayRemainingData (this, TRUE); | 182 rc = UADPlayRemainingData(this, TRUE); |
183 rc = UADStop (this); | 183 rc = UADStop(this); |
184 rc = UADClose (this); | 184 rc = UADClose(this); |
185 } | 185 } |
186 | 186 |
187 static void | 187 static void |
188 UMS_PlayAudio (_THIS) | 188 UMS_PlayAudio(_THIS) |
189 { | 189 { |
190 UMSAudioDevice_ReturnCode rc; | 190 UMSAudioDevice_ReturnCode rc; |
191 long samplesToWrite; | 191 long samplesToWrite; |
192 long samplesWritten; | 192 long samplesWritten; |
193 UMSAudioTypes_Buffer swpbuf; | 193 UMSAudioTypes_Buffer swpbuf; |
194 | 194 |
195 #ifdef DEBUG_AUDIO | 195 #ifdef DEBUG_AUDIO |
196 fprintf (stderr, "enter UMS_PlayAudio\n"); | 196 fprintf(stderr, "enter UMS_PlayAudio\n"); |
197 #endif | 197 #endif |
198 samplesToWrite = | 198 samplesToWrite = |
199 this->hidden->playbuf._length / this->hidden->bytesPerSample; | 199 this->hidden->playbuf._length / this->hidden->bytesPerSample; |
200 do { | 200 do { |
201 rc = UADWrite (this, &this->hidden->playbuf, | 201 rc = UADWrite(this, &this->hidden->playbuf, |
202 samplesToWrite, &samplesWritten); | 202 samplesToWrite, &samplesWritten); |
203 samplesToWrite -= samplesWritten; | 203 samplesToWrite -= samplesWritten; |
204 | 204 |
205 /* rc values: UMSAudioDevice_Success | 205 /* rc values: UMSAudioDevice_Success |
206 * UMSAudioDevice_Failure | 206 * UMSAudioDevice_Failure |
207 * UMSAudioDevice_Preempted | 207 * UMSAudioDevice_Preempted |
208 * UMSAudioDevice_Interrupted | 208 * UMSAudioDevice_Interrupted |
209 * UMSAudioDevice_DeviceError | 209 * UMSAudioDevice_DeviceError |
210 */ | 210 */ |
211 if (rc == UMSAudioDevice_DeviceError) { | 211 if (rc == UMSAudioDevice_DeviceError) { |
212 #ifdef DEBUG_AUDIO | 212 #ifdef DEBUG_AUDIO |
213 fprintf (stderr, "Returning from PlayAudio with devices error\n"); | 213 fprintf(stderr, "Returning from PlayAudio with devices error\n"); |
214 #endif | 214 #endif |
215 return; | 215 return; |
216 } | 216 } |
217 } | 217 } |
218 while (samplesToWrite > 0); | 218 while (samplesToWrite > 0); |
219 | 219 |
220 SDL_LockAudio (); | 220 SDL_LockAudio(); |
221 SDL_memcpy (&swpbuf, &this->hidden->playbuf, | 221 SDL_memcpy(&swpbuf, &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer)); |
222 sizeof (UMSAudioTypes_Buffer)); | 222 SDL_memcpy(&this->hidden->playbuf, &this->hidden->fillbuf, |
223 SDL_memcpy (&this->hidden->playbuf, &this->hidden->fillbuf, | 223 sizeof(UMSAudioTypes_Buffer)); |
224 sizeof (UMSAudioTypes_Buffer)); | 224 SDL_memcpy(&this->hidden->fillbuf, &swpbuf, sizeof(UMSAudioTypes_Buffer)); |
225 SDL_memcpy (&this->hidden->fillbuf, &swpbuf, | 225 SDL_UnlockAudio(); |
226 sizeof (UMSAudioTypes_Buffer)); | 226 |
227 SDL_UnlockAudio (); | 227 #ifdef DEBUG_AUDIO |
228 | 228 fprintf(stderr, "Wrote audio data and swapped buffer\n"); |
229 #ifdef DEBUG_AUDIO | |
230 fprintf (stderr, "Wrote audio data and swapped buffer\n"); | |
231 #endif | 229 #endif |
232 } | 230 } |
233 | 231 |
234 #if 0 | 232 #if 0 |
235 // /* Set the DSP frequency */ | 233 // /* Set the DSP frequency */ |
240 // } | 238 // } |
241 // spec->freq = value; | 239 // spec->freq = value; |
242 #endif | 240 #endif |
243 | 241 |
244 static int | 242 static int |
245 UMS_OpenAudio (_THIS, SDL_AudioSpec * spec) | 243 UMS_OpenAudio(_THIS, SDL_AudioSpec * spec) |
246 { | 244 { |
247 char *audiodev = "/dev/paud0"; | 245 char *audiodev = "/dev/paud0"; |
248 long lgain; | 246 long lgain; |
249 long rgain; | 247 long rgain; |
250 long outRate; | 248 long outRate; |
255 Uint16 test_format; | 253 Uint16 test_format; |
256 int frag_spec; | 254 int frag_spec; |
257 UMSAudioDevice_ReturnCode rc; | 255 UMSAudioDevice_ReturnCode rc; |
258 | 256 |
259 #ifdef DEBUG_AUDIO | 257 #ifdef DEBUG_AUDIO |
260 fprintf (stderr, "enter UMS_OpenAudio\n"); | 258 fprintf(stderr, "enter UMS_OpenAudio\n"); |
261 #endif | 259 #endif |
262 rc = UADOpen (this, audiodev, "PLAY", UMSAudioDevice_BlockingIO); | 260 rc = UADOpen(this, audiodev, "PLAY", UMSAudioDevice_BlockingIO); |
263 if (rc != UMSAudioDevice_Success) { | 261 if (rc != UMSAudioDevice_Success) { |
264 SDL_SetError ("Couldn't open %s: %s", audiodev, strerror (errno)); | 262 SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); |
265 return -1; | 263 return -1; |
266 } | 264 } |
267 | 265 |
268 rc = UADSetAudioFormatType (this, "PCM"); | 266 rc = UADSetAudioFormatType(this, "PCM"); |
269 | 267 |
270 success = 0; | 268 success = 0; |
271 test_format = SDL_FirstAudioFormat (spec->format); | 269 test_format = SDL_FirstAudioFormat(spec->format); |
272 do { | 270 do { |
273 #ifdef DEBUG_AUDIO | 271 #ifdef DEBUG_AUDIO |
274 fprintf (stderr, "Trying format 0x%4.4x\n", test_format); | 272 fprintf(stderr, "Trying format 0x%4.4x\n", test_format); |
275 #endif | 273 #endif |
276 switch (test_format) { | 274 switch (test_format) { |
277 case AUDIO_U8: | 275 case AUDIO_U8: |
278 /* from the mac code: better ? */ | 276 /* from the mac code: better ? */ |
279 /* sample_bits = spec->size / spec->samples / spec->channels * 8; */ | 277 /* sample_bits = spec->size / spec->samples / spec->channels * 8; */ |
280 success = 1; | 278 success = 1; |
281 bitsPerSample = 8; | 279 bitsPerSample = 8; |
282 rc = UADSetSampleRate (this, spec->freq << 16, &outRate); | 280 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
283 rc = UADSetByteOrder (this, "MSB"); /* irrelevant */ | 281 rc = UADSetByteOrder(this, "MSB"); /* irrelevant */ |
284 rc = UADSetNumberFormat (this, "UNSIGNED"); | 282 rc = UADSetNumberFormat(this, "UNSIGNED"); |
285 break; | 283 break; |
286 case AUDIO_S8: | 284 case AUDIO_S8: |
287 success = 1; | 285 success = 1; |
288 bitsPerSample = 8; | 286 bitsPerSample = 8; |
289 rc = UADSetSampleRate (this, spec->freq << 16, &outRate); | 287 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
290 rc = UADSetByteOrder (this, "MSB"); /* irrelevant */ | 288 rc = UADSetByteOrder(this, "MSB"); /* irrelevant */ |
291 rc = UADSetNumberFormat (this, "SIGNED"); | 289 rc = UADSetNumberFormat(this, "SIGNED"); |
292 break; | 290 break; |
293 case AUDIO_S16LSB: | 291 case AUDIO_S16LSB: |
294 success = 1; | 292 success = 1; |
295 bitsPerSample = 16; | 293 bitsPerSample = 16; |
296 rc = UADSetSampleRate (this, spec->freq << 16, &outRate); | 294 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
297 rc = UADSetByteOrder (this, "LSB"); | 295 rc = UADSetByteOrder(this, "LSB"); |
298 rc = UADSetNumberFormat (this, "SIGNED"); | 296 rc = UADSetNumberFormat(this, "SIGNED"); |
299 break; | 297 break; |
300 case AUDIO_S16MSB: | 298 case AUDIO_S16MSB: |
301 success = 1; | 299 success = 1; |
302 bitsPerSample = 16; | 300 bitsPerSample = 16; |
303 rc = UADSetSampleRate (this, spec->freq << 16, &outRate); | 301 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
304 rc = UADSetByteOrder (this, "MSB"); | 302 rc = UADSetByteOrder(this, "MSB"); |
305 rc = UADSetNumberFormat (this, "SIGNED"); | 303 rc = UADSetNumberFormat(this, "SIGNED"); |
306 break; | 304 break; |
307 case AUDIO_U16LSB: | 305 case AUDIO_U16LSB: |
308 success = 1; | 306 success = 1; |
309 bitsPerSample = 16; | 307 bitsPerSample = 16; |
310 rc = UADSetSampleRate (this, spec->freq << 16, &outRate); | 308 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
311 rc = UADSetByteOrder (this, "LSB"); | 309 rc = UADSetByteOrder(this, "LSB"); |
312 rc = UADSetNumberFormat (this, "UNSIGNED"); | 310 rc = UADSetNumberFormat(this, "UNSIGNED"); |
313 break; | 311 break; |
314 case AUDIO_U16MSB: | 312 case AUDIO_U16MSB: |
315 success = 1; | 313 success = 1; |
316 bitsPerSample = 16; | 314 bitsPerSample = 16; |
317 rc = UADSetSampleRate (this, spec->freq << 16, &outRate); | 315 rc = UADSetSampleRate(this, spec->freq << 16, &outRate); |
318 rc = UADSetByteOrder (this, "MSB"); | 316 rc = UADSetByteOrder(this, "MSB"); |
319 rc = UADSetNumberFormat (this, "UNSIGNED"); | 317 rc = UADSetNumberFormat(this, "UNSIGNED"); |
320 break; | 318 break; |
321 default: | 319 default: |
322 break; | 320 break; |
323 } | 321 } |
324 if (!success) { | 322 if (!success) { |
325 test_format = SDL_NextAudioFormat (); | 323 test_format = SDL_NextAudioFormat(); |
326 } | 324 } |
327 } | 325 } |
328 while (!success && test_format); | 326 while (!success && test_format); |
329 | 327 |
330 if (success == 0) { | 328 if (success == 0) { |
331 SDL_SetError ("Couldn't find any hardware audio formats"); | 329 SDL_SetError("Couldn't find any hardware audio formats"); |
332 return -1; | 330 return -1; |
333 } | 331 } |
334 | 332 |
335 spec->format = test_format; | 333 spec->format = test_format; |
336 | 334 |
337 for (frag_spec = 0; (0x01 << frag_spec) < spec->size; ++frag_spec); | 335 for (frag_spec = 0; (0x01 << frag_spec) < spec->size; ++frag_spec); |
338 if ((0x01 << frag_spec) != spec->size) { | 336 if ((0x01 << frag_spec) != spec->size) { |
339 SDL_SetError ("Fragment size must be a power of two"); | 337 SDL_SetError("Fragment size must be a power of two"); |
340 return -1; | 338 return -1; |
341 } | 339 } |
342 if (frag_spec > 2048) | 340 if (frag_spec > 2048) |
343 frag_spec = 2048; | 341 frag_spec = 2048; |
344 | 342 |
345 this->hidden->bytesPerSample = (bitsPerSample / 8) * spec->channels; | 343 this->hidden->bytesPerSample = (bitsPerSample / 8) * spec->channels; |
346 samplesPerSec = this->hidden->bytesPerSample * outRate; | 344 samplesPerSec = this->hidden->bytesPerSample * outRate; |
347 | 345 |
348 this->hidden->playbuf._length = 0; | 346 this->hidden->playbuf._length = 0; |
349 this->hidden->playbuf._maximum = spec->size; | 347 this->hidden->playbuf._maximum = spec->size; |
350 this->hidden->playbuf._buffer = (unsigned char *) SDL_malloc (spec->size); | 348 this->hidden->playbuf._buffer = (unsigned char *) SDL_malloc(spec->size); |
351 this->hidden->fillbuf._length = 0; | 349 this->hidden->fillbuf._length = 0; |
352 this->hidden->fillbuf._maximum = spec->size; | 350 this->hidden->fillbuf._maximum = spec->size; |
353 this->hidden->fillbuf._buffer = (unsigned char *) SDL_malloc (spec->size); | 351 this->hidden->fillbuf._buffer = (unsigned char *) SDL_malloc(spec->size); |
354 | 352 |
355 rc = UADSetBitsPerSample (this, bitsPerSample); | 353 rc = UADSetBitsPerSample(this, bitsPerSample); |
356 rc = UADSetDMABufferSize (this, frag_spec, &outBufSize); | 354 rc = UADSetDMABufferSize(this, frag_spec, &outBufSize); |
357 rc = UADSetChannels (this, spec->channels); /* functions reduces to mono or stereo */ | 355 rc = UADSetChannels(this, spec->channels); /* functions reduces to mono or stereo */ |
358 | 356 |
359 lgain = 100; /*maximum left input gain */ | 357 lgain = 100; /*maximum left input gain */ |
360 rgain = 100; /*maimum right input gain */ | 358 rgain = 100; /*maimum right input gain */ |
361 rc = UADEnableOutput (this, "LINE_OUT", &lgain, &rgain); | 359 rc = UADEnableOutput(this, "LINE_OUT", &lgain, &rgain); |
362 rc = UADInitialize (this); | 360 rc = UADInitialize(this); |
363 rc = UADStart (this); | 361 rc = UADStart(this); |
364 rc = UADSetVolume (this, 100); | 362 rc = UADSetVolume(this, 100); |
365 rc = UADSetBalance (this, 0); | 363 rc = UADSetBalance(this, 0); |
366 | 364 |
367 /* We're ready to rock and roll. :-) */ | 365 /* We're ready to rock and roll. :-) */ |
368 return 0; | 366 return 0; |
369 } | 367 } |
370 | 368 |
371 | 369 |
372 static UMSAudioDevice_ReturnCode | 370 static UMSAudioDevice_ReturnCode |
373 UADGetBitsPerSample (_THIS, long *bits) | 371 UADGetBitsPerSample(_THIS, long *bits) |
374 { | 372 { |
375 return UMSAudioDevice_get_bits_per_sample (this->hidden->umsdev, | 373 return UMSAudioDevice_get_bits_per_sample(this->hidden->umsdev, |
376 this->hidden->ev, bits); | 374 this->hidden->ev, bits); |
377 } | 375 } |
378 | 376 |
379 static UMSAudioDevice_ReturnCode | 377 static UMSAudioDevice_ReturnCode |
380 UADSetBitsPerSample (_THIS, long bits) | 378 UADSetBitsPerSample(_THIS, long bits) |
381 { | 379 { |
382 return UMSAudioDevice_set_bits_per_sample (this->hidden->umsdev, | 380 return UMSAudioDevice_set_bits_per_sample(this->hidden->umsdev, |
383 this->hidden->ev, bits); | 381 this->hidden->ev, bits); |
384 } | 382 } |
385 | 383 |
386 static UMSAudioDevice_ReturnCode | 384 static UMSAudioDevice_ReturnCode |
387 UADSetSampleRate (_THIS, long rate, long *set_rate) | 385 UADSetSampleRate(_THIS, long rate, long *set_rate) |
388 { | 386 { |
389 /* from the mac code: sample rate = spec->freq << 16; */ | 387 /* from the mac code: sample rate = spec->freq << 16; */ |
390 return UMSAudioDevice_set_sample_rate (this->hidden->umsdev, | 388 return UMSAudioDevice_set_sample_rate(this->hidden->umsdev, |
391 this->hidden->ev, rate, set_rate); | 389 this->hidden->ev, rate, set_rate); |
392 } | 390 } |
393 | 391 |
394 static UMSAudioDevice_ReturnCode | 392 static UMSAudioDevice_ReturnCode |
395 UADSetByteOrder (_THIS, string byte_order) | 393 UADSetByteOrder(_THIS, string byte_order) |
396 { | 394 { |
397 return UMSAudioDevice_set_byte_order (this->hidden->umsdev, | 395 return UMSAudioDevice_set_byte_order(this->hidden->umsdev, |
398 this->hidden->ev, byte_order); | 396 this->hidden->ev, byte_order); |
399 } | 397 } |
400 | 398 |
401 static UMSAudioDevice_ReturnCode | 399 static UMSAudioDevice_ReturnCode |
402 UADSetAudioFormatType (_THIS, string fmt) | 400 UADSetAudioFormatType(_THIS, string fmt) |
403 { | 401 { |
404 /* possible PCM, A_LAW or MU_LAW */ | 402 /* possible PCM, A_LAW or MU_LAW */ |
405 return UMSAudioDevice_set_audio_format_type (this->hidden->umsdev, | 403 return UMSAudioDevice_set_audio_format_type(this->hidden->umsdev, |
406 this->hidden->ev, fmt); | 404 this->hidden->ev, fmt); |
407 } | 405 } |
408 | 406 |
409 static UMSAudioDevice_ReturnCode | 407 static UMSAudioDevice_ReturnCode |
410 UADSetNumberFormat (_THIS, string fmt) | 408 UADSetNumberFormat(_THIS, string fmt) |
411 { | 409 { |
412 /* possible SIGNED, UNSIGNED, or TWOS_COMPLEMENT */ | 410 /* possible SIGNED, UNSIGNED, or TWOS_COMPLEMENT */ |
413 return UMSAudioDevice_set_number_format (this->hidden->umsdev, | 411 return UMSAudioDevice_set_number_format(this->hidden->umsdev, |
414 this->hidden->ev, fmt); | 412 this->hidden->ev, fmt); |
415 } | 413 } |
416 | 414 |
417 static UMSAudioDevice_ReturnCode | 415 static UMSAudioDevice_ReturnCode |
418 UADInitialize (_THIS) | 416 UADInitialize(_THIS) |
419 { | 417 { |
420 return UMSAudioDevice_initialize (this->hidden->umsdev, this->hidden->ev); | 418 return UMSAudioDevice_initialize(this->hidden->umsdev, this->hidden->ev); |
421 } | 419 } |
422 | 420 |
423 static UMSAudioDevice_ReturnCode | 421 static UMSAudioDevice_ReturnCode |
424 UADStart (_THIS) | 422 UADStart(_THIS) |
425 { | 423 { |
426 return UMSAudioDevice_start (this->hidden->umsdev, this->hidden->ev); | 424 return UMSAudioDevice_start(this->hidden->umsdev, this->hidden->ev); |
427 } | 425 } |
428 | 426 |
429 static UMSAudioDevice_ReturnCode | 427 static UMSAudioDevice_ReturnCode |
430 UADSetTimeFormat (_THIS, UMSAudioTypes_TimeFormat fmt) | 428 UADSetTimeFormat(_THIS, UMSAudioTypes_TimeFormat fmt) |
431 { | 429 { |
432 /* | 430 /* |
433 * Switches the time format to the new format, immediately. | 431 * Switches the time format to the new format, immediately. |
434 * possible UMSAudioTypes_Msecs, UMSAudioTypes_Bytes or UMSAudioTypes_Samples | 432 * possible UMSAudioTypes_Msecs, UMSAudioTypes_Bytes or UMSAudioTypes_Samples |
435 */ | 433 */ |
436 return UMSAudioDevice_set_time_format (this->hidden->umsdev, | 434 return UMSAudioDevice_set_time_format(this->hidden->umsdev, |
437 this->hidden->ev, fmt); | 435 this->hidden->ev, fmt); |
438 } | 436 } |
439 | 437 |
440 static UMSAudioDevice_ReturnCode | 438 static UMSAudioDevice_ReturnCode |
441 UADWriteBuffSize (_THIS, long *buff_size) | 439 UADWriteBuffSize(_THIS, long *buff_size) |
442 { | 440 { |
443 /* | 441 /* |
444 * returns write buffer size in the current time format | 442 * returns write buffer size in the current time format |
445 */ | 443 */ |
446 return UMSAudioDevice_write_buff_size (this->hidden->umsdev, | 444 return UMSAudioDevice_write_buff_size(this->hidden->umsdev, |
447 this->hidden->ev, buff_size); | 445 this->hidden->ev, buff_size); |
448 } | 446 } |
449 | 447 |
450 static UMSAudioDevice_ReturnCode | 448 static UMSAudioDevice_ReturnCode |
451 UADWriteBuffRemain (_THIS, long *buff_size) | 449 UADWriteBuffRemain(_THIS, long *buff_size) |
452 { | 450 { |
453 /* | 451 /* |
454 * returns amount of available space in the write buffer | 452 * returns amount of available space in the write buffer |
455 * in the current time format | 453 * in the current time format |
456 */ | 454 */ |
457 return UMSAudioDevice_write_buff_remain (this->hidden->umsdev, | 455 return UMSAudioDevice_write_buff_remain(this->hidden->umsdev, |
458 this->hidden->ev, buff_size); | 456 this->hidden->ev, buff_size); |
459 } | 457 } |
460 | 458 |
461 static UMSAudioDevice_ReturnCode | 459 static UMSAudioDevice_ReturnCode |
462 UADWriteBuffUsed (_THIS, long *buff_size) | 460 UADWriteBuffUsed(_THIS, long *buff_size) |
463 { | 461 { |
464 /* | 462 /* |
465 * returns amount of filled space in the write buffer | 463 * returns amount of filled space in the write buffer |
466 * in the current time format | 464 * in the current time format |
467 */ | 465 */ |
468 return UMSAudioDevice_write_buff_used (this->hidden->umsdev, | 466 return UMSAudioDevice_write_buff_used(this->hidden->umsdev, |
469 this->hidden->ev, buff_size); | 467 this->hidden->ev, buff_size); |
470 } | 468 } |
471 | 469 |
472 static UMSAudioDevice_ReturnCode | 470 static UMSAudioDevice_ReturnCode |
473 UADSetDMABufferSize (_THIS, long bytes, long *bytes_ret) | 471 UADSetDMABufferSize(_THIS, long bytes, long *bytes_ret) |
474 { | 472 { |
475 /* | 473 /* |
476 * Request a new DMA buffer size, maximum requested size 2048. | 474 * Request a new DMA buffer size, maximum requested size 2048. |
477 * Takes effect with next initialize() call. | 475 * Takes effect with next initialize() call. |
478 * Devices may or may not support DMA. | 476 * Devices may or may not support DMA. |
479 */ | 477 */ |
480 return UMSAudioDevice_set_DMA_buffer_size (this->hidden->umsdev, | 478 return UMSAudioDevice_set_DMA_buffer_size(this->hidden->umsdev, |
481 this->hidden->ev, | 479 this->hidden->ev, |
482 bytes, bytes_ret); | 480 bytes, bytes_ret); |
483 } | 481 } |
484 | 482 |
485 static UMSAudioDevice_ReturnCode | 483 static UMSAudioDevice_ReturnCode |
486 UADSetVolume (_THIS, long volume) | 484 UADSetVolume(_THIS, long volume) |
487 { | 485 { |
488 /* | 486 /* |
489 * Set the volume. | 487 * Set the volume. |
490 * Takes effect immediately. | 488 * Takes effect immediately. |
491 */ | 489 */ |
492 return UMSAudioDevice_set_volume (this->hidden->umsdev, | 490 return UMSAudioDevice_set_volume(this->hidden->umsdev, |
493 this->hidden->ev, volume); | 491 this->hidden->ev, volume); |
494 } | 492 } |
495 | 493 |
496 static UMSAudioDevice_ReturnCode | 494 static UMSAudioDevice_ReturnCode |
497 UADSetBalance (_THIS, long balance) | 495 UADSetBalance(_THIS, long balance) |
498 { | 496 { |
499 /* | 497 /* |
500 * Set the balance. | 498 * Set the balance. |
501 * Takes effect immediately. | 499 * Takes effect immediately. |
502 */ | 500 */ |
503 return UMSAudioDevice_set_balance (this->hidden->umsdev, | 501 return UMSAudioDevice_set_balance(this->hidden->umsdev, |
504 this->hidden->ev, balance); | 502 this->hidden->ev, balance); |
505 } | 503 } |
506 | 504 |
507 static UMSAudioDevice_ReturnCode | 505 static UMSAudioDevice_ReturnCode |
508 UADSetChannels (_THIS, long channels) | 506 UADSetChannels(_THIS, long channels) |
509 { | 507 { |
510 /* | 508 /* |
511 * Set mono or stereo. | 509 * Set mono or stereo. |
512 * Takes effect with next initialize() call. | 510 * Takes effect with next initialize() call. |
513 */ | 511 */ |
514 if (channels != 1) | 512 if (channels != 1) |
515 channels = 2; | 513 channels = 2; |
516 return UMSAudioDevice_set_number_of_channels (this->hidden->umsdev, | 514 return UMSAudioDevice_set_number_of_channels(this->hidden->umsdev, |
517 this->hidden->ev, channels); | 515 this->hidden->ev, channels); |
518 } | 516 } |
519 | 517 |
520 static UMSAudioDevice_ReturnCode | 518 static UMSAudioDevice_ReturnCode |
521 UADOpen (_THIS, string device, string mode, long flags) | 519 UADOpen(_THIS, string device, string mode, long flags) |
522 { | 520 { |
523 return UMSAudioDevice_open (this->hidden->umsdev, | 521 return UMSAudioDevice_open(this->hidden->umsdev, |
524 this->hidden->ev, device, mode, flags); | 522 this->hidden->ev, device, mode, flags); |
525 } | 523 } |
526 | 524 |
527 static UMSAudioDevice_ReturnCode | 525 static UMSAudioDevice_ReturnCode |
528 UADWrite (_THIS, UMSAudioTypes_Buffer * buff, | 526 UADWrite(_THIS, UMSAudioTypes_Buffer * buff, |
529 long samples, long *samples_written) | 527 long samples, long *samples_written) |
530 { | 528 { |
531 return UMSAudioDevice_write (this->hidden->umsdev, | 529 return UMSAudioDevice_write(this->hidden->umsdev, |
532 this->hidden->ev, | 530 this->hidden->ev, |
533 buff, samples, samples_written); | 531 buff, samples, samples_written); |
534 } | 532 } |
535 | 533 |
536 static UMSAudioDevice_ReturnCode | 534 static UMSAudioDevice_ReturnCode |
537 UADPlayRemainingData (_THIS, boolean block) | 535 UADPlayRemainingData(_THIS, boolean block) |
538 { | 536 { |
539 return UMSAudioDevice_play_remaining_data (this->hidden->umsdev, | 537 return UMSAudioDevice_play_remaining_data(this->hidden->umsdev, |
540 this->hidden->ev, block); | 538 this->hidden->ev, block); |
541 } | 539 } |
542 | 540 |
543 static UMSAudioDevice_ReturnCode | 541 static UMSAudioDevice_ReturnCode |
544 UADStop (_THIS) | 542 UADStop(_THIS) |
545 { | 543 { |
546 return UMSAudioDevice_stop (this->hidden->umsdev, this->hidden->ev); | 544 return UMSAudioDevice_stop(this->hidden->umsdev, this->hidden->ev); |
547 } | 545 } |
548 | 546 |
549 static UMSAudioDevice_ReturnCode | 547 static UMSAudioDevice_ReturnCode |
550 UADClose (_THIS) | 548 UADClose(_THIS) |
551 { | 549 { |
552 return UMSAudioDevice_close (this->hidden->umsdev, this->hidden->ev); | 550 return UMSAudioDevice_close(this->hidden->umsdev, this->hidden->ev); |
553 } | 551 } |
554 | 552 |
555 static UMSAudioDevice_ReturnCode | 553 static UMSAudioDevice_ReturnCode |
556 UADEnableOutput (_THIS, string output, long *left_gain, long *right_gain) | 554 UADEnableOutput(_THIS, string output, long *left_gain, long *right_gain) |
557 { | 555 { |
558 return UMSAudioDevice_enable_output (this->hidden->umsdev, | 556 return UMSAudioDevice_enable_output(this->hidden->umsdev, |
559 this->hidden->ev, | 557 this->hidden->ev, |
560 output, left_gain, right_gain); | 558 output, left_gain, right_gain); |
561 } | 559 } |
562 | 560 |
563 /* vi: set ts=4 sw=4 expandtab: */ | 561 /* vi: set ts=4 sw=4 expandtab: */ |