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