From 42dfefbb0e2d9564e977d392a651184b1ac8d490 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 4 May 2019 22:11:29 -0700 Subject: Fix when PulseAudio channel configuration changes --- Alc/backends/pulseaudio.cpp | 101 +++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 52 deletions(-) (limited to 'Alc/backends') diff --git a/Alc/backends/pulseaudio.cpp b/Alc/backends/pulseaudio.cpp index c640b293..d8e1c267 100644 --- a/Alc/backends/pulseaudio.cpp +++ b/Alc/backends/pulseaudio.cpp @@ -846,36 +846,6 @@ ALCboolean PulsePlayback::reset() !(mDevice->Flags&DEVICE_FREQUENCY_REQUEST)) flags |= PA_STREAM_FIX_RATE; - switch(mDevice->FmtType) - { - case DevFmtByte: - mDevice->FmtType = DevFmtUByte; - /* fall-through */ - case DevFmtUByte: - mSpec.format = PA_SAMPLE_U8; - break; - case DevFmtUShort: - mDevice->FmtType = DevFmtShort; - /* fall-through */ - case DevFmtShort: - mSpec.format = PA_SAMPLE_S16NE; - break; - case DevFmtUInt: - mDevice->FmtType = DevFmtInt; - /* fall-through */ - case DevFmtInt: - mSpec.format = PA_SAMPLE_S32NE; - break; - case DevFmtFloat: - mSpec.format = PA_SAMPLE_FLOAT32NE; - break; - } - mSpec.rate = mDevice->Frequency; - mSpec.channels = mDevice->channelsFromFmt(); - - if(pa_sample_spec_valid(&mSpec) == 0) - throw al::backend_exception{ALC_INVALID_VALUE, "Invalid sample spec"}; - pa_channel_map chanmap{}; switch(mDevice->FmtChans) { @@ -906,6 +876,35 @@ ALCboolean PulsePlayback::reset() } SetDefaultWFXChannelOrder(mDevice); + switch(mDevice->FmtType) + { + case DevFmtByte: + mDevice->FmtType = DevFmtUByte; + /* fall-through */ + case DevFmtUByte: + mSpec.format = PA_SAMPLE_U8; + break; + case DevFmtUShort: + mDevice->FmtType = DevFmtShort; + /* fall-through */ + case DevFmtShort: + mSpec.format = PA_SAMPLE_S16NE; + break; + case DevFmtUInt: + mDevice->FmtType = DevFmtInt; + /* fall-through */ + case DevFmtInt: + mSpec.format = PA_SAMPLE_S32NE; + break; + case DevFmtFloat: + mSpec.format = PA_SAMPLE_FLOAT32NE; + break; + } + mSpec.rate = mDevice->Frequency; + mSpec.channels = mDevice->channelsFromFmt(); + if(pa_sample_spec_valid(&mSpec) == 0) + throw al::backend_exception{ALC_INVALID_VALUE, "Invalid sample spec"}; + mAttr.maxlength = -1; mAttr.tlength = mDevice->BufferSize * pa_frame_size(&mSpec); mAttr.prebuf = 0; @@ -1149,27 +1148,6 @@ ALCenum PulseCapture::open(const ALCchar *name) mContext = connect_context(plock); pa_context_set_state_callback(mContext, &PulseCapture::contextStateCallbackC, this); - switch(mDevice->FmtType) - { - case DevFmtUByte: - mSpec.format = PA_SAMPLE_U8; - break; - case DevFmtShort: - mSpec.format = PA_SAMPLE_S16NE; - break; - case DevFmtInt: - mSpec.format = PA_SAMPLE_S32NE; - break; - case DevFmtFloat: - mSpec.format = PA_SAMPLE_FLOAT32NE; - break; - case DevFmtByte: - case DevFmtUShort: - case DevFmtUInt: - throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", - DevFmtTypeString(mDevice->FmtType)}; - } - pa_channel_map chanmap{}; switch(mDevice->FmtChans) { @@ -1199,9 +1177,28 @@ ALCenum PulseCapture::open(const ALCchar *name) DevFmtChannelsString(mDevice->FmtChans)}; } + switch(mDevice->FmtType) + { + case DevFmtUByte: + mSpec.format = PA_SAMPLE_U8; + break; + case DevFmtShort: + mSpec.format = PA_SAMPLE_S16NE; + break; + case DevFmtInt: + mSpec.format = PA_SAMPLE_S32NE; + break; + case DevFmtFloat: + mSpec.format = PA_SAMPLE_FLOAT32NE; + break; + case DevFmtByte: + case DevFmtUShort: + case DevFmtUInt: + throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", + DevFmtTypeString(mDevice->FmtType)}; + } mSpec.rate = mDevice->Frequency; mSpec.channels = mDevice->channelsFromFmt(); - if(pa_sample_spec_valid(&mSpec) == 0) throw al::backend_exception{ALC_INVALID_VALUE, "Invalid sample format"}; -- cgit v1.2.3