Start work on PConvSingle and VHE

This commit is contained in:
Martmists 2021-09-18 13:37:23 +02:00
parent 3db1c228a3
commit b8f2a30dbe
6 changed files with 263 additions and 3 deletions

View File

@ -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.

View File

@ -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;

64
src/effects/VHE.cpp Normal file
View File

@ -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();
}

32
src/effects/VHE.h Normal file
View File

@ -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;
};

View File

@ -0,0 +1,109 @@
//
// Created by mart on 9/12/21.
//
#include <cstdlib>
#include <cstring>
#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();
}

View File

@ -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
};