Added Mod Distortions DS1 and BigMuff

pull/764/head
jnonis 7 months ago
parent 2d854393a4
commit 6f05c233a6
  1. 3
      src/Makefile
  2. 2
      src/effect_base.h
  3. 229
      src/effect_bigmuff.cpp
  4. 84
      src/effect_bigmuff.h
  5. 225
      src/effect_ds1.cpp
  6. 81
      src/effect_ds1.h
  7. 8
      src/effects.h
  8. 8943
      src/moddistortion/ASinh.h
  9. 8941
      src/moddistortion/Cosh.h
  10. 431
      src/moddistortion/Distortion_BigMuff.cpp
  11. 12
      src/moddistortion/Distortion_BigMuff.h
  12. 979
      src/moddistortion/Distortion_DS1.cpp
  13. 72
      src/moddistortion/Distortion_DS1.h
  14. 84
      src/moddistortion/HyperbolicTables.cpp
  15. 10
      src/moddistortion/HyperbolicTables.h
  16. 414
      src/moddistortion/OverSample.cpp
  17. 32
      src/moddistortion/OverSample.h
  18. 8939
      src/moddistortion/Sinh.h
  19. 53
      src/uimenu.cpp
  20. 4
      src/uimenu.h

@ -10,6 +10,9 @@ OBJS = main.o kernel.o minidexed.o config.o userinterface.o uimenu.o \
mididevice.o midikeyboard.o serialmididevice.o pckeyboard.o \
sysexfileloader.o performanceconfig.o perftimer.o \
effect_base.o effect_chorus.o effect_delay.o \
effect_ds1.o effect_bigmuff.o \
moddistortion/Distortion_DS1.o moddistortion/Distortion_BigMuff.o \
moddistortion/HyperbolicTables.o moddistortion/OverSample.o \
effect_compressor.o effect_platervbstereo.o uibuttons.o midipin.o
OPTIMIZE = -O3

@ -9,6 +9,8 @@
#define EFFECT_CHORUS 1
#define EFFECT_DELAY 2
#define EFFECT_LPF 3
#define EFFECT_DS1 4
#define EFFECT_BIGMUFF 5
class AudioEffect
{

@ -0,0 +1,229 @@
#include <circle/logger.h>
#include "effect_bigmuff.h"
#include "moddistortion/OverSample.h"
LOGMODULE ("fx bigmuff");
AudioEffectBigMuff::AudioEffectBigMuff(float32_t samplerate) : AudioEffect(samplerate)
{
sustain = 0.5f;
tone = 0.5f;
level = 0.5f;
cont = 0;
u = (float*)malloc(2*TAMANHO_DO_BUFFER*sizeof(float));
y = (float*)malloc(2*TAMANHO_DO_BUFFER*sizeof(float));
u2 = (float*)malloc(8*TAMANHO_DO_BUFFER*sizeof(float));
y2 = (float*)malloc(8*TAMANHO_DO_BUFFER*sizeof(float));
u3 = (float*)malloc(TAMANHO_DO_BUFFER*sizeof(float));
y3 = (float*)malloc(TAMANHO_DO_BUFFER*sizeof(float));
nSust = 50;
Sust = (double*)calloc(nSust,sizeof(double));
SustainMedia_1 = 0.5;
T = 1/samplerate;
h1u_1 = 0;
h1y_1 = 0;
h2u_1 = 0;
h2y_1 = 0;
h2u_2 = 0;
h2y_2 = 0;
h2u_3 = 0;
h2y_3 = 0;
h3u_1 = 0;
h3y_1 = 0;
h3u_2 = 0;
h3y_2 = 0;
h3u_3 = 0;
h3y_3 = 0;
u_1 = 0;
y_1 = 0;
h4u_1 = 0;
h4y_1 = 0;
h4u_2 = 0;
h4y_2 = 0;
h4u_3 = 0;
h4y_3 = 0;
}
AudioEffectBigMuff::~AudioEffectBigMuff()
{
free(u);
free(y);
free(u2);
free(y2);
free(u3);
free(y3);
free(Sust);
}
unsigned AudioEffectBigMuff::getId()
{
return EFFECT_BIGMUFF;
}
void AudioEffectBigMuff::setParameter(unsigned param, unsigned value)
{
switch (param)
{
case AudioEffectBigMuff::Param::BYPASS:
this->setBypass(value == 1);
break;
case AudioEffectBigMuff::Param::SUSTAIN:
this->sustain = value / 100.0f;
break;
case AudioEffectBigMuff::Param::TONE:
this->tone = value / 100.0f;
break;
case AudioEffectBigMuff::Param::LEVEL:
this->level = value / 100.0f;
break;
default:
break;
}
}
unsigned AudioEffectBigMuff::getParameter(unsigned param)
{
switch (param)
{
case AudioEffectBigMuff::Param::BYPASS:
return this->getBypass() ? 1 : 0;
case AudioEffectBigMuff::Param::SUSTAIN:
return roundf(this->sustain * 100);
case AudioEffectBigMuff::Param::TONE:
return roundf(this->tone * 100);
case AudioEffectBigMuff::Param::LEVEL:
return roundf(this->level * 100);
default:
return 0;
}
}
void AudioEffectBigMuff::doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len)
{
if( (len > TAMANHO_DO_BUFFER) && (cont == 0) )
{
u = (float*)realloc(u, 2*len*sizeof(float));
y = (float*)realloc(y, 2*len*sizeof(float));
u2 = (float*)realloc(u2, 8*len*sizeof(float));
y2 = (float*)realloc(y2, 8*len*sizeof(float));
u3 = (float*)realloc(u3, len*sizeof(float));
y3 = (float*)realloc(y3, len*sizeof(float));
cont = 1;
return;
}
double Tone;
double Level;
double Sustain;
double SustainMedia = 0;
Tone = tone;
Level = level;
Sustain = sustain;
for (int i=0; i<nSust-1; i++)
{
Sust[i] = Sust[i+1];
}
Sust[nSust-1] = Sustain;
for (int i=0; i<nSust; i++)
{
SustainMedia = SustainMedia + Sust[i];
}
SustainMedia = SustainMedia/nSust;
double T2;
double T3;
uint32_t n2;
uint32_t n3;
/*
for (uint32_t i=1; i<=len; i++)
{
in[i-1] = INPUT_GAIN*in[i-1]; //15dB
}
*/
//Over 2x
T2 = 0.5*T;
Over2_Float((float *)inblockL, u, &h1u_1, len);
n2 = 2*len;
/*****************************************************************/
BM_Filter1(u, y, n2, T2, &h1u_1, &h1y_1 );
/*****************************************************************/
for (uint32_t i=1; i<=n2; i++)
{
u[i-1] = y[i-1];
}
/*****************************************************************/
BM_Filter2(u, y, n2, T2, &h2u_1, &h2y_1, &h2u_2, &h2y_2, &h2u_3, &h2y_3 );
/*****************************************************************/
for (uint32_t i=1; i<=n2; i++)
{
u[i-1] = y[i-1];
}
/*****************************************************************/
BM_Filter3(u, y, n2, T2, &h3u_1, &h3y_1, &h3u_2, &h3y_2, SustainMedia, SustainMedia_1 );
/*****************************************************************/
//Over 4x
T3 = 0.25*T2;
Over4_Float(y, u2, &u_1, n2);
n3 = 4*n2;
/*****************************************************************/
BM_Clip(u2, y2, n3, T3, &u_1, &y_1);
/*****************************************************************/
for (uint32_t i=1; i<=n3; i++)
{
u2[i-1] = y2[i-1];
}
/*****************************************************************/
Down8_Float(u3, y2, len);
/*****************************************************************/
BM_Filter4(u3, y3, len, T, &h4u_1, &h4y_1, &h4u_2, &h4y_2, &h4u_3, &h4y_3, Tone, Level);
/*****************************************************************/
for (uint32_t i=1; i<=len; i++)
{
outblockL[i-1] = y3[i-1]*OUTPUT_GAIN; //-26dB
}
SustainMedia_1 = SustainMedia;
}

@ -0,0 +1,84 @@
#ifndef _EFFECT_BIGMUFF_H
#define _EFFECT_BIGMUFF_H
#include "effect_base.h"
#include "moddistortion/Distortion_BigMuff.h"
class AudioEffectBigMuff : public AudioEffect
{
public:
static const unsigned TAMANHO_DO_BUFFER = 256;
static constexpr float32_t INPUT_GAIN = 1;
static constexpr float32_t OUTPUT_GAIN = 1;
enum Param
{
BYPASS,
SUSTAIN,
TONE,
LEVEL,
UNKNOWN
};
AudioEffectBigMuff(float32_t samplerate);
virtual ~AudioEffectBigMuff();
virtual unsigned getId();
virtual void setParameter(unsigned param, unsigned value);
virtual unsigned getParameter(unsigned param);
protected:
virtual size_t getParametersSize()
{
return sizeof(AudioEffectBigMuff::Param);
}
virtual void doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len);
private:
float tone;
float level;
float sustain;
float *u;
float *u2;
float *u3;
float *y;
float *y2;
float *y3;
double T;
float h1u_1;
float h1y_1;
float h2u_1;
float h2y_1;
float h2u_2;
float h2y_2;
float h2u_3;
float h2y_3;
float h3u_1;
float h3y_1;
float h3u_2;
float h3y_2;
float h3u_3;
float h3y_3;
float u_1;
float y_1;
float h4u_1;
float h4y_1;
float h4u_2;
float h4y_2;
float h4u_3;
float h4y_3;
int cont;
double *Sust;
int nSust;
double SustainMedia_1;
};
#endif // _EFFECT_BIGMUFF

@ -0,0 +1,225 @@
#include <circle/logger.h>
#include "effect_ds1.h"
#include "moddistortion/OverSample.h"
LOGMODULE ("fx ds1");
AudioEffectDS1::AudioEffectDS1(float32_t samplerate) : AudioEffect(samplerate)
{
dist = 0.5f;
tone = 0.5f;
level = 0.5f;
cont = 0;
u_f = (float*)malloc(2*TAMANHO_DO_BUFFER*sizeof(float));
y_f = (float*)malloc(2*TAMANHO_DO_BUFFER*sizeof(float));
u = (float*)malloc(2*TAMANHO_DO_BUFFER*sizeof(float));
y = (float*)malloc(2*TAMANHO_DO_BUFFER*sizeof(float));
u2 = (float*)malloc(8*TAMANHO_DO_BUFFER*sizeof(float));
y2 = (float*)malloc(8*TAMANHO_DO_BUFFER*sizeof(float));
v1 = (float*)malloc(8*TAMANHO_DO_BUFFER*sizeof(float));
v2 = (float*)malloc(8*TAMANHO_DO_BUFFER*sizeof(float));
v3 = (float*)malloc(8*TAMANHO_DO_BUFFER*sizeof(float));
T = 1/samplerate;
h1u_1 = 0;
h1y_1 = 0;
h2u_1 = 0;
h2y_1 = 0;
h2u_2 = 0;
h2y_2 = 0;
h2u_3 = 0;
h2y_3 = 0;
h2u_4 = 0;
h2y_4 = 0;
h3u_1 = 0;
h3y_1 = 0;
h3u_2 = 0;
h3y_2 = 0;
u_1 = 0;
y_1 = 0;
v1_1 = 0;
v2_1 = 0;
v3_1 = 0;
}
AudioEffectDS1::~AudioEffectDS1()
{
free(u_f);
free(y_f);
free(u);
free(y);
free(u2);
free(y2);
free(v1);
free(v2);
free(v3);
}
unsigned AudioEffectDS1::getId()
{
return EFFECT_DS1;
}
void AudioEffectDS1::setParameter(unsigned param, unsigned value)
{
switch (param)
{
case AudioEffectDS1::Param::BYPASS:
this->setBypass(value == 1);
break;
case AudioEffectDS1::Param::DIST:
this->dist = value / 100.0f;
break;
case AudioEffectDS1::Param::TONE:
this->tone = value / 100.0f;
break;
case AudioEffectDS1::Param::LEVEL:
this->level = value / 100.0f;
break;
default:
break;
}
}
unsigned AudioEffectDS1::getParameter(unsigned param)
{
switch (param)
{
case AudioEffectDS1::Param::BYPASS:
return this->getBypass() ? 1 : 0;
case AudioEffectDS1::Param::DIST:
return roundf(this->dist * 100);
case AudioEffectDS1::Param::TONE:
return roundf(this->tone * 100);
case AudioEffectDS1::Param::LEVEL:
return roundf(this->level * 100);
default:
return 0;
}
}
void AudioEffectDS1::doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len)
{
if( (len > TAMANHO_DO_BUFFER) && (cont == 0) )
{
u_f = (float*)realloc(u_f, 2*len*sizeof(float));
y_f = (float*)realloc(y_f, 2*len*sizeof(float));
u = (float*)realloc(u, 2*len*sizeof(float));
y = (float*)realloc(y, 2*len*sizeof(float));
u2 = (float*)realloc(u2, 8*len*sizeof(float));
y2 = (float*)realloc(y2, 8*len*sizeof(float));
v1 = (float*)realloc(v1, 8*len*sizeof(float));
v2 = (float*)realloc(v2, 8*len*sizeof(float));
v3 = (float*)realloc(v3, 8*len*sizeof(float));
cont = 1;
return;
}
float Tone;
float Level;
float Dist;
Tone = tone;
Level = level;
Dist = dist;
float T2;
float T3;
float SampleRate2;
uint32_t n2;
uint32_t n3;
/*
for (uint32_t i=1; i<=len; i++)
{
inblockL[i-1] = INPUT_GAIN * inblockL[i-1]; //15dB
}
*/
//Over 2x
T2 = 0.5*T;
SampleRate2 = 2* this->samplerate;
Over2_Float((float *)inblockL, u_f, &h1u_1, len);
n2 = 2*len;
/*****************************************************************/
if (this->samplerate == 48000)
{
Filter1_48000(u_f, y_f, n2, &h1u_1, &h1y_1 );
}
else
{
Filter1(u_f, y_f, n2, SampleRate2, &h1u_1, &h1y_1 );
}
/*****************************************************************/
for (uint32_t i=1; i<=n2; i++)
{
u_f[i-1] = y_f[i-1];
}
/*****************************************************************/
if (this->samplerate == 48000)
{
Filter2_48000(u_f, y_f, n2, &h2u_1, &h2y_1, &h2u_2, &h2y_2, &h2u_3, &h2y_3, &h2u_4, &h2y_4 );
}
else
{
Filter2(u_f, y_f, n2, SampleRate2, &h2u_1, &h2y_1, &h2u_2, &h2y_2, &h2u_3, &h2y_3, &h2u_4, &h2y_4 );
}
/*****************************************************************/
for (uint32_t i=1; i<=n2; i++)
{
u_f[i-1] = y_f[i-1];
}
if (this->samplerate == 48000)
{
FilterGain_48000(u_f, y_f, n2, Dist, &h3u_1, &h3y_1, &h3u_2, &h3y_2 );
}
else
{
FilterGain(u_f, y_f, n2, Dist, SampleRate2, &h3u_1, &h3y_1, &h3u_2, &h3y_2 );
}
//Over 4x
T3 = 0.25*T2;
Over4_Float(y_f, u2, &u_1, n2);
n3 = 4*n2;
DS1_Clip_Tone(u2, y2, v1, v2, v3, n3, T3, &u_1, &y_1, &v1_1, &v2_1, &v3_1, Tone, Level, &obj);
/*****************************************************************/
Down8_Float(outblockL, y2, len);
for (uint32_t i=1; i<=len; i++)
{
outblockL[i-1] = outblockL[i-1]*OUTPUT_GAIN; //-15dB
}
}

