From b8f2a30dbe746e86219c9b3799a39e1668fbd8d3 Mon Sep 17 00:00:00 2001 From: Martmists Date: Sat, 18 Sep 2021 13:37:23 +0200 Subject: [PATCH] Start work on PConvSingle and VHE --- CMakeLists.txt | 5 +- src/ProcessUnit_FX.h | 3 +- src/effects/VHE.cpp | 64 ++++++++++++++++++++ src/effects/VHE.h | 32 ++++++++++ src/utils/PConvSingle_F32.cpp | 109 ++++++++++++++++++++++++++++++++++ src/utils/PConvSingle_F32.h | 53 +++++++++++++++++ 6 files changed, 263 insertions(+), 3 deletions(-) create mode 100644 src/effects/VHE.cpp create mode 100644 src/effects/VHE.h create mode 100644 src/utils/PConvSingle_F32.cpp create mode 100644 src/utils/PConvSingle_F32.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eb5c20..0e96305 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ set(FILES src/effects/SpeakerCorrection.cpp src/effects/SpectrumExtend.cpp src/effects/TubeSimulator.cpp + src/effects/VHE.cpp src/effects/ViPERClarity.cpp # Utils @@ -46,11 +47,11 @@ set(FILES src/utils/MultiBiquad.cpp src/utils/NoiseSharpening.cpp src/utils/PassFilter.cpp + src/utils/PConvSingle_F32.cpp src/utils/PolesFilter.cpp src/utils/Subwoofer.cpp src/utils/TimeConstDelay.cpp - src/utils/WaveBuffer_I32.cpp -) + src/utils/WaveBuffer_I32.cpp) add_library( # Sets the name of the library. diff --git a/src/ProcessUnit_FX.h b/src/ProcessUnit_FX.h index 600905a..87bf8a7 100644 --- a/src/ProcessUnit_FX.h +++ b/src/ProcessUnit_FX.h @@ -15,6 +15,7 @@ #include "effects/TubeSimulator.h" #include "effects/Cure.h" #include "effects/DiffSurround.h" +#include "effects/VHE.h" class ProcessUnit_FX : public Effect { public: @@ -35,7 +36,7 @@ public: // AdaptiveBuffer_F32* adaptiveBuffer; WaveBuffer_I32* waveBuffer; // Convolver* convolver; -// VHE* vhe; + VHE* vhe; // ViPERDDC* vddc; SpectrumExtend* spectrumExtend; // IIRFilter* iirfilter; diff --git a/src/effects/VHE.cpp b/src/effects/VHE.cpp new file mode 100644 index 0000000..6bcf6b9 --- /dev/null +++ b/src/effects/VHE.cpp @@ -0,0 +1,64 @@ +// +// Created by mart on 9/18/21. +// + +#include "VHE.h" +#include "../constants.h" + +VHE::VHE() { + enabled = false; + effectLevel = 0; + convSize = 0; + samplerate = DEFAULT_SAMPLERATE; + + bufA = new WaveBuffer_I32(2, 0x1000); + bufB = new WaveBuffer_I32(2, 0x1000); + Reset(); +} + +VHE::~VHE() { + delete bufA; + delete bufB; +} + +void VHE::Process(float *source, float *dest, int frameSize) { + if (enabled && convLeft.InstanceUsable() && convRight.InstanceUsable()) { + if (bufA->PushSamples(source, frameSize) != 0) { + while (bufA->GetBufferOffset() > convSize) { + float *buffer = bufA->GetCurrentBufferI32Ptr(); + convLeft.ConvolveInterleaved(buffer, 0); + convRight.ConvolveInterleaved(buffer, 1); + bufB->PushSamples(buffer, convSize); + bufA->PopSamples(convSize, true); + } + bufB->PopSamples(dest, frameSize, false); + } + } +} + +void VHE::Reset() { + // TODO +} + +bool VHE::GetEnabled() { + return enabled; +} + +void VHE::SetEffectLevel(uint32_t level) { + if (level < 5) { + this->effectLevel = level; + Reset(); + } +} + +void VHE::SetEnable(bool enabled) { + this->enabled = enabled; + if (enabled) { + Reset(); + } +} + +void VHE::SetSamplingRate(uint32_t srate) { + this->samplerate = srate; + Reset(); +} diff --git a/src/effects/VHE.h b/src/effects/VHE.h new file mode 100644 index 0000000..aa96bf5 --- /dev/null +++ b/src/effects/VHE.h @@ -0,0 +1,32 @@ +// +// Created by mart on 9/18/21. +// + +#pragma once + + +#include "../utils/PConvSingle_F32.h" +#include "../utils/WaveBuffer_I32.h" + +class VHE { +public: + VHE(); + ~VHE(); + + void Process(float* source, float* dest, int frameSize); + void Reset(); + + bool GetEnabled(); + void SetEffectLevel(uint32_t level); + void SetEnable(bool enabled); + void SetSamplingRate(uint32_t srate); + + PConvSingle_F32 convLeft, convRight; + WaveBuffer_I32 *bufA, *bufB; + uint32_t samplerate; + bool enabled; + int effectLevel; + int convSize; +}; + + diff --git a/src/utils/PConvSingle_F32.cpp b/src/utils/PConvSingle_F32.cpp new file mode 100644 index 0000000..801e67a --- /dev/null +++ b/src/utils/PConvSingle_F32.cpp @@ -0,0 +1,109 @@ +// +// Created by mart on 9/12/21. +// + +#include +#include +#include "PConvSingle_F32.h" + +PConvSingle_F32::PConvSingle_F32() { + this->enabled = false; + this->segments = 0; + this->segmentSize = 0; + this->data = nullptr; +} + +PConvSingle_F32::~PConvSingle_F32() { + ReleaseResources(); +} + +void PConvSingle_F32::Reset() { + // TODO +} + +int PConvSingle_F32::GetFFTSize() { + return this->segmentSize * 2; +} + +int PConvSingle_F32::GetSegmentCount() { + return this->segments; +} + +int PConvSingle_F32::GetSegmentSize() { + return this->segmentSize; +} + +bool PConvSingle_F32::InstanceUsable() { + return this->enabled; +} + +void PConvSingle_F32::Convolve(float *buffer) { + ConvSegment(buffer, false, 0); +} + +void PConvSingle_F32::ConvolveInterleaved(float *buffer, int channel) { + ConvSegment(buffer, true, channel); +} + +void PConvSingle_F32::ConvSegment(float *buffer, bool interleaved, int channel) { + // TODO +} + +int PConvSingle_F32::LoadKernel(float *buf, int param_2, int segmentSize) { + if (buf == nullptr) { + return 0; + } + if (param_2 > 0 && segmentSize > 0 && segmentSize % 2 == 0) { + this->enabled = false; + ReleaseResources(); + this->data = malloc(0x140); // TODO: Sizeof + memset(this->data, 0, 0x140); // Ditto + this->segmentSize = segmentSize; + int n = ProcessKernel(buf, param_2, 1); + if (n != 0) { + this->enabled = true; + return n; + } + ReleaseResources(); + } + return 0; +} + +int PConvSingle_F32::LoadKernel(float *buf, float *param_2, int segmentSize, int param_4, int param_5) { + if (buf == nullptr) { + return 0; + } + if (param_5 > 0 && segmentSize > 0 && segmentSize % 2 == 0) { + this->enabled = false; + ReleaseResources(); + this->data = malloc(0x140); // TODO: Sizeof + memset(this->data, 0, 0x140); // Ditto + this->segmentSize = segmentSize; + int n = ProcessKernel(1, param_2, param_4, param_5); + if (n != 0) { + this->enabled = true; + return n; + } + ReleaseResources(); + } + return 0; +} + +int PConvSingle_F32::ProcessKernel(float *param_1, int param_2, int param_3) { + // TODO + return 0; +} + +int PConvSingle_F32::ProcessKernel(int param_2, float *param_3, int param_4, int param_5) { + // TODO + return 0; +} + +void PConvSingle_F32::ReleaseResources() { + // TODO +} + +void PConvSingle_F32::UnloadKernel() { + this->enabled = false; + ReleaseResources(); +} diff --git a/src/utils/PConvSingle_F32.h b/src/utils/PConvSingle_F32.h new file mode 100644 index 0000000..dfbb6c1 --- /dev/null +++ b/src/utils/PConvSingle_F32.h @@ -0,0 +1,53 @@ +// +// Created by mart on 9/12/21. +// + +#pragma once + +typedef struct { + int unk_0x00; + int unk_0x04; + int unk_0x08; + float* unk_buffer; + float* fftInputBuffer; + float* fftOutputBuffer; + float* unk_buffer_2; + float* unk_buffer_3; + int size_A; + void* field_A1; + void* field_A2; + int size_B; + void* field_B1; + void* field_B2; + int* unk_0x120; + void* fft_plan_1; + void* fft_plan_2; +} PConvData; + + +class PConvSingle_F32 { +public: + PConvSingle_F32(); + ~PConvSingle_F32(); + + void Reset(); + int GetFFTSize(); + int GetSegmentCount(); + int GetSegmentSize(); + bool InstanceUsable(); + + void Convolve(float* buffer); + void ConvolveInterleaved(float* buffer, int channel); + void ConvSegment(float* buffer, bool interleaved, int channel); + + int LoadKernel(float* buf, int param_2, int segmentSize); + int LoadKernel(float* buf, float* param_2, int segmentSize, int param_4, int param_5); + int ProcessKernel(float* param_1, int param_2, int param_3); + int ProcessKernel(int param_2, float *param_3, int param_4, int param_5); + void ReleaseResources(); + void UnloadKernel(); + + bool enabled; + int segments, segmentSize; + PConvData* data; // TODO: Type +};