comparison src/audio/ums/SDL_umsaudio.c @ 1895:c121d94672cb

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