From f2a36d4cbbaf399370e71fa487dadaf46ebfd3cb Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Wed, 2 Jun 2021 12:08:48 +0100 Subject: [PATCH] Force 48K sample rate when 44100 is detected. --- audiohandler.cpp | 15 +++++++++++---- audiohandler.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/audiohandler.cpp b/audiohandler.cpp index 0fbb3b3..9a8aaec 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -114,11 +114,18 @@ bool audioHandler::init(const quint8 bits, const quint8 radioChan, const quint16 } int resample_error = 0; + if (info.preferredSampleRate == 44100) { + qDebug(logAudio()) << "Preferred sample rate 44100, trying 48000"; + this->nativeSampleRate = 48000; + } + else { + this->nativeSampleRate = info.preferredSampleRate; + } if (isInput) { - resampler = wf_resampler_init(devChannels, info.preferredSampleRate, samplerate, resampleQuality, &resample_error); + resampler = wf_resampler_init(devChannels, this->nativeSampleRate, samplerate, resampleQuality, &resample_error); try { - audio.openStream(NULL, &aParams, RTAUDIO_SINT16, info.preferredSampleRate, &this->chunkSize, &staticWrite, this); + audio.openStream(NULL, &aParams, RTAUDIO_SINT16, this->nativeSampleRate, &this->chunkSize, &staticWrite, this); audio.startStream(); } catch (RtAudioError& e) { @@ -128,9 +135,9 @@ bool audioHandler::init(const quint8 bits, const quint8 radioChan, const quint16 } else { - resampler = wf_resampler_init(devChannels, samplerate, info.preferredSampleRate, resampleQuality, &resample_error); + resampler = wf_resampler_init(devChannels, samplerate, this->nativeSampleRate, resampleQuality, &resample_error); try { - audio.openStream(&aParams, NULL, RTAUDIO_SINT16, info.preferredSampleRate, &this->chunkSize, &staticRead, this); + audio.openStream(&aParams, NULL, RTAUDIO_SINT16, this->nativeSampleRate, &this->chunkSize, &staticRead, this); audio.startStream(); } catch (RtAudioError& e) { diff --git a/audiohandler.h b/audiohandler.h index d978644..7586a50 100644 --- a/audiohandler.h +++ b/audiohandler.h @@ -96,6 +96,7 @@ private: quint32 lastSeq; quint16 radioSampleRate; + quint16 nativeSampleRate=0; quint8 radioSampleBits; quint8 radioChannels;