FIX(client): Make PulseAudio always sample at 48000 Hz

A prominent feature of PulseAudio is automatic sample rate management. Mumble always wants 48000 Hz sample rate yet will often tell PulseAudio to sample at a different rate, such as 44100 Hz, and then resample internally reducing audio quality and wasting CPU time.
This commit is contained in:
TredwellGit 2020-09-01 14:33:36 -04:00
parent 0ebe6c1e51
commit aa3d708f53

View File

@ -191,8 +191,7 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) {
pa_channel_map pcm = qhChanMap.value(odev);
if ((pss.format != PA_SAMPLE_FLOAT32NE) && (pss.format != PA_SAMPLE_S16NE))
pss.format = PA_SAMPLE_FLOAT32NE;
if (pss.rate == 0)
pss.rate = SAMPLE_RATE;
pss.rate = SAMPLE_RATE;
if (pss.channels == 0)
pss.channels = 1;
@ -225,7 +224,7 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) {
pa_buffer_attr buff;
const pa_sample_spec *pss = pa_stream_get_sample_spec(pasOutput);
const size_t sampleSize = (pss->format == PA_SAMPLE_FLOAT32NE) ? sizeof(float) : sizeof(short);
const unsigned int iBlockLen = ((pao->iFrameSize * pss->rate) / SAMPLE_RATE) * pss->channels * static_cast<unsigned int>(sampleSize);
const unsigned int iBlockLen = pao->iFrameSize * pss->channels * static_cast<unsigned int>(sampleSize);
buff.tlength = iBlockLen * (g.s.iOutputDelay+1);
buff.minreq = iBlockLen;
buff.maxlength = -1;
@ -257,8 +256,7 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) {
pa_sample_spec pss = qhSpecMap.value(idev);
if ((pss.format != PA_SAMPLE_FLOAT32NE) && (pss.format != PA_SAMPLE_S16NE))
pss.format = PA_SAMPLE_FLOAT32NE;
if (pss.rate == 0)
pss.rate = SAMPLE_RATE;
pss.rate = SAMPLE_RATE;
pss.channels = 1;
pasInput = pa_stream_new(pacContext, "Microphone", &pss, nullptr);
@ -287,7 +285,7 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) {
pa_buffer_attr buff;
const pa_sample_spec *pss = pa_stream_get_sample_spec(pasInput);
const size_t sampleSize = (pss->format == PA_SAMPLE_FLOAT32NE) ? sizeof(float) : sizeof(short);
const unsigned int iBlockLen = ((pai->iFrameSize * pss->rate) / SAMPLE_RATE) * pss->channels * static_cast<unsigned int>(sampleSize);
const unsigned int iBlockLen = pai->iFrameSize * pss->channels * static_cast<unsigned int>(sampleSize);
buff.tlength = iBlockLen;
buff.minreq = iBlockLen;
buff.maxlength = -1;
@ -324,8 +322,7 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) {
pa_channel_map pcm = qhChanMap.value(edev);
if ((pss.format != PA_SAMPLE_FLOAT32NE) && (pss.format != PA_SAMPLE_S16NE))
pss.format = PA_SAMPLE_FLOAT32NE;
if (pss.rate == 0)
pss.rate = SAMPLE_RATE;
pss.rate = SAMPLE_RATE;
if ((pss.channels == 0) || (! g.s.bEchoMulti))
pss.channels = 1;
@ -357,7 +354,7 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) {
pa_buffer_attr buff;
const pa_sample_spec *pss = pa_stream_get_sample_spec(pasSpeaker);
const size_t sampleSize = (pss->format == PA_SAMPLE_FLOAT32NE) ? sizeof(float) : sizeof(short);
const unsigned int iBlockLen = ((pai->iFrameSize * pss->rate) / SAMPLE_RATE) * pss->channels * static_cast<unsigned int>(sampleSize);
const unsigned int iBlockLen = pai->iFrameSize * pss->channels * static_cast<unsigned int>(sampleSize);
buff.tlength = iBlockLen;
buff.minreq = iBlockLen;
buff.maxlength = -1;