mirror of
https://github.com/encounter/SDL.git
synced 2025-12-14 23:56:19 +00:00
cleanup/sync the main loop of *_OpenDevice functions to pick audio format
This commit is contained in:
@@ -547,14 +547,14 @@ static int
|
||||
PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
|
||||
{
|
||||
struct SDL_PrivateAudioData *h = NULL;
|
||||
Uint16 test_format = 0;
|
||||
SDL_AudioFormat test_format;
|
||||
pa_sample_spec paspec;
|
||||
pa_buffer_attr paattr;
|
||||
pa_channel_map pacmap;
|
||||
pa_stream_flags_t flags = 0;
|
||||
const char *name = NULL;
|
||||
SDL_bool iscapture = this->iscapture;
|
||||
int state = 0;
|
||||
int state = 0, format = PA_SAMPLE_INVALID;
|
||||
int rc = 0;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
@@ -565,48 +565,43 @@ PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
|
||||
}
|
||||
SDL_zerop(this->hidden);
|
||||
|
||||
paspec.format = PA_SAMPLE_INVALID;
|
||||
|
||||
/* Try for a closest match on audio format */
|
||||
for (test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
(paspec.format == PA_SAMPLE_INVALID) && test_format;) {
|
||||
for (test_format = SDL_FirstAudioFormat(this->spec.format); test_format; test_format = SDL_NextAudioFormat()) {
|
||||
#ifdef DEBUG_AUDIO
|
||||
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
|
||||
#endif
|
||||
switch (test_format) {
|
||||
case AUDIO_U8:
|
||||
paspec.format = PA_SAMPLE_U8;
|
||||
format = PA_SAMPLE_U8;
|
||||
break;
|
||||
case AUDIO_S16LSB:
|
||||
paspec.format = PA_SAMPLE_S16LE;
|
||||
format = PA_SAMPLE_S16LE;
|
||||
break;
|
||||
case AUDIO_S16MSB:
|
||||
paspec.format = PA_SAMPLE_S16BE;
|
||||
format = PA_SAMPLE_S16BE;
|
||||
break;
|
||||
case AUDIO_S32LSB:
|
||||
paspec.format = PA_SAMPLE_S32LE;
|
||||
format = PA_SAMPLE_S32LE;
|
||||
break;
|
||||
case AUDIO_S32MSB:
|
||||
paspec.format = PA_SAMPLE_S32BE;
|
||||
format = PA_SAMPLE_S32BE;
|
||||
break;
|
||||
case AUDIO_F32LSB:
|
||||
paspec.format = PA_SAMPLE_FLOAT32LE;
|
||||
format = PA_SAMPLE_FLOAT32LE;
|
||||
break;
|
||||
case AUDIO_F32MSB:
|
||||
paspec.format = PA_SAMPLE_FLOAT32BE;
|
||||
format = PA_SAMPLE_FLOAT32BE;
|
||||
break;
|
||||
default:
|
||||
paspec.format = PA_SAMPLE_INVALID;
|
||||
break;
|
||||
}
|
||||
if (paspec.format == PA_SAMPLE_INVALID) {
|
||||
test_format = SDL_NextAudioFormat();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (paspec.format == PA_SAMPLE_INVALID) {
|
||||
return SDL_SetError("Couldn't find any hardware audio formats");
|
||||
if (!test_format) {
|
||||
return SDL_SetError("%s: Unsupported audio format", "pulseaudio");
|
||||
}
|
||||
this->spec.format = test_format;
|
||||
paspec.format = format;
|
||||
|
||||
/* Calculate the final parameters for this audio specification */
|
||||
#ifdef PA_STREAM_ADJUST_LATENCY
|
||||
|
||||
Reference in New Issue
Block a user