mirror of
https://github.com/AndroidAudioMods/ViPERFX_RE.git
synced 2025-06-08 02:29:40 +08:00
Update
This commit is contained in:
parent
b6ee869c04
commit
b6a5a9a3dd
@ -4,21 +4,18 @@ set(CMAKE_CXX_COMPILER_VERSION 20)
|
|||||||
# NDK Settings
|
# NDK Settings
|
||||||
#set(ANDROID_ABI arm64-v8a)
|
#set(ANDROID_ABI arm64-v8a)
|
||||||
set(ANDROID_ABI armeabi-v7a)
|
set(ANDROID_ABI armeabi-v7a)
|
||||||
#set(ANDROID_ARM_NEON true)
|
set(ANDROID_ARM_NEON true)
|
||||||
set(ANDROID_PLATFORM android-21)
|
set(ANDROID_PLATFORM android-21)
|
||||||
SET(CMAKE_CXX_FLAGS "-O0")
|
|
||||||
SET(CMAKE_C_FLAGS "-O0")
|
|
||||||
|
|
||||||
project("ViPER4Android Reworked")
|
project("ViPER4Android")
|
||||||
add_compile_definitions(VERSION_MAJOR=1)
|
add_compile_definitions(VERSION_CODE=1)
|
||||||
add_compile_definitions(VERSION_MINOR=0)
|
add_compile_definitions(VERSION_NAME="1.0.0")
|
||||||
add_compile_definitions(VERSION_CODENAME="Reworked")
|
|
||||||
|
|
||||||
# KISS FFT
|
## KISS FFT
|
||||||
set(KISSFFT_PKGCONFIG OFF)
|
#set(KISSFFT_PKGCONFIG OFF)
|
||||||
set(KISSFFT_STATIC ON)
|
#set(KISSFFT_STATIC ON)
|
||||||
set(KISSFFT_TEST OFF)
|
#set(KISSFFT_TEST OFF)
|
||||||
set(KISSFFT_TOOLS OFF)
|
#set(KISSFFT_TOOLS OFF)
|
||||||
#add_subdirectory(src/cpp/viper/kissfft)
|
#add_subdirectory(src/cpp/viper/kissfft)
|
||||||
|
|
||||||
# ViPERFX
|
# ViPERFX
|
||||||
|
@ -159,13 +159,6 @@ static int32_t handleGetParam(ViperContext *pContext, effect_param_t *pCmdParam,
|
|||||||
memcpy(pReplyParam, pCmdParam, sizeof(effect_param_t) + pCmdParam->psize);
|
memcpy(pReplyParam, pCmdParam, sizeof(effect_param_t) + pCmdParam->psize);
|
||||||
|
|
||||||
switch (*(uint32_t *) pCmdParam->data) {
|
switch (*(uint32_t *) pCmdParam->data) {
|
||||||
case PARAM_GET_DRIVER_VERSION: {
|
|
||||||
pReplyParam->status = 0;
|
|
||||||
pReplyParam->vsize = sizeof(uint32_t);
|
|
||||||
*(uint32_t *) (pReplyParam->data + vOffset) = 0x2050005; // As original, change as needed
|
|
||||||
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case PARAM_GET_ENABLED: {
|
case PARAM_GET_ENABLED: {
|
||||||
pReplyParam->status = 0;
|
pReplyParam->status = 0;
|
||||||
pReplyParam->vsize = sizeof(int32_t);
|
pReplyParam->vsize = sizeof(int32_t);
|
||||||
@ -214,6 +207,20 @@ static int32_t handleGetParam(ViperContext *pContext, effect_param_t *pCmdParam,
|
|||||||
*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_DRIVER_VERSION_CODE: {
|
||||||
|
pReplyParam->status = 0;
|
||||||
|
pReplyParam->vsize = sizeof(uint32_t);
|
||||||
|
*(int32_t *) (pReplyParam->data + vOffset) = VERSION_CODE;
|
||||||
|
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
case PARAM_GET_DRIVER_VERSION_NAME: {
|
||||||
|
pReplyParam->status = 0;
|
||||||
|
pReplyParam->vsize = strlen(VERSION_NAME);
|
||||||
|
memcpy(pReplyParam->data + vOffset, VERSION_NAME, pReplyParam->vsize);
|
||||||
|
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -272,9 +279,7 @@ static int32_t Viper_ICommand(effect_handle_t self,
|
|||||||
static int32_t Viper_IGetDescriptor(effect_handle_t self, effect_descriptor_t *pDescriptor) {
|
static int32_t Viper_IGetDescriptor(effect_handle_t self, effect_descriptor_t *pDescriptor) {
|
||||||
auto pContext = reinterpret_cast<ViperContext *>(self);
|
auto pContext = reinterpret_cast<ViperContext *>(self);
|
||||||
|
|
||||||
if (pContext == nullptr || pDescriptor == nullptr) {
|
if (pContext == nullptr || pDescriptor == nullptr) return -EINVAL;
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
*pDescriptor = viper_descriptor;
|
*pDescriptor = viper_descriptor;
|
||||||
|
|
||||||
|
@ -9,12 +9,13 @@ extern "C" {
|
|||||||
#define COMMAND_CODE_SET 0x02
|
#define COMMAND_CODE_SET 0x02
|
||||||
|
|
||||||
// Param get
|
// Param get
|
||||||
#define PARAM_GET_DRIVER_VERSION 0
|
|
||||||
#define PARAM_GET_ENABLED 1
|
#define PARAM_GET_ENABLED 1
|
||||||
#define PARAM_GET_CONFIGURE 2
|
#define PARAM_GET_CONFIGURE 2
|
||||||
#define PARAM_GET_STREAMING 3
|
#define PARAM_GET_STREAMING 3
|
||||||
#define PARAM_GET_SAMPLING_RATE 4
|
#define PARAM_GET_SAMPLING_RATE 4
|
||||||
#define PARAM_GET_CONVOLUTION_KERNEL_ID 5
|
#define PARAM_GET_CONVOLUTION_KERNEL_ID 5
|
||||||
|
#define PARAM_GET_DRIVER_VERSION_CODE 6
|
||||||
|
#define PARAM_GET_DRIVER_VERSION_NAME 7
|
||||||
|
|
||||||
// Param set
|
// Param set
|
||||||
#define PARAM_SET_UPDATE_STATUS 0x9002
|
#define PARAM_SET_UPDATE_STATUS 0x9002
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
ViPER::ViPER() {
|
ViPER::ViPER() {
|
||||||
VIPER_LOGI("Welcome to ViPER FX");
|
VIPER_LOGI("Welcome to ViPER FX");
|
||||||
VIPER_LOGI("Current version is %s %s", VERSION_STRING, VERSION_CODENAME);
|
VIPER_LOGI("Current version is %s (%d)", VERSION_NAME, VERSION_CODE);
|
||||||
|
|
||||||
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
||||||
|
|
||||||
|
@ -8,9 +8,5 @@
|
|||||||
|
|
||||||
#include "../log.h" // TODO: Remove this dependency
|
#include "../log.h" // TODO: Remove this dependency
|
||||||
|
|
||||||
#define STR_HELPER(x) #x
|
|
||||||
#define STR(x) STR_HELPER(x)
|
|
||||||
#define VERSION_STRING "v" STR(VERSION_MAJOR) "." STR(VERSION_MINOR)
|
|
||||||
|
|
||||||
#define VIPER_DEFAULT_SAMPLING_RATE 44100
|
#define VIPER_DEFAULT_SAMPLING_RATE 44100
|
||||||
#define VIPER_AUTHORS "viper.WYF, Martmists, Iscle"
|
#define VIPER_AUTHORS "viper.WYF, Martmists, Iscle"
|
@ -1,5 +1,7 @@
|
|||||||
#include "Cure.h"
|
#include "Cure.h"
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
Cure::Cure() {
|
Cure::Cure() {
|
||||||
this->enabled = false;
|
this->enabled = false;
|
||||||
Reset();
|
Reset();
|
||||||
@ -17,15 +19,16 @@ float Cure::GetLevelDelay() {
|
|||||||
return this->crossfeed.GetLevelDelay();
|
return this->crossfeed.GetLevelDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Fix with crossfeed
|
||||||
struct Crossfeed::Preset Cure::GetPreset() {
|
struct Crossfeed::Preset Cure::GetPreset() {
|
||||||
return this->crossfeed.GetPreset();
|
return this->crossfeed.GetPreset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cure::Process(float *buffer, uint32_t size) {
|
void Cure::Process(float *buffer, uint32_t size) {
|
||||||
if (this->enabled) {
|
if (!this->enabled) return;
|
||||||
this->crossfeed.ProcessFrames(buffer, size);
|
|
||||||
this->passFilter.ProcessFrames(buffer, size);
|
this->crossfeed.ProcessFrames(buffer, size);
|
||||||
}
|
this->passFilter.ProcessFrames(buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cure::Reset() {
|
void Cure::Reset() {
|
||||||
@ -39,10 +42,10 @@ void Cure::SetCutoff(uint16_t cutoff) {
|
|||||||
|
|
||||||
void Cure::SetEnable(bool enabled) {
|
void Cure::SetEnable(bool enabled) {
|
||||||
if (this->enabled != enabled) {
|
if (this->enabled != enabled) {
|
||||||
this->enabled = enabled;
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
this->enabled = enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "../utils/Crossfeed.h"
|
#include "../utils/Crossfeed.h"
|
||||||
#include "../utils/PassFilter.h"
|
#include "../utils/PassFilter.h"
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
class Cure {
|
class Cure {
|
||||||
public:
|
public:
|
||||||
Cure();
|
Cure();
|
||||||
@ -11,7 +13,7 @@ public:
|
|||||||
uint16_t GetCutoff();
|
uint16_t GetCutoff();
|
||||||
float GetFeedback();
|
float GetFeedback();
|
||||||
float GetLevelDelay();
|
float GetLevelDelay();
|
||||||
struct Crossfeed::Preset GetPreset();
|
struct Crossfeed::Preset GetPreset(); // TODO: Fix with crossfeed
|
||||||
void Process(float *buffer, uint32_t size);
|
void Process(float *buffer, uint32_t size);
|
||||||
void Reset();
|
void Reset();
|
||||||
void SetCutoff(uint16_t cutoff);
|
void SetCutoff(uint16_t cutoff);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "IIRFilter.h"
|
#include "IIRFilter.h"
|
||||||
#include "../constants.h"
|
#include "../constants.h"
|
||||||
|
|
||||||
// Iscle: Verified with latest version at 13/12/2022
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
IIRFilter::IIRFilter(uint32_t bands) {
|
IIRFilter::IIRFilter(uint32_t bands) {
|
||||||
this->enable = false;
|
this->enable = false;
|
||||||
@ -75,10 +75,10 @@ void IIRFilter::SetBandLevel(uint32_t band, float level) {
|
|||||||
|
|
||||||
void IIRFilter::SetEnable(bool enable) {
|
void IIRFilter::SetEnable(bool enable) {
|
||||||
if (this->enable != enable) {
|
if (this->enable != enable) {
|
||||||
this->enable = enable;
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
this->enable = enable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "../utils/MinPhaseIIRCoeffs.h"
|
#include "../utils/MinPhaseIIRCoeffs.h"
|
||||||
|
|
||||||
// Iscle: Verified with latest version at 13/12/2022
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
class IIRFilter {
|
class IIRFilter {
|
||||||
public:
|
public:
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "SpeakerCorrection.h"
|
#include "SpeakerCorrection.h"
|
||||||
#include "../constants.h"
|
#include "../constants.h"
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
SpeakerCorrection::SpeakerCorrection() {
|
SpeakerCorrection::SpeakerCorrection() {
|
||||||
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
||||||
this->enable = false;
|
this->enable = false;
|
||||||
@ -43,7 +45,7 @@ void SpeakerCorrection::Reset() {
|
|||||||
|
|
||||||
void SpeakerCorrection::SetEnable(bool enable) {
|
void SpeakerCorrection::SetEnable(bool enable) {
|
||||||
if (this->enable != enable) {
|
if (this->enable != enable) {
|
||||||
if (!this->enable) {
|
if (enable) {
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
this->enable = enable;
|
this->enable = enable;
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "../utils/MultiBiquad.h"
|
#include "../utils/MultiBiquad.h"
|
||||||
#include "../utils/Biquad.h"
|
#include "../utils/Biquad.h"
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
class SpeakerCorrection {
|
class SpeakerCorrection {
|
||||||
public:
|
public:
|
||||||
SpeakerCorrection();
|
SpeakerCorrection();
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
#include "TubeSimulator.h"
|
#include "TubeSimulator.h"
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
TubeSimulator::TubeSimulator() {
|
TubeSimulator::TubeSimulator() {
|
||||||
this->acc[0] = 0.f;
|
this->acc[0] = 0.0;
|
||||||
this->acc[1] = 0.f;
|
this->acc[1] = 0.0;
|
||||||
this->enable = false;
|
this->enable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TubeSimulator::Reset() {
|
void TubeSimulator::Reset() {
|
||||||
this->acc[0] = 0.f;
|
this->acc[0] = 0.0;
|
||||||
this->acc[1] = 0.f;
|
this->acc[1] = 0.0;
|
||||||
this->enable = false;
|
this->enable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,16 +24,12 @@ void TubeSimulator::SetEnable(bool enable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TubeSimulator::TubeProcess(float *buffer, uint32_t size) {
|
void TubeSimulator::TubeProcess(float *buffer, uint32_t size) {
|
||||||
if (this->enable) {
|
if (!this->enable) return;
|
||||||
for (uint32_t x = 0; x < size; x++) {
|
|
||||||
this->acc[0] = (this->acc[0] + buffer[2 * x]) / 2.f;
|
for (uint32_t i = 0; i < size; i += 2) {
|
||||||
this->acc[1] = (this->acc[1] + buffer[2 * x + 1]) / 2.f;
|
this->acc[0] = (this->acc[0] + buffer[i * 2]) / 2.0;
|
||||||
buffer[2 * x] = this->acc[0];
|
this->acc[1] = (this->acc[1] + buffer[i * 2 + 1]) / 2.0;
|
||||||
buffer[2 * x + 1] = this->acc[1];
|
buffer[i * 2] = (float) this->acc[0];
|
||||||
}
|
buffer[i * 2 + 1] = (float) this->acc[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TubeSimulator::~TubeSimulator() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -2,17 +2,18 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
class TubeSimulator {
|
class TubeSimulator {
|
||||||
public:
|
public:
|
||||||
TubeSimulator();
|
TubeSimulator();
|
||||||
~TubeSimulator();
|
|
||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
void SetEnable(bool enable);
|
void SetEnable(bool enable);
|
||||||
void TubeProcess(float *buffer, uint32_t size);
|
void TubeProcess(float *buffer, uint32_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float acc[2];
|
double acc[2];
|
||||||
bool enable;
|
bool enable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,23 +1,25 @@
|
|||||||
#include "ViPERBass.h"
|
#include "ViPERBass.h"
|
||||||
#include "../constants.h"
|
#include "../constants.h"
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
ViPERBass::ViPERBass() {
|
ViPERBass::ViPERBass() {
|
||||||
this->enable = false;
|
|
||||||
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
|
||||||
this->speaker = 60;
|
this->speaker = 60;
|
||||||
this->samplingRatePeriod = 1.0 / VIPER_DEFAULT_SAMPLING_RATE;
|
this->enable = false;
|
||||||
this->antiPop = 0.0;
|
|
||||||
this->processMode = ProcessMode::NATURAL_BASS;
|
this->processMode = ProcessMode::NATURAL_BASS;
|
||||||
|
this->antiPop = 0.0;
|
||||||
this->bassFactor = 0.0;
|
this->bassFactor = 0.0;
|
||||||
|
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
||||||
|
this->samplingRatePeriod = 1.0 / VIPER_DEFAULT_SAMPLING_RATE;
|
||||||
this->polyphase = new Polyphase(2);
|
this->polyphase = new Polyphase(2);
|
||||||
this->biquad = new Biquad();
|
this->biquad = new Biquad();
|
||||||
this->subwoofer = new Subwoofer();
|
this->subwoofer = new Subwoofer();
|
||||||
this->waveBuffer = new WaveBuffer(1, 0x1000);
|
this->waveBuffer = new WaveBuffer(1, 4096);
|
||||||
|
|
||||||
this->biquad->Reset();
|
this->biquad->Reset();
|
||||||
this->biquad->SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
this->biquad->SetLowPassParameter((float) this->speaker, this->samplingRate, 0.53);
|
||||||
this->subwoofer->SetBassGain(this->samplingRate, 0.0);
|
this->subwoofer->SetBassGain(this->samplingRate, 0.0);
|
||||||
this->Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
ViPERBass::~ViPERBass() {
|
ViPERBass::~ViPERBass() {
|
||||||
@ -28,23 +30,17 @@ ViPERBass::~ViPERBass() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ViPERBass::Process(float *samples, uint32_t size) {
|
void ViPERBass::Process(float *samples, uint32_t size) {
|
||||||
if (!this->enable) {
|
if (!this->enable) return;
|
||||||
return;
|
if (size == 0) return;
|
||||||
}
|
|
||||||
|
|
||||||
if (size == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Iscle: TODO: Maybe we could attenuate the effect instead of the entire sample
|
||||||
if (this->antiPop < 1.0) {
|
if (this->antiPop < 1.0) {
|
||||||
for (uint32_t i = 0; i < size * 2; i += 2) {
|
for (uint32_t i = 0; i < size * 2; i += 2) {
|
||||||
samples[i] *= this->antiPop;
|
samples[i] *= this->antiPop;
|
||||||
samples[i + 1] *= this->antiPop;
|
samples[i + 1] *= this->antiPop;
|
||||||
|
|
||||||
float x = this->antiPop + this->samplingRatePeriod;
|
float x = this->antiPop + this->samplingRatePeriod;
|
||||||
if (x > 1.0) {
|
if (x > 1.0) x = 1.0;
|
||||||
x = 1.0;
|
|
||||||
}
|
|
||||||
this->antiPop = x;
|
this->antiPop = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,9 +104,7 @@ void ViPERBass::SetBassFactor(float bassFactor) {
|
|||||||
|
|
||||||
void ViPERBass::SetEnable(bool enable) {
|
void ViPERBass::SetEnable(bool enable) {
|
||||||
if (this->enable != enable) {
|
if (this->enable != enable) {
|
||||||
if (!this->enable) {
|
if (enable) Reset();
|
||||||
Reset();
|
|
||||||
}
|
|
||||||
this->enable = enable;
|
this->enable = enable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,7 +112,7 @@ void ViPERBass::SetEnable(bool enable) {
|
|||||||
void ViPERBass::SetProcessMode(ProcessMode processMode) {
|
void ViPERBass::SetProcessMode(ProcessMode processMode) {
|
||||||
if (this->processMode != processMode) {
|
if (this->processMode != processMode) {
|
||||||
this->processMode = processMode;
|
this->processMode = processMode;
|
||||||
this->Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "../utils/WaveBuffer.h"
|
#include "../utils/WaveBuffer.h"
|
||||||
#include "../utils/Polyphase.h"
|
#include "../utils/Polyphase.h"
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
class ViPERBass {
|
class ViPERBass {
|
||||||
public:
|
public:
|
||||||
enum ProcessMode {
|
enum ProcessMode {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "ViPERClarity.h"
|
#include "ViPERClarity.h"
|
||||||
#include "../constants.h"
|
#include "../constants.h"
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
ViPERClarity::ViPERClarity() {
|
ViPERClarity::ViPERClarity() {
|
||||||
for (auto &highShelf : this->highShelf) {
|
for (auto &highShelf : this->highShelf) {
|
||||||
highShelf.SetFrequency(12000.0);
|
highShelf.SetFrequency(12000.0);
|
||||||
@ -10,15 +12,13 @@ ViPERClarity::ViPERClarity() {
|
|||||||
|
|
||||||
this->enable = false;
|
this->enable = false;
|
||||||
this->processMode = ClarityMode::NATURAL;
|
this->processMode = ClarityMode::NATURAL;
|
||||||
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
|
||||||
this->clarityGainPercent = 0.0;
|
this->clarityGainPercent = 0.0;
|
||||||
|
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViPERClarity::Process(float *samples, uint32_t size) {
|
void ViPERClarity::Process(float *samples, uint32_t size) {
|
||||||
if (!this->enable) {
|
if (!this->enable) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (this->processMode) {
|
switch (this->processMode) {
|
||||||
case ClarityMode::NATURAL: {
|
case ClarityMode::NATURAL: {
|
||||||
@ -26,8 +26,9 @@ void ViPERClarity::Process(float *samples, uint32_t size) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ClarityMode::OZONE: {
|
case ClarityMode::OZONE: {
|
||||||
for (uint32_t i = 0; i < size * 2; i++) {
|
for (uint32_t i = 0; i < size * 2; i += 2) {
|
||||||
samples[i] = (float) this->highShelf[i % 2].Process(samples[i]);
|
samples[i] = (float) this->highShelf[0].Process(samples[i]);
|
||||||
|
samples[i + 1] = (float) this->highShelf[1].Process(samples[i + 1]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -41,7 +42,7 @@ void ViPERClarity::Process(float *samples, uint32_t size) {
|
|||||||
void ViPERClarity::Reset() {
|
void ViPERClarity::Reset() {
|
||||||
this->noiseSharpening.SetSamplingRate(this->samplingRate);
|
this->noiseSharpening.SetSamplingRate(this->samplingRate);
|
||||||
this->noiseSharpening.Reset();
|
this->noiseSharpening.Reset();
|
||||||
this->SetClarityToFilter();
|
SetClarityToFilter();
|
||||||
for (auto &highShelf : this->highShelf) {
|
for (auto &highShelf : this->highShelf) {
|
||||||
highShelf.SetFrequency(8250.0);
|
highShelf.SetFrequency(8250.0);
|
||||||
highShelf.SetSamplingRate(this->samplingRate);
|
highShelf.SetSamplingRate(this->samplingRate);
|
||||||
@ -52,10 +53,10 @@ void ViPERClarity::Reset() {
|
|||||||
|
|
||||||
void ViPERClarity::SetClarity(float gainPercent) {
|
void ViPERClarity::SetClarity(float gainPercent) {
|
||||||
this->clarityGainPercent = gainPercent;
|
this->clarityGainPercent = gainPercent;
|
||||||
if (this->processMode != ClarityMode::OZONE) {
|
if (this->processMode == ClarityMode::OZONE) {
|
||||||
this->SetClarityToFilter();
|
|
||||||
} else {
|
|
||||||
Reset();
|
Reset();
|
||||||
|
} else {
|
||||||
|
SetClarityToFilter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ void ViPERClarity::SetClarityToFilter() {
|
|||||||
|
|
||||||
void ViPERClarity::SetEnable(bool enable) {
|
void ViPERClarity::SetEnable(bool enable) {
|
||||||
if (this->enable != enable) {
|
if (this->enable != enable) {
|
||||||
if (!this->enable) {
|
if (enable) {
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
this->enable = enable;
|
this->enable = enable;
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include "../utils/HiFi.h"
|
#include "../utils/HiFi.h"
|
||||||
#include "../utils/HighShelf.h"
|
#include "../utils/HighShelf.h"
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
class ViPERClarity {
|
class ViPERClarity {
|
||||||
public:
|
public:
|
||||||
enum ClarityMode {
|
enum ClarityMode {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "Biquad.h"
|
#include "Biquad.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
// Some variable names RE'd with help from https://github.com/wooters/miniDSP/blob/master/biquad.c
|
// Some variable names RE'd with help from https://github.com/wooters/miniDSP/blob/master/biquad.c
|
||||||
|
|
||||||
Biquad::Biquad() {
|
Biquad::Biquad() {
|
||||||
@ -41,14 +42,14 @@ void Biquad::SetBandPassParameter(float frequency, uint32_t samplingRate, float
|
|||||||
double sinOmega = sin(omega);
|
double sinOmega = sin(omega);
|
||||||
double cosOmega = cos(omega);
|
double cosOmega = cos(omega);
|
||||||
|
|
||||||
double alpha = sinOmega / (2.0 * (double) qFactor);
|
double alpha = sinOmega / ((double) qFactor + (double) qFactor);
|
||||||
|
|
||||||
double a0 = 1.0 + alpha;
|
double a0 = alpha + 1.0;
|
||||||
double a1 = -2.0 * cosOmega;
|
double a1 = cosOmega * -2.0;
|
||||||
double a2 = 1.0 - alpha;
|
double a2 = 1.0 - alpha;
|
||||||
double b0 = sinOmega / 2.0; // Reference biquad implementation would use alpha here
|
double b0 = sinOmega / 2.0; // Reference biquad implementation would use alpha here
|
||||||
double b1 = 0.0;
|
double b1 = 0.0;
|
||||||
double b2 = -sinOmega / 2.0; // Reference biquad implementation would use -alpha here
|
double b2 = -(sinOmega / 2.0); // Reference biquad implementation would use -alpha here
|
||||||
|
|
||||||
SetCoeffs(a0, a1, a2, b0, b1, b2);
|
SetCoeffs(a0, a1, a2, b0, b1, b2);
|
||||||
}
|
}
|
||||||
@ -59,37 +60,30 @@ void Biquad::SetCoeffs(double a0, double a1, double a2, double b0, double b1, do
|
|||||||
this->y2 = 0.0;
|
this->y2 = 0.0;
|
||||||
this->y1 = 0.0;
|
this->y1 = 0.0;
|
||||||
|
|
||||||
this->a1 = -a1 / a0;
|
this->a1 = -(a1 / a0);
|
||||||
this->a2 = -a2 / a0;
|
this->a2 = -(a2 / a0);
|
||||||
this->b0 = b0 / a0;
|
this->b0 = b0 / a0;
|
||||||
this->b1 = b1 / a0;
|
this->b1 = b1 / a0;
|
||||||
this->b2 = b2 / a0;
|
this->b2 = b2 / a0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check
|
|
||||||
void
|
void
|
||||||
Biquad::SetHighPassParameter(float frequency, uint32_t samplingRate, double dbGain, float qFactor, double param_6) {
|
Biquad::SetHighPassParameter(float frequency, uint32_t samplingRate, double dbGain, float qFactor, double param_6) {
|
||||||
double omega = (2.0 * M_PI * (double) frequency) / (double) samplingRate;
|
double omega = (2.0 * M_PI * (double) frequency) / (double) samplingRate;
|
||||||
double sinX = sin(omega);
|
double sinOmega = sin(omega);
|
||||||
double cosX = cos(omega);
|
double cosOmega = cos(omega);
|
||||||
|
|
||||||
double A = pow(10.0, dbGain / 40.0);
|
double A = pow(10.0, dbGain / 40.0);
|
||||||
double sqrtY = sqrt(A);
|
double sqrtA = sqrt(A);
|
||||||
|
|
||||||
double z = sinX / 2.0 * sqrt((1.0 / A + A) * (1.0 / (double) qFactor - 1.0) + 2.0);
|
double z = sinOmega / 2.0 * sqrt((1.0 / A + A) * (1.0 / (double) qFactor - 1.0) + 2.0);
|
||||||
double a = (A - 1.0) * cosX;
|
|
||||||
double b = (A + 1.0) + a;
|
|
||||||
double c = (A + 1.0) * cosX;
|
|
||||||
double d = (A + 1.0) - a;
|
|
||||||
double e = pow(10.0, param_6 / 20.0);
|
|
||||||
double f = (A - 1.0) - c;
|
|
||||||
|
|
||||||
double a0 = d + (sqrtY * 2.0) * z;
|
double a0 = (A + 1.0) - (A - 1.0) * cosOmega + (sqrtA * 2.0) * z;
|
||||||
double a1 = f * 2.0;
|
double a1 = ((A - 1.0) - (A + 1.0) * cosOmega) * 2.0;
|
||||||
double a2 = d - (sqrtY * 2.0) * z;
|
double a2 = (A + 1.0) - (A - 1.0) * cosOmega - (sqrtA * 2.0) * z;
|
||||||
double b0 = (b + (sqrtY * 2.0) * z) * A * e;
|
double b0 = ((A + 1.0) + (A - 1.0) * cosOmega + (sqrtA * 2.0) * z) * A * omega;
|
||||||
double b1 = A * -2.0 * ((A - 1.0) + c) * e;
|
double b1 = A * -2.0 * ((A - 1.0) + (A + 1.0) * cosOmega) * omega;
|
||||||
double b2 = (b - (sqrtY * 2.0) * z) * A * e;
|
double b2 = ((A + 1.0) + (A - 1.0) * cosOmega - (sqrtA * 2.0) * z) * A * omega;
|
||||||
|
|
||||||
SetCoeffs(a0, a1, a2, b0, b1, b2);
|
SetCoeffs(a0, a1, a2, b0, b1, b2);
|
||||||
}
|
}
|
||||||
@ -99,10 +93,10 @@ void Biquad::SetLowPassParameter(float frequency, uint32_t samplingRate, float q
|
|||||||
double sinOmega = sin(omega);
|
double sinOmega = sin(omega);
|
||||||
double cosOmega = cos(omega);
|
double cosOmega = cos(omega);
|
||||||
|
|
||||||
double alpha = sinOmega / (2.0 * (double) qFactor);
|
double alpha = sinOmega / ((double) qFactor + (double) qFactor);
|
||||||
|
|
||||||
double a0 = 1.0 + alpha;
|
double a0 = alpha + 1.0;
|
||||||
double a1 = -2.0 * cosOmega;
|
double a1 = cosOmega * -2.0;
|
||||||
double a2 = 1.0 - alpha;
|
double a2 = 1.0 - alpha;
|
||||||
double b0 = (1.0 - cosOmega) / 2.0;
|
double b0 = (1.0 - cosOmega) / 2.0;
|
||||||
double b1 = 1.0 - cosOmega;
|
double b1 = 1.0 - cosOmega;
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
class Biquad {
|
class Biquad {
|
||||||
public:
|
public:
|
||||||
Biquad();
|
Biquad();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "../constants.h"
|
#include "../constants.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
// Iscle: Verified with latest version at 13/12/2022
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
static const float MIN_PHASE_IIR_COEFFS_FREQ_10BANDS[] = {
|
static const float MIN_PHASE_IIR_COEFFS_FREQ_10BANDS[] = {
|
||||||
31.0,
|
31.0,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
// Iscle: Verified with latest version at 13/12/2022
|
// Iscle: Verified with the latest version at 13/12/2022
|
||||||
|
|
||||||
class MinPhaseIIRCoeffs {
|
class MinPhaseIIRCoeffs {
|
||||||
public:
|
public:
|
||||||
|
@ -49,11 +49,11 @@ MultiBiquad::RefreshFilter(FilterType type, float gainAmp, float frequency, uint
|
|||||||
if (type == FilterType::LOW_SHELF || type == FilterType::HIGH_SHELF) {
|
if (type == FilterType::LOW_SHELF || type == FilterType::HIGH_SHELF) {
|
||||||
y = sinOmega / 2.0 * sqrt((1.0 / gain + gain) * (1.0 / (double) qFactor - 1.0) + 2.0);
|
y = sinOmega / 2.0 * sqrt((1.0 / gain + gain) * (1.0 / (double) qFactor - 1.0) + 2.0);
|
||||||
z = sqrt(gain) * 2.0 * y;
|
z = sqrt(gain) * 2.0 * y;
|
||||||
} else if (!param_7) {
|
} else if (param_7) {
|
||||||
y = sinOmega / ((double) qFactor * 2.0);
|
y = sinh(((double) qFactor * log(2.0) * omega / 2.0) / sinOmega) * sinOmega;
|
||||||
z = -1.0; // Unused in this case
|
z = -1.0; // Unused in this case
|
||||||
} else {
|
} else {
|
||||||
y = sinh(((double) qFactor * log(2.0) * omega / 2.0) / sinOmega) * sinOmega;
|
y = sinOmega / ((double) qFactor + (double) qFactor);
|
||||||
z = -1.0; // Unused in this case
|
z = -1.0; // Unused in this case
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,13 +143,13 @@ MultiBiquad::RefreshFilter(FilterType type, float gainAmp, float frequency, uint
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->x2 = 0.0;
|
|
||||||
this->x1 = 0.0;
|
this->x1 = 0.0;
|
||||||
this->y2 = 0.0;
|
this->x2 = 0.0;
|
||||||
this->y1 = 0.0;
|
this->y1 = 0.0;
|
||||||
|
this->y2 = 0.0;
|
||||||
|
|
||||||
this->a1 = -a1 / a0;
|
this->a1 = -(a1 / a0);
|
||||||
this->a2 = -a2 / a0;
|
this->a2 = -(a2 / a0);
|
||||||
this->b0 = b0 / a0;
|
this->b0 = b0 / a0;
|
||||||
this->b1 = b1 / a0;
|
this->b1 = b1 / a0;
|
||||||
this->b2 = b2 / a0;
|
this->b2 = b2 / a0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user