Fix ViPER DDC, add architecture info

This commit is contained in:
Iscle 2023-05-21 18:46:20 +02:00
parent 9764057ca7
commit 5c0d69d970
8 changed files with 149 additions and 170 deletions

View File

@ -19,6 +19,7 @@ extern "C" {
#define PARAM_GET_DISABLE_REASON 8 #define PARAM_GET_DISABLE_REASON 8
#define PARAM_GET_DISABLE_REASON_MESSAGE 9 #define PARAM_GET_DISABLE_REASON_MESSAGE 9
#define PARAM_GET_CONFIG 10 #define PARAM_GET_CONFIG 10
#define PARAM_GET_ARCHITECTURE 11
// Param set // Param set
#define PARAM_SET_UPDATE_STATUS 0x9002 #define PARAM_SET_UPDATE_STATUS 0x9002

View File

@ -4,6 +4,7 @@
#include <chrono> #include <chrono>
#include "ViperContext.h" #include "ViperContext.h"
#include "log.h" #include "log.h"
#include "viper/constants.h"
#define SET(type, ptr, value) (*(type *) (ptr) = (value)) #define SET(type, ptr, value) (*(type *) (ptr) = (value))
@ -280,6 +281,13 @@ int32_t ViperContext::handleGetParam(effect_param_t *pCmdParam, effect_param_t *
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize; *pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0; return 0;
} }
case PARAM_GET_ARCHITECTURE: {
pReplyParam->status = 0;
pReplyParam->vsize = sizeof(VIPER_ARCHITECTURE) - 1; // Exclude null terminator
memcpy(pReplyParam->data + vOffset, VIPER_ARCHITECTURE, pReplyParam->vsize);
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
default: { default: {
return -EINVAL; return -EINVAL;
} }

View File

@ -228,7 +228,7 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u
break; break;
} // 0x1000A } // 0x1000A
case PARAM_DDC_COEFFICIENTS: { case PARAM_DDC_COEFFICIENTS: {
this->viperDdc.SetCoeffs(arrSize, (float *) arr, (float *) (arr + arrSize * 4)); this->viperDdc.SetCoeffs(arrSize, (float *) arr, (float *) (arr + arrSize * sizeof(float)));
break; break;
} // 0x1000B } // 0x1000B
case PARAM_SPECTRUM_EXTENSION_ENABLE: { case PARAM_SPECTRUM_EXTENSION_ENABLE: {

View File

@ -8,6 +8,21 @@
#include "../log.h" // TODO: Remove this dependency #include "../log.h" // TODO: Remove this dependency
#if defined(__arm__)
#define VIPER_ARCHITECTURE "ARM"
#elif defined(__aarch64__)
#define VIPER_ARCHITECTURE "ARM64"
#elif defined(__i386__)
#define VIPER_ARCHITECTURE "x86"
#elif defined(__x86_64__)
#define VIPER_ARCHITECTURE "x86_64"
#else
#error "Unknown architecture"
// Note from the developer:
// There's no architecture dependent code in ViPER4Android, this is just for debugging purposes.
// Feel free to add your architecture if it's not listed here.
#endif
#define VIPER_NAME "ViPER4Android" #define VIPER_NAME "ViPER4Android"
#define VIPER_AUTHORS "viper.WYF, Martmists, Iscle" #define VIPER_AUTHORS "viper.WYF, Martmists, Iscle"
#define VIPER_DEFAULT_SAMPLING_RATE 44100 #define VIPER_DEFAULT_SAMPLING_RATE 44100

View File

@ -1,41 +1,27 @@
#include "ViPERDDC.h" #include "ViPERDDC.h"
#include "../../log.h" #include "../../log.h"
#include "../constants.h"
#include <cstring> #include <cstring>
ViPERDDC::ViPERDDC() { ViPERDDC::ViPERDDC() :
this->enable = false; enable(false),
this->samplingRate = 44100; setCoeffsOk(false),
this->setCoeffsOk = false; samplingRate(VIPER_DEFAULT_SAMPLING_RATE),
this->arrSize = 0; arrSize(0) {}
this->coeffsArr44100 = nullptr;
this->coeffsArr48000 = nullptr;
this->x2R = nullptr;
this->x2L = nullptr;
this->x1R = nullptr;
this->x1L = nullptr;
this->y2R = nullptr;
this->y2L = nullptr;
this->y1R = nullptr;
this->y1L = nullptr;
}
ViPERDDC::~ViPERDDC() {
ReleaseResources();
}
void ViPERDDC::Process(float *samples, uint32_t size) { void ViPERDDC::Process(float *samples, uint32_t size) {
if (!this->setCoeffsOk) return; if (!this->setCoeffsOk || this->arrSize == 0) return;
if (!this->enable) return; if (!this->enable) return;
float **coeffsArr; std::vector<std::array<float, 5>> *coeffsArr;
switch (this->samplingRate) { switch (this->samplingRate) {
case 44100: { case 44100: {
coeffsArr = this->coeffsArr44100; coeffsArr = &this->coeffsArr44100;
break; break;
} }
case 48000: { case 48000: {
coeffsArr = this->coeffsArr48000; coeffsArr = &this->coeffsArr48000;
break; break;
} }
default: { default: {
@ -45,145 +31,108 @@ void ViPERDDC::Process(float *samples, uint32_t size) {
} }
for (uint32_t i = 0; i < size * 2; i += 2) { for (uint32_t i = 0; i < size * 2; i += 2) {
if (this->arrSize == 0) { float sampleL = samples[i];
samples[i] = 0.0; float sampleR = samples[i + 1];
samples[i + 1] = 0.0;
} else {
float sample = samples[i];
for (uint32_t j = 0; j < this->arrSize; j++) { for (uint32_t j = 0; j < this->arrSize; j++) {
float *coeffs = coeffsArr[j]; std::array<float, 5> *coeffs = &(*coeffsArr)[j];
float b0 = coeffs[0]; float b0 = (*coeffs)[0];
float b1 = coeffs[1]; float b1 = (*coeffs)[1];
float b2 = coeffs[2]; float b2 = (*coeffs)[2];
float a1 = coeffs[3]; float a1 = (*coeffs)[3];
float a2 = coeffs[4]; float a2 = (*coeffs)[4];
float out = float outL =
sample * b0 + sampleL * b0 +
x1L[j] * b1 + x1L[j] * b1 +
x2L[j] * b2 + x2L[j] * b2 +
y1L[j] * a1 + y1L[j] * a1 +
y2L[j] * a2; y2L[j] * a2;
x2L[j] = x1L[j]; x2L[j] = x1L[j];
x1L[j] = sample; x1L[j] = sampleL;
y2L[j] = y1L[j]; y2L[j] = y1L[j];
y1L[j] = out; y1L[j] = outL;
sample = out; sampleL = outL;
}
samples[i] = sample;
sample = samples[i + 1]; float outR =
for (uint32_t j = 0; j < this->arrSize; j++) { sampleR * b0 +
float *coeffs = coeffsArr[j];
float b0 = coeffs[0];
float b1 = coeffs[1];
float b2 = coeffs[2];
float a1 = coeffs[3];
float a2 = coeffs[4];
float out =
sample * b0 +
x1R[j] * b1 + x1R[j] * b1 +
x2R[j] * b2 + x2R[j] * b2 +
y1R[j] * a1 + y1R[j] * a1 +
y2R[j] * a2; y2R[j] * a2;
x2R[j] = x1R[j]; x2R[j] = x1R[j];
x1R[j] = sample; x1R[j] = sampleR;
y2R[j] = y1R[j]; y2R[j] = y1R[j];
y1R[j] = out; y1R[j] = outR;
sample = out; sampleR = outR;
}
samples[i + 1] = sample;
} }
samples[i] = sampleL;
samples[i + 1] = sampleR;
} }
} }
void ViPERDDC::ReleaseResources() { void ViPERDDC::ReleaseResources() {
for (uint32_t i = 0; i < this->arrSize; i++) {
delete[] this->coeffsArr44100[i];
delete[] this->coeffsArr48000[i];
}
delete[] this->coeffsArr44100;
this->coeffsArr44100 = nullptr;
delete[] this->coeffsArr48000;
this->coeffsArr48000 = nullptr;
delete[] this->x1L;
this->x1L = nullptr;
delete[] this->x1R;
this->x1R = nullptr;
delete[] this->x2L;
this->x2L = nullptr;
delete[] this->x2R;
this->x2R = nullptr;
delete[] this->y1L;
this->y1L = nullptr;
delete[] this->y1R;
this->y1R = nullptr;
delete[] this->y2L;
this->y2L = nullptr;
delete[] this->y2R;
this->y2R = nullptr;
this->setCoeffsOk = false; this->setCoeffsOk = false;
this->coeffsArr44100.resize(0);
this->coeffsArr48000.resize(0);
this->x1L.resize(0);
this->x1R.resize(0);
this->x2L.resize(0);
this->x2R.resize(0);
this->y1L.resize(0);
this->y1R.resize(0);
this->y2L.resize(0);
this->y2R.resize(0);
} }
void ViPERDDC::Reset() { void ViPERDDC::Reset() {
if (!this->setCoeffsOk) return; if (!this->setCoeffsOk) return;
if (this->arrSize == 0) return; if (this->arrSize == 0) return;
memset(this->x1L, 0, this->arrSize * 4); memset(this->x1L.data(), 0, this->arrSize * sizeof(float));
memset(this->x1R, 0, this->arrSize * 4); memset(this->x1R.data(), 0, this->arrSize * sizeof(float));
} }
void ViPERDDC::SetCoeffs(uint32_t param_1, float *param_2, float *param_3) { void ViPERDDC::SetCoeffs(uint32_t newCoeffsSize, float *newCoeffs44100, float *newCoeffs48000) {
ReleaseResources(); ReleaseResources();
if (param_1 == 0) return; if (newCoeffsSize == 0) return;
this->arrSize = param_1 / 5; this->arrSize = newCoeffsSize / 5;
this->coeffsArr44100 = new float *[this->arrSize](); this->coeffsArr44100.resize(this->arrSize);
this->coeffsArr48000 = new float *[this->arrSize](); this->coeffsArr48000.resize(this->arrSize);
for (uint32_t i = 0; i < this->arrSize; i++) { for (uint32_t i = 0; i < this->arrSize; i++) {
this->coeffsArr44100[i] = new float[5]; this->coeffsArr44100[i][0] = newCoeffs44100[i * 5];
this->coeffsArr44100[i][0] = param_2[i * 5]; this->coeffsArr44100[i][1] = newCoeffs44100[i * 5 + 1];
this->coeffsArr44100[i][1] = param_2[i * 5 + 1]; this->coeffsArr44100[i][2] = newCoeffs44100[i * 5 + 2];
this->coeffsArr44100[i][2] = param_2[i * 5 + 2]; this->coeffsArr44100[i][3] = newCoeffs44100[i * 5 + 3];
this->coeffsArr44100[i][3] = param_2[i * 5 + 3]; this->coeffsArr44100[i][4] = newCoeffs44100[i * 5 + 4];
this->coeffsArr44100[i][4] = param_2[i * 5 + 4];
this->coeffsArr48000[i] = new float[5]; this->coeffsArr48000[i][0] = newCoeffs48000[i * 5];
this->coeffsArr48000[i][0] = param_3[i * 5]; this->coeffsArr48000[i][1] = newCoeffs48000[i * 5 + 1];
this->coeffsArr48000[i][1] = param_3[i * 5 + 1]; this->coeffsArr48000[i][2] = newCoeffs48000[i * 5 + 2];
this->coeffsArr48000[i][2] = param_3[i * 5 + 2]; this->coeffsArr48000[i][3] = newCoeffs48000[i * 5 + 3];
this->coeffsArr48000[i][3] = param_3[i * 5 + 3]; this->coeffsArr48000[i][4] = newCoeffs48000[i * 5 + 4];
this->coeffsArr48000[i][4] = param_3[i * 5 + 4];
} }
this->x1L = new float[this->arrSize](); this->x1L.resize(this->arrSize);
this->x1R = new float[this->arrSize](); this->x1R.resize(this->arrSize);
this->x2L = new float[this->arrSize](); this->x2L.resize(this->arrSize);
this->x2R = new float[this->arrSize](); this->x2R.resize(this->arrSize);
this->y1L = new float[this->arrSize](); this->y1L.resize(this->arrSize);
this->y1R = new float[this->arrSize](); this->y1R.resize(this->arrSize);
this->y2L = new float[this->arrSize](); this->y2L.resize(this->arrSize);
this->y2R = new float[this->arrSize](); this->y2R.resize(this->arrSize);
this->setCoeffsOk = true; this->setCoeffsOk = true;
} }

View File

@ -1,16 +1,16 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <vector>
#include <array>
class ViPERDDC { class ViPERDDC {
public: public:
ViPERDDC(); ViPERDDC();
~ViPERDDC();
void Process(float *samples, uint32_t size); void Process(float *samples, uint32_t size);
void ReleaseResources();
void Reset(); void Reset();
void SetCoeffs(uint32_t param_1, float *param_2, float *param_3); void SetCoeffs(uint32_t newCoeffsSize, float *newCoeffs44100, float *newCoeffs48000);
void SetEnable(bool enable); void SetEnable(bool enable);
void SetSamplingRate(uint32_t samplingRate); void SetSamplingRate(uint32_t samplingRate);
@ -19,16 +19,18 @@ private:
bool setCoeffsOk; bool setCoeffsOk;
uint32_t samplingRate; uint32_t samplingRate;
uint32_t arrSize; uint32_t arrSize;
float **coeffsArr44100; std::vector<std::array<float, 5>> coeffsArr44100;
float **coeffsArr48000; std::vector<std::array<float, 5>> coeffsArr48000;
float *x1L; std::vector<float> x1L;
float *x1R; std::vector<float> x1R;
float *x2L; std::vector<float> x2L;
float *x2R; std::vector<float> x2R;
float *y1L; std::vector<float> y1L;
float *y1R; std::vector<float> y1R;
float *y2L; std::vector<float> y2L;
float *y2R; std::vector<float> y2R;
void ReleaseResources();
}; };

View File

@ -22,7 +22,11 @@ void PConvSingle::ConvolveInterleaved(float *buffer, int channel) {
} }
void PConvSingle::ConvSegment(float *buffer, bool interleaved, int channel) { void PConvSingle::ConvSegment(float *buffer, bool interleaved, int channel) {
if (!interleaved) {
} else {
// TODO // TODO
}
} }
int PConvSingle::GetFFTSize() { int PConvSingle::GetFFTSize() {
@ -41,13 +45,13 @@ bool PConvSingle::InstanceUsable() {
return this->instanceUsable; return this->instanceUsable;
} }
int PConvSingle::LoadKernel(float *buf, int param_2, int segmentSize) { int PConvSingle::LoadKernel(const float *kernel, int kernelSize, int segmentSize) {
if (buf != nullptr && param_2 > 0 && segmentSize > 0 && segmentSize % 2 == 0) { if (kernel != nullptr && kernelSize >= 2 && segmentSize >= 2 && (segmentSize & (segmentSize - 1)) == 0) {
this->instanceUsable = false; this->instanceUsable = false;
ReleaseResources(); ReleaseResources();
this->data = new PConvData(); //(PConvData *) malloc(0x140); // TODO: Sizeof this->data = new PConvData(); //(PConvData *) malloc(0x140); // TODO: Sizeof
this->segmentSize = segmentSize; this->segmentSize = segmentSize;
int n = ProcessKernel(buf, param_2, 1); int n = ProcessKernel(kernel, kernelSize, 1);
if (n != 0) { if (n != 0) {
this->instanceUsable = true; this->instanceUsable = true;
return n; return n;
@ -57,28 +61,28 @@ int PConvSingle::LoadKernel(float *buf, int param_2, int segmentSize) {
return 0; return 0;
} }
int PConvSingle::LoadKernel(const float *param_2,float param_3,int param_4,int param_5) { int PConvSingle::LoadKernel(const float *kernel, float param_3, int kernelSize, int segmentSize) {
// if (buf != nullptr && param_5 > 0 && segmentSize > 0 && segmentSize % 2 == 0) { if (kernel != nullptr && kernelSize >= 2 && segmentSize >= 2 && (segmentSize & (segmentSize - 1)) == 0) {
// this->enable = false; this->instanceUsable = false;
// ReleaseResources(); ReleaseResources();
//// this->data = new PConvData(); //(PConvData *) malloc(0x140); // TODO: Sizeof this->data = new PConvData(); //(PConvData *) malloc(0x140); // TODO: Sizeof
// this->segmentSize = segmentSize; this->segmentSize = segmentSize;
// int n = ProcessKernel(1, param_2, param_4, param_5); int n = ProcessKernel(kernel, param_3, kernelSize, 1);
// if (n != 0) { if (n != 0) {
// this->enable = true; this->instanceUsable = true;
// return n; return n;
// } }
// ReleaseResources(); ReleaseResources();
// } }
return 0; return 0;
} }
int PConvSingle::ProcessKernel(float *param_1, int param_2, int param_3) { int PConvSingle::ProcessKernel(const float *kernel, int kernelSize, int param_4) {
// TODO // TODO
return 0; return 0;
} }
int PConvSingle::ProcessKernel(int param_2, float *param_3, int param_4, int param_5) { int PConvSingle::ProcessKernel(const float *kernel, float param_3, int kernelSize, int param_5) {
// TODO // TODO
return 0; return 0;
} }

View File

@ -25,13 +25,13 @@ public:
void ConvSegment(float *buffer, bool interleaved, int channel); void ConvSegment(float *buffer, bool interleaved, int channel);
int LoadKernel(float *buf, int param_2, int segmentSize); int LoadKernel(const float *kernel, int kernelSize, int segmentSize);
int LoadKernel(const float *param_2,float param_3,int param_4,int param_5); int LoadKernel(const float *kernel, float param_3, int kernelSize, int segmentSize);
int ProcessKernel(float *param_1, int param_2, int param_3); int ProcessKernel(const float *kernel, int kernelSize, int param_4);
int ProcessKernel(int param_2, float *param_3, int param_4, int param_5); int ProcessKernel(const float *kernel, float param_3, int kernelSize, int param_5);
void ReleaseResources(); void ReleaseResources();