Mercurial > sdl-ios-xcode
comparison src/audio/openbsd/SDL_openbsdaudio.c @ 131:5d08b230932e
Fixed audio format selection for OpenBSD (thanks Peter!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 31 Jul 2001 05:39:36 +0000 |
parents | 43febd46d49d |
children | e8157fcb3114 |
comparison
equal
deleted
inserted
replaced
130:14af14ff7c19 | 131:5d08b230932e |
---|---|
310 | 310 |
311 static int | 311 static int |
312 OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec) | 312 OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec) |
313 { | 313 { |
314 char audiodev[64]; | 314 char audiodev[64]; |
315 Uint16 setenc; | 315 Uint16 format; |
316 audio_encoding_t enc; | |
317 audio_info_t info; | 316 audio_info_t info; |
318 | 317 |
319 AUDIO_INITINFO(&info); | 318 AUDIO_INITINFO(&info); |
320 | 319 |
321 /* Calculate the final parameters for this audio specification */ | 320 /* Calculate the final parameters for this audio specification */ |
338 SDL_SetError("Couldn't put device into play mode"); | 337 SDL_SetError("Couldn't put device into play mode"); |
339 return(-1); | 338 return(-1); |
340 } | 339 } |
341 | 340 |
342 mixbuf = NULL; | 341 mixbuf = NULL; |
343 setenc = 0; | 342 AUDIO_INITINFO(&info); |
344 | 343 for (format = SDL_FirstAudioFormat(spec->format); |
345 for(enc.index = 0; (ioctl(audio_fd, AUDIO_GETENC, &enc)>=0) | 344 format; format = SDL_NextAudioFormat()) |
346 && (enc.encoding != setenc); enc.index++) | |
347 { | 345 { |
348 switch(spec->format) | 346 switch(format) { |
349 { | 347 case AUDIO_U8: |
350 case AUDIO_U8: /* 8-bit unsigned linear */ | 348 info.play.encoding = AUDIO_ENCODING_ULINEAR; |
351 setenc = AUDIO_ENCODING_PCM8; | 349 info.play.precision = 8; |
352 break; | 350 break; |
353 case AUDIO_S8: /* 8-bit signed linear */ | 351 case AUDIO_S8: |
354 setenc = AUDIO_ENCODING_SLINEAR; | 352 info.play.encoding = AUDIO_ENCODING_SLINEAR; |
355 break; | 353 info.play.precision = 8; |
356 case AUDIO_U16LSB: /* 16-bit unsigned linear, LSB */ | 354 break; |
357 setenc = AUDIO_ENCODING_ULINEAR_LE; | 355 case AUDIO_S16LSB: |
358 break; | 356 info.play.encoding = AUDIO_ENCODING_SLINEAR_LE; |
359 case AUDIO_U16MSB: /* 16-bit unsigned linear, MSB */ | 357 info.play.precision = 16; |
360 setenc = AUDIO_ENCODING_ULINEAR_BE; | 358 break; |
361 break; | 359 case AUDIO_S16MSB: |
362 case AUDIO_S16LSB: /* 16-bit signed linear, LSB */ | 360 info.play.encoding = AUDIO_ENCODING_SLINEAR_BE; |
363 setenc = AUDIO_ENCODING_SLINEAR_LE; | 361 info.play.precision = 16; |
364 break; | 362 break; |
365 case AUDIO_S16MSB: /* 16-bit signed linear, MSB */ | 363 case AUDIO_U16LSB: |
366 setenc = AUDIO_ENCODING_SLINEAR_BE; | 364 info.play.encoding = AUDIO_ENCODING_ULINEAR_LE; |
367 break; | 365 info.play.precision = 16; |
366 break; | |
367 case AUDIO_U16MSB: | |
368 info.play.encoding = AUDIO_ENCODING_ULINEAR_BE; | |
369 info.play.precision = 16; | |
370 break; | |
371 default: | |
372 continue; | |
368 } | 373 } |
369 #ifdef DEBUG_AUDIO | 374 if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0) |
370 fprintf(stderr,"encoding #%i: \"%s\" %i-bit (0x%x) flags=%i...\n", | 375 break; |
371 enc.index, enc.name, enc.precision, enc.encoding, enc.flags); | 376 } |
372 #endif | 377 |
373 } | 378 if(!format) { |
374 | |
375 if(!setenc) { | |
376 SDL_SetError("No supported encoding for 0x%x", spec->format); | 379 SDL_SetError("No supported encoding for 0x%x", spec->format); |
377 return(-1); | 380 return(-1); |
378 } | 381 } |
379 | 382 |
380 /* Set audio encoding */ | 383 spec->format = format; |
381 info.play.encoding = enc.encoding; | 384 |
382 info.play.precision = enc.precision; | 385 AUDIO_INITINFO(&info); |
383 if((ioctl(audio_fd, AUDIO_SETINFO, &info) < 0)) { | |
384 SDL_SetError("Couldn't set encoding to 0x%x %i-bit", | |
385 enc.encoding, enc.precision); | |
386 return(-1); | |
387 } | |
388 | |
389 /* Set audio channels */ | |
390 info.play.channels = spec->channels; | 386 info.play.channels = spec->channels; |
391 if(ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) { | 387 if (ioctl(audio_fd, AUDIO_SETINFO, &info) == -1) |
392 info.play.channels = (spec->channels > 1); | 388 spec->channels = 1; |
393 ioctl(audio_fd, AUDIO_SETINFO, &info); | 389 AUDIO_INITINFO(&info); |
394 } | |
395 | |
396 /* Set the sample rate */ | |
397 info.play.sample_rate = spec->freq; | 390 info.play.sample_rate = spec->freq; |
398 if(ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) { | 391 (void)ioctl(audio_fd, AUDIO_SETINFO, &info); |
399 SDL_SetError("Couldn't set sample rate to %i Hz", spec->freq); | 392 (void)ioctl(audio_fd, AUDIO_GETINFO, &info); |
400 return(-1); | 393 spec->freq = info.play.sample_rate; |
401 } | |
402 | |
403 /* Allocate mixing buffer */ | 394 /* Allocate mixing buffer */ |
404 mixlen = spec->size; | 395 mixlen = spec->size; |
405 mixbuf = (Uint8*)SDL_AllocAudioMem(mixlen); | 396 mixbuf = (Uint8*)SDL_AllocAudioMem(mixlen); |
406 if(mixbuf == NULL) { | 397 if(mixbuf == NULL) { |
407 return(-1); | 398 return(-1); |