@ -0,0 +1,81 @@
#ifndef _EFFECT_DS1_H
#define _EFFECT_DS1_H
#include "effect_base.h"
#include "moddistortion/Distortion_DS1.h"
class AudioEffectDS1 : public AudioEffect
{
public:
static const unsigned TAMANHO_DO_BUFFER = 256;
static constexpr float32_t INPUT_GAIN = 1;
static constexpr float32_t OUTPUT_GAIN = 1;
enum Param
{
BYPASS,
DIST,
TONE,
LEVEL,
UNKNOWN
};
AudioEffectDS1(float32_t samplerate);
virtual ~AudioEffectDS1();
virtual unsigned getId();
virtual void setParameter(unsigned param, unsigned value);
virtual unsigned getParameter(unsigned param);
protected:
virtual size_t getParametersSize()
{
return sizeof(AudioEffectDS1::Param);
}
virtual void doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len);
private:
float tone;
float level;
float dist;
float *u_f;
float *y_f;
float *u;
float *u2;
float *y;
float *y2;
float *v1;
float *v2;
float *v3;
float T;
float h1u_1;
float h1y_1;
float h2u_1;
float h2y_1;
float h2u_2;
float h2y_2;
float h2u_3;
float h2y_3;
float h2u_4;
float h2y_4;
float h3u_1;
float h3y_1;
float h3u_2;
float h3y_2;
float u_1;
float y_1;
float v1_1;
float v2_1;
float v3_1;
int cont;
ClipClass obj;
};
#endif // _EFFECT_DS1_H

