comparison src/audio/ums/SDL_umsaudio.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents d910939febfa
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
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 static UMSAudioDevice_ReturnCode UADClose(_THIS); 54 long flags);
55 static UMSAudioDevice_ReturnCode UADGetBitsPerSample(_THIS, long* bits); 55 static UMSAudioDevice_ReturnCode UADClose (_THIS);
56 static UMSAudioDevice_ReturnCode UADSetBitsPerSample(_THIS, long bits); 56 static UMSAudioDevice_ReturnCode UADGetBitsPerSample (_THIS, long *bits);
57 static UMSAudioDevice_ReturnCode UADSetSampleRate(_THIS, long rate, long* set_rate); 57 static UMSAudioDevice_ReturnCode UADSetBitsPerSample (_THIS, long bits);
58 static UMSAudioDevice_ReturnCode UADSetByteOrder(_THIS, string byte_order); 58 static UMSAudioDevice_ReturnCode UADSetSampleRate (_THIS, long rate,
59 static UMSAudioDevice_ReturnCode UADSetAudioFormatType(_THIS, string fmt); 59 long *set_rate);
60 static UMSAudioDevice_ReturnCode UADSetNumberFormat(_THIS, string fmt); 60 static UMSAudioDevice_ReturnCode UADSetByteOrder (_THIS, string byte_order);
61 static UMSAudioDevice_ReturnCode UADInitialize(_THIS); 61 static UMSAudioDevice_ReturnCode UADSetAudioFormatType (_THIS, string fmt);
62 static UMSAudioDevice_ReturnCode UADStart(_THIS); 62 static UMSAudioDevice_ReturnCode UADSetNumberFormat (_THIS, string fmt);
63 static UMSAudioDevice_ReturnCode UADStop(_THIS); 63 static UMSAudioDevice_ReturnCode UADInitialize (_THIS);
64 static UMSAudioDevice_ReturnCode UADSetTimeFormat(_THIS, UMSAudioTypes_TimeFormat fmt ); 64 static UMSAudioDevice_ReturnCode UADStart (_THIS);
65 static UMSAudioDevice_ReturnCode UADWriteBuffSize(_THIS, long* buff_size ); 65 static UMSAudioDevice_ReturnCode UADStop (_THIS);
66 static UMSAudioDevice_ReturnCode UADWriteBuffRemain(_THIS, long* buff_size ); 66 static UMSAudioDevice_ReturnCode UADSetTimeFormat (_THIS,
67 static UMSAudioDevice_ReturnCode UADWriteBuffUsed(_THIS, long* buff_size ); 67 UMSAudioTypes_TimeFormat
68 static UMSAudioDevice_ReturnCode UADSetDMABufferSize(_THIS, long bytes, long* bytes_ret ); 68 fmt);
69 static UMSAudioDevice_ReturnCode UADSetVolume(_THIS, long volume ); 69 static UMSAudioDevice_ReturnCode UADWriteBuffSize (_THIS, long *buff_size);
70 static UMSAudioDevice_ReturnCode UADSetBalance(_THIS, long balance ); 70 static UMSAudioDevice_ReturnCode UADWriteBuffRemain (_THIS, long *buff_size);
71 static UMSAudioDevice_ReturnCode UADSetChannels(_THIS, long channels ); 71 static UMSAudioDevice_ReturnCode UADWriteBuffUsed (_THIS, long *buff_size);
72 static UMSAudioDevice_ReturnCode UADPlayRemainingData(_THIS, boolean block ); 72 static UMSAudioDevice_ReturnCode UADSetDMABufferSize (_THIS, long bytes,
73 static UMSAudioDevice_ReturnCode UADEnableOutput(_THIS, string output, long* left_gain, long* right_gain); 73 long *bytes_ret);
74 static UMSAudioDevice_ReturnCode UADWrite(_THIS, UMSAudioTypes_Buffer* buff, long samples, long* samples_written); 74 static UMSAudioDevice_ReturnCode UADSetVolume (_THIS, long volume);
75 static UMSAudioDevice_ReturnCode UADSetBalance (_THIS, long balance);
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);
87 SDL_free(this->hidden); 97 if (this->hidden->fillbuf._buffer)
88 SDL_free(this); 98 SDL_free (this->hidden->fillbuf._buffer);
89 } 99 _somFree (this->hidden->umsdev);
90 100 SDL_free (this->hidden);
91 static SDL_AudioDevice *Audio_CreateDevice(int devindex) 101 SDL_free (this);
102 }
103
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 }
105 SDL_OutOfMemory(); 119 if ((this == NULL) || (this->hidden == NULL)) {
106 if ( this ) { 120 SDL_OutOfMemory ();
107 SDL_free(this); 121 if (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 *
144 { 159 UMS_GetAudioBuf (_THIS)
145 #ifdef DEBUG_AUDIO 160 {
146 fprintf(stderr, "enter UMS_GetAudioBuf\n"); 161 #ifdef DEBUG_AUDIO
162 fprintf (stderr, "enter UMS_GetAudioBuf\n");
147 #endif 163 #endif
148 return this->hidden->fillbuf._buffer; 164 return this->hidden->fillbuf._buffer;
149 /* 165 /*
150 long bufSize; 166 long bufSize;
151 UMSAudioDevice_ReturnCode rc; 167 UMSAudioDevice_ReturnCode rc;
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");
164 #endif 181 #endif
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); 219
202 220 SDL_LockAudio ();
203 SDL_LockAudio(); 221 SDL_memcpy (&swpbuf, &this->hidden->playbuf,
204 SDL_memcpy( &swpbuf, &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer) ); 222 sizeof (UMSAudioTypes_Buffer));
205 SDL_memcpy( &this->hidden->playbuf, &this->hidden->fillbuf, sizeof(UMSAudioTypes_Buffer) ); 223 SDL_memcpy (&this->hidden->playbuf, &this->hidden->fillbuf,
206 SDL_memcpy( &this->hidden->fillbuf, &swpbuf, sizeof(UMSAudioTypes_Buffer) ); 224 sizeof (UMSAudioTypes_Buffer));
207 SDL_UnlockAudio(); 225 SDL_memcpy (&this->hidden->fillbuf, &swpbuf,
208 226 sizeof (UMSAudioTypes_Buffer));
209 #ifdef DEBUG_AUDIO 227 SDL_UnlockAudio ();
210 fprintf(stderr, "Wrote audio data and swapped buffer\n"); 228
229 #ifdef DEBUG_AUDIO
230 fprintf (stderr, "Wrote audio data and swapped buffer\n");
211 #endif 231 #endif
212 } 232 }
213 233
214 #if 0 234 #if 0
215 // /* Set the DSP frequency */ 235 // /* Set the DSP frequency */
216 // value = spec->freq; 236 // value = spec->freq;
217 // if ( ioctl(this->hidden->audio_fd, SOUND_PCM_WRITE_RATE, &value) < 0 ) { 237 // if ( ioctl(this->hidden->audio_fd, SOUND_PCM_WRITE_RATE, &value) < 0 ) {
218 // SDL_SetError("Couldn't set audio frequency"); 238 // SDL_SetError("Couldn't set audio frequency");
219 // return(-1); 239 // return(-1);
220 // } 240 // }
221 // spec->freq = value; 241 // spec->freq = value;
222 #endif 242 #endif
223 243
224 static int UMS_OpenAudio(_THIS, SDL_AudioSpec *spec) 244 static int
225 { 245 UMS_OpenAudio (_THIS, SDL_AudioSpec * spec)
226 char* audiodev = "/dev/paud0"; 246 {
227 long lgain; 247 char *audiodev = "/dev/paud0";
228 long rgain; 248 long lgain;
229 long outRate; 249 long rgain;
230 long outBufSize; 250 long outRate;
231 long bitsPerSample; 251 long outBufSize;
232 long samplesPerSec; 252 long bitsPerSample;
233 long success; 253 long samplesPerSec;
254 long success;
234 Uint16 test_format; 255 Uint16 test_format;
235 int frag_spec; 256 int frag_spec;
236 UMSAudioDevice_ReturnCode rc; 257 UMSAudioDevice_ReturnCode rc;
237 258
238 #ifdef DEBUG_AUDIO 259 #ifdef DEBUG_AUDIO
239 fprintf(stderr, "enter UMS_OpenAudio\n"); 260 fprintf (stderr, "enter UMS_OpenAudio\n");
240 #endif 261 #endif
241 rc = UADOpen(this, audiodev,"PLAY", UMSAudioDevice_BlockingIO); 262 rc = UADOpen (this, audiodev, "PLAY", UMSAudioDevice_BlockingIO);
242 if ( rc != UMSAudioDevice_Success ) { 263 if (rc != UMSAudioDevice_Success) {
243 SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno)); 264 SDL_SetError ("Couldn't open %s: %s", audiodev, strerror (errno));
244 return -1; 265 return -1;
245 } 266 }
246 267
247 rc = UADSetAudioFormatType(this, "PCM"); 268 rc = UADSetAudioFormatType (this, "PCM");
248 269
249 success = 0; 270 success = 0;
250 test_format = SDL_FirstAudioFormat(spec->format); 271 test_format = SDL_FirstAudioFormat (spec->format);
251 do 272 do {
252 { 273 #ifdef DEBUG_AUDIO
253 #ifdef DEBUG_AUDIO 274 fprintf (stderr, "Trying format 0x%4.4x\n", test_format);
254 fprintf(stderr, "Trying format 0x%4.4x\n", test_format); 275 #endif
255 #endif 276 switch (test_format) {
256 switch ( test_format )
257 {
258 case AUDIO_U8: 277 case AUDIO_U8:
259 /* from the mac code: better ? */ 278 /* from the mac code: better ? */
260 /* sample_bits = spec->size / spec->samples / spec->channels * 8; */ 279 /* sample_bits = spec->size / spec->samples / spec->channels * 8; */
261 success = 1; 280 success = 1;
262 bitsPerSample = 8; 281 bitsPerSample = 8;
263 rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); 282 rc = UADSetSampleRate (this, spec->freq << 16, &outRate);
264 rc = UADSetByteOrder(this, "MSB"); /* irrelevant */ 283 rc = UADSetByteOrder (this, "MSB"); /* irrelevant */
265 rc = UADSetNumberFormat(this, "UNSIGNED"); 284 rc = UADSetNumberFormat (this, "UNSIGNED");
266 break; 285 break;
267 case AUDIO_S8: 286 case AUDIO_S8:
268 success = 1; 287 success = 1;
269 bitsPerSample = 8; 288 bitsPerSample = 8;
270 rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); 289 rc = UADSetSampleRate (this, spec->freq << 16, &outRate);
271 rc = UADSetByteOrder(this, "MSB"); /* irrelevant */ 290 rc = UADSetByteOrder (this, "MSB"); /* irrelevant */
272 rc = UADSetNumberFormat(this, "SIGNED"); 291 rc = UADSetNumberFormat (this, "SIGNED");
273 break; 292 break;
274 case AUDIO_S16LSB: 293 case AUDIO_S16LSB:
275 success = 1; 294 success = 1;
276 bitsPerSample = 16; 295 bitsPerSample = 16;
277 rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); 296 rc = UADSetSampleRate (this, spec->freq << 16, &outRate);
278 rc = UADSetByteOrder(this, "LSB"); 297 rc = UADSetByteOrder (this, "LSB");
279 rc = UADSetNumberFormat(this, "SIGNED"); 298 rc = UADSetNumberFormat (this, "SIGNED");
280 break; 299 break;
281 case AUDIO_S16MSB: 300 case AUDIO_S16MSB:
282 success = 1; 301 success = 1;
283 bitsPerSample = 16; 302 bitsPerSample = 16;
284 rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); 303 rc = UADSetSampleRate (this, spec->freq << 16, &outRate);
285 rc = UADSetByteOrder(this, "MSB"); 304 rc = UADSetByteOrder (this, "MSB");
286 rc = UADSetNumberFormat(this, "SIGNED"); 305 rc = UADSetNumberFormat (this, "SIGNED");
287 break; 306 break;
288 case AUDIO_U16LSB: 307 case AUDIO_U16LSB:
289 success = 1; 308 success = 1;
290 bitsPerSample = 16; 309 bitsPerSample = 16;
291 rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); 310 rc = UADSetSampleRate (this, spec->freq << 16, &outRate);
292 rc = UADSetByteOrder(this, "LSB"); 311 rc = UADSetByteOrder (this, "LSB");
293 rc = UADSetNumberFormat(this, "UNSIGNED"); 312 rc = UADSetNumberFormat (this, "UNSIGNED");
294 break; 313 break;
295 case AUDIO_U16MSB: 314 case AUDIO_U16MSB:
296 success = 1; 315 success = 1;
297 bitsPerSample = 16; 316 bitsPerSample = 16;
298 rc = UADSetSampleRate(this, spec->freq << 16, &outRate ); 317 rc = UADSetSampleRate (this, spec->freq << 16, &outRate);
299 rc = UADSetByteOrder(this, "MSB"); 318 rc = UADSetByteOrder (this, "MSB");
300 rc = UADSetNumberFormat(this, "UNSIGNED"); 319 rc = UADSetNumberFormat (this, "UNSIGNED");
301 break; 320 break;
302 default: 321 default:
303 break; 322 break;
304 } 323 }
305 if ( ! success ) { 324 if (!success) {
306 test_format = SDL_NextAudioFormat(); 325 test_format = SDL_NextAudioFormat ();
307 } 326 }
308 } 327 }
309 while ( ! success && test_format ); 328 while (!success && test_format);
310 329
311 if ( success == 0 ) { 330 if (success == 0) {
312 SDL_SetError("Couldn't find any hardware audio formats"); 331 SDL_SetError ("Couldn't find any hardware audio formats");
313 return -1; 332 return -1;
314 } 333 }
315 334
316 spec->format = test_format; 335 spec->format = test_format;
317 336
318 for ( frag_spec = 0; (0x01<<frag_spec) < spec->size; ++frag_spec ); 337 for (frag_spec = 0; (0x01 << frag_spec) < spec->size; ++frag_spec);
319 if ( (0x01<<frag_spec) != spec->size ) { 338 if ((0x01 << frag_spec) != spec->size) {
320 SDL_SetError("Fragment size must be a power of two"); 339 SDL_SetError ("Fragment size must be a power of two");
321 return -1; 340 return -1;
322 } 341 }
323 if ( frag_spec > 2048 ) frag_spec = 2048; 342 if (frag_spec > 2048)
324 343 frag_spec = 2048;
325 this->hidden->bytesPerSample = (bitsPerSample / 8) * spec->channels; 344
326 samplesPerSec = this->hidden->bytesPerSample * outRate; 345 this->hidden->bytesPerSample = (bitsPerSample / 8) * spec->channels;
327 346 samplesPerSec = this->hidden->bytesPerSample * outRate;
328 this->hidden->playbuf._length = 0; 347
348 this->hidden->playbuf._length = 0;
329 this->hidden->playbuf._maximum = spec->size; 349 this->hidden->playbuf._maximum = spec->size;
330 this->hidden->playbuf._buffer = (unsigned char*)SDL_malloc(spec->size); 350 this->hidden->playbuf._buffer = (unsigned char *) SDL_malloc (spec->size);
331 this->hidden->fillbuf._length = 0; 351 this->hidden->fillbuf._length = 0;
332 this->hidden->fillbuf._maximum = spec->size; 352 this->hidden->fillbuf._maximum = spec->size;
333 this->hidden->fillbuf._buffer = (unsigned char*)SDL_malloc(spec->size); 353 this->hidden->fillbuf._buffer = (unsigned char *) SDL_malloc (spec->size);
334 354
335 rc = UADSetBitsPerSample(this, bitsPerSample ); 355 rc = UADSetBitsPerSample (this, bitsPerSample);
336 rc = UADSetDMABufferSize(this, frag_spec, &outBufSize ); 356 rc = UADSetDMABufferSize (this, frag_spec, &outBufSize);
337 rc = UADSetChannels(this, spec->channels); /* functions reduces to mono or stereo */ 357 rc = UADSetChannels (this, spec->channels); /* functions reduces to mono or stereo */
338 358
339 lgain = 100; /*maximum left input gain*/ 359 lgain = 100; /*maximum left input gain */
340 rgain = 100; /*maimum right input gain*/ 360 rgain = 100; /*maimum right input gain */
341 rc = UADEnableOutput(this, "LINE_OUT",&lgain,&rgain); 361 rc = UADEnableOutput (this, "LINE_OUT", &lgain, &rgain);
342 rc = UADInitialize(this); 362 rc = UADInitialize (this);
343 rc = UADStart(this); 363 rc = UADStart (this);
344 rc = UADSetVolume(this, 100); 364 rc = UADSetVolume (this, 100);
345 rc = UADSetBalance(this, 0); 365 rc = UADSetBalance (this, 0);
346 366
347 /* We're ready to rock and roll. :-) */ 367 /* We're ready to rock and roll. :-) */
348 return 0; 368 return 0;
349 } 369 }
350
351 370
352 static UMSAudioDevice_ReturnCode UADGetBitsPerSample(_THIS, long* bits) 371
353 { 372 static UMSAudioDevice_ReturnCode
354 return UMSAudioDevice_get_bits_per_sample( this->hidden->umsdev, 373 UADGetBitsPerSample (_THIS, long *bits)
355 this->hidden->ev, 374 {
356 bits ); 375 return UMSAudioDevice_get_bits_per_sample (this->hidden->umsdev,
357 } 376 this->hidden->ev, bits);
358 377 }
359 static UMSAudioDevice_ReturnCode UADSetBitsPerSample(_THIS, long bits) 378
360 { 379 static UMSAudioDevice_ReturnCode
361 return UMSAudioDevice_set_bits_per_sample( this->hidden->umsdev, 380 UADSetBitsPerSample (_THIS, long bits)
362 this->hidden->ev, 381 {
363 bits ); 382 return UMSAudioDevice_set_bits_per_sample (this->hidden->umsdev,
364 } 383 this->hidden->ev, bits);
365 384 }
366 static UMSAudioDevice_ReturnCode UADSetSampleRate(_THIS, long rate, long* set_rate) 385
386 static UMSAudioDevice_ReturnCode
387 UADSetSampleRate (_THIS, long rate, long *set_rate)
367 { 388 {
368 /* from the mac code: sample rate = spec->freq << 16; */ 389 /* from the mac code: sample rate = spec->freq << 16; */
369 return UMSAudioDevice_set_sample_rate( this->hidden->umsdev, 390 return UMSAudioDevice_set_sample_rate (this->hidden->umsdev,
370 this->hidden->ev, 391 this->hidden->ev, rate, set_rate);
371 rate, 392 }
372 set_rate ); 393
373 } 394 static UMSAudioDevice_ReturnCode
374 395 UADSetByteOrder (_THIS, string byte_order)
375 static UMSAudioDevice_ReturnCode UADSetByteOrder(_THIS, string byte_order) 396 {
376 { 397 return UMSAudioDevice_set_byte_order (this->hidden->umsdev,
377 return UMSAudioDevice_set_byte_order( this->hidden->umsdev, 398 this->hidden->ev, byte_order);
378 this->hidden->ev, 399 }
379 byte_order ); 400
380 } 401 static UMSAudioDevice_ReturnCode
381 402 UADSetAudioFormatType (_THIS, string fmt)
382 static UMSAudioDevice_ReturnCode UADSetAudioFormatType(_THIS, string fmt)
383 { 403 {
384 /* possible PCM, A_LAW or MU_LAW */ 404 /* possible PCM, A_LAW or MU_LAW */
385 return UMSAudioDevice_set_audio_format_type( this->hidden->umsdev, 405 return UMSAudioDevice_set_audio_format_type (this->hidden->umsdev,
386 this->hidden->ev, 406 this->hidden->ev, fmt);
387 fmt ); 407 }
388 } 408
389 409 static UMSAudioDevice_ReturnCode
390 static UMSAudioDevice_ReturnCode UADSetNumberFormat(_THIS, string fmt) 410 UADSetNumberFormat (_THIS, string fmt)
391 { 411 {
392 /* possible SIGNED, UNSIGNED, or TWOS_COMPLEMENT */ 412 /* possible SIGNED, UNSIGNED, or TWOS_COMPLEMENT */
393 return UMSAudioDevice_set_number_format( this->hidden->umsdev, 413 return UMSAudioDevice_set_number_format (this->hidden->umsdev,
394 this->hidden->ev, 414 this->hidden->ev, fmt);
395 fmt ); 415 }
396 } 416
397 417 static UMSAudioDevice_ReturnCode
398 static UMSAudioDevice_ReturnCode UADInitialize(_THIS) 418 UADInitialize (_THIS)
399 { 419 {
400 return UMSAudioDevice_initialize( this->hidden->umsdev, 420 return UMSAudioDevice_initialize (this->hidden->umsdev, this->hidden->ev);
401 this->hidden->ev ); 421 }
402 } 422
403 423 static UMSAudioDevice_ReturnCode
404 static UMSAudioDevice_ReturnCode UADStart(_THIS) 424 UADStart (_THIS)
405 { 425 {
406 return UMSAudioDevice_start( this->hidden->umsdev, 426 return UMSAudioDevice_start (this->hidden->umsdev, this->hidden->ev);
407 this->hidden->ev ); 427 }
408 } 428
409 429 static UMSAudioDevice_ReturnCode
410 static UMSAudioDevice_ReturnCode UADSetTimeFormat(_THIS, UMSAudioTypes_TimeFormat fmt ) 430 UADSetTimeFormat (_THIS, UMSAudioTypes_TimeFormat fmt)
411 { 431 {
412 /* 432 /*
413 * Switches the time format to the new format, immediately. 433 * Switches the time format to the new format, immediately.
414 * possible UMSAudioTypes_Msecs, UMSAudioTypes_Bytes or UMSAudioTypes_Samples 434 * possible UMSAudioTypes_Msecs, UMSAudioTypes_Bytes or UMSAudioTypes_Samples
415 */ 435 */
416 return UMSAudioDevice_set_time_format( this->hidden->umsdev, 436 return UMSAudioDevice_set_time_format (this->hidden->umsdev,
417 this->hidden->ev, 437 this->hidden->ev, fmt);
418 fmt ); 438 }
419 } 439
420 440 static UMSAudioDevice_ReturnCode
421 static UMSAudioDevice_ReturnCode UADWriteBuffSize(_THIS, long* buff_size ) 441 UADWriteBuffSize (_THIS, long *buff_size)
422 { 442 {
423 /* 443 /*
424 * returns write buffer size in the current time format 444 * returns write buffer size in the current time format
425 */ 445 */
426 return UMSAudioDevice_write_buff_size( this->hidden->umsdev, 446 return UMSAudioDevice_write_buff_size (this->hidden->umsdev,
427 this->hidden->ev, 447 this->hidden->ev, buff_size);
428 buff_size ); 448 }
429 } 449
430 450 static UMSAudioDevice_ReturnCode
431 static UMSAudioDevice_ReturnCode UADWriteBuffRemain(_THIS, long* buff_size ) 451 UADWriteBuffRemain (_THIS, long *buff_size)
432 { 452 {
433 /* 453 /*
434 * returns amount of available space in the write buffer 454 * returns amount of available space in the write buffer
435 * in the current time format 455 * in the current time format
436 */ 456 */
437 return UMSAudioDevice_write_buff_remain( this->hidden->umsdev, 457 return UMSAudioDevice_write_buff_remain (this->hidden->umsdev,
438 this->hidden->ev, 458 this->hidden->ev, buff_size);
439 buff_size ); 459 }
440 } 460
441 461 static UMSAudioDevice_ReturnCode
442 static UMSAudioDevice_ReturnCode UADWriteBuffUsed(_THIS, long* buff_size ) 462 UADWriteBuffUsed (_THIS, long *buff_size)
443 { 463 {
444 /* 464 /*
445 * returns amount of filled space in the write buffer 465 * returns amount of filled space in the write buffer
446 * in the current time format 466 * in the current time format
447 */ 467 */
448 return UMSAudioDevice_write_buff_used( this->hidden->umsdev, 468 return UMSAudioDevice_write_buff_used (this->hidden->umsdev,
449 this->hidden->ev, 469 this->hidden->ev, buff_size);
450 buff_size ); 470 }
451 } 471
452 472 static UMSAudioDevice_ReturnCode
453 static UMSAudioDevice_ReturnCode UADSetDMABufferSize(_THIS, long bytes, long* bytes_ret ) 473 UADSetDMABufferSize (_THIS, long bytes, long *bytes_ret)
454 { 474 {
455 /* 475 /*
456 * Request a new DMA buffer size, maximum requested size 2048. 476 * Request a new DMA buffer size, maximum requested size 2048.
457 * Takes effect with next initialize() call. 477 * Takes effect with next initialize() call.
458 * Devices may or may not support DMA. 478 * Devices may or may not support DMA.
459 */ 479 */
460 return UMSAudioDevice_set_DMA_buffer_size( this->hidden->umsdev, 480 return UMSAudioDevice_set_DMA_buffer_size (this->hidden->umsdev,
461 this->hidden->ev, 481 this->hidden->ev,
462 bytes, 482 bytes, bytes_ret);
463 bytes_ret ); 483 }
464 } 484
465 485 static UMSAudioDevice_ReturnCode
466 static UMSAudioDevice_ReturnCode UADSetVolume(_THIS, long volume ) 486 UADSetVolume (_THIS, long volume)
467 { 487 {
468 /* 488 /*
469 * Set the volume. 489 * Set the volume.
470 * Takes effect immediately. 490 * Takes effect immediately.
471 */ 491 */
472 return UMSAudioDevice_set_volume( this->hidden->umsdev, 492 return UMSAudioDevice_set_volume (this->hidden->umsdev,
473 this->hidden->ev, 493 this->hidden->ev, volume);
474 volume ); 494 }
475 } 495
476 496 static UMSAudioDevice_ReturnCode
477 static UMSAudioDevice_ReturnCode UADSetBalance(_THIS, long balance ) 497 UADSetBalance (_THIS, long balance)
478 { 498 {
479 /* 499 /*
480 * Set the balance. 500 * Set the balance.
481 * Takes effect immediately. 501 * Takes effect immediately.
482 */ 502 */
483 return UMSAudioDevice_set_balance( this->hidden->umsdev, 503 return UMSAudioDevice_set_balance (this->hidden->umsdev,
484 this->hidden->ev, 504 this->hidden->ev, balance);
485 balance ); 505 }
486 } 506
487 507 static UMSAudioDevice_ReturnCode
488 static UMSAudioDevice_ReturnCode UADSetChannels(_THIS, long channels ) 508 UADSetChannels (_THIS, long channels)
489 { 509 {
490 /* 510 /*
491 * Set mono or stereo. 511 * Set mono or stereo.
492 * Takes effect with next initialize() call. 512 * Takes effect with next initialize() call.
493 */ 513 */
494 if ( channels != 1 ) channels = 2; 514 if (channels != 1)
495 return UMSAudioDevice_set_number_of_channels( this->hidden->umsdev, 515 channels = 2;
496 this->hidden->ev, 516 return UMSAudioDevice_set_number_of_channels (this->hidden->umsdev,
497 channels ); 517 this->hidden->ev, channels);
498 } 518 }
499 519
500 static UMSAudioDevice_ReturnCode UADOpen(_THIS, string device, string mode, long flags) 520 static UMSAudioDevice_ReturnCode
501 { 521 UADOpen (_THIS, string device, string mode, long flags)
502 return UMSAudioDevice_open( this->hidden->umsdev, 522 {
503 this->hidden->ev, 523 return UMSAudioDevice_open (this->hidden->umsdev,
504 device, 524 this->hidden->ev, device, mode, flags);
505 mode, 525 }
506 flags ); 526
507 } 527 static UMSAudioDevice_ReturnCode
508 528 UADWrite (_THIS, UMSAudioTypes_Buffer * buff,
509 static UMSAudioDevice_ReturnCode UADWrite(_THIS, UMSAudioTypes_Buffer* buff, 529 long samples, long *samples_written)
510 long samples, 530 {
511 long* samples_written) 531 return UMSAudioDevice_write (this->hidden->umsdev,
512 { 532 this->hidden->ev,
513 return UMSAudioDevice_write( this->hidden->umsdev, 533 buff, samples, samples_written);
514 this->hidden->ev, 534 }
515 buff, 535
516 samples, 536 static UMSAudioDevice_ReturnCode
517 samples_written ); 537 UADPlayRemainingData (_THIS, boolean block)
518 } 538 {
519 539 return UMSAudioDevice_play_remaining_data (this->hidden->umsdev,
520 static UMSAudioDevice_ReturnCode UADPlayRemainingData(_THIS, boolean block ) 540 this->hidden->ev, block);
521 { 541 }
522 return UMSAudioDevice_play_remaining_data( this->hidden->umsdev, 542
523 this->hidden->ev, 543 static UMSAudioDevice_ReturnCode
524 block); 544 UADStop (_THIS)
525 } 545 {
526 546 return UMSAudioDevice_stop (this->hidden->umsdev, this->hidden->ev);
527 static UMSAudioDevice_ReturnCode UADStop(_THIS) 547 }
528 { 548
529 return UMSAudioDevice_stop( this->hidden->umsdev, 549 static UMSAudioDevice_ReturnCode
530 this->hidden->ev ); 550 UADClose (_THIS)
531 } 551 {
532 552 return UMSAudioDevice_close (this->hidden->umsdev, this->hidden->ev);
533 static UMSAudioDevice_ReturnCode UADClose(_THIS) 553 }
534 { 554
535 return UMSAudioDevice_close( this->hidden->umsdev, 555 static UMSAudioDevice_ReturnCode
536 this->hidden->ev ); 556 UADEnableOutput (_THIS, string output, long *left_gain, long *right_gain)
537 } 557 {
538 558 return UMSAudioDevice_enable_output (this->hidden->umsdev,
539 static UMSAudioDevice_ReturnCode UADEnableOutput(_THIS, string output, long* left_gain, long* right_gain) 559 this->hidden->ev,
540 { 560 output, left_gain, right_gain);
541 return UMSAudioDevice_enable_output( this->hidden->umsdev, 561 }
542 this->hidden->ev, 562
543 output, 563 /* vi: set ts=4 sw=4 expandtab: */
544 left_gain,
545 right_gain );
546 }
547