From 40339a15cd926d4ba0454b17ba3608fc9d1f7b1c Mon Sep 17 00:00:00 2001 From: Iscle Date: Fri, 16 Sep 2022 03:16:58 +0200 Subject: [PATCH] Update --- CMakeLists.txt | 3 ++ src/cpp/viper/ViPER.cpp | 20 +++++------ src/cpp/viper/ViPER.h | 6 ++-- src/cpp/viper/effects/AnalogX.cpp | 12 +++---- src/cpp/viper/effects/AnalogX.h | 1 + src/cpp/viper/effects/ColorfulMusic.cpp | 38 ++++++++++++++------ src/cpp/viper/effects/ColorfulMusic.h | 15 ++++++-- src/cpp/viper/effects/Cure.cpp | 9 +++-- src/cpp/viper/effects/DiffSurround.cpp | 46 +++++++++++++----------- src/cpp/viper/effects/DiffSurround.h | 2 +- src/cpp/viper/effects/DynamicSystem.cpp | 13 +++++-- src/cpp/viper/effects/ViPERBass.cpp | 24 ++++++++++--- src/cpp/viper/effects/ViPERBass.h | 23 ++++++++++-- src/cpp/viper/effects/ViPERClarity.cpp | 4 --- src/cpp/viper/utils/AdaptiveBuffer.cpp | 20 +++++------ src/cpp/viper/utils/AdaptiveBuffer.h | 10 +++--- src/cpp/viper/utils/CAllpassFilter.cpp | 14 +++----- src/cpp/viper/utils/CAllpassFilter.h | 13 ++----- src/cpp/viper/utils/CCombFilter.cpp | 38 +++++++++----------- src/cpp/viper/utils/CCombFilter.h | 13 +++---- src/cpp/viper/utils/DepthSurround.cpp | 24 +++++++------ src/cpp/viper/utils/FIR.cpp | 35 ++++++++++++++++++ src/cpp/viper/utils/FIR.h | 26 ++++++++++++++ src/cpp/viper/utils/HiFi.cpp | 4 --- src/cpp/viper/utils/HiFi.h | 4 --- src/cpp/viper/utils/MultiBiquad.cpp | 2 -- src/cpp/viper/utils/Polyphase.cpp | 26 ++++++++++++++ src/cpp/viper/utils/Polyphase.h | 28 +++++++++++++++ src/cpp/viper/utils/Stereo3DSurround.cpp | 22 ++++++++++++ src/cpp/viper/utils/Stereo3DSurround.h | 22 ++++++++++++ src/cpp/viper/utils/WaveBuffer_I32.cpp | 4 --- src/cpp/viper/utils/WaveBuffer_I32.h | 4 --- 32 files changed, 363 insertions(+), 162 deletions(-) create mode 100644 src/cpp/viper/utils/FIR.cpp create mode 100644 src/cpp/viper/utils/FIR.h create mode 100644 src/cpp/viper/utils/Polyphase.cpp create mode 100644 src/cpp/viper/utils/Polyphase.h create mode 100644 src/cpp/viper/utils/Stereo3DSurround.cpp create mode 100644 src/cpp/viper/utils/Stereo3DSurround.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4582119..9d2b973 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ set(FILES src/cpp/viper/utils/Crossfeed.cpp src/cpp/viper/utils/DepthSurround.cpp src/cpp/viper/utils/DynamicBass.cpp + src/cpp/viper/utils/FIR.cpp src/cpp/viper/utils/FixedBiquad.cpp src/cpp/viper/utils/Harmonic.cpp src/cpp/viper/utils/HiFi.cpp @@ -62,6 +63,8 @@ set(FILES src/cpp/viper/utils/PassFilter.cpp src/cpp/viper/utils/PConvSingle_F32.cpp src/cpp/viper/utils/PolesFilter.cpp + src/cpp/viper/utils/Polyphase.cpp + src/cpp/viper/utils/Stereo3DSurround.cpp src/cpp/viper/utils/Subwoofer.cpp src/cpp/viper/utils/TimeConstDelay.cpp src/cpp/viper/utils/WaveBuffer_I32.cpp) diff --git a/src/cpp/viper/ViPER.cpp b/src/cpp/viper/ViPER.cpp index 1335eeb..28b1ea1 100644 --- a/src/cpp/viper/ViPER.cpp +++ b/src/cpp/viper/ViPER.cpp @@ -87,7 +87,7 @@ ViPER::ViPER() { this->tubeSimulator->Reset(); this->analogX = new AnalogX(); - this->analogX->enabled = false; //SetEnable(false); +// this->analogX->SetEnable(false); this->analogX->SetSamplingRate(this->sampleRate); this->analogX->SetProcessingModel(0); this->analogX->Reset(); @@ -104,10 +104,10 @@ ViPER::ViPER() { this->fetcomp_enabled = false; this->init_ok = true; - this->scale_frames_if_not_1point0 = 1.0; - this->pan_frames_if_less_than_1point0 = 1.0; + this->frame_scale = 1.0; + this->left_pan = 1.0; this->process_time_ms = 0; - this->pan_frames_if_less_than_1point0_2 = 1.0; + this->right_pan = 1.0; this->enabled = false; this->force_enabled = false; this->update_status = false; @@ -171,7 +171,7 @@ ViPER::~ViPER() { delete this->speakerCorrection; this->speakerCorrection = nullptr; - for (auto &softwareLimiter: softwareLimiters) { + for (auto &softwareLimiter: this->softwareLimiters) { delete softwareLimiter; softwareLimiter = nullptr; } @@ -322,7 +322,7 @@ void ViPER::processBuffer(float *buffer, int frameSize) { this->process_time_ms = time.tv_sec * 1000 + time.tv_usec / 1000; } - int ret; + uint32_t ret; // if convolver is enabled ret = this->waveBuffer->PushSamples(buffer, frameSize); @@ -366,11 +366,11 @@ void ViPER::processBuffer(float *buffer, int frameSize) { this->analogX->Process(pAdaptiveBuffer, ret); } - if (this->scale_frames_if_not_1point0 != 1.0) { - this->adaptiveBuffer->ScaleFrames(this->scale_frames_if_not_1point0); + if (this->frame_scale != 1.0) { + this->adaptiveBuffer->ScaleFrames(this->frame_scale); } - if (this->pan_frames_if_less_than_1point0 < 1.0 || this->pan_frames_if_less_than_1point0_2 < 1.0) { - this->adaptiveBuffer->PanFrames(this->pan_frames_if_less_than_1point0, this->pan_frames_if_less_than_1point0_2); + if (this->left_pan < 1.0 || this->right_pan < 1.0) { + this->adaptiveBuffer->PanFrames(this->left_pan, this->right_pan); } if (ret << 1 != 0) { diff --git a/src/cpp/viper/ViPER.h b/src/cpp/viper/ViPER.h index bac7c52..a26df3a 100644 --- a/src/cpp/viper/ViPER.h +++ b/src/cpp/viper/ViPER.h @@ -73,7 +73,7 @@ public: SpeakerCorrection *speakerCorrection; SoftwareLimiter *softwareLimiters[2]; - float scale_frames_if_not_1point0; - float pan_frames_if_less_than_1point0; - float pan_frames_if_less_than_1point0_2; + float frame_scale; + float left_pan; + float right_pan; }; diff --git a/src/cpp/viper/effects/AnalogX.cpp b/src/cpp/viper/effects/AnalogX.cpp index e290f7c..9bfada6 100644 --- a/src/cpp/viper/effects/AnalogX.cpp +++ b/src/cpp/viper/effects/AnalogX.cpp @@ -7,12 +7,12 @@ static float ANALOGX_HARMONICS[10] = { 0.02f, 0.0001f, 0.001f, - 0.f, - 0.f, - 0.f, - 0.f, - 0.f, - 0.f + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f }; AnalogX::AnalogX() { diff --git a/src/cpp/viper/effects/AnalogX.h b/src/cpp/viper/effects/AnalogX.h index fb7e09f..4124a29 100644 --- a/src/cpp/viper/effects/AnalogX.h +++ b/src/cpp/viper/effects/AnalogX.h @@ -14,6 +14,7 @@ public: void SetProcessingModel(int processingModel); void SetSamplingRate(uint32_t samplingRate); +private: MultiBiquad highpass[2]; Harmonic harmonic[2]; MultiBiquad lowpass[2]; diff --git a/src/cpp/viper/effects/ColorfulMusic.cpp b/src/cpp/viper/effects/ColorfulMusic.cpp index e02aff7..4bada30 100644 --- a/src/cpp/viper/effects/ColorfulMusic.cpp +++ b/src/cpp/viper/effects/ColorfulMusic.cpp @@ -1,7 +1,12 @@ #include "ColorfulMusic.h" +#include "../constants.h" ColorfulMusic::ColorfulMusic() { - + this->samplingRate = DEFAULT_SAMPLERATE; + this->enabled = false; + this->stereo3DSurround->SetStereoWiden(0.0f); + this->depthSurround->SetSamplingRate(this->samplingRate); + this->depthSurround->SetStrength(0); } ColorfulMusic::~ColorfulMusic() { @@ -9,29 +14,42 @@ ColorfulMusic::~ColorfulMusic() { } void ColorfulMusic::Process(float *samples, uint32_t size) { + if (!this->enabled) { + return; + } + this->depthSurround->Process(samples, size); + this->stereo3DSurround->Process(samples, size); } void ColorfulMusic::Reset() { - + this->depthSurround->SetSamplingRate(this->samplingRate); } -void ColorfulMusic::SetDepthValue() { - +void ColorfulMusic::SetDepthValue(short depthValue) { + this->depthSurround->SetStrength(depthValue); } void ColorfulMusic::SetEnable(bool enable) { - + if (this->enabled != enable) { + this->enabled = enable; + if (enable) { + Reset(); + } + } } -void ColorfulMusic::SetMidImageValue() { - +void ColorfulMusic::SetMidImageValue(float midImageValue) { + this->stereo3DSurround->SetMiddleImage(midImageValue); } void ColorfulMusic::SetSamplingRate(uint32_t samplingRate) { - + if (this->samplingRate != samplingRate) { + this->samplingRate = samplingRate; + this->depthSurround->SetSamplingRate(this->samplingRate); + } } -void ColorfulMusic::SetWidenValue() { - +void ColorfulMusic::SetWidenValue(float widenValue) { + this->stereo3DSurround->SetStereoWiden(widenValue); } diff --git a/src/cpp/viper/effects/ColorfulMusic.h b/src/cpp/viper/effects/ColorfulMusic.h index 156be50..3a25cc5 100644 --- a/src/cpp/viper/effects/ColorfulMusic.h +++ b/src/cpp/viper/effects/ColorfulMusic.h @@ -1,6 +1,8 @@ #pragma once #include +#include "../utils/Stereo3DSurround.h" +#include "../utils/DepthSurround.h" class ColorfulMusic { public: @@ -9,11 +11,18 @@ public: void Process(float *samples, uint32_t size); void Reset(); - void SetDepthValue(); + void SetDepthValue(short depthValue); void SetEnable(bool enable); - void SetMidImageValue(); + void SetMidImageValue(float midImageValue); void SetSamplingRate(uint32_t samplingRate); - void SetWidenValue(); + void SetWidenValue(float widenValue); + +private: + Stereo3DSurround *stereo3DSurround; + DepthSurround *depthSurround; + uint32_t samplingRate; + bool enabled; + }; diff --git a/src/cpp/viper/effects/Cure.cpp b/src/cpp/viper/effects/Cure.cpp index 758665c..6f7df3e 100644 --- a/src/cpp/viper/effects/Cure.cpp +++ b/src/cpp/viper/effects/Cure.cpp @@ -26,8 +26,12 @@ void Cure::Reset() { } void Cure::SetEnable(bool enabled) { - Reset(); - this->enabled = enabled; + if (this->enabled != enabled) { + this->enabled = enabled; + if (enabled) { + Reset(); + } + } } void Cure::SetSamplingRate(uint32_t samplerate) { @@ -53,7 +57,6 @@ preset_t Cure::GetPreset() { void Cure::SetCutoff(uint16_t cutoff) { this->crossfeed.SetCutoff(cutoff); - } void Cure::SetFeedback(float feedback) { diff --git a/src/cpp/viper/effects/DiffSurround.cpp b/src/cpp/viper/effects/DiffSurround.cpp index e044999..44c6dd1 100644 --- a/src/cpp/viper/effects/DiffSurround.cpp +++ b/src/cpp/viper/effects/DiffSurround.cpp @@ -1,22 +1,21 @@ -// -// Created by mart on 7/31/21. -// - #include #include "DiffSurround.h" #include "../constants.h" DiffSurround::DiffSurround() { this->samplerate = DEFAULT_SAMPLERATE; - this->delayTime = 0.f; + this->delayTime = 0.0f; this->enabled = false; - this->buffers[0] = new WaveBuffer_I32(1, 0x1000); - this->buffers[1] = new WaveBuffer_I32(1, 0x1000); + for (auto &buffer : this->buffers) { + buffer = new WaveBuffer_I32(1, 0x1000); + } } DiffSurround::~DiffSurround() { - delete this->buffers[0]; - delete this->buffers[1]; + for (auto &buffer : this->buffers) { + delete buffer; + buffer = nullptr; + } } void DiffSurround::Process(float *samples, uint32_t size) { @@ -44,25 +43,32 @@ void DiffSurround::Process(float *samples, uint32_t size) { } void DiffSurround::Reset() { - this->buffers[0]->Reset(); - this->buffers[1]->Reset(); + for (auto &buffer : this->buffers) { + buffer->Reset(); + } - this->buffers[1]->PushZeros((uint32_t) (this->delayTime / 1000.f * (float) this->samplerate)); + this->buffers[1]->PushZeros((uint32_t) (this->delayTime / 1000.0f * (float) this->samplerate)); } -void DiffSurround::SetDelayTime(float value) { - this->delayTime = value; - Reset(); +void DiffSurround::SetDelayTime(float delayTime) { + if (this->delayTime != delayTime) { + this->delayTime = delayTime; + this->Reset(); + } } void DiffSurround::SetEnable(bool enabled) { - this->enabled = enabled; - if (this->enabled) { - Reset(); + if (this->enabled != enabled) { + this->enabled = enabled; + if (enabled) { + Reset(); + } } } void DiffSurround::SetSamplingRate(uint32_t samplerate) { - this->samplerate = samplerate; - Reset(); + if (this->samplerate != samplerate) { + this->samplerate = samplerate; + this->Reset(); + } } diff --git a/src/cpp/viper/effects/DiffSurround.h b/src/cpp/viper/effects/DiffSurround.h index 1a4c888..6d12c0e 100644 --- a/src/cpp/viper/effects/DiffSurround.h +++ b/src/cpp/viper/effects/DiffSurround.h @@ -10,7 +10,7 @@ public: void Process(float *samples, uint32_t size); void Reset(); - void SetDelayTime(float value); + void SetDelayTime(float delayTime); void SetEnable(bool enabled); void SetSamplingRate(uint32_t samplerate); diff --git a/src/cpp/viper/effects/DynamicSystem.cpp b/src/cpp/viper/effects/DynamicSystem.cpp index 70135ee..bf57fe2 100644 --- a/src/cpp/viper/effects/DynamicSystem.cpp +++ b/src/cpp/viper/effects/DynamicSystem.cpp @@ -28,7 +28,12 @@ void DynamicSystem::SetBassGain(float gain) { } void DynamicSystem::SetEnable(bool enable) { - this->enabled = enable; + if (this->enabled != enable) { + this->enabled = enable; + if (enable) { + Reset(); + } + } } void DynamicSystem::SetSideGain(float gainX, float gainY) { @@ -44,8 +49,10 @@ void DynamicSystem::SetYCoeffs(uint32_t low, uint32_t high) { } void DynamicSystem::SetSamplingRate(uint32_t samplerate) { - this->samplerate = samplerate; - this->bass.SetSamplingRate(samplerate); + if (this->samplerate != samplerate) { + this->samplerate = samplerate; + this->bass.SetSamplingRate(samplerate); + } } DynamicSystem::~DynamicSystem() { diff --git a/src/cpp/viper/effects/ViPERBass.cpp b/src/cpp/viper/effects/ViPERBass.cpp index 436068e..57c37de 100644 --- a/src/cpp/viper/effects/ViPERBass.cpp +++ b/src/cpp/viper/effects/ViPERBass.cpp @@ -1,3 +1,4 @@ +#include #include "ViPERBass.h" ViPERBass::ViPERBass() { @@ -13,18 +14,29 @@ void ViPERBass::Process(float *samples, uint32_t size) { } void ViPERBass::Reset() { - + this->polyphase->SetSamplingRate(this->samplingRate); + this->polyphase->Reset(); + this->waveBuffer->Reset(); + this->waveBuffer->PushZeros(this->polyphase->GetLatency()); + this->subwoofer->SetBassGain(this->samplingRate, this->bassFactor * 2.5f); + this->fixedBiquad->SetLowPassParameter(this->speaker, this->samplingRate, 0.53); + this->unknown1 = 0.0f; } -void ViPERBass::SetBassFactor() { +void ViPERBass::SetBassFactor(float bassFactor) { + if (abs(this->bassFactor - bassFactor) <= 0.01) { + return; + } + this->bassFactor = bassFactor; + this->subwoofer->SetBassGain(this->samplingRate, bassFactor * 2.5f); } void ViPERBass::SetEnable(bool enable) { } -void ViPERBass::SetProcessMode() { +void ViPERBass::SetProcessMode(int processMode) { } @@ -32,6 +44,10 @@ void ViPERBass::SetSamplingRate(uint32_t samplingRate) { } -void ViPERBass::SetSpeaker() { +void ViPERBass::SetSpeaker(float speaker) { + if (this->speaker != speaker) { + this->speaker = speaker; + Reset(); + } } diff --git a/src/cpp/viper/effects/ViPERBass.h b/src/cpp/viper/effects/ViPERBass.h index c71243f..2e5b158 100644 --- a/src/cpp/viper/effects/ViPERBass.h +++ b/src/cpp/viper/effects/ViPERBass.h @@ -1,6 +1,10 @@ #pragma once #include +#include "../utils/FixedBiquad.h" +#include "../utils/Subwoofer.h" +#include "../utils/WaveBuffer_I32.h" +#include "../utils/Polyphase.h" class ViPERBass { public: @@ -9,11 +13,24 @@ public: void Process(float *samples, uint32_t size); void Reset(); - void SetBassFactor(); + void SetBassFactor(float bassFactor); void SetEnable(bool enable); - void SetProcessMode(); + void SetProcessMode(int processMode); void SetSamplingRate(uint32_t samplingRate); - void SetSpeaker(); + void SetSpeaker(float speaker); + +private: + Polyphase *polyphase; + FixedBiquad *fixedBiquad; + Subwoofer *subwoofer; + WaveBuffer_I32 *waveBuffer; + bool enable; + bool initOk; + int processMode; + uint32_t samplingRate; + float unknown1; + float speaker; + float bassFactor; }; diff --git a/src/cpp/viper/effects/ViPERClarity.cpp b/src/cpp/viper/effects/ViPERClarity.cpp index d5702d0..7c3db09 100644 --- a/src/cpp/viper/effects/ViPERClarity.cpp +++ b/src/cpp/viper/effects/ViPERClarity.cpp @@ -1,7 +1,3 @@ -// -// Created by mart on 7/31/21. -// - #include "ViPERClarity.h" #include "../constants.h" diff --git a/src/cpp/viper/utils/AdaptiveBuffer.cpp b/src/cpp/viper/utils/AdaptiveBuffer.cpp index d24030b..66b4a50 100644 --- a/src/cpp/viper/utils/AdaptiveBuffer.cpp +++ b/src/cpp/viper/utils/AdaptiveBuffer.cpp @@ -21,19 +21,19 @@ void AdaptiveBuffer::FlushBuffer() { this->offset = 0; } -uint32_t AdaptiveBuffer::GetBufferLength() { +uint32_t AdaptiveBuffer::GetBufferLength() const { return this->length; } -uint32_t AdaptiveBuffer::GetBufferOffset() { +uint32_t AdaptiveBuffer::GetBufferOffset() const { return this->offset; } -float *AdaptiveBuffer::GetBufferPointer() { +float *AdaptiveBuffer::GetBufferPointer() const { return this->buffer; } -uint32_t AdaptiveBuffer::GetChannels() { +uint32_t AdaptiveBuffer::GetChannels() const { return this->channels; } @@ -58,14 +58,14 @@ int AdaptiveBuffer::PopFrames(float *frames, uint32_t length) { memcpy(frames, this->buffer, length * this->channels * sizeof(*frames)); this->offset = this->offset - length; if (this->offset != 0) { - memmove(this->buffer, &this->buffer[length * this->channels], this->offset * this->channels * sizeof(*this->buffer)); + memmove(this->buffer, &this->buffer[length * this->channels], this->offset * this->channels * sizeof(float)); } } return 1; } -int AdaptiveBuffer::PushFrames(float *frames, uint32_t length) { +int AdaptiveBuffer::PushFrames(const float *frames, uint32_t length) { if (this->buffer == nullptr) { return 0; } @@ -73,13 +73,13 @@ int AdaptiveBuffer::PushFrames(float *frames, uint32_t length) { if (length != 0) { if (this->offset + length > this->length) { auto tmp = new float[(this->offset + length) * this->channels]; - memcpy(tmp, this->buffer, this->offset * this->channels * sizeof(*this->buffer)); + memcpy(tmp, this->buffer, this->offset * this->channels * sizeof(float)); delete this->buffer; this->buffer = tmp; this->length = this->offset + length; } - memcpy(&this->buffer[this->offset * this->channels], frames, length * this->channels * sizeof(*frames)); + memcpy(&this->buffer[this->offset * this->channels], frames, length * this->channels * sizeof(float)); this->offset = this->offset + length; } @@ -93,13 +93,13 @@ int AdaptiveBuffer::PushZero(uint32_t length) { if (this->offset + length > this->length) { auto tmp = new float[(this->offset + length) * this->channels]; - memcpy(tmp, this->buffer, this->offset * this->channels * sizeof(*this->buffer)); + memcpy(tmp, this->buffer, this->offset * this->channels * sizeof(float)); delete this->buffer; this->buffer = tmp; this->length = this->offset + length; } - memset(&this->buffer[this->offset * this->channels], 0, length * this->channels * sizeof(*this->buffer)); + memset(&this->buffer[this->offset * this->channels], 0, length * this->channels * sizeof(float)); this->offset = this->offset + length; return 1; diff --git a/src/cpp/viper/utils/AdaptiveBuffer.h b/src/cpp/viper/utils/AdaptiveBuffer.h index e2c8807..cd73d92 100644 --- a/src/cpp/viper/utils/AdaptiveBuffer.h +++ b/src/cpp/viper/utils/AdaptiveBuffer.h @@ -8,13 +8,13 @@ public: ~AdaptiveBuffer(); void FlushBuffer(); - uint32_t GetBufferLength(); - uint32_t GetBufferOffset(); - float *GetBufferPointer(); - uint32_t GetChannels(); + uint32_t GetBufferLength() const; + uint32_t GetBufferOffset() const; + float *GetBufferPointer() const; + uint32_t GetChannels() const; void PanFrames(float left, float right); int PopFrames(float *frames, uint32_t length); - int PushFrames(float *frames, uint32_t length); + int PushFrames(const float *frames, uint32_t length); int PushZero(uint32_t length); void ScaleFrames(float scale); void SetBufferOffset(uint32_t offset); diff --git a/src/cpp/viper/utils/CAllpassFilter.cpp b/src/cpp/viper/utils/CAllpassFilter.cpp index 8071160..1c7e69f 100644 --- a/src/cpp/viper/utils/CAllpassFilter.cpp +++ b/src/cpp/viper/utils/CAllpassFilter.cpp @@ -1,9 +1,5 @@ -// -// Created by mart on 7/26/21. -// - -#include #include "CAllpassFilter.h" +#include CAllpassFilter::CAllpassFilter() { this->buffer = nullptr; @@ -12,6 +8,10 @@ CAllpassFilter::CAllpassFilter() { this->feedback = 0; } +float CAllpassFilter::GetFeedback() { + return this->feedback; +} + void CAllpassFilter::Mute() { memset(this->buffer, 0, this->bufsize * sizeof(float)); } @@ -26,10 +26,6 @@ float CAllpassFilter::Process(float sample) { return outSample - sample; } -float CAllpassFilter::GetFeedback() { - return this->feedback; -} - void CAllpassFilter::SetBuffer(float *buffer, uint32_t size) { this->buffer = buffer; this->bufsize = size; diff --git a/src/cpp/viper/utils/CAllpassFilter.h b/src/cpp/viper/utils/CAllpassFilter.h index bcc0132..6c35acc 100644 --- a/src/cpp/viper/utils/CAllpassFilter.h +++ b/src/cpp/viper/utils/CAllpassFilter.h @@ -1,7 +1,3 @@ -// -// Created by mart on 7/26/21. -// - #pragma once #include @@ -10,16 +6,13 @@ class CAllpassFilter { public: CAllpassFilter(); - void Mute(); - - float Process(float sample); - float GetFeedback(); - + void Mute(); + float Process(float sample); void SetBuffer(float *buffer, uint32_t size); - void SetFeedback(float feedback); +private: float *buffer; uint32_t bufidx; uint32_t bufsize; diff --git a/src/cpp/viper/utils/CCombFilter.cpp b/src/cpp/viper/utils/CCombFilter.cpp index 0c0f34a..c5c75a7 100644 --- a/src/cpp/viper/utils/CCombFilter.cpp +++ b/src/cpp/viper/utils/CCombFilter.cpp @@ -1,9 +1,5 @@ -// -// Created by mart on 7/27/21. -// - -#include #include "CCombFilter.h" +#include CCombFilter::CCombFilter() { this->buffer = nullptr; @@ -15,9 +11,21 @@ CCombFilter::CCombFilter() { this->damp2 = 0; } +float CCombFilter::GetDamp() { + return this->damp; +} + +float CCombFilter::GetFeedback() { + return this->feedback; +} + +void CCombFilter::Mute() { + memset(this->buffer, 0, this->size * sizeof(float)); +} + float CCombFilter::Process(float sample) { float output = this->buffer[this->bufidx]; - this->filterstore = output * this->damp2 + this->filterstore * this->damp;; + this->filterstore = output * this->damp2 + this->filterstore * this->damp; this->buffer[this->bufidx] = sample + this->filterstore * this->feedback; this->bufidx++; if (this->bufidx >= this->size) { @@ -26,16 +34,9 @@ float CCombFilter::Process(float sample) { return output; } -void CCombFilter::Mute() { - memset(this->buffer, 0, this->size * sizeof(float)); -} - -float CCombFilter::GetDamp() { - return this->damp; -} - -float CCombFilter::GetFeedback() { - return this->feedback; +void CCombFilter::SetBuffer(float *buffer, uint32_t size) { + this->buffer = buffer; + this->size = size; } void CCombFilter::SetDamp(float damp) { @@ -46,8 +47,3 @@ void CCombFilter::SetDamp(float damp) { void CCombFilter::SetFeedback(float feedback) { this->feedback = feedback; } - -void CCombFilter::SetBuffer(float *buffer, uint32_t size) { - this->buffer = buffer; - this->size = size; -} diff --git a/src/cpp/viper/utils/CCombFilter.h b/src/cpp/viper/utils/CCombFilter.h index e4de3ba..0b4af08 100644 --- a/src/cpp/viper/utils/CCombFilter.h +++ b/src/cpp/viper/utils/CCombFilter.h @@ -10,20 +10,15 @@ class CCombFilter { public: CCombFilter(); - float Process(float sample); - - void Mute(); - float GetDamp(); - float GetFeedback(); - + void Mute(); + float Process(float sample); + void SetBuffer(float *buffer, uint32_t size); void SetDamp(float damp); - void SetFeedback(float feedback); - void SetBuffer(float *buffer, uint32_t size); - +private: float feedback; float filterstore; float damp; diff --git a/src/cpp/viper/utils/DepthSurround.cpp b/src/cpp/viper/utils/DepthSurround.cpp index 1577677..dd2b53c 100644 --- a/src/cpp/viper/utils/DepthSurround.cpp +++ b/src/cpp/viper/utils/DepthSurround.cpp @@ -12,9 +12,11 @@ DepthSurround::DepthSurround() { this->enabled = false; this->strengthAtLeast500 = false; this->gain = 0; - memset(&this->prev, 0, 2 * sizeof(float)); - SetSamplingRate(DEFAULT_SAMPLERATE); - RefreshStrength(this->strength); + for (auto &prev : this->prev) { + prev = 0.0f; + } + this->SetSamplingRate(DEFAULT_SAMPLERATE); + this->RefreshStrength(this->strength); } void DepthSurround::Process(float *samples, uint32_t size) { @@ -61,11 +63,11 @@ void DepthSurround::RefreshStrength(short strength) { this->strengthAtLeast500 = strength >= 500; this->enabled = strength != 0; if (strength != 0) { - float _gain = powf(10.f, ((strength / 1000.f) * 10.f - 15.f) / 20.f); - if (fabsf(_gain) > 1.f) { - _gain = 1.f; + float gain = powf(10.0f, ((strength / 1000.0f) * 10.0f - 15.0f) / 20.0f); + if (fabsf(gain) > 1.0f) { + gain = 1.0f; } - this->gain = _gain; + this->gain = gain; } else { this->gain = 0; } @@ -74,11 +76,13 @@ void DepthSurround::RefreshStrength(short strength) { void DepthSurround::SetSamplingRate(uint32_t samplerate) { this->delay[0].SetParameters(samplerate, 0.02); this->delay[1].SetParameters(samplerate, 0.014); - this->highpass.SetHighPassParameter(800.f, samplerate, -11.0f, 0.72f, 0); - memset(&this->prev, 0, 2 * sizeof(float)); + this->highpass.SetHighPassParameter(800.0f, samplerate, -11.0f, 0.72f, 0); + for (auto &prev : this->prev) { + prev = 0.0f; + } } void DepthSurround::SetStrength(short strength) { this->strength = strength; - RefreshStrength(strength); + this->RefreshStrength(strength); } \ No newline at end of file diff --git a/src/cpp/viper/utils/FIR.cpp b/src/cpp/viper/utils/FIR.cpp new file mode 100644 index 0000000..42ce13d --- /dev/null +++ b/src/cpp/viper/utils/FIR.cpp @@ -0,0 +1,35 @@ +#include "FIR.h" + +FIR::FIR() { + +} + +FIR::~FIR() { + delete this->offsetBlock; + delete this->coeffs; + delete this->block; +} + +void FIR::FilterSamples(int *samples, uint32_t size) { + this->FilterSamplesInterleaved(samples, size, 1); +} + +void FIR::FilterSamplesInterleaved(int *samples, uint32_t size, uint32_t channels) { + +} + +int FIR::GetBlockLength() { + return this->blockLength; +} + +int FIR::LoadCoefficients(float *coeffs, uint32_t coeffsize, int blockLength) { + return 0; +} + +void FIR::Reset() { + if (this->offsetBlock != nullptr && this->coeffsize + this->blockLength > -1) { + for (int i = 0; i < this->coeffsize + this->blockLength; i++) { + this->offsetBlock[i] = 0; + } + } +} diff --git a/src/cpp/viper/utils/FIR.h b/src/cpp/viper/utils/FIR.h new file mode 100644 index 0000000..d21529a --- /dev/null +++ b/src/cpp/viper/utils/FIR.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +class FIR { +public: + FIR(); + ~FIR(); + + void FilterSamples(int *samples, uint32_t size); + void FilterSamplesInterleaved(int *samples, uint32_t size, uint32_t channels); + int GetBlockLength(); + int LoadCoefficients(float *coeffs, uint32_t coeffsize, int blockLength); + void Reset(); + +private: + int *offsetBlock; + float *coeffs; + float *block; + int coeffsize; + int blockLength; + bool enabled; + +}; + + diff --git a/src/cpp/viper/utils/HiFi.cpp b/src/cpp/viper/utils/HiFi.cpp index b67469b..ea6a4a4 100644 --- a/src/cpp/viper/utils/HiFi.cpp +++ b/src/cpp/viper/utils/HiFi.cpp @@ -1,7 +1,3 @@ -// -// Created by mart on 7/31/21. -// - #include "HiFi.h" #include "../constants.h" diff --git a/src/cpp/viper/utils/HiFi.h b/src/cpp/viper/utils/HiFi.h index 359ab6c..e42e48e 100644 --- a/src/cpp/viper/utils/HiFi.h +++ b/src/cpp/viper/utils/HiFi.h @@ -1,7 +1,3 @@ -// -// Created by mart on 7/31/21. -// - #pragma once diff --git a/src/cpp/viper/utils/MultiBiquad.cpp b/src/cpp/viper/utils/MultiBiquad.cpp index b58dd47..8f6571e 100644 --- a/src/cpp/viper/utils/MultiBiquad.cpp +++ b/src/cpp/viper/utils/MultiBiquad.cpp @@ -30,8 +30,6 @@ float MultiBiquad::ProcessSample(float sample) { void MultiBiquad::RefreshFilter(FilterType type, float gainAmp, float freq, float samplerate, float qFactor, bool param_7) { bool uVar1; - int iVar2; - int iVar3; double dVar4; double dVar5; double dVar6; diff --git a/src/cpp/viper/utils/Polyphase.cpp b/src/cpp/viper/utils/Polyphase.cpp new file mode 100644 index 0000000..4715b3b --- /dev/null +++ b/src/cpp/viper/utils/Polyphase.cpp @@ -0,0 +1,26 @@ +#include "Polyphase.h" + +Polyphase::Polyphase() { + +} + +Polyphase::~Polyphase() { + +} + +uint32_t Polyphase::GetLatency() { + return 63; +} + +void Polyphase::Process(float *samples, uint32_t size) { + +} + +void Polyphase::Reset() { + +} + +void Polyphase::SetSamplingRate(uint32_t samplingRate) { + +} + diff --git a/src/cpp/viper/utils/Polyphase.h b/src/cpp/viper/utils/Polyphase.h new file mode 100644 index 0000000..eb96c48 --- /dev/null +++ b/src/cpp/viper/utils/Polyphase.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include "WaveBuffer_I32.h" +#include "FIR.h" + +class Polyphase { +public: + Polyphase(); + ~Polyphase(); + + uint32_t GetLatency(); + void Process(float *samples, uint32_t size); + void Reset(); + void SetSamplingRate(uint32_t samplingRate); + +private: + FIR *fir1; + FIR *fir2; + WaveBuffer_I32 *waveBuffer1; + WaveBuffer_I32 *waveBuffer2; + int *unknown1; + bool enabled; + // 3 unknowns + uint32_t samplingRate; +}; + + diff --git a/src/cpp/viper/utils/Stereo3DSurround.cpp b/src/cpp/viper/utils/Stereo3DSurround.cpp new file mode 100644 index 0000000..f4f183e --- /dev/null +++ b/src/cpp/viper/utils/Stereo3DSurround.cpp @@ -0,0 +1,22 @@ +#include "Stereo3DSurround.h" + +Stereo3DSurround::Stereo3DSurround() { + this->midImage = 1.0f; + this->stereoWiden = 0.0f; + this->unknown1 = 1.0f; + this->unknown2 = 0.5f; + this->coeffLeft = 0.5f; + this->coeffRight = 0.5f; +} + +void Stereo3DSurround::Process(float *samples, uint32_t size) { + +} + +void Stereo3DSurround::SetMiddleImage(float middleImage) { + +} + +void Stereo3DSurround::SetStereoWiden(float stereoWiden) { + +} diff --git a/src/cpp/viper/utils/Stereo3DSurround.h b/src/cpp/viper/utils/Stereo3DSurround.h new file mode 100644 index 0000000..7d3822b --- /dev/null +++ b/src/cpp/viper/utils/Stereo3DSurround.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +class Stereo3DSurround { +public: + Stereo3DSurround(); + + void Process(float *samples, uint32_t size); + void SetMiddleImage(float middleImage); + void SetStereoWiden(float stereoWiden); + +private: + float stereoWiden; + float midImage; + float unknown1; + float unknown2; + float coeffLeft; + float coeffRight; +}; + + diff --git a/src/cpp/viper/utils/WaveBuffer_I32.cpp b/src/cpp/viper/utils/WaveBuffer_I32.cpp index 1232162..9b08da1 100644 --- a/src/cpp/viper/utils/WaveBuffer_I32.cpp +++ b/src/cpp/viper/utils/WaveBuffer_I32.cpp @@ -1,7 +1,3 @@ -// -// Created by mart on 7/31/21. -// - #include #include #include "WaveBuffer_I32.h" diff --git a/src/cpp/viper/utils/WaveBuffer_I32.h b/src/cpp/viper/utils/WaveBuffer_I32.h index fe1e65d..243dcfd 100644 --- a/src/cpp/viper/utils/WaveBuffer_I32.h +++ b/src/cpp/viper/utils/WaveBuffer_I32.h @@ -1,7 +1,3 @@ -// -// Created by mart on 7/31/21. -// - #pragma once