@ -6,6 +6,8 @@
#include "effect_chorus.h"
#include "effect_delay.h"
#include "effect_lpf.h"
#include "effect_ds1.h"
#include "effect_bigmuff.h"
inline AudioEffect* newAudioEffect(unsigned type, float32_t samplerate)
{
@ -17,6 +19,10 @@ inline AudioEffect* newAudioEffect(unsigned type, float32_t samplerate)
return new AudioEffectDelay(samplerate);
case EFFECT_LPF:
return new AudioEffectLPF(samplerate);
case EFFECT_DS1:
return new AudioEffectDS1(samplerate);
case EFFECT_BIGMUFF:
return new AudioEffectBigMuff(samplerate);
case EFFECT_NONE:
default:
return new AudioEffectNone(samplerate);
@ -30,6 +36,8 @@ inline std::string getFXTypeName(int nValue)
case EFFECT_CHORUS: return "Juno Chorus";
case EFFECT_DELAY: return "Delay";
case EFFECT_LPF: return "LP Filter";
case EFFECT_DS1: return "DS1";
case EFFECT_BIGMUFF: return "Big Muff";
case EFFECT_NONE:
default: return "None";
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,431 @@
#include <cmath>
#include "Distortion_BigMuff.h"
#include "HyperbolicTables.h"
void BM_Filter1(float *u, float *y, int N, double T, float *U_1, float *Y_1 )
{
const float R1 = 56e3;
const float R4 = 330e3;
//const float R5 = 10e3;
//const float R6 = 47e3;
//const float R7 = 62e3;
//const float R8 = 560e3;
//const float R9 = 47;
//const float R10 = 8.2e3;
//const float R13 = 470e3;
//const float R14 = 5.6e3;
//const float R15 = 1.2e3;
//const float R16 = 100e3;
const float C1 = 150e-9;
//const float C3 = 4.7e-9;
//const float C4 = 10e-9;
//const float C5 = 10e-6;
//const float C6 = 10e-6;
//const float C7 = 4.7e-6;
//const float C9 = 150e-12;
//const float C10 = 100e-9;
//const float C11 = 1e-6;
//const float C12 = 120e-9;
//const float P1 = 10e3;
//const float P2 = 10e3;
//const float P3 = 100e3;
float c = 2/T;
float y_1 = Y_1[0];
float u_1 = U_1[0];
/*
b1s + b0
G(s) = ----------
a1s + a0
B0 + B1z¹
G(z) = ----------
A0 + A1z¹
y[k] = (-A1*y[k-1] + B0*u[k] + B1*u[k-1] )/A0
*/
const float b0 = 0;
const float b1 = -C1*R4;
const float a0 = 1;
const float a1 = C1*R1;
float B0 = b0 + b1*c;
float B1 = b0 - b1*c;
float A0 = a0 + a1*c;
float A1 = a0 - a1*c;
y[0] = (-A1*y_1 + B0*u[0] + B1*u_1)/A0;
for (int i=1; i<=N-1; i++)
{
y[i] = (-A1*y[i-1] + B0*u[i] + B1*u[i-1] )/A0;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
}
void BM_Filter2(float *u, float *y, int N, double T, float *U_1, float *Y_1, float *U_2, float *Y_2, float*U_3, float *Y_3 )
{
//const double R1 = 56e3;
//const double R4 = 330e3;
const double R5 = 10e3;
const double R6 = 47e3;
const double R7 = 62e3;
const double R8 = 560e3;
//const double R9 = 47;
//const double R10 = 8.2e3;
//const double R13 = 470e3;
//const double R14 = 5.6e3;
//const double R15 = 1.2e3;
//const double R16 = 100e3;
//const double C1 = 150e-9;
const double C3 = 4.7e-9;
const double C4 = 10e-9;
const double C5 = 10e-6;
//const double C6 = 10e-6;
//const double C7 = 4.7e-6;
//const double C9 = 150e-12;
//const double C10 = 100e-9;
//const double C11 = 1e-6;
//const double C12 = 120e-9;
//const double P1 = 10e3;
//const double P2 = 10e3;
//const double P3 = 100e3;
double c = 2/T;
double y_1 = Y_1[0];
double u_1 = U_1[0];
double y_2 = Y_2[0];
double u_2 = U_2[0];
double y_3 = Y_3[0];
double u_3 = U_3[0];
/*
b3s³ + b2s² + b1s + b0
G(s) = ------------------------
a3s³ + a2s² + a1s + a0
B0 + B1z¹ + B2z² + B3z3 Y(z)
G(z) = -------------------------- = ----
A0 + A1z¹ + A2z² + A3z3 U(z)
y[k] = (-A1*y[k-1] -A2*y[k-2] - A3*y[k-3] + B0*u[k] + B1*u[k-1] + B2*u[k-2] + B3*u[k-3] )/A0
*/
const double b0 = 1;
const double b1 = C5*(R7+R8);
const double b2 = 0;
const double b3 = 0;
const double a0 = 1;
const double a1 = C4*(R5 + R6) + C5*R7;
const double a2 = C4*C5*(R5 + R6)*R7 + C3*R5*(C4*R6 - C5*R8);
const double a3 = C3*C4*C5*R5*R6*R7;
double c2 = pow(c,2);
double c3 = pow(c,3);
double B0 = -b0 - b1*c - b2*c2 - b3*c3;
double B1 = -3*b0 - b1*c + b2*c2 + 3*b3*c3;
double B2 = -3*b0 + b1*c + b2*c2 - 3*b3*c3;
double B3 = -b0 + b1*c - b2*c2 + b3*c3;
double A0 = -a0 - a1*c - a2*c2 - a3*c3;
double A1 = -3*a0 - a1*c + a2*c2 + 3*a3*c3;
double A2 = -3*a0 + a1*c + a2*c2 - 3*a3*c3;
double A3 = -a0 + a1*c - a2*c2 + a3*c3;
y[0] = (-A1*y_1 -A2*y_2 -A3*y_3 + B0*u[0] + B1*u_1 + B2*u_2 + B3*u_3)/A0;
y[1] = (-A1*y[0] -A2*y_1 -A3*y_2 + B0*u[1] + B1*u[0] + B2*u_1 + B3*u_2)/A0;
y[2] = (-A1*y[1] -A2*y[0] -A3*y_1 + B0*u[2] + B1*u[1] + B2*u[0] + B3*u_1)/A0;
for (int i=3; i<=N-1; i++)
{
y[i] = (-A1*y[i-1] -A2*y[i-2] -A3*y[i-3] + B0*u[i] + B1*u[i-1] + B2*u[i-2] + B3*u[i-3])/A0;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
U_2[0] = u[N-2];
Y_2[0] = y[N-2];
U_3[0] = u[N-3];
Y_3[0] = y[N-3];
}
void BM_Filter3(float *u, float *y, int N, double T, float *U_1, float *Y_1, float *U_2, float *Y_2, double x, double x_1 )
{
//const double R1 = 56e3;
//const double R4 = 330e3;
//const double R5 = 10e3;
//const double R6 = 47e3;
//const double R7 = 62e3;
//const double R8 = 560e3;
const double R9 = 47;
const double R10 = 8.2e3;
//const double R13 = 470e3;
//const double R14 = 5.6e3;
//const double R15 = 1.2e3;
//const double R16 = 100e3;
//const double C1 = 150e-9;
//const double C3 = 4.7e-9;
//const double C4 = 10e-9;
//const double C5 = 10e-6;
const double C6 = 10e-6;
const double C7 = 4.7e-6;
//const double C9 = 150e-12;
//const double C10 = 100e-9;
//const double C11 = 1e-6;
//const double C12 = 120e-9;
const double P1 = 10e3;
//const double P2 = 10e3;
//const double P3 = 100e3;
double c = 2/T;
double y_1 = Y_1[0];
double u_1 = U_1[0];
double y_2 = Y_2[0];
double u_2 = U_2[0];
/*
b2s² + b1s + b0
G(s) = ----------------
a2s² + a1s + a0
B0 + B1z¹ + B2z² Y(z)
G(z) = ------------------- = ----
A0 + A1z¹ + A2z² U(z)
y[k] = (-A1*y[k-1] -A2*y[k-2] + B0*u[k] + B1*u[k-1] + B2*u[k-2] )/A0
*/
double X = ( (N-1-0)*x_1 + (0)*x )/(N-1);
const double b0 = 0;
const double b1 = 0;
double b2 = -C6*C7*R10*(R9 + P1*X);
const double a0 = -1;
double a1 = -C6*(P1 + R9) - C7*(R10 + R9 + P1*X);
double a2 = C6*C7*(-R10*R9 + P1*P1*(-1 + X)*X - P1*(R10 + R9 - R9*X));
double c2 = pow(c,2);
double B0 = b0 + b1*c + b2*c2;
double B1 = 2*b0 - 2*b2*c2;
double B2 = b0 - b1*c + b2*c2;
double A0 = a0 + a1*c + a2*c2;
double A1 = 2*a0 - 2*a2*c2;
double A2 = a0 - a1*c + a2*c2;
y[0] = (-A1*y_1 -A2*y_2 + B0*u[0] + B1*u_1 + B2*u_2)/A0;
X = ( (N-1-1)*x_1 + (1)*x )/(N-1);
b2 = -C6*C7*R10*(R9 + P1*X);
a1 = -C6*(P1 + R9) - C7*(R10 + R9 + P1*X);
a2 = C6*C7*(-R10*R9 + P1*P1*(-1 + X)*X - P1*(R10 + R9 - R9*X));
B0 = b0 + b1*c + b2*c2;
B1 = 2*b0 - 2*b2*c2;
B2 = b0 - b1*c + b2*c2;
A0 = a0 + a1*c + a2*c2;
A1 = 2*a0 - 2*a2*c2;
A2 = a0 - a1*c + a2*c2;
y[1] = (-A1*y[0] -A2*y_1 + B0*u[1] + B1*u[0] + B2*u_1)/A0;
for (int i=2; i<=N-1; i++)
{
X = ( (N-1-i)*x_1 + (i)*x )/(N-1);
b2 = -C6*C7*R10*(R9 + P1*X);
a1 = -C6*(P1 + R9) - C7*(R10 + R9 + P1*X);
a2 = C6*C7*(-R10*R9 + P1*P1*(-1 + X)*X - P1*(R10 + R9 - R9*X));
B0 = b0 + b1*c + b2*c2;
B1 = 2*b0 - 2*b2*c2;
B2 = b0 - b1*c + b2*c2;
A0 = a0 + a1*c + a2*c2;
A1 = 2*a0 - 2*a2*c2;
A2 = a0 - a1*c + a2*c2;
y[i] = (-A1*y[i-1] -A2*y[i-2] + B0*u[i] + B1*u[i-1] + B2*u[i-2])/A0;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
U_2[0] = u[N-2];
Y_2[0] = y[N-2];
}
void BM_Clip(float *u, float *y, int N, double T, float *U_1, float *Y_1 )
{
//const double R1 = 56e3;
//const double R4 = 330e3;
//const double R5 = 10e3;
//const double R6 = 47e3;
//const double R7 = 62e3;
//const double R8 = 560e3;
//const double R9 = 47;
const double R10 = 8.2e3;
const double R13 = 470e3;
//const double R14 = 5.6e3;
//const double R15 = 1.2e3;
//const double R16 = 100e3;
//const double C1 = 150e-9;
//const double C3 = 4.7e-9;
//const double C4 = 10e-9;
//const double C5 = 10e-6;
//const double C6 = 10e-6;
//const double C7 = 4.7e-6;
const double C9 = 150e-12;
//const double C10 = 100e-9;
//const double C11 = 1e-6;
//const double C12 = 120e-9;
//const double P1 = 10e3;
//const double P2 = 10e3;
//const double P3 = 100e3;
const double Is = 2.52*pow(10,-9);
const double Vt = 3*45.3/1000;
//double c = 2/T;
double y_1 = Y_1[0];
double u_1 = U_1[0];
double A;
double B;
double D;
/*
*/
A = y_1;
B = T*Vt*(R13*(4*Is*R10*SINH(y_1/Vt)+u_1+u[0])+2*R10*y_1);
D = R10*((2*C9*R13+T)*Vt+2*Is*R13*T*COSH(y_1/Vt));
y[0] = A - B/D;
for (int k=1; k<=N-1; k++)
{
A = y[k-1];
B = T*Vt*(R13*(4*Is*R10*SINH(y[k-1]/Vt)+u[k-1]+u[k])+2*R10*y[k-1]);
D = R10*((2*C9*R13+T)*Vt+2*Is*R13*T*COSH(y[k-1]/Vt));
y[k] = A - B/D;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
}
void BM_Filter4(float *u, float *y, int N, double T, float *U_1, float *Y_1, float *U_2, float *Y_2, float *U_3, float *Y_3, double tone, double vol )
{
//const double R1 = 56e3;
//const double R4 = 330e3;
//const double R5 = 10e3;
//const double R6 = 47e3;
//const double R7 = 62e3;
//const double R8 = 560e3;
//const double R9 = 47;
//const double R10 = 8.2e3;
//const double R13 = 470e3;
const double R14 = 5.6e3;
const double R15 = 1.2e3;
const double R16 = 100e3;
//const double C1 = 150e-9;
//const double C3 = 4.7e-9;
//const double C4 = 10e-9;
//const double C5 = 10e-6;
//const double C6 = 10e-6;
//const double C7 = 4.7e-6;
//const double C9 = 150e-12;
const double C10 = 100e-9;
const double C11 = 1e-6;
const double C12 = 120e-9;
//const double P1 = 10e3;
const double P2 = 10e3;
const double P3 = 100e3;
double c = 2/T;
double y_1 = Y_1[0];
double u_1 = U_1[0];
double y_2 = Y_2[0];
double u_2 = U_2[0];
double y_3 = Y_3[0];
double u_3 = U_3[0];
/*
b3s³ + b2s² + b1s + b0
G(s) = ------------------------
a3s³ + a2s² + a1s + a0
B0 + B1z¹ + B2z² + B3z3 Y(z)
G(z) = -------------------------- = ----
A0 + A1z¹ + A2z² + A3z3 U(z)
y[k] = (-A1*y[k-1] -A2*y[k-2] - A3*y[k-3] + B0*u[k] + B1*u[k-1] + B2*u[k-2] + B3*u[k-3] )/A0
*/
const double b0 = 0;
const double b1 = -P3*R16*(C10*R15+C11*(P2+R15-P2*tone))*vol;
const double b2 = -C10*P3*R15*R16*(C11*(P2+R14)+C12*P2*tone)*vol;
const double b3 = -C10*C11*C12*P2*P3*R14*R15*R16*tone*vol;
const double a0 = -(P3+R15)*R16-P3*(P3+R15)*vol+P3*P3*vol*vol+P2*(-1+tone)*(R16+P3*vol);
const double a1 = -(C10*(P2+P3)*R15+C12*P3*(P2+R15)+C11*(P3*R14+P2*(P3+R14)+(P3+R14)*R15))*R16-P2*(-C10*R15+C12*(P2+R15)+C11*(P2-R14+R15))*R16*tone+(C11+C12)*P2*P2*R16*tone*tone-P3*(C10*R15*(P2+P3-P2*tone)+C12*(P3*(P2+R15)+P2*(P2+R15)*tone-P2*P2*tone*tone)+C11*(P3*R14+(P3+R14)*R15-P2*P2*(-1+tone)*tone+P2*(P3+R14-R14*tone+R15*tone)))*vol+P3*P3*(C10*R15+C12*(P2+R15)+C11*(P2+R14+R15))*vol*vol;
const double a2 = C10*C12*P2*R15*(-P3*R16+P2*R16*(-1+tone)*tone+P2*P3*(-1+tone)*tone*vol+P3*P3*(-1+vol)*vol)+C11*(C10*R15*(P2*P2*(-1+tone)*tone*(R16+P3*vol)+P3*R14*(-R16+P3*(-1+vol)*vol)+P2*(-P3*R16+R14*R16*(-1+tone)+P3*R14*(-1+tone)*vol+P3*P3*(-1+vol)*vol))+C12*R14*(P2*P2*(-1+tone)*tone*(R16+P3*vol)+P3*R15*(-R16+P3*(-1+vol)*vol)+P2*(-R15*R16*tone+P3*P3*(-1+vol)*vol-P3*(R16+R15*tone*vol))));
const double a3 = C10*C11*C12*P2*R14*R15*(-P3*R16+P2*R16*(-1+tone)*tone+P2*P3*(-1+tone)*tone*vol+P3*P3*(-1+vol)*vol);
double c2 = pow(c,2);
double c3 = pow(c,3);
double B0 = -b0 - b1*c - b2*c2 - b3*c3;
double B1 = -3*b0 - b1*c + b2*c2 + 3*b3*c3;
double B2 = -3*b0 + b1*c + b2*c2 - 3*b3*c3;
double B3 = -b0 + b1*c - b2*c2 + b3*c3;
double A0 = -a0 - a1*c - a2*c2 - a3*c3;
double A1 = -3*a0 - a1*c + a2*c2 + 3*a3*c3;
double A2 = -3*a0 + a1*c + a2*c2 - 3*a3*c3;
double A3 = -a0 + a1*c - a2*c2 + a3*c3;
y[0] = (-A1*y_1 -A2*y_2 -A3*y_3 + B0*u[0] + B1*u_1 + B2*u_2 + B3*u_3)/A0;
y[1] = (-A1*y[0] -A2*y_1 -A3*y_2 + B0*u[1] + B1*u[0] + B2*u_1 + B3*u_2)/A0;
y[2] = (-A1*y[1] -A2*y[0] -A3*y_1 + B0*u[2] + B1*u[1] + B2*u[0] + B3*u_1)/A0;
for (int i=3; i<=N-1; i++)
{
y[i] = (-A1*y[i-1] -A2*y[i-2] -A3*y[i-3] + B0*u[i] + B1*u[i-1] + B2*u[i-2] + B3*u[i-3])/A0;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
U_2[0] = u[N-2];
Y_2[0] = y[N-2];
U_3[0] = u[N-3];
Y_3[0] = y[N-3];
}

@ -0,0 +1,12 @@
#ifndef _DISTORTION_BIGMUFF_H
#define _DISTORTION_BIGMUFF_H
#include <cmath>
void BM_Filter1(float *u, float *y, int N, double T, float *U_1, float *Y_1 );
void BM_Filter2(float *u, float *y, int N, double T, float *U_1, float *Y_1, float *U_2, float *Y_2, float*U_3, float *Y_3 );
void BM_Filter3(float *u, float *y, int N, double T, float *U_1, float *Y_1, float *U_2, float *Y_2, double x, double x_1 );
void BM_Clip(float *u, float *y, int N, double T, float *U_1, float *Y_1 );
void BM_Filter4(float *u, float *y, int N, double T, float *U_1, float *Y_1, float *U_2, float *Y_2, float *U_3, float *Y_3, double tone, double vol );
#endif // _DISTORTION_BIGMUFF_H

@ -0,0 +1,979 @@
#include <cmath>
#include "Distortion_DS1.h"
#include "HyperbolicTables.h"
ClipClass::ClipClass( )
{
R1 = 2.2e3;
R2 = 6.8e3;
R3 = 2.2e3;
R4 = 6.8e3;
Rt = 20e3;
Rv = 100e3;
C1 = 470e-9;
C2 = 10e-9;
C3 = 100e-9;
C4 = 22e-9;
Is = 2.52e-9;
Vt = 45.3e-3;
T = 1.0/(8*48000);
t = 0.5;
vol = 0.5;
c1 = (1 + R3*( 1/R4 + 1/Rt ) )/( t*vol ) + (1-t)*(Rt/Rv)*(1 + R3*(1/R4 + 1/( (1-t)*Rt) ) )/vol; //t, vol
c2 = ( (t-1)/t )*(1 + R3*(1/R4 + 1/( (1-t)*Rt) ) ); //t
c3 = ( 1/R4 + 1/Rt )/( t*vol ) + (1-t)*(Rt/Rv)*(1/R4 + 1/( (1-t)*Rt) )/vol; //t, vol
c4 = ( (t-1)/t )*(1/R4 + 1/( (1-t)*Rt) ); //t
E[0][0] = 1;
E[0][1] = -1;
E[0][2] = 0;
E[0][3] = 0;
E[1][0] = 0;
E[1][1] = ((T*Is)/(C2*Vt)); //Muda
E[1][2] = 0;
E[1][3] = 0;
E[2][0] = 0;
E[2][1] = 0;
E[2][2] = 1;
E[2][3] = 0;
E[3][0] = 0;
E[3][1] = 1;
E[3][2] = -c2; //t
E[3][3] = -c1; //t, vol
F[0][0] = 1/( 2*R1*C1 );
F[0][1] = 0;
F[0][2] = 0;
F[0][3] = 0;
F[1][0] = 1/( 2*R1*C2 );
F[1][1] = 1/( 2*R2*C2 );
F[1][2] = (c4 - 1/R2)/( 2*C2 ); //t
F[1][3] = c3/(2*C2); //t, vol
F[2][0] = 0;
F[2][1] = -1/( 2*R2*C3 );
F[2][2] = ( 1/R2 + 1/(t*Rt) )/( 2*C3 ); //t
F[2][3] = -1/( 2*vol*t*Rt*C3 ); //t, vol
F[3][0] = 0;
F[3][1] = 0;
F[3][2] = -c4/(2*C4); //t
F[3][3] = -c3/(2*C4); //t, vol
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
{
A[i][j] = E[i][j] + T*F[i][j];
A_[i][j] = E[i][j] - T*F[i][j];
}
}
Ka1[0] = A[2][3]*A[3][2] - A[2][2]*A[3][3];
Ka1[1] = 0;
Ka1[2] = 0;
Ka1[3] = 0;
K1[0] = A[1][3]*A[2][2]*A[3][1] - A[1][2]*A[2][3]*A[3][1] - A[1][3]*A[2][1]*A[3][2] + A[1][2]*A[2][1]*A[3][3];
K1[1] = -A[1][0]*A[2][3]*A[3][2] + A[1][0]*A[2][2]*A[3][3];
K1[2] = A[1][0]*A[2][3]*A[3][1] - A[1][0]*A[2][1]*A[3][3];
K1[3] = -A[1][0]*A[2][2]*A[3][1] + A[1][0]*A[2][1]*A[3][2];
Ka2[0] = 0;
Ka2[1] = 0;
Ka2[2] = 0;
Ka2[3] = 0;
K2[0] = -A[0][1]*A[2][3]*A[3][2] + A[0][1]*A[2][2]*A[3][3];
K2[1] = A[0][0]*A[2][3]*A[3][2] - A[0][0]*A[2][2]*A[3][3];
K2[2] = -A[0][0]*A[2][3]*A[3][1] + A[0][0]*A[2][1]*A[3][3];
K2[3] = A[0][0]*A[2][2]*A[3][1] - A[0][0]*A[2][1]*A[3][2];
Ka3[0] = 0;
Ka3[1] = 0;
Ka3[2] = -A[0][0]*A[3][3];
Ka3[3] = A[0][0]*A[3][2];
K3[0] = A[0][1]*A[1][3]*A[3][2] - A[0][1]*A[1][2]*A[3][3];
K3[1] = -A[0][0]*A[1][3]*A[3][2] + A[0][0]*A[1][2]*A[3][3];
K3[2] = A[0][0]*A[1][3]*A[3][1] + A[0][1]*A[1][0]*A[3][3];
K3[3] = -A[0][0]*A[1][2]*A[3][1] - A[0][1]*A[1][0]*A[3][2];
Ka4[0] = 0;
Ka4[1] = 0;
Ka4[2] = A[0][0]*A[2][3];
Ka4[3] = -A[0][0]*A[2][2];
K4[0] = -A[0][1]*A[1][3]*A[2][2] + A[0][1]*A[1][2]*A[2][3];
K4[1] = A[0][0]*A[1][3]*A[2][2] - A[0][0]*A[1][2]*A[2][3];
K4[2] = -A[0][0]*A[1][3]*A[2][1] - A[0][1]*A[1][0]*A[2][3];
K4[3] = A[0][0]*A[1][2]*A[2][1] + A[0][1]*A[1][0]*A[2][2];
DENa = A[0][0]*A[2][3]*A[3][2]-A[0][0]*A[2][2]*A[3][3];
DEN = A[0][0]*A[1][3]*A[2][2]*A[3][1] - A[0][0]*A[1][2]*A[2][3]*A[3][1] - A[0][0]*A[1][3]*A[2][1]*A[3][2]
- A[0][1]*A[1][0]*A[2][3]*A[3][2] + A[0][0]*A[1][2]*A[2][1]*A[3][3] + A[0][1]*A[1][0]*A[2][2]*A[3][3];
Ku1 = T/( 2*R1*C1 );
Ku2 = T/( 2*R1*C2 );
Kv = -(2*T*Is/C2);
}
void ClipClass::ChangeVolTone(float Volume, float Tone )
{
vol = Volume;
t = Tone;
c1 = (1 + R3*( 1/R4 + 1/Rt ) )/( t*vol ) + (1-t)*(Rt/Rv)*(1 + R3*(1/R4 + 1/( (1-t)*Rt) ) )/vol; //t, vol
c2 = ( (t-1)/t )*(1 + R3*(1/R4 + 1/( (1-t)*Rt) ) ); //t
c3 = ( 1/R4 + 1/Rt )/( t*vol ) + (1-t)*(Rt/Rv)*(1/R4 + 1/( (1-t)*Rt) )/vol; //t, vol
c4 = ( (t-1)/t )*(1/R4 + 1/( (1-t)*Rt) ); //t
E[3][2] = -c2; //t
E[3][3] = -c1; //t, vol
F[1][2] = (c4 - 1/R2)/( 2*C2 ); //t
F[1][3] = c3/(2*C2); //t, vol
F[2][2] = ( 1/R2 + 1/(t*Rt) )/( 2*C3 ); //t
F[2][3] = -1/( 2*vol*t*Rt*C3 ); //t, vol
F[3][2] = -c4/(2*C4); //t
F[3][3] = -c3/(2*C4); //t, vol
A[1][2] = E[1][2] + T*F[1][2] ; //t
A[1][3] = E[1][3] + T*F[1][3] ; //t, vol
A[2][2] = E[2][2] + T*F[2][2] ; //t
A[2][3] = E[2][3] + T*F[2][3] ; //t, vol
A[3][2] = E[3][2] + T*F[3][2]; //t
A[3][3] = E[3][3] + T*F[3][3] ; //t, vol
A_[1][2] = E[1][2] - T*F[1][2] ; //t
A_[1][3] = E[1][3] - T*F[1][3] ; //t, vol
A_[2][2] = E[2][2] - T*F[2][2] ; //t
A_[2][3] = E[2][3] - T*F[2][3] ; //t, vol
A_[3][2] = E[3][2] - T*F[3][2]; //t
A_[3][3] = E[3][3] - T*F[3][3] ; //t, vol
Ka1[0] = A[2][3]*A[3][2] - A[2][2]*A[3][3];
K1[0] = A[1][3]*A[2][2]*A[3][1] - A[1][2]*A[2][3]*A[3][1] - A[1][3]*A[2][1]*A[3][2] + A[1][2]*A[2][1]*A[3][3];
K1[1] = -A[1][0]*A[2][3]*A[3][2] + A[1][0]*A[2][2]*A[3][3];
K1[2] = A[1][0]*A[2][3]*A[3][1] - A[1][0]*A[2][1]*A[3][3];
K1[3] = -A[1][0]*A[2][2]*A[3][1] + A[1][0]*A[2][1]*A[3][2];
K2[0] = -A[0][1]*A[2][3]*A[3][2] + A[0][1]*A[2][2]*A[3][3];
K2[1] = A[0][0]*A[2][3]*A[3][2] - A[0][0]*A[2][2]*A[3][3];
K2[2] = -A[0][0]*A[2][3]*A[3][1] + A[0][0]*A[2][1]*A[3][3];
K2[3] = A[0][0]*A[2][2]*A[3][1] - A[0][0]*A[2][1]*A[3][2];
Ka3[2] = -A[0][0]*A[3][3];
Ka3[3] = A[0][0]*A[3][2];
K3[0] = A[0][1]*A[1][3]*A[3][2] - A[0][1]*A[1][2]*A[3][3];
K3[1] = -A[0][0]*A[1][3]*A[3][2] + A[0][0]*A[1][2]*A[3][3];
K3[2] = A[0][0]*A[1][3]*A[3][1] + A[0][1]*A[1][0]*A[3][3];
K3[3] = -A[0][0]*A[1][2]*A[3][1] - A[0][1]*A[1][0]*A[3][2];
Ka4[2] = A[0][0]*A[2][3];
Ka4[3] = -A[0][0]*A[2][2];
K4[0] = -A[0][1]*A[1][3]*A[2][2] + A[0][1]*A[1][2]*A[2][3];
K4[1] = A[0][0]*A[1][3]*A[2][2] - A[0][0]*A[1][2]*A[2][3];
K4[2] = -A[0][0]*A[1][3]*A[2][1] - A[0][1]*A[1][0]*A[2][3];
K4[3] = A[0][0]*A[1][2]*A[2][1] + A[0][1]*A[1][0]*A[2][2];
DENa = A[0][0]*A[2][3]*A[3][2]-A[0][0]*A[2][2]*A[3][3];
DEN = A[0][0]*A[1][3]*A[2][2]*A[3][1] - A[0][0]*A[1][2]*A[2][3]*A[3][1] - A[0][0]*A[1][3]*A[2][1]*A[3][2]
- A[0][1]*A[1][0]*A[2][3]*A[3][2] + A[0][0]*A[1][2]*A[2][1]*A[3][3] + A[0][1]*A[1][0]*A[2][2]*A[3][3];
}
void ClipClass::ChangeVol(float Volume)
{
vol = Volume;
c1 = (1 + R3*( 1/R4 + 1/Rt ) )/( t*vol ) + (1-t)*(Rt/Rv)*(1 + R3*(1/R4 + 1/( (1-t)*Rt) ) )/vol; //t, vol
c3 = ( 1/R4 + 1/Rt )/( t*vol ) + (1-t)*(Rt/Rv)*(1/R4 + 1/( (1-t)*Rt) )/vol; //t, vol
E[3][3] = -c1; //t, vol
F[1][3] = c3/(2*C2); //t, vol
F[2][3] = -1/( 2*vol*t*Rt*C3 ); //t, vol
F[3][3] = -c3/(2*C4); //t, vol
A[1][3] = E[1][3] + T*F[1][3] ; //t, vol
A[2][3] = E[2][3] + T*F[2][3] ; //t, vol
A[3][3] = E[3][3] + T*F[3][3] ; //t, vol
A_[1][3] = E[1][3] - T*F[1][3] ; //t, vol
A_[2][3] = E[2][3] - T*F[2][3] ; //t, vol
A_[3][3] = E[3][3] - T*F[3][3] ; //t, vol
Ka1[0] = A[2][3]*A[3][2] - A[2][2]*A[3][3];
K1[0] = A[1][3]*A[2][2]*A[3][1] - A[1][2]*A[2][3]*A[3][1] - A[1][3]*A[2][1]*A[3][2] + A[1][2]*A[2][1]*A[3][3];
K1[1] = -A[1][0]*A[2][3]*A[3][2] + A[1][0]*A[2][2]*A[3][3];
K1[2] = A[1][0]*A[2][3]*A[3][1] - A[1][0]*A[2][1]*A[3][3];
K1[3] = -A[1][0]*A[2][2]*A[3][1] + A[1][0]*A[2][1]*A[3][2];
K2[0] = -A[0][1]*A[2][3]*A[3][2] + A[0][1]*A[2][2]*A[3][3];
K2[1] = A[0][0]*A[2][3]*A[3][2] - A[0][0]*A[2][2]*A[3][3];
K2[2] = -A[0][0]*A[2][3]*A[3][1] + A[0][0]*A[2][1]*A[3][3];
K2[3] = A[0][0]*A[2][2]*A[3][1] - A[0][0]*A[2][1]*A[3][2];
Ka3[2] = -A[0][0]*A[3][3];
Ka3[3] = A[0][0]*A[3][2];
K3[0] = A[0][1]*A[1][3]*A[3][2] - A[0][1]*A[1][2]*A[3][3];
K3[1] = -A[0][0]*A[1][3]*A[3][2] + A[0][0]*A[1][2]*A[3][3];
K3[2] = A[0][0]*A[1][3]*A[3][1] + A[0][1]*A[1][0]*A[3][3];
K3[3] = -A[0][0]*A[1][2]*A[3][1] - A[0][1]*A[1][0]*A[3][2];
Ka4[2] = A[0][0]*A[2][3];
Ka4[3] = -A[0][0]*A[2][2];
K4[0] = -A[0][1]*A[1][3]*A[2][2] + A[0][1]*A[1][2]*A[2][3];
K4[1] = A[0][0]*A[1][3]*A[2][2] - A[0][0]*A[1][2]*A[2][3];
K4[2] = -A[0][0]*A[1][3]*A[2][1] - A[0][1]*A[1][0]*A[2][3];
K4[3] = A[0][0]*A[1][2]*A[2][1] + A[0][1]*A[1][0]*A[2][2];
DENa = A[0][0]*A[2][3]*A[3][2]-A[0][0]*A[2][2]*A[3][3];
DEN = A[0][0]*A[1][3]*A[2][2]*A[3][1] - A[0][0]*A[1][2]*A[2][3]*A[3][1] - A[0][0]*A[1][3]*A[2][1]*A[3][2]
- A[0][1]*A[1][0]*A[2][3]*A[3][2] + A[0][0]*A[1][2]*A[2][1]*A[3][3] + A[0][1]*A[1][0]*A[2][2]*A[3][3];
}
void ClipClass::ChangeSampleRate(float SampleRate)
{
T = 1.0/SampleRate;
E[1][1] = ((T*Is)/(C2*Vt)); //Muda
Ku1 = T/( 2*R1*C1 );
Ku2 = T/( 2*R1*C2 );
Kv = -(2*T*Is/C2);
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
{
A[i][j] = E[i][j] + T*F[i][j];
A_[i][j] = E[i][j] - T*F[i][j];
}
}
Ka1[0] = A[2][3]*A[3][2] - A[2][2]*A[3][3];
K1[0] = A[1][3]*A[2][2]*A[3][1] - A[1][2]*A[2][3]*A[3][1] - A[1][3]*A[2][1]*A[3][2] + A[1][2]*A[2][1]*A[3][3];
K1[1] = -A[1][0]*A[2][3]*A[3][2] + A[1][0]*A[2][2]*A[3][3];
K1[2] = A[1][0]*A[2][3]*A[3][1] - A[1][0]*A[2][1]*A[3][3];
K1[3] = -A[1][0]*A[2][2]*A[3][1] + A[1][0]*A[2][1]*A[3][2];
K2[0] = -A[0][1]*A[2][3]*A[3][2] + A[0][1]*A[2][2]*A[3][3];
K2[1] = A[0][0]*A[2][3]*A[3][2] - A[0][0]*A[2][2]*A[3][3];
K2[2] = -A[0][0]*A[2][3]*A[3][1] + A[0][0]*A[2][1]*A[3][3];
K2[3] = A[0][0]*A[2][2]*A[3][1] - A[0][0]*A[2][1]*A[3][2];
Ka3[2] = -A[0][0]*A[3][3];
Ka3[3] = A[0][0]*A[3][2];
K3[0] = A[0][1]*A[1][3]*A[3][2] - A[0][1]*A[1][2]*A[3][3];
K3[1] = -A[0][0]*A[1][3]*A[3][2] + A[0][0]*A[1][2]*A[3][3];
K3[2] = A[0][0]*A[1][3]*A[3][1] + A[0][1]*A[1][0]*A[3][3];
K3[3] = -A[0][0]*A[1][2]*A[3][1] - A[0][1]*A[1][0]*A[3][2];
Ka4[2] = A[0][0]*A[2][3];
Ka4[3] = -A[0][0]*A[2][2];
K4[0] = -A[0][1]*A[1][3]*A[2][2] + A[0][1]*A[1][2]*A[2][3];
K4[1] = A[0][0]*A[1][3]*A[2][2] - A[0][0]*A[1][2]*A[2][3];
K4[2] = -A[0][0]*A[1][3]*A[2][1] - A[0][1]*A[1][0]*A[2][3];
K4[3] = A[0][0]*A[1][2]*A[2][1] + A[0][1]*A[1][0]*A[2][2];
DENa = A[0][0]*A[2][3]*A[3][2]-A[0][0]*A[2][2]*A[3][3];
DEN = A[0][0]*A[1][3]*A[2][2]*A[3][1] - A[0][0]*A[1][2]*A[2][3]*A[3][1] - A[0][0]*A[1][3]*A[2][1]*A[3][2]
- A[0][1]*A[1][0]*A[2][3]*A[3][2] + A[0][0]*A[1][2]*A[2][1]*A[3][3] + A[0][1]*A[1][0]*A[2][2]*A[3][3];
}
void Filter1(float *u, float *y, int N, float SampleRate, float *U_1, float *Y_1 )
{
const float R1 = 1000;
const float R2 = 470e3;
const float C1 = 47e-9;
float c = 2*SampleRate;
float y_1 = Y_1[0];
float u_1 = U_1[0];
/*
R2C1s b1s + b0
G(s) = -------------- = --------
(R1+R2)C1s + 1 a1s + a0
B0 + B1z¹
G(z) = ----------
A0 + A1z¹
y[k] = (-A1*y[k-1] + B0*u[k] + B1*u[k-1] )/A0
*/
const float b0 = 0;
const float b1 = R2*C1;
const float a0 = 1;
const float a1 = (R1+R2)*C1;
const float B0 = b0 + b1*c;
const float B1 = b0 - b1*c;
const float A0 = a0 + a1*c;
const float A1 = a0 - a1*c;
y[0] = (-A1*y_1 + B0*u[0] + B1*u_1)/A0;
for (int i=1; i<=N-1; i++)
{
y[i] = (-A1*y[i-1] + B0*u[i] + B1*u[i-1] )/A0;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
}
void Filter2(float *u, float *y, int N, float SampleRate, float *U_1, float *Y_1, float *U_2, float *Y_2, float *U_3, float *Y_3, float *U_4, float *Y_4 )
{
const double R45 = 90.909090909090907e3;
const double R6 = 100e3;
const double R7 = 470e3;
const double R8 = 10e3;
const double R9 = 22;
const double R10 = 100e3;
const double G45 = 1/R45;
const double G6 = 1/R6;
const double G7 = 1/R7;
const double G8 = 1/R8;
const double G9 = 1/R9;
const double G10 = 1/R10;
const double C2 = 470e-9;
const double C3 = 47e-9;
const double C4 = 250e-12;
const double C5 = 68e-9;
double c = 2*SampleRate;
double y_1 = Y_1[0];
double u_1 = U_1[0];
double y_2 = Y_2[0];
double u_2 = U_2[0];
double y_3 = Y_3[0];
double u_3 = U_3[0];
double y_4 = Y_4[0];
double u_4 = U_4[0];
double const b4 = C2*C3*C4*C5;
double const b3 = C2*C3*C5*(G7 - G9);
double const b2 = 0;
double const b1 = 0;
double const b0 = 0;
double const a4 = C2*C3*C4*C5;
double const a3 = (C2*C3*C4 + C2*C3*C5 + C2*C4*C5 + C3*C4*C5)*G10 + C2*C3*C5*G7 + C2*C4*C5*G6 + C2*C3*C5*G8 + C3*C4*C5*G6 + C2*C4*C5*G8 + C2*C4*C5*G9 + C3*C4*C5*G8 + C3*C4*C5*G9 + C3*C4*C5*G45;
double const a2 = (C2*C3*G7 + C2*C4*G6 + C2*C3*G8 + C2*C5*G6 + C3*C4*G6 + C2*C4*G8 + C2*C5*G7 + C3*C5*G6 + C2*C4*G9 + C3*C4*G8 + C3*C5*G7 + C3*C4*G9 + C3*C4*G45 + C3*C5*G45 + C4*C5*G45)*G10 + C2*C5*G6*G7 + C2*C5*G6*G8 + C3*C5*G6*G7 + C2*C5*G7*G8 + C3*C5*G6*G8 + C2*C5*G7*G9 + C3*C5*G7*G8 + C3*C5*G7*G9 + C3*C5*G7*G45 + C4*C5*G6*G45 + C3*C5*G8*G45 + C4*C5*G8*G45 + C4*C5*G9*G45;
double const a1 = (C2*G6*G7 + C2*G6*G8 + C3*G6*G7 + C2*G7*G8 + C3*G6*G8 + C2*G7*G9 + C3*G7*G8 + C3*G7*G9 + C3*G7*G45 + C4*G6*G45 + C3*G8*G45 + C5*G6*G45 + C4*G8*G45 + C5*G7*G45 + C4*G9*G45)*G10 + C5*G6*G7*G45 + C5*G6*G8*G45 + C5*G7*G8*G45 + C5*G7*G9*G45;
double const a0 = G10*G45*(G6*G7 + G6*G8 + G7*G8 + G7*G9);
const double B0 = b4*pow(c,4) + b3*pow(c,3) + b2*c*c + b1*c + b0;
const double B1 = -4*b4*pow(c,4) - 2*b3*pow(c,3) + 2*b1*c + 4*b0;
const double B2 = 6*b4*pow(c,4) - 2*b2*c*c + 6*b0;
const double B3 = -4*b4*pow(c,4) + 2*b3*pow(c,3) - 2*b1*c + 4*b0;
const double B4 = b4*pow(c,4) - b3*pow(c,3) + b2*c*c - b1*c + b0;
const double A0 = a4*pow(c,4) + a3*pow(c,3) + a2*c*c + a1*c + a0;
const double A1 = -4*a4*pow(c,4) - 2*a3*pow(c,3) + 2*a1*c + 4*a0;
const double A2 = 6*a4*pow(c,4) - 2*a2*c*c + 6*a0;
const double A3 = -4*a4*pow(c,4) + 2*a3*pow(c,3) - 2*a1*c + 4*a0;
const double A4 = a4*pow(c,4) - a3*pow(c,3) + a2*c*c - a1*c + a0;
y[0] = (-A1*y_1 -A2*y_2 - A3*y_3 - A4*y_4 + B0*u[0] + B1*u_1 + B2*u_2 + B3*u_3 + B4*u_4 )/A0;
y[1] = (-A1*y[0] -A2*y_1 - A3*y_2 - A4*y_3 + B0*u[1] + B1*u[0] + B2*u_1 + B3*u_2 + B4*u_3 )/A0;
y[2] = (-A1*y[1] -A2*y[0] - A3*y_1 - A4*y_2 + B0*u[2] + B1*u[1] + B2*u[0] + B3*u_1 + B4*u_2 )/A0;
y[3] = (-A1*y[2] -A2*y[1] - A3*y[0] - A4*y_1 + B0*u[3] + B1*u[2] + B2*u[1] + B3*u[0] + B4*u_1 )/A0;
for (int i=4; i<=N-1; i++)
{
y[i] = (-A1*y[i-1] -A2*y[i-2] - A3*y[i-3] - A4*y[i-4] + B0*u[i] + B1*u[i-1] + B2*u[i-2] + B3*u[i-3] + B4*u[i-4] )/A0;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
U_2[0] = u[N-2];
Y_2[0] = y[N-2];
U_3[0] = u[N-3];
Y_3[0] = y[N-3];
U_4[0] = u[N-4];
Y_4[0] = y[N-4];
}
void FilterGain(float *u, float *y, int N, float Dist, float SampleRate, float *U_1, float *Y_1, float *U_2, float *Y_2 )
{
const float Rd = 100e3;
const float R13 = 4.7e3;
const float Cc = 10e-12;
const float Cz = 470e-9;
//const float Cc = 250e-12;
//const float Cz = 1000e-9;
float Rt = Dist*Rd;
float Rb = (1-Dist)*Rd + R13;
float Gt = 1/Rt;
float Gb = 1/Rb;
float b0;
float b1;
float b2;
float a0;
float a1;
float a2;
float B0;
float B1;
float B2;
float A0;
float A1;
float A2;
float c = 2*SampleRate;
float y_1 = Y_1[0];
float u_1 = U_1[0];
float y_2 = Y_2[0];
float u_2 = U_2[0];
/*
Cz Cc s² + (Cc Gb + Cz Gb + Cz Gt) s + Gb Gt b2s² + b1s + b0
G(s) = --------------------------------------------- = ----------------
Cz Cc s² + (Cc Gb + Cz Gt) s + Gb Gt a2s² + a1s + a0
Rt = DRd
Rb = (1-D)Rd + R13
B0 + B1z¹ + B2z²
G(z) = -------------------
A0 + A1z¹ + A2z²
y[k] = (-A1*y[k-1] -A2*y[k-2] + B0*u[k] + B1*u[k-1] + B2*u[k-2] )/A0
*/
a0 = Gb*Gt;
a1 = Cc*Gb + Cz*Gt;
a2 = Cz*Cc;
b0 = a0;
b1 = a1 + Cz*Gb;
b2 = a2;
//Bilinear transform
B0 = b0 + b1*c + b2*c*c;
B1 = 2*b0 - 2*b2*c*c;
B2 = b0 - b1*c + b2*c*c;
A0 = a0 + a1*c + a2*c*c;
A1 = 2*a0 - 2*a2*c*c;
A2 = a0 - a1*c + a2*c*c;
y[0] = (-A1*y_1 -A2*y_2 + B0*u[0] + B1*u_1 + B2*u_2 )/A0;
y[1] = (-A1*y[0] -A2*y_1 + B0*u[1] + B1*u[0] + B2*u_1 )/A0;
for (int i=2; i<=N-1; i++)
{
y[i] = (-A1*y[i-1] -A2*y[i-2] + B0*u[i] + B1*u[i-1] + B2*u[i-2] )/A0;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
U_2[0] = u[N-2];
Y_2[0] = y[N-2];
}
void DS1_Clip_Tone(float *u, float *y, float *v1, float *v2, float *v3, int N, float T, float *U_1, float *Y_1, float *V1_1, float *V2_1, float *V3_1, float t, float vol, ClipClass *obj)
{
float Vt = obj->Vt;
float y_1 = Y_1[0];
float u_1 = U_1[0];
float v1_1 = V1_1[0];
float v2_1 = V2_1[0];
float v3_1 = V3_1[0];
if( T != obj->T)
{
obj->ChangeSampleRate( 1.0/T );
}
if( t != obj->t )
{
obj->ChangeVolTone(vol, t);
}
else
{
if (vol != obj->vol)
{
obj->ChangeVol(vol);
}
}
float E2_2 = 1 + obj->E[1][1]*COSH( v2_1/Vt ); //Muda
float A2_2 = E2_2 + T*obj->F[1][1]; //Muda
float A_2_2 = E2_2 - T*obj->F[1][1]; //Muda
float B1 = obj->Ku1*( u[0] + u_1) + obj->A_[0][0]*v1_1 -v2_1 ; //Muda
float B2 = obj->Ku2*( u[0] + u_1) + obj->A_[1][0]*v1_1 + A_2_2*v2_1 + obj->A_[1][2]*v3_1 + obj->A_[1][3]*y_1 + obj->Kv*SINH( v2_1/Vt) ; //Muda
float B3 = obj->A_[2][1]*v2_1 + obj->A_[2][2]*v3_1 + obj->A_[2][3]*y_1; //Muda
float B4 = v2_1 + obj->A_[3][2]*v3_1 + obj->A_[3][3]*y_1;
/*
A*X[k] = B*X[k-1] + Y
X[k] = [V1[k] V2[k] V3[k] Vout[k] ]'
X[k-1] = [V1[k-1] V2[k-1] V3[k-1] Vout[k-1] ]'
*/
float Denominator = A2_2*obj->DENa + obj->DEN; //Muda
v1[0] = ( B1*( A2_2*obj->Ka1[0] + obj->K1[0] ) + B2*( obj->K2[0] ) + B3*( obj->K3[0] ) + B4*( obj->K4[0] ) )/Denominator ;
v2[0] = ( B1*( obj->K1[1] ) + B2*( obj->K2[1] ) + B3*( obj->K3[1] ) + B4*( obj->K4[1] ) )/Denominator ;
v3[0] = ( B1*( obj->K1[2] ) + B2*( obj->K2[2] ) + B3*( A2_2*obj->Ka3[2] + obj->K3[2] ) + B4*( A2_2*obj->Ka4[2] + obj->K4[2] ) )/Denominator ;
y[0] = ( B1*( obj->K1[3] ) + B2*( obj->K2[3] ) + B3*( A2_2*obj->Ka3[3] + obj->K3[3] ) + B4*( A2_2*obj->Ka4[3] + obj->K4[3] ) )/Denominator ;
for (int i=1; i<=N-1; i++)
{
E2_2 = 1 + obj->E[1][1]*COSH( v2[i-1]/Vt );
A2_2 = E2_2 + T*obj->F[1][1];
A_2_2 = E2_2 - T*obj->F[1][1];
Denominator = A2_2*obj->DENa + obj->DEN;
B1 = obj->Ku1*( u[i] + u[i-1]) + obj->A_[0][0]*v1[i-1] -v2[i-1]; //Muda
B2 = obj->Ku2*( u[i] + u[i-1]) + obj->A_[1][0]*v1[i-1] + A_2_2*v2[i-1] + obj->A_[1][2]*v3[i-1] + obj->A_[1][3]*y[i-1] + obj->Kv*SINH( v2[i-1]/Vt) ; //Muda
B3 = obj->A_[2][1]*v2[i-1] + obj->A_[2][2]*v3[i-1] + obj->A_[2][3]*y[i-1]; //Muda
B4 = v2[i-1] + obj->A_[3][2]*v3[i-1] + obj->A_[3][3]*y[i-1];
v1[i] = ( B1*( A2_2*obj->Ka1[0] + obj->K1[0] ) + B2*( obj->K2[0] ) + B3*( obj->K3[0] ) + B4*( obj->K4[0] ) )/Denominator ;
v2[i] = ( B1*( obj->K1[1] ) + B2*( obj->K2[1] ) + B3*( obj->K3[1] ) + B4*( obj->K4[1] ) )/Denominator ;
v3[i] = ( B1*( obj->K1[2] ) + B2*( obj->K2[2] ) + B3*( A2_2*obj->Ka3[2] + obj->K3[2] ) + B4*( A2_2*obj->Ka4[2] + obj->K4[2] ) )/Denominator ;
y[i] = ( B1*( obj->K1[3] ) + B2*( obj->K2[3] ) + B3*( A2_2*obj->Ka3[3] + obj->K3[3] ) + B4*( A2_2*obj->Ka4[3] + obj->K4[3] ) )/Denominator ;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
V1_1[0] = v1[N-1];
V2_1[0] = v2[N-1];
V3_1[0] = v3[N-1];
}
void Filter1_48000(float *u, float *y, int N, float *U_1, float *Y_1 )
{
const float R1 = 1000;
const float R2 = 470e3;
const float C1 = 47e-9;
const float c = 2*2*48000;
float y_1 = Y_1[0];
float u_1 = U_1[0];
/*
R2C1s b1s + b0
G(s) = -------------- = --------
(R1+R2)C1s + 1 a1s + a0
B0 + B1z¹
G(z) = ----------
A0 + A1z¹
y[k] = (-A1*y[k-1] + B0*u[k] + B1*u[k-1] )/A0
*/
const float b0 = 0;
const float b1 = R2*C1;
const float a0 = 1;
const float a1 = (R1+R2)*C1;
const float B0 = b0 + b1*c;
const float B1 = b0 - b1*c;
const float A0 = a0 + a1*c;
const float A1 = a0 - a1*c;
y[0] = (-A1*y_1 + B0*u[0] + B1*u_1)/A0;
for (int i=1; i<=N-1; i++)
{
y[i] = (-A1*y[i-1] + B0*u[i] + B1*u[i-1] )/A0;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
}
void Filter2_48000(float *u, float *y, int N, float *U_1, float *Y_1, float *U_2, float *Y_2, float *U_3, float *Y_3, float *U_4, float *Y_4 )
{
const double R45 = 90.909090909090907e3;
const double R6 = 100e3;
const double R7 = 470e3;
const double R8 = 10e3;
const double R9 = 22;
const double R10 = 100e3;
const double G45 = 1/R45;
const double G6 = 1/R6;
const double G7 = 1/R7;
const double G8 = 1/R8;
const double G9 = 1/R9;
const double G10 = 1/R10;
const double C2 = 470e-9;
const double C3 = 47e-9;
const double C4 = 250e-12;
const double C5 = 68e-9;
const double c = 2*2*48000;
double y_1 = Y_1[0];
double u_1 = U_1[0];
double y_2 = Y_2[0];
double u_2 = U_2[0];
double y_3 = Y_3[0];
double u_3 = U_3[0];
double y_4 = Y_4[0];
double u_4 = U_4[0];
double const b4 = C2*C3*C4*C5;
double const b3 = C2*C3*C5*(G7 - G9);
double const b2 = 0;
double const b1 = 0;
double const b0 = 0;
double const a4 = C2*C3*C4*C5;
double const a3 = (C2*C3*C4 + C2*C3*C5 + C2*C4*C5 + C3*C4*C5)*G10 + C2*C3*C5*G7 + C2*C4*C5*G6 + C2*C3*C5*G8 + C3*C4*C5*G6 + C2*C4*C5*G8 + C2*C4*C5*G9 + C3*C4*C5*G8 + C3*C4*C5*G9 + C3*C4*C5*G45;
double const a2 = (C2*C3*G7 + C2*C4*G6 + C2*C3*G8 + C2*C5*G6 + C3*C4*G6 + C2*C4*G8 + C2*C5*G7 + C3*C5*G6 + C2*C4*G9 + C3*C4*G8 + C3*C5*G7 + C3*C4*G9 + C3*C4*G45 + C3*C5*G45 + C4*C5*G45)*G10 + C2*C5*G6*G7 + C2*C5*G6*G8 + C3*C5*G6*G7 + C2*C5*G7*G8 + C3*C5*G6*G8 + C2*C5*G7*G9 + C3*C5*G7*G8 + C3*C5*G7*G9 + C3*C5*G7*G45 + C4*C5*G6*G45 + C3*C5*G8*G45 + C4*C5*G8*G45 + C4*C5*G9*G45;
double const a1 = (C2*G6*G7 + C2*G6*G8 + C3*G6*G7 + C2*G7*G8 + C3*G6*G8 + C2*G7*G9 + C3*G7*G8 + C3*G7*G9 + C3*G7*G45 + C4*G6*G45 + C3*G8*G45 + C5*G6*G45 + C4*G8*G45 + C5*G7*G45 + C4*G9*G45)*G10 + C5*G6*G7*G45 + C5*G6*G8*G45 + C5*G7*G8*G45 + C5*G7*G9*G45;
double const a0 = G10*G45*(G6*G7 + G6*G8 + G7*G8 + G7*G9);
const double B0 = b4*pow(c,4) + b3*pow(c,3) + b2*c*c + b1*c + b0;
const double B1 = -4*b4*pow(c,4) - 2*b3*pow(c,3) + 2*b1*c + 4*b0;
const double B2 = 6*b4*pow(c,4) - 2*b2*c*c + 6*b0;
const double B3 = -4*b4*pow(c,4) + 2*b3*pow(c,3) - 2*b1*c + 4*b0;
const double B4 = b4*pow(c,4) - b3*pow(c,3) + b2*c*c - b1*c + b0;
const double A0 = a4*pow(c,4) + a3*pow(c,3) + a2*c*c + a1*c + a0;
const double A1 = -4*a4*pow(c,4) - 2*a3*pow(c,3) + 2*a1*c + 4*a0;
const double A2 = 6*a4*pow(c,4) - 2*a2*c*c + 6*a0;
const double A3 = -4*a4*pow(c,4) + 2*a3*pow(c,3) - 2*a1*c + 4*a0;
const double A4 = a4*pow(c,4) - a3*pow(c,3) + a2*c*c - a1*c + a0;
y[0] = (-A1*y_1 -A2*y_2 - A3*y_3 - A4*y_4 + B0*u[0] + B1*u_1 + B2*u_2 + B3*u_3 + B4*u_4 )/A0;
y[1] = (-A1*y[0] -A2*y_1 - A3*y_2 - A4*y_3 + B0*u[1] + B1*u[0] + B2*u_1 + B3*u_2 + B4*u_3 )/A0;
y[2] = (-A1*y[1] -A2*y[0] - A3*y_1 - A4*y_2 + B0*u[2] + B1*u[1] + B2*u[0] + B3*u_1 + B4*u_2 )/A0;
y[3] = (-A1*y[2] -A2*y[1] - A3*y[0] - A4*y_1 + B0*u[3] + B1*u[2] + B2*u[1] + B3*u[0] + B4*u_1 )/A0;
for (int i=4; i<=N-1; i++)
{
y[i] = (-A1*y[i-1] -A2*y[i-2] - A3*y[i-3] - A4*y[i-4] + B0*u[i] + B1*u[i-1] + B2*u[i-2] + B3*u[i-3] + B4*u[i-4] )/A0;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
U_2[0] = u[N-2];
Y_2[0] = y[N-2];
U_3[0] = u[N-3];
Y_3[0] = y[N-3];
U_4[0] = u[N-4];
Y_4[0] = y[N-4];
}
void FilterGain_48000(float *u, float *y, int N, float Dist, float *U_1, float *Y_1, float *U_2, float *Y_2 )
{
const float Rd = 100e3;
const float R13 = 4.7e3;
const float Cc = 10e-12;
const float Cz = 470e-9;
//const float Cc = 250e-12;
//const float Cz = 1000e-9;
float Rt = Dist*Rd;
float Rb = (1-Dist)*Rd + R13;
float Gt = 1/Rt;
float Gb = 1/Rb;
float b0;
float b1;
float b2;
float a0;
float a1;
float a2;
float B0;
float B1;
float B2;
float A0;
float A1;
float A2;
const float c = 2*2*48000;
float y_1 = Y_1[0];
float u_1 = U_1[0];
float y_2 = Y_2[0];
float u_2 = U_2[0];
/*
Cz Cc s² + (Cc Gb + Cz Gb + Cz Gt) s + Gb Gt b2s² + b1s + b0
G(s) = --------------------------------------------- = ----------------
Cz Cc s² + (Cc Gb + Cz Gt) s + Gb Gt a2s² + a1s + a0
Rt = DRd
Rb = (1-D)Rd + R13
B0 + B1z¹ + B2z²
G(z) = -------------------
A0 + A1z¹ + A2z²
y[k] = (-A1*y[k-1] -A2*y[k-2] + B0*u[k] + B1*u[k-1] + B2*u[k-2] )/A0
*/
a0 = Gb*Gt;
a1 = Cc*Gb + Cz*Gt;
a2 = Cz*Cc;
b0 = a0;
b1 = a1 + Cz*Gb;
b2 = a2;
//Bilinear transform
B0 = b0 + b1*c + b2*c*c;
B1 = 2*b0 - 2*b2*c*c;
B2 = b0 - b1*c + b2*c*c;
A0 = a0 + a1*c + a2*c*c;
A1 = 2*a0 - 2*a2*c*c;
A2 = a0 - a1*c + a2*c*c;
y[0] = (-A1*y_1 -A2*y_2 + B0*u[0] + B1*u_1 + B2*u_2 )/A0;
y[1] = (-A1*y[0] -A2*y_1 + B0*u[1] + B1*u[0] + B2*u_1 )/A0;
for (int i=2; i<=N-1; i++)
{
y[i] = (-A1*y[i-1] -A2*y[i-2] + B0*u[i] + B1*u[i-1] + B2*u[i-2] )/A0;
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
U_2[0] = u[N-2];
Y_2[0] = y[N-2];
}
void DS1_Clip_Tone_48000(float *u, float *y, float *v1, float *v2, float *v3, int N, float *U_1, float *Y_1, float *V1_1, float *V2_1, float *V3_1, float t, float vol)
{
const float SampleRate = 8*48000;
const float T = 1/SampleRate;
const float R1 = 2.2e3;
const float R2 = 6.8e3;
const float R3 = 2.2e3;
const float R4 = 6.8e3;
const float Rt = 20e3;
const float Rv = 100e3;
const float C1 = 470e-9;
const float C2 = 10e-9;
const float C3 = 100e-9;
const float C4 = 22e-9;
const float Is = 2.52e-9;
const float Vt = 45.3e-3;
float c1 = (1 + R3*( 1/R4 + 1/Rt ) )/( t*vol ) + (1-t)*(Rt/Rv)*(1 + R3*(1/R4 + 1/( (1-t)*Rt) ) )/vol; //t, vol
float c2 = ( (t-1)/t )*(1 + R3*(1/R4 + 1/( (1-t)*Rt) ) ); //t
float c3 = ( 1/R4 + 1/Rt )/( t*vol ) + (1-t)*(Rt/Rv)*(1/R4 + 1/( (1-t)*Rt) )/vol; //t, vol
float c4 = ( (t-1)/t )*(1/R4 + 1/( (1-t)*Rt) ); //t
float y_1 = Y_1[0];
float u_1 = U_1[0];
float v1_1 = V1_1[0];
float v2_1 = V2_1[0];
float v3_1 = V3_1[0];
const float E1_1 = 1;
//float const E1_2 = -1;
//float const E1_3 = 0;
//float const E1_4 = 0;
const float E2_1 = 0;
float E2_2 = 1 + ((T*Is)/(C2*Vt))*COSH( v2_1/Vt ); //Muda
const float E2_3 = 0;
const float E2_4 = 0;
//float const E3_1 = 0;
const float E3_2 = 0;
const float E3_3 = 1;
const float E3_4 = 0;
//float const E4_1 = 0;
//float const E4_2 = 1;
float E4_3 = -c2; //t
float E4_4 = -c1; //t, vol
const float F1_1 = 1/( 2*R1*C1 );
//float const F1_2 = 0;
//float const F1_3 = 0;
//float const F1_4 = 0;
const float F2_1 = 1/( 2*R1*C2 );
const float F2_2 = 1/( 2*R2*C2 );
float F2_3 = (c4 - 1/R2)/( 2*C2 ); //t
float F2_4 = c3/(2*C2); //t, vol
//float const F3_1 = 0;
float const F3_2 = -1/( 2*R2*C3 );
float F3_3 = ( 1/R2 + 1/(t*Rt) )/( 2*C3 ); //t
float F3_4 = -1/( 2*vol*t*Rt*C3 ); //t, vol
//float const F4_1 = 0;
//float const F4_2 = 0;
float F4_3 = -c4/(2*C4); //t
float F4_4 = -c3/(2*C4); //t, vol
const float A1_1 = E1_1 + T*F1_1;
//float A1_2 = -1;
//float A1_3 = 0;
//float A1_4 = 0;
const float A2_1 = E2_1 + T*F2_1;
float A2_2 = E2_2 + T*F2_2; //Muda
float A2_3 = E2_3 + T*F2_3; //t
float A2_4 = E2_4 + T*F2_4; //t, vol
//float A3_1 = 0;
const float A3_2 = E3_2 + T*F3_2;
float A3_3 = E3_3 + T*F3_3; //t
float A3_4 = E3_4 + T*F3_4; //t, vol
//float A4_1 = 0;
//float A4_2 = 1;
float A4_3 = E4_3 + T*F4_3; //t
float A4_4 = E4_4 + T*F4_4; //t, vol
const float A_1_1 = E1_1 - T*F1_1;
const float A_1_2 = -1;
const float A_1_3 = 0;
const float A_1_4 = 0;
const float A_2_1 = E2_1 - T*F2_1;
float A_2_2 = E2_2 - T*F2_2; //Muda
float A_2_3 = E2_3 - T*F2_3; //t
float A_2_4 = E2_4 - T*F2_4; //t, vol
const float A_3_1 = 0;
const float A_3_2 = E3_2 - T*F3_2;
float A_3_3 = E3_3 - T*F3_3; //t
float A_3_4 = E3_4 - T*F3_4; //t, vol
const float A_4_1 = 0;
const float A_4_2 = 1;
float A_4_3 = E4_3 - T*F4_3; //t
float A_4_4 = E4_4 - T*F4_4; //t, vol
float B1 = (T/( 2*R1*C1 ))*( u[0] + u_1) + A_1_1*v1_1 + A_1_2*v2_1 + A_1_3*v3_1 + A_1_4*y_1 ; //Muda
float B2 = (T/( 2*R1*C2 ))*( u[0] + u_1) + A_2_1*v1_1 + A_2_2*v2_1 + A_2_3*v3_1 + A_2_4*y_1 -(2*T*Is/C2)*SINH( v2_1/Vt) ; //Muda
float B3 = A_3_1*v1_1 + A_3_2*v2_1 + A_3_3*v3_1 + A_3_4*y_1; //Muda
float B4 = A_4_1*v1_1 + A_4_2*v2_1 + A_4_3*v3_1 + A_4_4*y_1; //Muda
/*
A*X[k] = B*X[k-1] + Y
X[k] = [V1[k] V2[k] V3[k] Vout[k] ]'
X[k-1] = [V1[k-1] V2[k-1] V3[k-1] Vout[k-1] ]'
*/
v1[0] = (A2_3*A3_4*B1 - A2_4*A3_3*B1 + A2_3*A3_4*B4 - A2_4*A3_3*B4 - A2_3*A4_4*B3 + A2_4*A4_3*B3 + A3_3*A4_4*B2 - A3_4*A4_3*B2 + A2_2*A3_3*A4_4*B1 - A2_2*A3_4*A4_3*B1 - A2_3*A3_2*A4_4*B1 + A2_4*A3_2*A4_3*B1)/(A1_1*A2_3*A3_4 - A1_1*A2_4*A3_3 + A2_1*A3_3*A4_4 - A2_1*A3_4*A4_3 + A1_1*A2_2*A3_3*A4_4 - A1_1*A2_2*A3_4*A4_3 - A1_1*A2_3*A3_2*A4_4 + A1_1*A2_4*A3_2*A4_3);
v2[0] = (A1_1*A2_3*A3_4*B4 - A1_1*A2_4*A3_3*B4 - A1_1*A2_3*A4_4*B3 + A1_1*A2_4*A4_3*B3 + A1_1*A3_3*A4_4*B2 - A1_1*A3_4*A4_3*B2 - A2_1*A3_3*A4_4*B1 + A2_1*A3_4*A4_3*B1)/(A1_1*A2_3*A3_4 - A1_1*A2_4*A3_3 + A2_1*A3_3*A4_4 - A2_1*A3_4*A4_3 + A1_1*A2_2*A3_3*A4_4 - A1_1*A2_2*A3_4*A4_3 - A1_1*A2_3*A3_2*A4_4 + A1_1*A2_4*A3_2*A4_3);
v3[0] = -(A1_1*A2_4*B3 - A1_1*A3_4*B2 + A2_1*A3_4*B1 + A2_1*A3_4*B4 - A2_1*A4_4*B3 + A1_1*A2_2*A3_4*B4 - A1_1*A2_4*A3_2*B4 - A1_1*A2_2*A4_4*B3 + A1_1*A3_2*A4_4*B2 - A2_1*A3_2*A4_4*B1)/(A1_1*A2_3*A3_4 - A1_1*A2_4*A3_3 + A2_1*A3_3*A4_4 - A2_1*A3_4*A4_3 + A1_1*A2_2*A3_3*A4_4 - A1_1*A2_2*A3_4*A4_3 - A1_1*A2_3*A3_2*A4_4 + A1_1*A2_4*A3_2*A4_3);
y[0] = (A1_1*A2_3*B3 - A1_1*A3_3*B2 + A2_1*A3_3*B1 + A2_1*A3_3*B4 - A2_1*A4_3*B3 + A1_1*A2_2*A3_3*B4 - A1_1*A2_3*A3_2*B4 - A1_1*A2_2*A4_3*B3 + A1_1*A3_2*A4_3*B2 - A2_1*A3_2*A4_3*B1)/(A1_1*A2_3*A3_4 - A1_1*A2_4*A3_3 + A2_1*A3_3*A4_4 - A2_1*A3_4*A4_3 + A1_1*A2_2*A3_3*A4_4 - A1_1*A2_2*A3_4*A4_3 - A1_1*A2_3*A3_2*A4_4 + A1_1*A2_4*A3_2*A4_3);
for (int i=1; i<=N-1; i++)
{
E2_2 = 1 + ((T*Is)/(C2*Vt))*COSH( v2[i-1]/Vt );
A2_2 = E2_2 + T*F2_2;
A_2_2 = E2_2 - T*F2_2;
B1 = (T/( 2*R1*C1 ))*( u[i] + u[i-1]) + A_1_1*v1[i-1] + A_1_2*v2[i-1] + A_1_3*v3[i-1] + A_1_4*y[i-1] ; //Muda
B2 = (T/( 2*R1*C2 ))*( u[i] + u[i-1]) + A_2_1*v1[i-1] + A_2_2*v2[i-1] + A_2_3*v3[i-1] + A_2_4*y[i-1] -(2*T*Is/C2)*SINH( v2[i-1]/Vt) ; //Muda
B3 = A_3_1*v1[i-1] + A_3_2*v2[i-1] + A_3_3*v3[i-1] + A_3_4*y[i-1]; //Muda
B4 = A_4_1*v1[i-1] + A_4_2*v2[i-1] + A_4_3*v3[i-1] + A_4_4*y[i-1];
v1[i] = (A2_3*A3_4*B1 - A2_4*A3_3*B1 + A2_3*A3_4*B4 - A2_4*A3_3*B4 - A2_3*A4_4*B3 + A2_4*A4_3*B3 + A3_3*A4_4*B2 - A3_4*A4_3*B2 + A2_2*A3_3*A4_4*B1 - A2_2*A3_4*A4_3*B1 - A2_3*A3_2*A4_4*B1 + A2_4*A3_2*A4_3*B1)/(A1_1*A2_3*A3_4 - A1_1*A2_4*A3_3 + A2_1*A3_3*A4_4 - A2_1*A3_4*A4_3 + A1_1*A2_2*A3_3*A4_4 - A1_1*A2_2*A3_4*A4_3 - A1_1*A2_3*A3_2*A4_4 + A1_1*A2_4*A3_2*A4_3);
v2[i] = (A1_1*A2_3*A3_4*B4 - A1_1*A2_4*A3_3*B4 - A1_1*A2_3*A4_4*B3 + A1_1*A2_4*A4_3*B3 + A1_1*A3_3*A4_4*B2 - A1_1*A3_4*A4_3*B2 - A2_1*A3_3*A4_4*B1 + A2_1*A3_4*A4_3*B1)/(A1_1*A2_3*A3_4 - A1_1*A2_4*A3_3 + A2_1*A3_3*A4_4 - A2_1*A3_4*A4_3 + A1_1*A2_2*A3_3*A4_4 - A1_1*A2_2*A3_4*A4_3 - A1_1*A2_3*A3_2*A4_4 + A1_1*A2_4*A3_2*A4_3);
v3[i] = -(A1_1*A2_4*B3 - A1_1*A3_4*B2 + A2_1*A3_4*B1 + A2_1*A3_4*B4 - A2_1*A4_4*B3 + A1_1*A2_2*A3_4*B4 - A1_1*A2_4*A3_2*B4 - A1_1*A2_2*A4_4*B3 + A1_1*A3_2*A4_4*B2 - A2_1*A3_2*A4_4*B1)/(A1_1*A2_3*A3_4 - A1_1*A2_4*A3_3 + A2_1*A3_3*A4_4 - A2_1*A3_4*A4_3 + A1_1*A2_2*A3_3*A4_4 - A1_1*A2_2*A3_4*A4_3 - A1_1*A2_3*A3_2*A4_4 + A1_1*A2_4*A3_2*A4_3);
y[i] = (A1_1*A2_3*B3 - A1_1*A3_3*B2 + A2_1*A3_3*B1 + A2_1*A3_3*B4 - A2_1*A4_3*B3 + A1_1*A2_2*A3_3*B4 - A1_1*A2_3*A3_2*B4 - A1_1*A2_2*A4_3*B3 + A1_1*A3_2*A4_3*B2 - A2_1*A3_2*A4_3*B1)/(A1_1*A2_3*A3_4 - A1_1*A2_4*A3_3 + A2_1*A3_3*A4_4 - A2_1*A3_4*A4_3 + A1_1*A2_2*A3_3*A4_4 - A1_1*A2_2*A3_4*A4_3 - A1_1*A2_3*A3_2*A4_4 + A1_1*A2_4*A3_2*A4_3);
}
U_1[0] = u[N-1];
Y_1[0] = y[N-1];
V1_1[0] = v1[N-1];
V2_1[0] = v2[N-1];
V3_1[0] = v3[N-1];
}

@ -0,0 +1,72 @@
#ifndef _DISTORTION_DS1_H
#define _DISTORTION_DS1_H
#include <cmath>
class ClipClass
{
public:
ClipClass();
void ChangeVolTone(float Volume, float Tone);
void ChangeVol(float Volume);
void ChangeSampleRate(float SampleRate);
float R1;
float R2;
float R3;
float R4;
float Rt;
float Rv;
float C1;
float C2;
float C3;
float C4;
float Is;
float Vt;
float T;
float t;
float vol;
float c1;
float c2;
float c3;
float c4;
float E[4][4];
float F[4][4];
float A[4][4];
float A_[4][4];
float Ka1[4];
float Ka2[4];
float Ka3[4];
float Ka4[4];
float K1[4];
float K2[4];
float K3[4];
float K4[4];
float DENa;
float DEN;
float Ku1;
float Ku2;
float Kv;
};
void Filter1(float *u, float *y, int N, float SampleRate, float *U_1, float *Y_1 );
void Filter2(float *u, float *y, int N, float SampleRate, float *U_1, float *Y_1, float *U_2, float *Y_2, float *U_3, float *Y_3, float *U_4, float *Y_4 );
void FilterGain(float *u, float *y, int N, float Dist, float SampleRate, float *U_1, float *Y_1, float *U_2, float *Y_2 );
void DS1_Clip_Tone(float *u, float *y, float *v1, float *v2, float *v3, int N, float T, float *U_1, float *Y_1, float *V1_1, float *V2_1, float *V3_1, float t, float vol, ClipClass *obj);
void Filter1_48000(float *u, float *y, int N, float *U_1, float *Y_1 );
void Filter2_48000(float *u, float *y, int N, float *U_1, float *Y_1, float *U_2, float *Y_2, float *U_3, float *Y_3, float *U_4, float *Y_4 );
void FilterGain_48000(float *u, float *y, int N, float Dist, float *U_1, float *Y_1, float *U_2, float *Y_2 );
void DS1_Clip_Tone_48000(float *u, float *y, float *v1, float *v2, float *v3, int N, float *U_1, float *Y_1, float *V1_1, float *V2_1, float *V3_1, float t, float vol);
#endif // _DISTORTION_DS1_H

@ -0,0 +1,84 @@
#include <cmath>
#include <iostream>
#include "Sinh.h"
#include "ASinh.h"
#include "Cosh.h"
#include "HyperbolicTables.h"
using namespace std;
float SINH( float x)
{
int flag = 1;
if (x < 0)
{
flag = -1;
x = -x;
}
float SinH;
if( x > SINH_fim)
{
SinH = (Sinh[SINH_N-1])*flag;
}
else
{
float naux = x*SINH_Idx;
int n = round(naux);
SinH = Sinh[n]*flag;
}
return SinH;
}
float COSH( float x)
{
if (x < 0)
{
x = -x;
}
float CosH;
if( x > COSH_fim)
{
CosH = Cosh[COSH_N-1];
}
else
{
float naux = x*COSH_Idx;
int n = round(naux);
CosH = Cosh[n];
}
return CosH;
}
float ASINH( float x)
{
int flag = 1;
if (x < 0)
{
flag = -1;
x = -x;
}
float ASinH;
if( x > ASINH_fim)
{
ASinH = (ASinh[ASINH_N-1])*flag;
}
else
{
float naux = x*ASINH_Idx;
int n = round(naux);
ASinH = ASinh[n]*flag;
}
return ASinH;
}

@ -0,0 +1,10 @@
#ifndef _HYPERBOLIC_TABLES_H
#define _HYPERBOLIC_TABLES_H
#include <cmath>
float SINH( float x);
float COSH( float x);
float ASINH( float x);
#endif // _HYPERBOLIC_TABLES_H

@ -0,0 +1,414 @@
#include <math.h>
#include "OverSample.h"
void Over1_Float(float *in, float *u, float *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[i-1] = in[i-1];
}
}
void Over2_Float(float *in, float *u, float *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[2*i - 1] = in[i-1];
}
u[0] = 0.5*(u_1[0]+in[0]);
for (uint32_t i = 2; i <= n; i++)
{
u[2*i - 2] = 0.5*(u[2*i - 3]+u[2*i - 1]);
}
}
void Over4_Float(float *in, float *u, float *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[4*i - 1] = in[i-1];
}
u[1] = 0.5*(u_1[0]+in[0]);
u[0] = 0.5*(u_1[0]+u[1]);
u[2] = 0.5*(u[1]+in[0]);
for (uint32_t i = 2; i <= n; i++)
{
u[4*i - 3] = 0.5*(u[4*i - 1]+u[4*i - 5]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[4*i - 4] = 0.5*(u[4*i - 5]+u[4*i - 3]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[4*i - 2] = 0.5*(u[4*i - 3]+u[4*i - 1]);
}
}
void Over8_Float(float *in, float *u, float *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[8*i - 1] = in[i-1];
}
u[3] = 0.5*(u_1[0]+u[7]);
u[1] = 0.5*(u_1[0]+u[3]);
u[5] = 0.5*(u[3]+u[7]);
u[2] = 0.5*(u[1]+u[3]);
u[4] = 0.5*(u[3]+u[5]);
u[0] = 0.5*(u[1]+u_1[0]);
u[6] = 0.5*(u[5]+u[7]);
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 5] = 0.5*(u[8*i - 1]+u[8*i - 9]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 7] = 0.5*(u[8*i - 5]+u[8*i - 9]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 3] = 0.5*(u[8*i - 1]+u[8*i - 5]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 8] = 0.5*(u[8*i - 7]+u[8*i - 9]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 6] = 0.5*(u[8*i - 5]+u[8*i - 7]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 4] = 0.5*(u[8*i - 3]+u[8*i - 5]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 2] = 0.5*(u[8*i - 3]+u[8*i - 1]);
}
}
void Over1(float *in, double *u, double *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[i-1] = in[i-1];
}
}
void Over2(float *in, double *u, double *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[2*i - 1] = in[i-1];
}
u[0] = 0.5*(u_1[0]+in[0]);
for (uint32_t i = 2; i <= n; i++)
{
u[2*i - 2] = 0.5*(u[2*i - 3]+u[2*i - 1]);
}
}
void Over4(float *in, double *u, double *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[4*i - 1] = in[i-1];
}
u[1] = 0.5*(u_1[0]+in[0]);
u[0] = 0.5*(u_1[0]+u[1]);
u[2] = 0.5*(u[1]+in[0]);
for (uint32_t i = 2; i <= n; i++)
{
u[4*i - 3] = 0.5*(u[4*i - 1]+u[4*i - 5]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[4*i - 4] = 0.5*(u[4*i - 5]+u[4*i - 3]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[4*i - 2] = 0.5*(u[4*i - 3]+u[4*i - 1]);
}
}
void Over8(float *in, double *u, double *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[8*i - 1] = in[i-1];
}
u[3] = 0.5*(u_1[0]+u[7]);
u[1] = 0.5*(u_1[0]+u[3]);
u[5] = 0.5*(u[3]+u[7]);
u[2] = 0.5*(u[1]+u[3]);
u[4] = 0.5*(u[3]+u[5]);
u[0] = 0.5*(u[1]+u_1[0]);
u[6] = 0.5*(u[5]+u[7]);
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 5] = 0.5*(u[8*i - 1]+u[8*i - 9]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 7] = 0.5*(u[8*i - 5]+u[8*i - 9]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 3] = 0.5*(u[8*i - 1]+u[8*i - 5]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 8] = 0.5*(u[8*i - 7]+u[8*i - 9]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 6] = 0.5*(u[8*i - 5]+u[8*i - 7]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 4] = 0.5*(u[8*i - 3]+u[8*i - 5]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 2] = 0.5*(u[8*i - 3]+u[8*i - 1]);
}
}
void Over1_Double(double *in, double *u, double *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[i-1] = in[i-1];
}
}
void Over2_Double(double *in, double *u, double *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[2*i - 1] = in[i-1];
}
u[0] = 0.5*(u_1[0]+in[0]);
for (uint32_t i = 2; i <= n; i++)
{
u[2*i - 2] = 0.5*(u[2*i - 3]+u[2*i - 1]);
}
}
void Over4_Double(double *in, double *u, double *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[4*i - 1] = in[i-1];
}
u[1] = 0.5*(u_1[0]+in[0]);
u[0] = 0.5*(u_1[0]+u[1]);
u[2] = 0.5*(u[1]+in[0]);
for (uint32_t i = 2; i <= n; i++)
{
u[4*i - 3] = 0.5*(u[4*i - 1]+u[4*i - 5]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[4*i - 4] = 0.5*(u[4*i - 5]+u[4*i - 3]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[4*i - 2] = 0.5*(u[4*i - 3]+u[4*i - 1]);
}
}
void Over8_Double(double *in, double *u, double *u_1, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
u[8*i - 1] = in[i-1];
}
u[3] = 0.5*(u_1[0]+u[7]);
u[1] = 0.5*(u_1[0]+u[3]);
u[5] = 0.5*(u[3]+u[7]);
u[2] = 0.5*(u[1]+u[3]);
u[4] = 0.5*(u[3]+u[5]);
u[0] = 0.5*(u[1]+u_1[0]);
u[6] = 0.5*(u[5]+u[7]);
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 5] = 0.5*(u[8*i - 1]+u[8*i - 9]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 7] = 0.5*(u[8*i - 5]+u[8*i - 9]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 3] = 0.5*(u[8*i - 1]+u[8*i - 5]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 8] = 0.5*(u[8*i - 7]+u[8*i - 9]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 6] = 0.5*(u[8*i - 5]+u[8*i - 7]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 4] = 0.5*(u[8*i - 3]+u[8*i - 5]);
}
for (uint32_t i = 2; i <= n; i++)
{
u[8*i - 2] = 0.5*(u[8*i - 3]+u[8*i - 1]);
}
}
void Down1_Float(float *out, float *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[i-1];
}
}
void Down2_Float(float *out, float *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[2*i-1];
}
}
void Down4_Float(float *out, float *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[4*i-1];
}
}
void Down8_Float(float *out, float *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[8*i-1];
}
}
void Down1(float *out, double *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[i-1];
}
}
void Down2(float *out, double *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[2*i-1];
}
}
void Down4(float *out, double *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[4*i-1];
}
}
void Down8(float *out, double *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[8*i-1];
}
}
void Down1_Double(double *out, double *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[i-1];
}
}
void Down2_Double(double *out, double *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[2*i-1];
}
}
void Down4_Double(double *out, double *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[4*i-1];
}
}
void Down8_Double(double *out, double *y, uint32_t n)
{
for (uint32_t i = 1; i <= n; i++)
{
out[i-1] = y[8*i-1];
}
}

