From 11e5cb6918811b757a6e69bbf42a902befe363ec Mon Sep 17 00:00:00 2001 From: Iscle Date: Tue, 9 Apr 2024 03:38:01 +0200 Subject: [PATCH] ViPERDDC: Do not spam log when sampling rate is invalid --- src/viper/effects/ViPERDDC.cpp | 14 +++++++++----- src/viper/effects/ViPERDDC.h | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/viper/effects/ViPERDDC.cpp b/src/viper/effects/ViPERDDC.cpp index d59354c..f3d0362 100644 --- a/src/viper/effects/ViPERDDC.cpp +++ b/src/viper/effects/ViPERDDC.cpp @@ -12,6 +12,7 @@ ViPERDDC::ViPERDDC() : void ViPERDDC::Process(float *samples, uint32_t size) { if (!this->setCoeffsOk || this->arrSize == 0) return; if (!this->enable) return; + if (!isSamplingRateValid()) return; std::vector> *coeffsArr; @@ -24,10 +25,6 @@ void ViPERDDC::Process(float *samples, uint32_t size) { coeffsArr = &this->coeffsArr48000; break; } - default: { - VIPER_LOGD("ViPERDDC::Process() -> Invalid sampling rate: %d", this->samplingRate); - return; - } } for (uint32_t i = 0; i < size * 2; i += 2) { @@ -101,7 +98,7 @@ void ViPERDDC::Reset() { memset(this->x1R.data(), 0, this->arrSize * sizeof(float)); } -void ViPERDDC::SetCoeffs(uint32_t newCoeffsSize, float *newCoeffs44100, float *newCoeffs48000) { +void ViPERDDC::SetCoeffs(uint32_t newCoeffsSize, const float *newCoeffs44100, const float *newCoeffs48000) { ReleaseResources(); if (newCoeffsSize == 0) return; @@ -148,6 +145,13 @@ void ViPERDDC::SetEnable(bool enable) { void ViPERDDC::SetSamplingRate(uint32_t samplingRate) { if (this->samplingRate != samplingRate) { this->samplingRate = samplingRate; + if (!isSamplingRateValid()) { + VIPER_LOGE("ViPERDDC::SetSamplingRate() -> Invalid sampling rate: %d", this->samplingRate); + } Reset(); } } + +bool ViPERDDC::isSamplingRateValid() const { + return this->samplingRate == 44100 || this->samplingRate == 48000; +} diff --git a/src/viper/effects/ViPERDDC.h b/src/viper/effects/ViPERDDC.h index 65b9c54..c8d2de0 100644 --- a/src/viper/effects/ViPERDDC.h +++ b/src/viper/effects/ViPERDDC.h @@ -10,7 +10,7 @@ class ViPERDDC { void Process(float *samples, uint32_t size); void Reset(); - void SetCoeffs(uint32_t newCoeffsSize, float *newCoeffs44100, float *newCoeffs48000); + void SetCoeffs(uint32_t newCoeffsSize, const float *newCoeffs44100, const float *newCoeffs48000); void SetEnable(bool enable); void SetSamplingRate(uint32_t samplingRate); @@ -31,6 +31,7 @@ class ViPERDDC { std::vector y2R; void ReleaseResources(); + bool isSamplingRateValid() const; };