diff --git a/src/ViPER4Android.cpp b/src/ViPER4Android.cpp index d3a917b..e2bac23 100644 --- a/src/ViPER4Android.cpp +++ b/src/ViPER4Android.cpp @@ -184,7 +184,7 @@ static int32_t handleGetParam(ViperContext *pContext, effect_param_t *pCmdParam, struct timeval time{}; gettimeofday(&time, nullptr); - uint64_t currentMs = (time.tv_sec * 1000) + (time.tv_usec / 1000); + uint64_t currentMs = (uint64_t) (time.tv_sec * 1000) + (uint64_t) (time.tv_usec / 1000); uint64_t lastProcessTime = pContext->viper->processTimeMs; uint64_t diff; diff --git a/src/viper/ViPER.cpp b/src/viper/ViPER.cpp index e13ea87..99e1f37 100644 --- a/src/viper/ViPER.cpp +++ b/src/viper/ViPER.cpp @@ -148,7 +148,7 @@ void ViPER::processBuffer(float *buffer, uint32_t size) { if (this->updateProcessTime) { struct timeval time{}; gettimeofday(&time, nullptr); - this->processTimeMs = time.tv_sec * 1000 + time.tv_usec / 1000; + this->processTimeMs = (uint64_t) (time.tv_sec * 1000) + (uint64_t) (time.tv_usec / 1000); } uint32_t ret; diff --git a/src/viper/effects/VHE.h b/src/viper/effects/VHE.h index c338618..f547314 100644 --- a/src/viper/effects/VHE.h +++ b/src/viper/effects/VHE.h @@ -21,7 +21,7 @@ public: uint32_t samplingRate; bool enabled; int effectLevel; - int convSize; + uint32_t convSize; }; diff --git a/src/viper/effects/ViPERDDC.cpp b/src/viper/effects/ViPERDDC.cpp index 0ff2b00..0fada82 100644 --- a/src/viper/effects/ViPERDDC.cpp +++ b/src/viper/effects/ViPERDDC.cpp @@ -1,33 +1,140 @@ #include "ViPERDDC.h" +#include "../../log.h" +#include ViPERDDC::ViPERDDC() { - + this->enable = false; + this->samplingRate = 44100; + this->setCoeffsOk = false; + this->arrSize = 0; + this->arrPtr44100 = nullptr; + this->arrPtr48000 = nullptr; + this->arr4 = nullptr; + this->arr3 = nullptr; + this->arr2 = nullptr; + this->arr1 = nullptr; + this->arr8 = nullptr; + this->arr7 = nullptr; + this->arr6 = nullptr; + this->arr5 = nullptr; } ViPERDDC::~ViPERDDC() { - + ReleaseResources(); } void ViPERDDC::Process(float *samples, uint32_t size) { + if (!this->setCoeffsOk) return; + if (!this->enable) return; + switch (this->samplingRate) { + case 44100: { + break; + } + case 48000: { + break; + } + default: { + VIPER_LOGD("ViPERDDC::Process() -> Invalid sampling rate: %d", this->samplingRate); + } + } } void ViPERDDC::ReleaseResources() { + for (uint32_t i = 0; i < this->arrSize; i++) { + delete[] this->arrPtr44100[i]; + delete[] this->arrPtr48000[i]; + } + delete[] this->arrPtr44100; + this->arrPtr44100 = nullptr; + + delete[] this->arrPtr48000; + this->arrPtr48000 = nullptr; + + delete[] this->arr1; + this->arr1 = nullptr; + + delete[] this->arr2; + this->arr2 = nullptr; + + delete[] this->arr3; + this->arr3 = nullptr; + + delete[] this->arr4; + this->arr4 = nullptr; + + delete[] this->arr5; + this->arr5 = nullptr; + + delete[] this->arr6; + this->arr6 = nullptr; + + delete[] this->arr7; + this->arr7 = nullptr; + + delete[] this->arr8; + this->arr8 = nullptr; + + this->setCoeffsOk = false; } void ViPERDDC::Reset() { + if (!this->setCoeffsOk) return; + if (this->arrSize == 0) return; + memset(this->arr1, 0, this->arrSize * 4); + memset(this->arr2, 0, this->arrSize * 4); } -void ViPERDDC::SetCoeffs() { +void ViPERDDC::SetCoeffs(uint32_t param_1, float *param_2, float *param_3) { + ReleaseResources(); + if (param_1 == 0) return; + + this->arrSize = param_1 / 5; + this->arrPtr44100 = new float *[this->arrSize](); + this->arrPtr48000 = new float *[this->arrSize](); + + for (uint32_t i = 0; i < this->arrSize; i++) { + this->arrPtr44100[i] = new float[5]; + this->arrPtr44100[i][0] = param_2[i * 5]; + this->arrPtr44100[i][1] = param_2[i * 5 + 1]; + this->arrPtr44100[i][2] = param_2[i * 5 + 2]; + this->arrPtr44100[i][3] = param_2[i * 5 + 3]; + this->arrPtr44100[i][4] = param_2[i * 5 + 4]; + + this->arrPtr48000[i] = new float[5]; + this->arrPtr48000[i][0] = param_3[i * 5]; + this->arrPtr48000[i][1] = param_3[i * 5 + 1]; + this->arrPtr48000[i][2] = param_3[i * 5 + 2]; + this->arrPtr48000[i][3] = param_3[i * 5 + 3]; + this->arrPtr48000[i][4] = param_3[i * 5 + 4]; + } + + this->arr1 = new float[this->arrSize](); + this->arr2 = new float[this->arrSize](); + this->arr3 = new float[this->arrSize](); + this->arr4 = new float[this->arrSize](); + this->arr5 = new float[this->arrSize](); + this->arr6 = new float[this->arrSize](); + this->arr7 = new float[this->arrSize](); + this->arr8 = new float[this->arrSize](); + this->setCoeffsOk = true; } void ViPERDDC::SetEnable(bool enable) { - + if (this->enable != enable) { + this->enable = enable; + if (enable) { + Reset(); + } + } } void ViPERDDC::SetSamplingRate(uint32_t samplingRate) { - + if (this->samplingRate != samplingRate) { + this->samplingRate = samplingRate; + Reset(); + } } diff --git a/src/viper/effects/ViPERDDC.h b/src/viper/effects/ViPERDDC.h index 98edd5f..31ecb29 100644 --- a/src/viper/effects/ViPERDDC.h +++ b/src/viper/effects/ViPERDDC.h @@ -10,9 +10,25 @@ public: void Process(float *samples, uint32_t size); void ReleaseResources(); void Reset(); - void SetCoeffs(); + void SetCoeffs(uint32_t param_1, float *param_2, float *param_3); void SetEnable(bool enable); void SetSamplingRate(uint32_t samplingRate); + +private: + bool enable; + bool setCoeffsOk; + uint32_t samplingRate; + uint32_t arrSize; + float **arrPtr44100; + float **arrPtr48000; + float *arr1; + float *arr2; + float *arr3; + float *arr4; + float *arr5; + float *arr6; + float *arr7; + float *arr8; }; diff --git a/src/viper/utils/NoiseSharpening.h b/src/viper/utils/NoiseSharpening.h index 21c3537..5af4752 100644 --- a/src/viper/utils/NoiseSharpening.h +++ b/src/viper/utils/NoiseSharpening.h @@ -17,7 +17,7 @@ public: IIR_1st filters[2]; float in[2]; - int32_t samplingRate; + uint32_t samplingRate; float gain; }; diff --git a/src/viper/utils/TimeConstDelay.cpp b/src/viper/utils/TimeConstDelay.cpp index ec23189..27fb944 100644 --- a/src/viper/utils/TimeConstDelay.cpp +++ b/src/viper/utils/TimeConstDelay.cpp @@ -15,7 +15,7 @@ float TimeConstDelay::ProcessSample(float sample) { if (this->samples != nullptr) { float val = this->samples[this->offset]; this->samples[this->offset] = sample; - this->offset = (int) modf((float) this->offset + 1, (float *) &this->sampleCount); // TODO: check if this is correct + this->offset = (uint32_t) modf((float) this->offset + 1, (float *) &this->sampleCount); // TODO: check if this is correct return val; } return 0.0;