@ -0,0 +1,32 @@
#ifndef _OVER_SAMPLE_H
#define _OVER_SAMPLE_H
#include <math.h>
#include <stdint.h>
void Over1_Float(float *in, float *u, float *u_1, uint32_t n);
void Over2_Float(float *in, float *u, float *u_1, uint32_t n);
void Over4_Float(float *in, float *u, float *u_1, uint32_t n);
void Over8_Float(float *in, float *u, float *u_1, uint32_t n);
void Over1(float *in, double *u, double *u_1, uint32_t n);
void Over2(float *in, double *u, double *u_1, uint32_t n);
void Over4(float *in, double *u, double *u_1, uint32_t n);
void Over8(float *in, double *u, double *u_1, uint32_t n);
void Over1_Double(double *in, double *u, double *u_1, uint32_t n);
void Over2_Double(double *in, double *u, double *u_1, uint32_t n);
void Over4_Double(double *in, double *u, double *u_1, uint32_t n);
void Over8_Double(double *in, double *u, double *u_1, uint32_t n);
void Down1_Float(float *out, float *y, uint32_t n);
void Down2_Float(float *out, float *y, uint32_t n);
void Down4_Float(float *out, float *y, uint32_t n);
void Down8_Float(float *out, float *y, uint32_t n);
void Down1(float *out, double *y, uint32_t n);
void Down2(float *out, double *y, uint32_t n);
void Down4(float *out, double *y, uint32_t n);
void Down8(float *out, double *y, uint32_t n);
void Down1_Double(double *out, double *y, uint32_t n);
void Down2_Double(double *out, double *y, uint32_t n);
void Down4_Double(double *out, double *y, uint32_t n);
void Down8_Double(double *out, double *y, uint32_t n);
#endif // _OVER_SAMPLE_H

