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