2022-08-28 19:02:27 +02:00
|
|
|
#include "ViPER.h"
|
2022-08-30 00:39:15 +02:00
|
|
|
#include <ctime>
|
2021-07-27 19:00:39 +02:00
|
|
|
#include "constants.h"
|
2021-07-27 09:47:15 +02:00
|
|
|
|
2022-08-28 19:02:27 +02:00
|
|
|
ViPER::ViPER() {
|
|
|
|
VIPER_LOGI("Welcome to ViPER FX");
|
|
|
|
VIPER_LOGI("Current version is %s %s", VERSION_STRING, VERSION_CODENAME);
|
2022-08-24 01:08:20 +02:00
|
|
|
|
2022-09-18 03:39:40 +02:00
|
|
|
this->adaptiveBuffer = new AdaptiveBuffer(2, 4096);
|
2022-09-18 03:38:22 +02:00
|
|
|
this->waveBuffer = new WaveBuffer(2, 4096);
|
2022-08-24 01:08:20 +02:00
|
|
|
|
|
|
|
this->convolver = new Convolver();
|
2022-08-30 00:39:15 +02:00
|
|
|
this->convolver->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->convolver->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->convolver->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
|
|
|
|
this->vhe = new VHE();
|
|
|
|
this->vhe->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->vhe->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->vhe->Reset();
|
|
|
|
|
|
|
|
this->viperDdc = new ViPERDDC();
|
2022-08-30 00:39:15 +02:00
|
|
|
this->viperDdc->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->viperDdc->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->viperDdc->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
|
|
|
|
this->spectrumExtend = new SpectrumExtend();
|
|
|
|
this->spectrumExtend->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->spectrumExtend->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->spectrumExtend->SetReferenceFrequency(7600);
|
|
|
|
this->spectrumExtend->SetExciter(0);
|
|
|
|
this->spectrumExtend->Reset();
|
|
|
|
|
2022-09-27 03:48:49 +02:00
|
|
|
this->iirFilter = new IIRFilter(10);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->iirFilter->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->iirFilter->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->iirFilter->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
|
|
|
|
this->colorfulMusic = new ColorfulMusic();
|
2022-08-30 00:39:15 +02:00
|
|
|
this->colorfulMusic->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->colorfulMusic->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->colorfulMusic->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
|
|
|
|
this->reverberation = new Reverberation();
|
|
|
|
this->reverberation->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->reverberation->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->reverberation->Reset();
|
|
|
|
|
|
|
|
this->playbackGain = new PlaybackGain();
|
2022-08-30 00:39:15 +02:00
|
|
|
this->playbackGain->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->playbackGain->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->playbackGain->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
|
|
|
|
this->fetCompressor = new FETCompressor();
|
2022-08-30 00:39:15 +02:00
|
|
|
this->fetCompressor->SetParameter(0, 0.0);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->fetCompressor->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->fetCompressor->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
|
|
|
|
this->dynamicSystem = new DynamicSystem();
|
|
|
|
this->dynamicSystem->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->dynamicSystem->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->dynamicSystem->Reset();
|
|
|
|
|
|
|
|
this->viperBass = new ViPERBass();
|
2022-09-27 03:48:49 +02:00
|
|
|
this->viperBass->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->viperBass->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
|
|
|
|
this->viperClarity = new ViPERClarity();
|
2022-09-27 03:48:49 +02:00
|
|
|
this->viperClarity->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->viperClarity->Reset();
|
|
|
|
|
|
|
|
this->diffSurround = new DiffSurround();
|
|
|
|
this->diffSurround->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->diffSurround->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->diffSurround->Reset();
|
|
|
|
|
|
|
|
this->cure = new Cure();
|
|
|
|
this->cure->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->cure->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->cure->Reset();
|
|
|
|
|
|
|
|
this->tubeSimulator = new TubeSimulator();
|
2022-08-30 00:39:15 +02:00
|
|
|
this->tubeSimulator->enabled = false; //SetEnable(false);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->tubeSimulator->Reset();
|
|
|
|
|
|
|
|
this->analogX = new AnalogX();
|
2022-09-16 03:16:58 +02:00
|
|
|
// this->analogX->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->analogX->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->analogX->SetProcessingModel(0);
|
|
|
|
this->analogX->Reset();
|
|
|
|
|
|
|
|
this->speakerCorrection = new SpeakerCorrection();
|
|
|
|
this->speakerCorrection->SetEnable(false);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->speakerCorrection->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->speakerCorrection->Reset();
|
|
|
|
|
2022-08-24 09:44:23 +02:00
|
|
|
for (auto &softwareLimiter: this->softwareLimiters) {
|
|
|
|
softwareLimiter = new SoftwareLimiter();
|
2022-08-30 00:39:15 +02:00
|
|
|
softwareLimiter->ResetLimiter();
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 00:39:15 +02:00
|
|
|
this->fetcomp_enabled = false;
|
2022-08-24 01:08:20 +02:00
|
|
|
this->init_ok = true;
|
2022-09-16 03:16:58 +02:00
|
|
|
this->frame_scale = 1.0;
|
|
|
|
this->left_pan = 1.0;
|
2022-08-30 00:39:15 +02:00
|
|
|
this->process_time_ms = 0;
|
2022-09-16 03:16:58 +02:00
|
|
|
this->right_pan = 1.0;
|
2022-08-24 01:08:20 +02:00
|
|
|
this->enabled = false;
|
|
|
|
this->force_enabled = false;
|
2022-08-30 00:39:15 +02:00
|
|
|
this->update_status = false;
|
2021-07-27 09:47:15 +02:00
|
|
|
}
|
|
|
|
|
2022-08-28 19:02:27 +02:00
|
|
|
ViPER::~ViPER() {
|
2022-08-24 10:02:52 +02:00
|
|
|
delete this->adaptiveBuffer;
|
|
|
|
delete this->waveBuffer;
|
|
|
|
delete this->convolver;
|
|
|
|
delete this->vhe;
|
|
|
|
delete this->viperDdc;
|
|
|
|
delete this->spectrumExtend;
|
|
|
|
delete this->iirFilter;
|
|
|
|
delete this->colorfulMusic;
|
|
|
|
delete this->reverberation;
|
|
|
|
delete this->playbackGain;
|
|
|
|
delete this->fetCompressor;
|
|
|
|
delete this->dynamicSystem;
|
|
|
|
delete this->viperBass;
|
|
|
|
delete this->viperClarity;
|
|
|
|
delete this->diffSurround;
|
|
|
|
delete this->cure;
|
|
|
|
delete this->tubeSimulator;
|
|
|
|
delete this->analogX;
|
|
|
|
delete this->speakerCorrection;
|
2022-09-16 03:16:58 +02:00
|
|
|
for (auto &softwareLimiter: this->softwareLimiters) {
|
2022-08-24 10:02:52 +02:00
|
|
|
delete softwareLimiter;
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
2021-07-27 09:47:15 +02:00
|
|
|
}
|
|
|
|
|
2022-09-27 03:48:49 +02:00
|
|
|
// TODO: Return int
|
|
|
|
void ViPER::processBuffer(float *buffer, uint32_t size) {
|
2022-08-30 00:39:15 +02:00
|
|
|
if (!this->enabled) return;
|
2022-09-27 03:48:49 +02:00
|
|
|
if (size == 0) return;
|
2022-08-30 00:39:15 +02:00
|
|
|
if (!this->init_ok) return;
|
|
|
|
|
|
|
|
if (this->update_status) {
|
|
|
|
struct timeval time{};
|
|
|
|
gettimeofday(&time, nullptr);
|
|
|
|
this->process_time_ms = time.tv_sec * 1000 + time.tv_usec / 1000;
|
|
|
|
}
|
|
|
|
|
2022-09-16 03:16:58 +02:00
|
|
|
uint32_t ret;
|
2022-08-30 00:39:15 +02:00
|
|
|
|
|
|
|
// if convolver is enabled
|
2022-09-27 03:48:49 +02:00
|
|
|
ret = this->waveBuffer->PushSamples(buffer, size);
|
2022-08-30 00:39:15 +02:00
|
|
|
if (ret == 0) {
|
|
|
|
this->waveBuffer->Reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-18 03:38:22 +02:00
|
|
|
auto pWaveBuffer = this->waveBuffer->GetBuffer();
|
2022-09-27 03:48:49 +02:00
|
|
|
this->convolver->Process(pWaveBuffer, pWaveBuffer, size);
|
|
|
|
this->vhe->Process(pWaveBuffer, pWaveBuffer, size);
|
|
|
|
this->waveBuffer->SetBufferOffset(size);
|
2022-08-30 00:39:15 +02:00
|
|
|
|
2022-09-27 03:48:49 +02:00
|
|
|
ret = this->adaptiveBuffer->PushZero(size);
|
2022-08-30 00:39:15 +02:00
|
|
|
if (ret == 0) {
|
|
|
|
this->waveBuffer->Reset();
|
|
|
|
this->adaptiveBuffer->FlushBuffer();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pAdaptiveBuffer = this->adaptiveBuffer->GetBufferPointer();
|
2022-09-27 03:48:49 +02:00
|
|
|
ret = this->waveBuffer->PopSamples((float *) pAdaptiveBuffer, size, true);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->adaptiveBuffer->SetBufferOffset(ret);
|
|
|
|
|
|
|
|
pAdaptiveBuffer = this->adaptiveBuffer->GetBufferPointer();
|
|
|
|
if (ret != 0) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->viperDdc->Process(pAdaptiveBuffer, size);
|
|
|
|
this->spectrumExtend->Process(pAdaptiveBuffer, size);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->iirFilter->Process(pAdaptiveBuffer, ret);
|
|
|
|
this->colorfulMusic->Process(pAdaptiveBuffer, ret);
|
|
|
|
this->diffSurround->Process(pAdaptiveBuffer, ret);
|
|
|
|
this->reverberation->Process(pAdaptiveBuffer, ret);
|
|
|
|
this->speakerCorrection->Process(pAdaptiveBuffer, ret);
|
|
|
|
this->playbackGain->Process(pAdaptiveBuffer, ret);
|
|
|
|
this->fetCompressor->Process(pAdaptiveBuffer, ret);
|
|
|
|
this->dynamicSystem->Process(pAdaptiveBuffer, ret);
|
|
|
|
this->viperBass->Process(pAdaptiveBuffer, ret);
|
|
|
|
this->viperClarity->Process(pAdaptiveBuffer, ret);
|
|
|
|
this->cure->Process(pAdaptiveBuffer, ret);
|
2022-09-27 03:48:49 +02:00
|
|
|
this->tubeSimulator->TubeProcess(pAdaptiveBuffer, size);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->analogX->Process(pAdaptiveBuffer, ret);
|
|
|
|
}
|
|
|
|
|
2022-09-16 03:16:58 +02:00
|
|
|
if (this->frame_scale != 1.0) {
|
|
|
|
this->adaptiveBuffer->ScaleFrames(this->frame_scale);
|
2022-08-30 00:39:15 +02:00
|
|
|
}
|
2022-09-16 03:16:58 +02:00
|
|
|
if (this->left_pan < 1.0 || this->right_pan < 1.0) {
|
|
|
|
this->adaptiveBuffer->PanFrames(this->left_pan, this->right_pan);
|
2022-08-30 00:39:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret << 1 != 0) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-27 09:47:15 +02:00
|
|
|
}
|
|
|
|
|
2022-09-28 03:38:57 +02:00
|
|
|
void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, uint32_t arrSize,
|
|
|
|
signed char *arr) {
|
2021-07-27 09:47:15 +02:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2022-08-28 19:02:27 +02:00
|
|
|
void ViPER::ResetAllEffects() {
|
2022-08-24 01:08:20 +02:00
|
|
|
if (this->adaptiveBuffer != nullptr) {
|
2022-08-30 00:39:15 +02:00
|
|
|
this->adaptiveBuffer->FlushBuffer();
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
|
|
|
if (this->waveBuffer != nullptr) {
|
|
|
|
this->waveBuffer->Reset();
|
|
|
|
}
|
|
|
|
if (this->convolver != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->convolver->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->convolver->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
|
|
|
if (this->vhe != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->vhe->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->vhe->Reset();
|
|
|
|
}
|
|
|
|
if (this->viperDdc != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->viperDdc->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->viperDdc->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
|
|
|
if (this->spectrumExtend != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->spectrumExtend->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->spectrumExtend->Reset();
|
|
|
|
}
|
|
|
|
if (this->iirFilter != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->iirFilter->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->iirFilter->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
|
|
|
if (this->colorfulMusic != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->colorfulMusic->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->colorfulMusic->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
|
|
|
if (this->reverberation != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->reverberation->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->reverberation->Reset();
|
|
|
|
}
|
|
|
|
if (this->playbackGain != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->playbackGain->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->playbackGain->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
|
|
|
if (this->fetCompressor != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->fetCompressor->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->fetCompressor->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
|
|
|
if (this->dynamicSystem != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->dynamicSystem->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->dynamicSystem->Reset();
|
|
|
|
}
|
|
|
|
if (this->viperBass != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->viperBass->SetSamplingRate(this->samplingRate);
|
2022-08-30 00:39:15 +02:00
|
|
|
this->viperBass->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
|
|
|
if (this->viperClarity != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->viperClarity->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->viperClarity->Reset();
|
|
|
|
}
|
|
|
|
if (this->diffSurround != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->diffSurround->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->diffSurround->Reset();
|
|
|
|
}
|
|
|
|
if (this->cure != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->cure->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->cure->Reset();
|
|
|
|
}
|
|
|
|
if (this->tubeSimulator != nullptr) {
|
2022-08-30 00:39:15 +02:00
|
|
|
this->tubeSimulator->Reset();
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
|
|
|
if (this->analogX != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->analogX->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->analogX->Reset();
|
|
|
|
}
|
|
|
|
if (this->speakerCorrection != nullptr) {
|
2022-09-27 03:48:49 +02:00
|
|
|
this->speakerCorrection->SetSamplingRate(this->samplingRate);
|
2022-08-24 01:08:20 +02:00
|
|
|
this->speakerCorrection->Reset();
|
|
|
|
}
|
2022-08-24 09:48:11 +02:00
|
|
|
for (auto &softwareLimiter: softwareLimiters) {
|
|
|
|
if (softwareLimiter != nullptr) {
|
2022-08-30 00:39:15 +02:00
|
|
|
softwareLimiter->ResetLimiter();
|
2022-08-24 01:08:20 +02:00
|
|
|
}
|
|
|
|
}
|
2021-07-27 09:47:15 +02:00
|
|
|
}
|