File diff suppressed because it is too large Load Diff

@ -178,6 +178,24 @@ const CUIMenu::TMenuItem CUIMenu::s_FXLPFilter[] =
{0}
};
const CUIMenu::TMenuItem CUIMenu::s_FXDS1[] =
{
{"Bypass", EditTGFXParameter, 0, AudioEffectDS1::Param::BYPASS},
{"Dist", EditTGFXParameter, 0, AudioEffectDS1::Param::DIST},
{"Tone", EditTGFXParameter, 0, AudioEffectDS1::Param::TONE},
{"Level", EditTGFXParameter, 0, AudioEffectDS1::Param::LEVEL},
{0}
};
const CUIMenu::TMenuItem CUIMenu::s_FXBigMuff[] =
{
{"Bypass", EditTGFXParameter, 0, AudioEffectBigMuff::Param::BYPASS},
{"Sustain", EditTGFXParameter, 0, AudioEffectBigMuff::Param::SUSTAIN},
{"Tone", EditTGFXParameter, 0, AudioEffectBigMuff::Param::TONE},
{"Level", EditTGFXParameter, 0, AudioEffectBigMuff::Param::LEVEL},
{0}
};
// inserting menu items before "OP1" affect OPShortcutHandler()
const CUIMenu::TMenuItem CUIMenu::s_EditVoiceMenu[] =
{
@ -269,7 +287,7 @@ const CUIMenu::TParameter CUIMenu::s_TGParameter[CMiniDexed::TGParameterUnknown]
{0, CSysExFileLoader::VoicesPerBank-1, 1}, // TGParameterProgram
{0, 127, 8, ToVolume}, // TGParameterVolume
{0, 127, 8, ToPan}, // TGParameterPan
{0, 3, 1, ToFXType}, // TGParameterInsertFXType
{0, 5, 1, ToFXType}, // TGParameterInsertFXType
{-99, 99, 1}, // TGParameterMasterTune
{0, 99, 1}, // TGParameterCutoff
{0, 99, 1}, // TGParameterResonance
@ -327,6 +345,24 @@ const CUIMenu::TParameter CUIMenu::s_TGFXLPFParam[AudioEffectLPF::Param::UNKNOWN
{0, 100, 1} // RESONANCE
};
// must match AudioEffectDS1::Param
const CUIMenu::TParameter CUIMenu::s_TGFXDS1Param[AudioEffectDS1::Param::UNKNOWN] =
{
{0, 1, 1, ToOnOff}, // BYPASS
{1, 99, 1}, // DIST
{1, 99, 1}, // TONE
{1, 99, 1} // LEVEL
};
// must match AudioEffectDS1::Param
const CUIMenu::TParameter CUIMenu::s_TGFXBigMuffParam[AudioEffectBigMuff::Param::UNKNOWN] =
{
{0, 1, 1, ToOnOff}, // BYPASS
{0, 100, 1}, // SUSTAIN
{0, 100, 1}, // TONE
{0, 100, 1} // LEVEL
};
// must match DexedVoiceParameters in Synth_Dexed
const CUIMenu::TParameter CUIMenu::s_VoiceParameter[] =
{
@ -841,6 +877,15 @@ void CUIMenu::EditInsertFX (CUIMenu *pUIMenu, TMenuEvent Event)
case EFFECT_LPF:
pUIMenu->m_pCurrentMenu = s_FXLPFilter;
break;
case EFFECT_DS1:
pUIMenu->m_pCurrentMenu = s_FXDS1;
break;
case EFFECT_BIGMUFF:
pUIMenu->m_pCurrentMenu = s_FXBigMuff;
break;
default:
pUIMenu->m_pCurrentMenu = s_FXNone;
@ -929,6 +974,12 @@ void CUIMenu::EditTGFXParameter (CUIMenu *pUIMenu, TMenuEvent Event)
case EFFECT_LPF:
pParam = s_TGFXLPFParam[nParam];
break;
case EFFECT_DS1:
pParam = s_TGFXDS1Param[nParam];
break;
case EFFECT_BIGMUFF:
pParam = s_TGFXBigMuffParam[nParam];
break;
default:
return;
}

@ -156,6 +156,8 @@ private:
static const TMenuItem s_FXChorus[];
static const TMenuItem s_FXDelay[];
static const TMenuItem s_FXLPFilter[];
static const TMenuItem s_FXDS1[];
static const TMenuItem s_FXBigMuff[];
static const TMenuItem s_EditVoiceMenu[];
static const TMenuItem s_OperatorMenu[];
static const TMenuItem s_SaveMenu[];
@ -171,6 +173,8 @@ private:
static const TParameter s_TGFXChorusParam[];
static const TParameter s_TGFXDelayParam[];
static const TParameter s_TGFXLPFParam[];
static const TParameter s_TGFXDS1Param[];
static const TParameter s_TGFXBigMuffParam[];
static const TParameter s_VoiceParameter[];
static const TParameter s_OPParameter[];

Loading…
Cancel
Save