├── cetone033 ├── images │ ├── gui.bmp │ ├── buttons.bmp │ └── knobs.bmp ├── MidiStack.h ├── FilterBiquad.h ├── FilterMoog.h ├── CetoneLpFilter.h ├── SynthOscillator.h ├── globalfunctions.h ├── MidiStack.cpp ├── defines.h ├── CetoneEditor.h ├── structures.h ├── FilterMoog.cpp ├── globalfunctions.cpp ├── CetoneLpFilter.cpp ├── SynthOscillator.cpp ├── Cetone033.h └── FilterBiquad.cpp ├── cetonesynth ├── Images │ ├── gui.bmp │ ├── knobs.bmp │ └── buttons.bmp ├── FilterDirty.h ├── MidiStack.h ├── FilterMoog2.h ├── Filter303.h ├── FilterCh12db.h ├── FilterButterworth24db.h ├── Filter8580.h ├── FilterMoog.h ├── SynthLfo.h ├── MidiStack.cpp ├── SynthOscillator.h ├── SynthEnvelope.h ├── GlobalFunctions.h ├── CetoneEditor.h ├── FilterCh12db.cpp ├── FilterDirty.cpp ├── Filter8580.cpp ├── FilterMoog.cpp ├── FilterMoog2.cpp ├── Filter303.cpp ├── Defines.h ├── Structures.h ├── SynthLfo.cpp ├── FilterButterworth24db.cpp ├── SynthOscillator.cpp ├── CetoneSynth.h └── SynthEnvelope.cpp ├── cetonesynth2 ├── images │ ├── arch.bmp │ ├── copy.bmp │ ├── gui.dat │ ├── gui.txt │ ├── led.bmp │ ├── chars.bmp │ ├── knobs.bmp │ ├── CS2NGui.exe │ ├── buttons.bmp │ ├── sliders.bmp │ └── background.bmp ├── log.h ├── resource.h ├── log.cpp ├── arp.h ├── osc.cpp ├── envelope.cpp ├── arp.cpp ├── statics.h ├── Synth.h ├── lfo.cpp ├── CetoneSynth2.h ├── envelope.h ├── lfo.h ├── svoice.h ├── defines.h ├── parameters.h ├── filter.cpp └── filter.h ├── cetonesynthlight ├── Images │ ├── gui.bmp │ ├── knobs.bmp │ └── buttons.bmp ├── FilterBiquad.h ├── FilterDirty.h ├── MidiStack.h ├── FilterMoog2.h ├── Filter303.h ├── FilterCh12db.h ├── Filter8580.h ├── FilterMoog.h ├── SynthLfo.h ├── SynthEnvelope.h ├── MidiStack.cpp ├── GlobalFunctions.h ├── SynthOscillator.h ├── CetoneEditor.h ├── Filter303.cpp ├── FilterCh12db.cpp ├── FilterDirty.cpp ├── FilterBiquad.cpp ├── Filter8580.cpp ├── FilterMoog.cpp ├── FilterMoog2.cpp ├── Structures.h ├── Defines.h ├── SynthLfo.cpp ├── SynthEnvelope.cpp ├── CetoneSynth.h └── SynthOscillator.cpp ├── cetoneorg ├── statics.h ├── lfo.h ├── data.h ├── defines.h ├── statics.cpp ├── CetoneOrg.h ├── tonewheel.h ├── Synth.h ├── chorus.h ├── Synth.cpp └── reverb.h └── README.txt /cetone033/images/gui.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetone033/images/gui.bmp -------------------------------------------------------------------------------- /cetone033/images/buttons.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetone033/images/buttons.bmp -------------------------------------------------------------------------------- /cetone033/images/knobs.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetone033/images/knobs.bmp -------------------------------------------------------------------------------- /cetonesynth/Images/gui.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth/Images/gui.bmp -------------------------------------------------------------------------------- /cetonesynth/Images/knobs.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth/Images/knobs.bmp -------------------------------------------------------------------------------- /cetonesynth2/images/arch.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth2/images/arch.bmp -------------------------------------------------------------------------------- /cetonesynth2/images/copy.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth2/images/copy.bmp -------------------------------------------------------------------------------- /cetonesynth2/images/gui.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth2/images/gui.dat -------------------------------------------------------------------------------- /cetonesynth2/images/gui.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth2/images/gui.txt -------------------------------------------------------------------------------- /cetonesynth2/images/led.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth2/images/led.bmp -------------------------------------------------------------------------------- /cetonesynth/Images/buttons.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth/Images/buttons.bmp -------------------------------------------------------------------------------- /cetonesynth2/images/chars.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth2/images/chars.bmp -------------------------------------------------------------------------------- /cetonesynth2/images/knobs.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth2/images/knobs.bmp -------------------------------------------------------------------------------- /cetonesynth2/images/CS2NGui.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth2/images/CS2NGui.exe -------------------------------------------------------------------------------- /cetonesynth2/images/buttons.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth2/images/buttons.bmp -------------------------------------------------------------------------------- /cetonesynth2/images/sliders.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth2/images/sliders.bmp -------------------------------------------------------------------------------- /cetonesynthlight/Images/gui.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynthlight/Images/gui.bmp -------------------------------------------------------------------------------- /cetonesynthlight/Images/knobs.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynthlight/Images/knobs.bmp -------------------------------------------------------------------------------- /cetonesynth2/images/background.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynth2/images/background.bmp -------------------------------------------------------------------------------- /cetonesynth2/log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void logOpen(char* name); 4 | void logPrintf(char* text, ...); 5 | void logClose(); 6 | -------------------------------------------------------------------------------- /cetonesynthlight/Images/buttons.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rjeschke/cetonesynths/HEAD/cetonesynthlight/Images/buttons.bmp -------------------------------------------------------------------------------- /cetonesynthlight/FilterBiquad.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterBiquad 4 | { 5 | public: 6 | CFilterBiquad(); 7 | ~CFilterBiquad(); 8 | void Reset(); 9 | void Set(float cutoff, float q); 10 | void SetSampleRate(float fs); 11 | float Run(float inputout); 12 | 13 | private: 14 | float t0, t1; 15 | float min_fc; 16 | float a1, a2; 17 | float b0, b1, b2; 18 | float buffer[6]; 19 | }; 20 | -------------------------------------------------------------------------------- /cetonesynth/FilterDirty.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterDirty 4 | { 5 | public: 6 | CFilterDirty(void); 7 | ~CFilterDirty(void); 8 | 9 | void Set(float cutoff, float q); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | private: 16 | float CutOff; 17 | float Q; 18 | int Mode; 19 | 20 | float fb, f, buf0, buf1; 21 | }; 22 | -------------------------------------------------------------------------------- /cetone033/MidiStack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CMidiStack 4 | { 5 | public: 6 | CMidiStack(void); 7 | ~CMidiStack(void); 8 | 9 | bool IsEmpty(); 10 | void Push(int p0, int p1, int p2, int delta); 11 | void Pop(int* p0, int* p1, int* p2, int* delta); 12 | 13 | private: 14 | int P0[4096]; 15 | int P1[4096]; 16 | int P2[4096]; 17 | int Delta[4096]; 18 | int StackLow; 19 | int StackHigh; 20 | }; 21 | -------------------------------------------------------------------------------- /cetonesynth/MidiStack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CMidiStack 4 | { 5 | public: 6 | CMidiStack(void); 7 | ~CMidiStack(void); 8 | 9 | bool IsEmpty(); 10 | void Push(int p0, int p1, int p2, int delta); 11 | void Pop(int* p0, int* p1, int* p2, int* delta); 12 | 13 | private: 14 | int P0[4096]; 15 | int P1[4096]; 16 | int P2[4096]; 17 | int Delta[4096]; 18 | int StackLow; 19 | int StackHigh; 20 | }; 21 | -------------------------------------------------------------------------------- /cetonesynthlight/FilterDirty.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterDirty 4 | { 5 | public: 6 | CFilterDirty(void); 7 | ~CFilterDirty(void); 8 | 9 | void Set(float cutoff, float q); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | private: 16 | float CutOff; 17 | float Q; 18 | int Mode; 19 | 20 | float fb, f, buf0, buf1; 21 | }; 22 | -------------------------------------------------------------------------------- /cetonesynthlight/MidiStack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CMidiStack 4 | { 5 | public: 6 | CMidiStack(void); 7 | ~CMidiStack(void); 8 | 9 | bool IsEmpty(); 10 | void Push(int p0, int p1, int p2, int delta); 11 | void Pop(int* p0, int* p1, int* p2, int* delta); 12 | 13 | private: 14 | int P0[4096]; 15 | int P1[4096]; 16 | int P2[4096]; 17 | int Delta[4096]; 18 | int StackLow; 19 | int StackHigh; 20 | }; 21 | -------------------------------------------------------------------------------- /cetonesynth/FilterMoog2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterMoog2 4 | { 5 | public: 6 | CFilterMoog2(void); 7 | ~CFilterMoog2(void); 8 | 9 | void Set(float cutoff, float q); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | private: 16 | float CutOff; 17 | float Q; 18 | int Mode; 19 | 20 | float f, p, q2; 21 | float b0, b1, b2, b3, b4; 22 | }; 23 | -------------------------------------------------------------------------------- /cetonesynth/Filter303.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilter303 4 | { 5 | public: 6 | CFilter303(void); 7 | ~CFilter303(void); 8 | 9 | void Set(float cutoff, float q, float mod); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | private: 16 | float CutOff; 17 | float Q; 18 | float env_mod; 19 | float res_coef; 20 | 21 | float a, b, c, d1, d2; 22 | }; 23 | -------------------------------------------------------------------------------- /cetonesynthlight/FilterMoog2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterMoog2 4 | { 5 | public: 6 | CFilterMoog2(void); 7 | ~CFilterMoog2(void); 8 | 9 | void Set(float cutoff, float q); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | private: 16 | float CutOff; 17 | float Q; 18 | int Mode; 19 | 20 | float f, p, q2; 21 | float b0, b1, b2, b3, b4; 22 | }; 23 | -------------------------------------------------------------------------------- /cetonesynthlight/Filter303.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilter303 4 | { 5 | public: 6 | CFilter303(void); 7 | ~CFilter303(void); 8 | 9 | void Set(float cutoff, float q, float mod); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | private: 16 | float CutOff; 17 | float Q; 18 | float env_mod; 19 | float res_coef; 20 | 21 | float a, b, c, d1, d2; 22 | }; 23 | -------------------------------------------------------------------------------- /cetonesynth/FilterCh12db.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterCh12db 4 | { 5 | public: 6 | CFilterCh12db(void); 7 | ~CFilterCh12db(void); 8 | 9 | void Set(float cutoff, float q); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | private: 16 | float CutOff; 17 | float Q; 18 | int Mode; 19 | 20 | float f; 21 | float Low; 22 | float Band; 23 | float High; 24 | float Notch; 25 | }; 26 | -------------------------------------------------------------------------------- /cetonesynthlight/FilterCh12db.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterCh12db 4 | { 5 | public: 6 | CFilterCh12db(void); 7 | ~CFilterCh12db(void); 8 | 9 | void Set(float cutoff, float q); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | private: 16 | float CutOff; 17 | float Q; 18 | int Mode; 19 | 20 | float f; 21 | float Low; 22 | float Band; 23 | float High; 24 | float Notch; 25 | }; 26 | -------------------------------------------------------------------------------- /cetonesynth/FilterButterworth24db.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterButterworth24db 4 | { 5 | public: 6 | CFilterButterworth24db(void); 7 | ~CFilterButterworth24db(void); 8 | void SetSampleRate(float fs); 9 | void Set(float cutoff, float q); 10 | float Run(float input); 11 | void Reset(); 12 | 13 | private: 14 | float t0, t1, t2, t3; 15 | float coef0, coef1, coef2, coef3; 16 | float history1, history2, history3, history4; 17 | float gain; 18 | float min_cutoff, max_cutoff; 19 | }; 20 | -------------------------------------------------------------------------------- /cetonesynth/Filter8580.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilter8580 4 | { 5 | public: 6 | CFilter8580(void); 7 | ~CFilter8580(void); 8 | 9 | void Set(float cutoff, float q); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | void CalcClock(); 16 | 17 | private: 18 | float CutOff; 19 | float Q; 20 | int Mode; 21 | int Clock; 22 | 23 | float w0; 24 | float q_par; 25 | 26 | float Vhp; 27 | float Vbp; 28 | float Vlp; 29 | }; 30 | -------------------------------------------------------------------------------- /cetonesynthlight/Filter8580.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilter8580 4 | { 5 | public: 6 | CFilter8580(void); 7 | ~CFilter8580(void); 8 | 9 | void Set(float cutoff, float q); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | void CalcClock(); 16 | 17 | private: 18 | float CutOff; 19 | float Q; 20 | int Mode; 21 | int Clock; 22 | 23 | float w0; 24 | float q_par; 25 | 26 | float Vhp; 27 | float Vbp; 28 | float Vlp; 29 | }; 30 | -------------------------------------------------------------------------------- /cetonesynth2/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by CetoneSynth2.rc 4 | // 5 | #define IDB_BITMAP1 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /cetone033/FilterBiquad.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterBiquad 4 | { 5 | public: 6 | CFilterBiquad(); 7 | ~CFilterBiquad(); 8 | void Reset(); 9 | void Set(float cutoff, float q); 10 | void SetSampleRate(float fs); 11 | float Run(float inputout); 12 | 13 | private: 14 | float t0, t1; 15 | float min_fc; 16 | float a1, a2; 17 | float b0, b1, b2; 18 | 19 | float a1b, a2b; 20 | float b0b, b1b, b2b; 21 | 22 | float buffer0[6]; 23 | float buffer1[6]; 24 | float buffer2[6]; 25 | float waveshaper[16384]; 26 | }; 27 | -------------------------------------------------------------------------------- /cetone033/FilterMoog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterMoog 4 | { 5 | public: 6 | CFilterMoog(void); 7 | ~CFilterMoog(void); 8 | 9 | void Set(float cutoff, float q); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | private: 16 | float CutOff; 17 | float Q; 18 | 19 | float p, k, r; 20 | 21 | float y1; 22 | float y2; 23 | float y3; 24 | float y4; 25 | float oldx; 26 | float oldy1; 27 | float oldy2; 28 | float oldy3; 29 | }; 30 | -------------------------------------------------------------------------------- /cetonesynth/FilterMoog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterMoog 4 | { 5 | public: 6 | CFilterMoog(void); 7 | ~CFilterMoog(void); 8 | 9 | void Set(float cutoff, float q); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | private: 16 | float CutOff; 17 | float Q; 18 | 19 | float p, k, r; 20 | 21 | float y1; 22 | float y2; 23 | float y3; 24 | float y4; 25 | float oldx; 26 | float oldy1; 27 | float oldy2; 28 | float oldy3; 29 | }; 30 | -------------------------------------------------------------------------------- /cetonesynthlight/FilterMoog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CFilterMoog 4 | { 5 | public: 6 | CFilterMoog(void); 7 | ~CFilterMoog(void); 8 | 9 | void Set(float cutoff, float q); 10 | void SetMode(int mode); 11 | int GetMode(); 12 | float Run(float val); 13 | void Reset(); 14 | 15 | private: 16 | float CutOff; 17 | float Q; 18 | 19 | float p, k, r; 20 | 21 | float y1; 22 | float y2; 23 | float y3; 24 | float y4; 25 | float oldx; 26 | float oldy1; 27 | float oldy2; 28 | float oldy3; 29 | }; 30 | -------------------------------------------------------------------------------- /cetonesynth2/log.cpp: -------------------------------------------------------------------------------- 1 | #include "log.h" 2 | #include 3 | #include 4 | 5 | static FILE* logFile = 0; 6 | 7 | void logOpen(char* name) 8 | { 9 | if((logFile != 0) || (name == NULL)) 10 | return; 11 | 12 | fopen_s(&logFile, name, "wt"); 13 | } 14 | 15 | void logPrintf(char* text, ...) 16 | { 17 | if(!logFile) 18 | return; 19 | 20 | va_list args; 21 | va_start(args, text); 22 | vfprintf(logFile, text, args); 23 | va_end(args); 24 | } 25 | 26 | void logClose() 27 | { 28 | if(!logFile) 29 | return; 30 | fclose(logFile); 31 | logFile = 0; 32 | } 33 | -------------------------------------------------------------------------------- /cetone033/CetoneLpFilter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "filtermoog.h" 4 | #include "filterbiquad.h" 5 | 6 | class CCetoneLpFilter 7 | { 8 | public: 9 | CCetoneLpFilter(void); 10 | ~CCetoneLpFilter(void); 11 | 12 | void Reset(); 13 | 14 | void Set(float cutoff, float q); 15 | void SetSampleRate(float fs); 16 | void Name(int type, char* text); 17 | 18 | float Run(float inputout); 19 | 20 | void SetType(int type); 21 | int GetType(); 22 | 23 | private: 24 | int Type; 25 | float Cutoff, Resonance; 26 | 27 | CFilterMoog* FilterMoog; 28 | CFilterBiquad* FilterBiquad; 29 | }; 30 | -------------------------------------------------------------------------------- /cetoneorg/statics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef struct 4 | { 5 | int offset[16]; 6 | } GENERATOR; 7 | 8 | extern float g_sine[SINE_SIZE * 3 * 128]; 9 | extern GENERATOR g_generators[61]; 10 | extern int g_all_sizes[4]; 11 | extern int g_comb_sizes[8]; 12 | 13 | int irand(); 14 | void initStatics(float fs); 15 | 16 | __forceinline float spline(float t, float* ps) 17 | { 18 | return ( 19 | (((-t + 3.0f) * t - 3.0f) * t + 1.0f) * ps[0] 20 | + (((3.0f * t - 6.0f) * t) * t + 4.0f) * ps[1] 21 | + (((-3.0f * t + 3.0f) * t + 3.0f) * t + 1.0f) * ps[2] 22 | + (t * t * t) * ps[3] 23 | ) * (1.0f / 6.0f); 24 | } 25 | -------------------------------------------------------------------------------- /cetone033/SynthOscillator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cetone033.h" 4 | 5 | class CSynthOscillator 6 | { 7 | public: 8 | CSynthOscillator(void); 9 | ~CSynthOscillator(void); 10 | 11 | void Set(float pw, int wave); 12 | void SetPitch(int pitch); 13 | void SetPw(float pw); 14 | void SetWave(int wave); 15 | 16 | float Run(); 17 | 18 | void Reset(); 19 | 20 | private: 21 | int Waveform; 22 | 23 | int IndexInt; 24 | int IndexFrac; 25 | 26 | int StepInt; 27 | int StepFrac; 28 | 29 | int PwOffset; 30 | float PwWaveOffset; 31 | float TriWaveScale; 32 | 33 | float* SawPtr; 34 | float* ParabolaPtr; 35 | }; 36 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | The Cetone Synth series: 2 | ======================== 3 | 4 | Source code for some of my old VSTi synthesizers. Provided 'as is' 5 | and license free for public use. 6 | 7 | The projects won't build out-of-the box (makefile/project missing) 8 | and you will need additional stuff (e.g. the VST SDK). But maybe 9 | these source codes can be of any help for VSTi/synth starters. 10 | 11 | If you want to try them out, have a look here: 12 | 13 | http://www.kvraudio.com/forum/viewtopic.php?p=4680507#4680507 14 | 15 | No VST host? Get one (IMHO the best) here: 16 | 17 | http://www.cantabilesoftware.com/lite/ 18 | 19 | --- 20 | René Jeschke -------------------------------------------------------------------------------- /cetonesynth/SynthLfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CSynthLfo 4 | { 5 | public: 6 | CSynthLfo(void); 7 | ~CSynthLfo(void); 8 | 9 | void Set(float speed, int pw, int wave, bool trig); 10 | 11 | void SetSpeed(float speed); 12 | float GetSpeed(); 13 | 14 | void SetPw(int pw); 15 | int GetPw(); 16 | 17 | void SetWave(int wave); 18 | int GetWave(); 19 | 20 | void SetTrigger(bool trig); 21 | bool GetTrigger(); 22 | 23 | float GetValue(); 24 | 25 | float Run(); 26 | void Trigger(); 27 | 28 | void Reset(); 29 | 30 | private: 31 | int OscNow; 32 | int OscStep; 33 | int Waveform; 34 | int PulseWidth; 35 | float Value; 36 | float Pitch; 37 | bool DoTrigger; 38 | int ShiftRegister; 39 | }; 40 | -------------------------------------------------------------------------------- /cetonesynthlight/SynthLfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CSynthLfo 4 | { 5 | public: 6 | CSynthLfo(void); 7 | ~CSynthLfo(void); 8 | 9 | void Set(float speed, int pw, int wave, bool trig); 10 | 11 | void SetSpeed(float speed); 12 | float GetSpeed(); 13 | 14 | void SetPw(int pw); 15 | int GetPw(); 16 | 17 | void SetWave(int wave); 18 | int GetWave(); 19 | 20 | void SetTrigger(bool trig); 21 | bool GetTrigger(); 22 | 23 | float GetValue(); 24 | 25 | float Run(); 26 | void Trigger(); 27 | 28 | void Reset(); 29 | 30 | private: 31 | int OscNow; 32 | int OscStep; 33 | int Waveform; 34 | int PulseWidth; 35 | float Value; 36 | float Pitch; 37 | bool DoTrigger; 38 | int ShiftRegister; 39 | }; 40 | -------------------------------------------------------------------------------- /cetone033/globalfunctions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void wave2str (int wave, char* text); 4 | void myfloat2string (float val, char* text); 5 | void bool2string (bool val, char* text); 6 | 7 | int c_val2fine (float value); 8 | float c_fine2val (int value); 9 | int c_val2coarse (float value); 10 | float c_coarse2val (int value); 11 | float c_val2cutoff (float value); 12 | float c_cutoff2val (float value); 13 | bool c_val2bool (float value); 14 | float c_bool2val (bool value); 15 | 16 | int pf2i (float val, int max); 17 | float pi2f (int val, int max); 18 | 19 | inline int truncate(float flt) 20 | { 21 | int i; 22 | _asm 23 | { 24 | fld flt 25 | fistp i 26 | } 27 | return i; 28 | } 29 | -------------------------------------------------------------------------------- /cetonesynthlight/SynthEnvelope.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CSynthEnvelope 4 | { 5 | public: 6 | CSynthEnvelope(void); 7 | ~CSynthEnvelope(void); 8 | 9 | void Gate(bool gate); 10 | float Run(); 11 | 12 | void Set(float a, float h, float d, float s, float r); 13 | 14 | float GetAttack(); 15 | float GetHold(); 16 | float GetDecay(); 17 | float GetSustain(); 18 | float GetRelease(); 19 | 20 | float TimeValue(float val); 21 | 22 | void SetPreAttack(float val); 23 | 24 | void Reset(); 25 | 26 | private: 27 | float Attack, Hold, Decay, Sustain, Release, PreAttack; 28 | int sAttack, sHold, sDecay, sRelease, sPreAttack; 29 | float sAttackf, sHoldf, sDecayf, sReleasef, sPreAttackf; 30 | 31 | int Phase; 32 | int LastPhase; 33 | 34 | float VolStep; 35 | float VolNow; 36 | 37 | int Counter; 38 | int Samples; 39 | }; 40 | -------------------------------------------------------------------------------- /cetone033/MidiStack.cpp: -------------------------------------------------------------------------------- 1 | #include "MidiStack.h" 2 | 3 | CMidiStack::CMidiStack(void) 4 | { 5 | this->StackLow = 0; 6 | this->StackHigh = 0; 7 | } 8 | 9 | CMidiStack::~CMidiStack(void) 10 | { 11 | } 12 | 13 | bool CMidiStack::IsEmpty() 14 | { 15 | return (this->StackLow == this->StackHigh) ? true : false; 16 | } 17 | 18 | void CMidiStack::Push(int p0, int p1, int p2, int delta) 19 | { 20 | this->P0[this->StackHigh] = p0; 21 | this->P1[this->StackHigh] = p1; 22 | this->P2[this->StackHigh] = p2; 23 | this->Delta[this->StackHigh] = delta; 24 | 25 | this->StackHigh++; 26 | this->StackHigh &= 4095; 27 | } 28 | 29 | void CMidiStack::Pop(int *p0, int *p1, int *p2, int *delta) 30 | { 31 | *p0 = this->P0[this->StackLow]; 32 | *p1 = this->P1[this->StackLow]; 33 | *p2 = this->P2[this->StackLow]; 34 | *delta = this->Delta[this->StackLow]; 35 | 36 | this->StackLow++; 37 | this->StackLow &= 4095; 38 | } 39 | -------------------------------------------------------------------------------- /cetonesynth/MidiStack.cpp: -------------------------------------------------------------------------------- 1 | #include "MidiStack.h" 2 | 3 | CMidiStack::CMidiStack(void) 4 | { 5 | this->StackLow = 0; 6 | this->StackHigh = 0; 7 | } 8 | 9 | CMidiStack::~CMidiStack(void) 10 | { 11 | } 12 | 13 | bool CMidiStack::IsEmpty() 14 | { 15 | return (this->StackLow == this->StackHigh) ? true : false; 16 | } 17 | 18 | void CMidiStack::Push(int p0, int p1, int p2, int delta) 19 | { 20 | this->P0[this->StackHigh] = p0; 21 | this->P1[this->StackHigh] = p1; 22 | this->P2[this->StackHigh] = p2; 23 | this->Delta[this->StackHigh] = delta; 24 | 25 | this->StackHigh++; 26 | this->StackHigh &= 4095; 27 | } 28 | 29 | void CMidiStack::Pop(int *p0, int *p1, int *p2, int *delta) 30 | { 31 | *p0 = this->P0[this->StackLow]; 32 | *p1 = this->P1[this->StackLow]; 33 | *p2 = this->P2[this->StackLow]; 34 | *delta = this->Delta[this->StackLow]; 35 | 36 | this->StackLow++; 37 | this->StackLow &= 4095; 38 | } 39 | -------------------------------------------------------------------------------- /cetonesynthlight/MidiStack.cpp: -------------------------------------------------------------------------------- 1 | #include "MidiStack.h" 2 | 3 | CMidiStack::CMidiStack(void) 4 | { 5 | this->StackLow = 0; 6 | this->StackHigh = 0; 7 | } 8 | 9 | CMidiStack::~CMidiStack(void) 10 | { 11 | } 12 | 13 | bool CMidiStack::IsEmpty() 14 | { 15 | return (this->StackLow == this->StackHigh) ? true : false; 16 | } 17 | 18 | void CMidiStack::Push(int p0, int p1, int p2, int delta) 19 | { 20 | this->P0[this->StackHigh] = p0; 21 | this->P1[this->StackHigh] = p1; 22 | this->P2[this->StackHigh] = p2; 23 | this->Delta[this->StackHigh] = delta; 24 | 25 | this->StackHigh++; 26 | this->StackHigh &= 4095; 27 | } 28 | 29 | void CMidiStack::Pop(int *p0, int *p1, int *p2, int *delta) 30 | { 31 | *p0 = this->P0[this->StackLow]; 32 | *p1 = this->P1[this->StackLow]; 33 | *p2 = this->P2[this->StackLow]; 34 | *delta = this->Delta[this->StackLow]; 35 | 36 | this->StackLow++; 37 | this->StackLow &= 4095; 38 | } 39 | -------------------------------------------------------------------------------- /cetone033/defines.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define UNDENORM(v) if((*(unsigned __int32*)&v & 0x7f800000) == 0) v = 0.0f 4 | 5 | #define FILTER_DELAY 256 6 | 7 | #define FILTER_TYPE_BIQUAD 0 8 | #define FILTER_TYPE_MOOG 1 9 | 10 | #define FILTER_TYPE_MAX 1 11 | 12 | #define MOD_CHANGE_SPEED 0.05f 13 | 14 | #define START_VOLUME 0.01f 15 | 16 | #define NOTE_MAX 144 17 | #define NOTE_MAX1 143 18 | #define PITCH_MAX 14400 19 | #define PITCH_MAX1 14399 20 | #define BASE_FREQUENCE 6.875f 21 | #define NOTE_OFFSET 3 22 | 23 | #define WAVETABLE_LENGTH 2048 24 | #define WAVETABLE_LENGTHf 2048.f 25 | #define WAVETABLE_LENGTH2 1024 26 | #define WAVETABLE_LENGTH4 512 27 | #define WAVETABLE_MASK 2047 28 | 29 | #define EFFECT_NAME "Cetone033" 30 | #define VENDOR_NAME "Neotec Software" 31 | #define PRODUCT_NAME "Cetone033" 32 | #define VERSION_NUMBER 1000; 33 | 34 | #define WAVE_SAW 0 35 | #define WAVE_PULSE 1 36 | #define WAVE_TRI 2 37 | 38 | #define WAVE_MAX 2 39 | -------------------------------------------------------------------------------- /cetonesynth/SynthOscillator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CetoneSynth.h" 4 | 5 | class CSynthOscillator 6 | { 7 | public: 8 | CSynthOscillator(void); 9 | ~CSynthOscillator(void); 10 | 11 | void Set(int pw, int wave, bool sync); 12 | 13 | void SetPitch(int pitch); 14 | int GetPitch(); 15 | 16 | void SetPw(int pw); 17 | int GetPw(); 18 | 19 | void SetWave(int wave); 20 | int GetWave(); 21 | 22 | float Run(); 23 | 24 | void Sync(); 25 | void SetSync(bool sync); 26 | void SetSyncDest(CSynthOscillator* osc); 27 | 28 | void Reset(); 29 | 30 | private: 31 | int Waveform; 32 | int PulseWidth; 33 | int Value; 34 | int Pitch; 35 | int ShiftRegister; 36 | 37 | int IndexInt; 38 | int IndexFrac; 39 | 40 | int StepInt; 41 | int StepFrac; 42 | 43 | float PwFloat; 44 | float PwWaveOffset; 45 | int PwOffset; 46 | 47 | float* SawPtr; 48 | float* ParabolaPtr; 49 | 50 | bool DoSync; 51 | CSynthOscillator* SyncOsc; 52 | }; 53 | -------------------------------------------------------------------------------- /cetonesynth/SynthEnvelope.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class CSynthEnvelope 4 | { 5 | public: 6 | CSynthEnvelope(void); 7 | ~CSynthEnvelope(void); 8 | 9 | void Gate(bool gate); 10 | float Run(); 11 | 12 | void Set(float a, float h, float d, float s, float r); 13 | 14 | void SetAttack(float val); 15 | float GetAttack(); 16 | void SetHold(float val); 17 | float GetHold(); 18 | void SetDecay(float val); 19 | float GetDecay(); 20 | void SetSustain(float val); 21 | float GetSustain(); 22 | void SetRelease(float val); 23 | float GetRelease(); 24 | 25 | void SetPreAttack(float val); 26 | 27 | void Reset(); 28 | 29 | private: 30 | float Attack, Hold, Decay, Sustain, Release, PreAttack; 31 | int sAttack, sHold, sDecay, sRelease, sPreAttack; 32 | float sAttackf, sHoldf, sDecayf, sReleasef, sPreAttackf; 33 | 34 | int Phase; 35 | int LastPhase; 36 | 37 | float VolStep; 38 | float VolNow; 39 | 40 | int Counter; 41 | int Samples; 42 | }; 43 | -------------------------------------------------------------------------------- /cetonesynth/GlobalFunctions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void wave2str (int wave, char* text); 4 | void owave2str (int wave, char* text); 5 | void fmode2str (int mode, char* text); 6 | void ftype2str (int mode, char* text); 7 | void msrc2str (int val, char* text); 8 | void mdest2str (int val, char* text); 9 | void arp2str (int val, char* text); 10 | void myfloat2string (float val, char* text); 11 | void bool2string (bool val, char* text); 12 | 13 | int c_val2fine (float value); 14 | float c_fine2val (int value); 15 | int c_val2coarse (float value); 16 | float c_coarse2val (int value); 17 | float c_val2cutoff (float value); 18 | float c_cutoff2val (float value); 19 | int c_val2pw (float value); 20 | float c_pw2val (int value); 21 | bool c_val2bool (float value); 22 | float c_bool2val (bool value); 23 | 24 | int pf2i (float val, int max); 25 | float pi2f (int val, int max); 26 | 27 | inline int truncate(float flt) 28 | { 29 | int i; 30 | _asm 31 | { 32 | fld flt 33 | fistp i 34 | } 35 | return i; 36 | } -------------------------------------------------------------------------------- /cetonesynthlight/GlobalFunctions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void wave2str (int wave, char* text); 4 | void owave2str (int wave, char* text); 5 | void fmode2str (int mode, char* text); 6 | void ftype2str (int mode, char* text); 7 | void msrc2str (int val, char* text); 8 | void mdest2str (int val, char* text); 9 | void arp2str (int val, char* text); 10 | void myfloat2string (float val, char* text); 11 | void bool2string (bool val, char* text); 12 | 13 | int c_val2fine (float value); 14 | float c_fine2val (int value); 15 | int c_val2coarse (float value); 16 | float c_coarse2val (int value); 17 | float c_val2cutoff (float value); 18 | float c_cutoff2val (float value); 19 | int c_val2pw (float value); 20 | float c_pw2val (int value); 21 | bool c_val2bool (float value); 22 | float c_bool2val (bool value); 23 | 24 | int pf2i (float val, int max); 25 | float pi2f (int val, int max); 26 | 27 | inline int truncate(float flt) 28 | { 29 | int i; 30 | _asm 31 | { 32 | fld flt 33 | fistp i 34 | } 35 | return i; 36 | } -------------------------------------------------------------------------------- /cetonesynthlight/SynthOscillator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CetoneSynth.h" 4 | 5 | class CSynthOscillator 6 | { 7 | public: 8 | CSynthOscillator(void); 9 | ~CSynthOscillator(void); 10 | 11 | void Set(int pw, int wave, bool sync); 12 | 13 | void SetPitch(int pitch); 14 | int GetPitch(); 15 | 16 | void SetPw(int pw); 17 | int GetPw(); 18 | 19 | void SetWave(int wave); 20 | int GetWave(); 21 | 22 | float Run(); 23 | 24 | void Sync(); 25 | void SetSyncPitch(int pitch); 26 | void ProcessSync(); 27 | void SetSync(bool sync); 28 | void SetSyncDest(CSynthOscillator* osc); 29 | 30 | void Reset(); 31 | 32 | private: 33 | int Waveform; 34 | int PulseWidth; 35 | int Value; 36 | int Pitch; 37 | int SyncPitch; 38 | int ShiftRegister; 39 | 40 | int IndexInt; 41 | int IndexFrac; 42 | 43 | int StepInt; 44 | int StepFrac; 45 | 46 | float PwFloat; 47 | float PwWaveOffset; 48 | int PwOffset; 49 | 50 | float* SawPtr; 51 | float* ParabolaPtr; 52 | 53 | bool DoSync; 54 | bool WasPeriod; 55 | CSynthOscillator* SyncOsc; 56 | }; 57 | -------------------------------------------------------------------------------- /cetone033/CetoneEditor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cetone033.h" 4 | 5 | #include "aeffguieditor.h" 6 | 7 | enum 8 | { 9 | rBackground = 128, 10 | rKnobs, 11 | rButtons 12 | }; 13 | 14 | class CLabel : public CParamDisplay 15 | { 16 | public: 17 | CLabel(CRect &size, char *text); 18 | void draw(CDrawContext *context); 19 | void setLabel(char *text); 20 | 21 | protected: 22 | char label[256]; 23 | }; 24 | 25 | class CCetoneEditor : public AEffGUIEditor, public CControlListener 26 | { 27 | public: 28 | CCetoneEditor(AudioEffect* effect); 29 | virtual ~CCetoneEditor(void); 30 | 31 | virtual bool getRect(ERect **rect); 32 | virtual bool open(void *ptr); 33 | virtual void close(); 34 | 35 | virtual void setParameter(VstInt32 index, float value); 36 | virtual void valueChanged(CDrawContext* context, CControl* control); 37 | 38 | virtual void idle(); 39 | 40 | private: 41 | ERect GuiSize; 42 | CBitmap* BmpBackground; 43 | CBitmap* BmpKnob; 44 | CBitmap* BmpButton; 45 | 46 | CAnimKnob* Knobs[pParameters]; 47 | COnOffButton* Buttons[pParameters]; 48 | CLabel* Labels[pParameters]; 49 | }; 50 | -------------------------------------------------------------------------------- /cetonesynth/CetoneEditor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cetonesynth.h" 4 | 5 | #include "aeffguieditor.h" 6 | 7 | enum 8 | { 9 | rBackground = 128, 10 | rKnobs, 11 | rButtons 12 | }; 13 | 14 | class CLabel : public CParamDisplay 15 | { 16 | public: 17 | CLabel(CRect &size, char *text); 18 | void draw(CDrawContext *context); 19 | void setLabel(char *text); 20 | 21 | protected: 22 | char label[256]; 23 | }; 24 | 25 | class CCetoneEditor : public AEffGUIEditor, public CControlListener 26 | { 27 | public: 28 | CCetoneEditor(AudioEffect* effect); 29 | virtual ~CCetoneEditor(void); 30 | 31 | virtual bool getRect(ERect **rect); 32 | virtual bool open(void *ptr); 33 | virtual void close(); 34 | 35 | virtual void setParameter(VstInt32 index, float value); 36 | virtual void valueChanged(CDrawContext* context, CControl* control); 37 | 38 | virtual void idle(); 39 | 40 | private: 41 | ERect GuiSize; 42 | CBitmap* BmpBackground; 43 | CBitmap* BmpKnob; 44 | CBitmap* BmpButton; 45 | 46 | CAnimKnob* Knobs[pParameters]; 47 | COnOffButton* Buttons[pParameters]; 48 | CLabel* Labels[pParameters]; 49 | }; 50 | -------------------------------------------------------------------------------- /cetonesynthlight/CetoneEditor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cetonesynth.h" 4 | 5 | #include "aeffguieditor.h" 6 | 7 | enum 8 | { 9 | rBackground = 128, 10 | rKnobs, 11 | rButtons 12 | }; 13 | 14 | class CLabel : public CParamDisplay 15 | { 16 | public: 17 | CLabel(CRect &size, char *text); 18 | void draw(CDrawContext *context); 19 | void setLabel(char *text); 20 | 21 | protected: 22 | char label[256]; 23 | }; 24 | 25 | class CCetoneEditor : public AEffGUIEditor, public CControlListener 26 | { 27 | public: 28 | CCetoneEditor(AudioEffect* effect); 29 | virtual ~CCetoneEditor(void); 30 | 31 | virtual bool getRect(ERect **rect); 32 | virtual bool open(void *ptr); 33 | virtual void close(); 34 | 35 | virtual void setParameter(VstInt32 index, float value); 36 | virtual void valueChanged(CDrawContext* context, CControl* control); 37 | 38 | virtual void idle(); 39 | 40 | private: 41 | ERect GuiSize; 42 | CBitmap* BmpBackground; 43 | CBitmap* BmpKnob; 44 | CBitmap* BmpButton; 45 | 46 | CAnimKnob* Knobs[pParameters]; 47 | COnOffButton* Buttons[pParameters]; 48 | CLabel* Labels[pParameters]; 49 | }; 50 | -------------------------------------------------------------------------------- /cetoneorg/lfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | #include "statics.h" 5 | 6 | class LFO 7 | { 8 | public: 9 | LFO() 10 | { 11 | this->Speed = 10.0f; 12 | this->Pos.int32 = this->Step.int32 = 0; 13 | this->Phase = SINE_SIZE / 2; 14 | } 15 | 16 | ~LFO() 17 | { 18 | } 19 | 20 | void setSpeed(float speed) 21 | { 22 | this->Speed = speed; 23 | this->Step.int32 = truncate(((SINE_SIZEf * speed) / this->FS) * 65536.0f + 0.5f); 24 | } 25 | 26 | void setPhase(int phase) 27 | { 28 | this->Phase = phase * (SINE_SIZE / 128); 29 | } 30 | 31 | void setSampleRate(float fs) 32 | { 33 | this->FS = fs; 34 | this->setSpeed(this->Speed); 35 | } 36 | 37 | void Render(float* buf0, float* buf1, int samples) 38 | { 39 | int i; 40 | for(i = 0; i < samples; i++) 41 | { 42 | buf0[i] = g_sine[this->Pos.fixed.index]; 43 | buf1[i] = g_sine[(this->Pos.fixed.index + this->Phase) & (SINE_SIZE-1)]; 44 | this->Pos.int32 += this->Step.int32; 45 | this->Pos.fixed.index &= SINE_SIZE - 1; 46 | } 47 | } 48 | 49 | private: 50 | float FS; 51 | float Speed; 52 | sSTEP Pos; 53 | sSTEP Step; 54 | int Phase; 55 | }; -------------------------------------------------------------------------------- /cetonesynth2/arp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | #include "statics.h" 5 | 6 | class ARP 7 | { 8 | public: 9 | ARP(); 10 | ~ARP(); 11 | void Retrigger(); 12 | void SetTempo(float f); 13 | void SetSampleRate(float fs); 14 | void SetSpeed(int speed); 15 | void SetSync(int sync); 16 | void SetLoop(int loop); 17 | void SetLength(int len); 18 | void SetNote(int idx, int note); 19 | 20 | __forceinline int Process() 21 | { 22 | if(!this->Speed) 23 | return 0; 24 | 25 | if((this->Pos > this->Length) && !this->Loop) 26 | return 0; 27 | 28 | if(this->Samples-- <= 0) 29 | { 30 | this->Pos++; 31 | if(this->Pos > this->Length) 32 | { 33 | if(this->Loop) 34 | this->Pos = 0; 35 | else 36 | return 0; 37 | } 38 | this->Samples = this->Delay; 39 | this->fPos += this->fDelay; 40 | if(this->fPos > 0xffff) 41 | { 42 | this->Samples++; 43 | this->fPos &= 0xffff; 44 | } 45 | } 46 | 47 | return this->Notes[this->Pos]; 48 | }; 49 | private: 50 | float m2f[128]; 51 | int Notes[8]; 52 | float FS; 53 | int Length; 54 | int Speed; 55 | bool Loop; 56 | bool Sync; 57 | int Pos; 58 | int fPos; 59 | int Delay; 60 | int fDelay; 61 | int Samples; 62 | float Tempo; 63 | }; 64 | -------------------------------------------------------------------------------- /cetoneorg/data.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int g_rotors[267] = 4 | { 5 | 2,85,104, 6 | 2,71,82, 7 | 2,67,73, 8 | 2,70,72, 9 | 2,69,67, 10 | 4,54,99, 11 | 4,37,64, 12 | 4,49,80, 13 | 4,48,74, 14 | 4,66,96, 15 | 4,67,92, 16 | 4,54,70, 17 | 4,85,104, 18 | 4,71,82, 19 | 4,67,73, 20 | 4,70,72, 21 | 4,69,67, 22 | 8,54,99, 23 | 8,37,64, 24 | 8,49,80, 25 | 8,48,74, 26 | 8,66,96, 27 | 8,67,92, 28 | 8,54,70, 29 | 8,85,104, 30 | 8,71,82, 31 | 8,67,73, 32 | 8,70,72, 33 | 8,69,67, 34 | 16,54,99, 35 | 16,37,64, 36 | 16,49,80, 37 | 16,48,74, 38 | 16,66,96, 39 | 16,67,92, 40 | 16,54,70, 41 | 16,85,104, 42 | 16,71,82, 43 | 16,67,73, 44 | 16,70,72, 45 | 16,69,67, 46 | 16,84,77, 47 | 16,74,64, 48 | 16,98,80, 49 | 16,96,74, 50 | 16,88,64, 51 | 16,67,46, 52 | 16,108,70, 53 | 16,85,52, 54 | 16,71,41, 55 | 16,134,73, 56 | 16,105,54, 57 | 16,103,50, 58 | 32,84,77, 59 | 32,74,64, 60 | 32,98,80, 61 | 32,96,74, 62 | 32,88,64, 63 | 32,67,46, 64 | 32,108,70, 65 | 32,85,52, 66 | 32,71,41, 67 | 32,134,73, 68 | 32,105,54, 69 | 32,103,50, 70 | 64,84,77, 71 | 64,74,64, 72 | 64,98,80, 73 | 64,96,74, 74 | 64,88,64, 75 | 64,67,46, 76 | 64,108,70, 77 | 64,85,52, 78 | 64,71,41, 79 | 64,134,73, 80 | 64,105,54, 81 | 64,103,50, 82 | 128,84,77, 83 | 128,74,64, 84 | 128,98,80, 85 | 128,96,74, 86 | 128,88,64, 87 | 128,67,46, 88 | 128,108,70, 89 | 128,85,52, 90 | 128,71,41, 91 | 128,134,73, 92 | 128,105,54, 93 | 128,103,50}; 94 | -------------------------------------------------------------------------------- /cetonesynth2/osc.cpp: -------------------------------------------------------------------------------- 1 | #include "osc.h" 2 | 3 | OSC::OSC() 4 | { 5 | this->Pitch = 0; 6 | this->SetWave(OSCW_OFF); 7 | this->SetMode(OSCM_NORMAL); 8 | this->SetPw(1024); 9 | this->DoSync = false; 10 | this->IsSync = false; 11 | this->IsAM = false; 12 | this->SetSpread(0); 13 | this->SetPitch(6900); 14 | this->Reset(); 15 | 16 | this->SIndex[0].fixed.index = irand() & WAVETABLE_MASK; 17 | this->SIndex[1].fixed.index = irand() & WAVETABLE_MASK; 18 | this->SIndex[2].fixed.index = irand() & WAVETABLE_MASK; 19 | this->SIndex[3].fixed.index = irand() & WAVETABLE_MASK; 20 | this->SIndex[4].fixed.index = irand() & WAVETABLE_MASK; 21 | } 22 | 23 | void OSC::SetWave(int wave) 24 | { 25 | this->Waveform = wave & 15; 26 | } 27 | 28 | void OSC::SetMode(int mode) 29 | { 30 | this->Modus = mode; 31 | } 32 | 33 | void OSC::SetSpread(int val) 34 | { 35 | if(val < 0) 36 | val = 0; 37 | else if(val > 31) 38 | val = 31; 39 | val++; 40 | this->Spread[0] = val; 41 | this->Spread[1] = 2 * val; 42 | val = this->Pitch; 43 | this->Pitch = -1; 44 | this->SetPitch(val); 45 | } 46 | 47 | void OSC::AlertSlave(bool sync) 48 | { 49 | this->IsSync = sync; 50 | this->SetTables(); 51 | } 52 | 53 | void OSC::SetSync(int val) 54 | { 55 | this->DoSync = (val) ? true : false; 56 | this->Slave->AlertSlave(this->DoSync); 57 | } 58 | 59 | void OSC::Reset() 60 | { 61 | this->Sync(); 62 | } 63 | -------------------------------------------------------------------------------- /cetone033/structures.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum 4 | { 5 | pOsc1Coarse, 6 | pOsc1Fine, 7 | pOsc1Wave, 8 | pOsc1Morph, 9 | pOsc1Volume, 10 | 11 | pOsc2Coarse, 12 | pOsc2Fine, 13 | pOsc2Wave, 14 | pOsc2Morph, 15 | pOsc2Volume, 16 | 17 | pEnv1Attack, 18 | pEnv1Decay, 19 | 20 | pEnv2Attack, 21 | pEnv2Decay, 22 | 23 | pModEnv, 24 | pModVel, 25 | pModRes, 26 | 27 | pCutoff, 28 | pResonance, 29 | 30 | pGlideState, 31 | pGlideSpeed, 32 | 33 | pClipState, 34 | pVolume, 35 | 36 | pFilterType, 37 | 38 | pParameters 39 | }; 40 | 41 | struct SynthProgramOld 42 | { 43 | char Name[128]; 44 | 45 | int Coarse[2]; 46 | int Fine[2]; 47 | int Wave[2]; 48 | float Morph[2]; 49 | float Volume[2]; 50 | 51 | float Attack[2]; 52 | float Decay[2]; 53 | 54 | float ModEnv; 55 | float ModVel; 56 | float ModRes; 57 | 58 | float Cutoff; 59 | float Resonance; 60 | 61 | bool GlideState; 62 | float GlideSpeed; 63 | 64 | bool ClipState; 65 | float MainVolume; 66 | }; 67 | 68 | struct SynthProgram 69 | { 70 | char Name[128]; 71 | 72 | int Coarse[2]; 73 | int Fine[2]; 74 | int Wave[2]; 75 | float Morph[2]; 76 | float Volume[2]; 77 | 78 | float Attack[2]; 79 | float Decay[2]; 80 | 81 | float ModEnv; 82 | float ModVel; 83 | float ModRes; 84 | 85 | float Cutoff; 86 | float Resonance; 87 | int FilterType; 88 | 89 | bool GlideState; 90 | float GlideSpeed; 91 | 92 | bool ClipState; 93 | float MainVolume; 94 | }; -------------------------------------------------------------------------------- /cetonesynthlight/Filter303.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "cetonesynth.h" 4 | 5 | #include "Filter303.h" 6 | 7 | CFilter303::CFilter303(void) 8 | { 9 | this->Reset(); 10 | 11 | this->Q = 1.0; 12 | 13 | this->Set(1.f, 0.f, 0.f); 14 | } 15 | 16 | CFilter303::~CFilter303(void) 17 | { 18 | 19 | } 20 | 21 | void CFilter303::Reset() 22 | { 23 | this->a = 0.f; 24 | this->b = 0.f; 25 | this->c = 0.f; 26 | this->d1 = 0.f; 27 | this->d2 = 0.f; 28 | } 29 | 30 | void CFilter303::Set(float cutoff, float q, float mod) 31 | { 32 | if (cutoff < 0.f) 33 | cutoff = 0.f; 34 | else if (cutoff > 1.f) 35 | cutoff = 1.f; 36 | 37 | if (q < 0.f) 38 | q = 0.f; 39 | else if (q > 1.f) 40 | q = 1.f; 41 | 42 | if (mod < -1.f) 43 | mod = -1.f; 44 | else if(mod > 1.f) 45 | mod = 1.f; 46 | 47 | this->CutOff = cutoff; 48 | if(q != this->Q) 49 | { 50 | this->Q = q; 51 | this->res_coef = expf(-1.2f + 3.455f * q); 52 | } 53 | 54 | float w = expf(6.109f + 1.5876f * mod + 2.1553f * cutoff - 1.2f * (1.f - q)) * CCetoneSynth::SampleRatePi; 55 | float k = expf(-w / this->res_coef); 56 | 57 | this->a = 2.f * cosf(2.f * w) * k; 58 | this->b = -k * k; 59 | this->c = 1.f - this->a - this->b; 60 | } 61 | 62 | void CFilter303::SetMode(int mode) 63 | { 64 | // Nothing here 65 | } 66 | 67 | int CFilter303::GetMode() 68 | { 69 | return FMODE_LOW; 70 | } 71 | 72 | float CFilter303::Run(float val) 73 | { 74 | float output; 75 | 76 | output = this->a * this->d1 + this->b * this->d2 + this->c * val; 77 | this->d2 = this->d1; 78 | this->d1 = output; 79 | 80 | return output; 81 | } 82 | -------------------------------------------------------------------------------- /cetonesynthlight/FilterCh12db.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "FilterCh12db.h" 3 | #include 4 | 5 | CFilterCh12db::CFilterCh12db(void) 6 | { 7 | this->Reset(); 8 | 9 | this->Set(1.f, 0.f); 10 | this->SetMode(FMODE_LOW); 11 | } 12 | 13 | CFilterCh12db::~CFilterCh12db(void) 14 | { 15 | } 16 | 17 | void CFilterCh12db::Reset() 18 | { 19 | this->Low = 0.f; 20 | this->High = 0.f; 21 | this->Band = 0.f; 22 | this->Notch = 0.f; 23 | } 24 | 25 | void CFilterCh12db::SetMode(int mode) 26 | { 27 | this->Mode = mode; 28 | } 29 | 30 | int CFilterCh12db::GetMode() 31 | { 32 | return this->Mode; 33 | } 34 | 35 | void CFilterCh12db::Set(float cutoff, float q) 36 | { 37 | if(cutoff < 0.f) 38 | cutoff = 0.f; 39 | else if(cutoff > 1.f) 40 | cutoff = 1.f; 41 | 42 | if(q < 0.f) 43 | q = 0.f; 44 | else if(q > 1.f) 45 | q = 1.f; 46 | 47 | #if ANALOGUE_BEHAVIOR > 0 48 | q *= CH12DB_Q_MAX; 49 | #endif 50 | 51 | this->f = sinf(CCetoneSynth::Pi * cutoff * 0.5f); 52 | 53 | this->CutOff = cutoff; 54 | this->Q = 1.f - q; 55 | } 56 | 57 | float CFilterCh12db::Run(float val) 58 | { 59 | this->Low += this->f * this->Band; 60 | this->High = this->Q * val - this->Low - this->Q * this->Band; 61 | this->Band = this->f * this->High + this->Band; 62 | this->Notch = this->High + this->Low; 63 | 64 | switch (this->Mode) 65 | { 66 | default: 67 | return 0.f; 68 | case FMODE_BAND: 69 | return this->Band; 70 | case FMODE_LOW: 71 | return this->Low; 72 | case FMODE_HIGH: 73 | return this->High; 74 | case FMODE_NOTCH: 75 | return this->Notch; 76 | } 77 | } -------------------------------------------------------------------------------- /cetonesynthlight/FilterDirty.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "FilterDirty.h" 3 | 4 | CFilterDirty::CFilterDirty(void) 5 | { 6 | this->Reset(); 7 | 8 | this->Set(1.f, 0.f); 9 | this->SetMode(FMODE_LOW); 10 | } 11 | 12 | CFilterDirty::~CFilterDirty(void) 13 | { 14 | } 15 | 16 | void CFilterDirty::Reset() 17 | { 18 | this->buf0 = this->buf1 = 0.f; 19 | } 20 | 21 | void CFilterDirty::SetMode(int mode) 22 | { 23 | if(mode < 0) 24 | mode = 0; 25 | else if(mode > FMODE_NOTCH) 26 | mode = FMODE_NOTCH; 27 | 28 | this->Mode = mode; 29 | } 30 | 31 | int CFilterDirty::GetMode() 32 | { 33 | return this->Mode; 34 | } 35 | 36 | void CFilterDirty::Set(float cutoff, float q) 37 | { 38 | if(cutoff < 0.f) 39 | cutoff = 0.f; 40 | else if(cutoff > 0.999f) 41 | cutoff = 0.999f; 42 | 43 | if(q < 0.f) 44 | q = 0.f; 45 | else if(q > 1.f) 46 | q = 1.f; 47 | 48 | #if ANALOGUE_BEHAVIOR > 0 49 | q *= DIRTY_Q_MAX; 50 | #endif 51 | 52 | this->f = cutoff; 53 | 54 | this->fb = q + q / (1.f - cutoff); 55 | 56 | this->CutOff = cutoff; 57 | this->Q = q; 58 | } 59 | 60 | float CFilterDirty::Run(float val) 61 | { 62 | float hp = val - this->buf0; 63 | float bp = this->buf0 - this->buf1; 64 | 65 | this->buf0 += this->f * (hp + this->fb * bp); 66 | this->buf1 += this->f * (this->buf0 - this->buf1); 67 | 68 | switch (this->Mode) 69 | { 70 | default: 71 | return 0.f; 72 | case FMODE_LOW: 73 | return this->buf1; 74 | case FMODE_HIGH: 75 | return hp; 76 | case FMODE_BAND: 77 | return bp; 78 | case FMODE_NOTCH: 79 | return this->buf1 + hp; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /cetonesynth2/envelope.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "defines.h" 3 | #include "envelope.h" 4 | 5 | Envelope::Envelope() 6 | { 7 | int i; 8 | for(i = 0; i < 128; i++) 9 | { 10 | float f = (float)(i + 5) / 128.0f; 11 | f *= f; 12 | this->m2f[i] = powf(2.0f, f * 5.0f) - 1.0f; 13 | } 14 | this->Reset(); 15 | } 16 | 17 | Envelope::~Envelope() 18 | { 19 | } 20 | 21 | void Envelope::SetSampleRate(float fs) 22 | { 23 | this->FS = fs; 24 | this->Reset(); 25 | } 26 | 27 | void Envelope::Attack(int val) 28 | { 29 | this->A = this->m2f[val & 127]; 30 | } 31 | 32 | void Envelope::Hold(int val) 33 | { 34 | this->H = this->m2f[val & 127]; 35 | } 36 | 37 | void Envelope::Decay(int val) 38 | { 39 | this->D = this->m2f[val & 127]; 40 | } 41 | 42 | void Envelope::Sustain(int val) 43 | { 44 | this->S = (float)(val & 127) / 127.0f; 45 | } 46 | 47 | void Envelope::Release(int val) 48 | { 49 | this->R = this->m2f[val & 127]; 50 | } 51 | 52 | void Envelope::GateOn() 53 | { 54 | if(this->state != sOff) 55 | { 56 | this->state = sPreAttack; 57 | this->samples = truncate(m2f[0] * this->FS); 58 | this->step = this->Value / (float)this->samples; 59 | } 60 | else 61 | { 62 | this->Value = 0.0f; 63 | this->state = sAttack; 64 | this->samples = truncate(this->A * this->FS); 65 | this->step = 1.0f / (float)this->samples; 66 | } 67 | } 68 | 69 | void Envelope::GateOff() 70 | { 71 | if(this->state != sOff) 72 | { 73 | this->state = sRelease; 74 | this->samples = truncate(this->R * this->FS); 75 | this->step = this->Value / (float)this->samples; 76 | } 77 | } 78 | 79 | void Envelope::Reset() 80 | { 81 | this->Value = 0.0f; 82 | this->state = sOff; 83 | } 84 | -------------------------------------------------------------------------------- /cetonesynthlight/FilterBiquad.cpp: -------------------------------------------------------------------------------- 1 | #include "cetonesynth.h" 2 | #include "FilterBiquad.h" 3 | #include 4 | 5 | CFilterBiquad::CFilterBiquad() 6 | { 7 | this->min_fc = 0.0025f; 8 | 9 | this->Reset(); 10 | 11 | this->SetSampleRate(CCetoneSynth::SampleRate); 12 | this->Set(1.f, 0.f); 13 | } 14 | 15 | CFilterBiquad::~CFilterBiquad() 16 | { 17 | } 18 | 19 | void CFilterBiquad::Reset() 20 | { 21 | for(int i = 0; i < 6; i++) 22 | this->buffer[i] = 0.f; 23 | } 24 | 25 | void CFilterBiquad::Set(float cutoff, float q) 26 | { 27 | if(cutoff < this->min_fc) 28 | cutoff = this->min_fc; 29 | else if(cutoff > 0.999f) 30 | cutoff = 0.999f; 31 | 32 | if(q < 0.f) 33 | q = 0.f; 34 | else if(q > 1.f) 35 | q = 1.f; 36 | 37 | q = 1.f + q * 199.f; 38 | 39 | float omega = this->t1 * cutoff; 40 | float cs = cosf(omega); 41 | float alpha = sinf(omega) / q; 42 | 43 | float a0 = 1.0f + alpha; 44 | this->b0 = (1.0f - cs) / (2.f * a0); 45 | this->b1 = (1.0f - cs) / a0; 46 | this->b2 = this->b0; 47 | this->a1 = (-2.f * cs) / a0; 48 | this->a2 = (1.0f - alpha) / a0; 49 | } 50 | 51 | void CFilterBiquad::SetSampleRate(float fs) 52 | { 53 | float pi = 4.f * atanf(1.f); 54 | this->t0 = pi * fs; 55 | this->t1 = pi;// * 0.5f; 56 | } 57 | 58 | float CFilterBiquad::Run(float inputout) 59 | { 60 | float* buf = this->buffer; 61 | 62 | buf[2] = buf[1]; 63 | buf[1] = buf[0]; 64 | buf[5] = buf[4]; 65 | buf[4] = buf[3]; 66 | 67 | buf[0] = inputout; 68 | 69 | buf[3] = this->b0 * buf[0] 70 | + this->b1 * buf[1] 71 | + this->b2 * buf[2] 72 | - this->a1 * buf[4] 73 | - this->a2 * buf[5]; 74 | 75 | inputout = buf[3]; 76 | 77 | return inputout; 78 | } 79 | -------------------------------------------------------------------------------- /cetone033/FilterMoog.cpp: -------------------------------------------------------------------------------- 1 | #include "Cetone033.h" 2 | #include "FilterMoog.h" 3 | #include 4 | 5 | CFilterMoog::CFilterMoog(void) 6 | { 7 | this->Reset(); 8 | 9 | this->Set(1.f, 0.f); 10 | } 11 | 12 | CFilterMoog::~CFilterMoog(void) 13 | { 14 | } 15 | 16 | void CFilterMoog::Reset() 17 | { 18 | this->y1 = 0.f; 19 | this->y2 = 0.f; 20 | this->y3 = 0.f; 21 | this->y4 = 0.f; 22 | this->oldx = 0.f; 23 | this->oldy1 = 0.f; 24 | this->oldy3 = 0.f; 25 | this->oldy2 = 0.f; 26 | } 27 | 28 | void CFilterMoog::Set(float cutoff, float q) 29 | { 30 | if (cutoff < 0.f) 31 | cutoff = 0.f; 32 | else if (cutoff > 1.f) 33 | cutoff = 1.f; 34 | 35 | cutoff *= cutoff; 36 | 37 | if (q < 0.f) 38 | q = 0.f; 39 | else if (q > 1.f) 40 | q = 1.f; 41 | 42 | float f = cutoff; 43 | this->k = 3.6f * f - 1.6f * f * f - 1.f; 44 | this->p = (this->k + 1.f) * 0.5f; 45 | float scale = expf((1.f - this->p) * 1.386249f); 46 | this->r = q * scale; 47 | 48 | this->CutOff = cutoff; 49 | this->Q = q; 50 | 51 | } 52 | 53 | float CFilterMoog::Run(float val) 54 | { 55 | float x = val - this->r * this->y4; 56 | 57 | this->y1 = x * this->p + this->oldx * this->p - this->k * this->y1; 58 | this->y2 = this->y1 * this->p + this->oldy1 * this->p - this->k * this->y2; 59 | this->y3 = this->y2 * this->p + this->oldy2 * this->p - this->k * this->y3; 60 | this->y4 = this->y3 * this->p + this->oldy3 * this->p - this->k * this->y4; 61 | 62 | this->y4 = this->y4 - this->y4 * this->y4 * this->y4 * 0.1666667f; 63 | 64 | this->oldx = x; 65 | this->oldy1 = this->y1; 66 | this->oldy2 = this->y2; 67 | this->oldy3 = this->y3; 68 | 69 | return this->y4 * 1.25f; 70 | } -------------------------------------------------------------------------------- /cetonesynth/FilterCh12db.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "FilterCh12db.h" 3 | #include 4 | 5 | CFilterCh12db::CFilterCh12db(void) 6 | { 7 | this->Reset(); 8 | 9 | this->Set(CCetoneSynth::SampleRate2, 0.f); 10 | this->SetMode(FMODE_LOW); 11 | } 12 | 13 | CFilterCh12db::~CFilterCh12db(void) 14 | { 15 | } 16 | 17 | void CFilterCh12db::Reset() 18 | { 19 | this->Low = 0.f; 20 | this->High = 0.f; 21 | this->Band = 0.f; 22 | this->Notch = 0.f; 23 | } 24 | 25 | void CFilterCh12db::SetMode(int mode) 26 | { 27 | this->Mode = mode; 28 | } 29 | 30 | int CFilterCh12db::GetMode() 31 | { 32 | return this->Mode; 33 | } 34 | 35 | void CFilterCh12db::Set(float cutoff, float q) 36 | { 37 | if(cutoff < 0.f) 38 | cutoff = 0.f; 39 | else if(cutoff > CCetoneSynth::SampleRate2) 40 | cutoff = CCetoneSynth::SampleRate2; 41 | 42 | if(q < 0.f) 43 | q = 0.f; 44 | else if(q > 1.f) 45 | q = 1.f; 46 | 47 | #if ANALOGUE_BEHAVIOR > 0 48 | q *= CH12DB_Q_MAX; 49 | #endif 50 | 51 | this->f = sinf(CCetoneSynth::Pi * cutoff * CCetoneSynth::SampleRate_1); 52 | 53 | this->CutOff = cutoff; 54 | this->Q = 1.f - q; 55 | } 56 | 57 | float CFilterCh12db::Run(float val) 58 | { 59 | this->Low += this->f * this->Band; 60 | this->High = this->Q * val - this->Low - this->Q * this->Band; 61 | this->Band = this->f * this->High + this->Band; 62 | this->Notch = this->High + this->Low; 63 | 64 | switch (this->Mode) 65 | { 66 | default: 67 | return 0.f; 68 | case FMODE_BAND: 69 | return this->Band; 70 | case FMODE_LOW: 71 | return this->Low; 72 | case FMODE_HIGH: 73 | return this->High; 74 | case FMODE_NOTCH: 75 | return this->Notch; 76 | } 77 | } -------------------------------------------------------------------------------- /cetonesynth/FilterDirty.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "FilterDirty.h" 3 | 4 | CFilterDirty::CFilterDirty(void) 5 | { 6 | this->Reset(); 7 | 8 | this->Set(CCetoneSynth::SampleRate2, 0.f); 9 | this->SetMode(FMODE_LOW); 10 | } 11 | 12 | CFilterDirty::~CFilterDirty(void) 13 | { 14 | } 15 | 16 | void CFilterDirty::Reset() 17 | { 18 | this->buf0 = this->buf1 = 0.f; 19 | } 20 | 21 | void CFilterDirty::SetMode(int mode) 22 | { 23 | if(mode < 0) 24 | mode = 0; 25 | else if(mode > FMODE_NOTCH) 26 | mode = FMODE_NOTCH; 27 | 28 | this->Mode = mode; 29 | } 30 | 31 | int CFilterDirty::GetMode() 32 | { 33 | return this->Mode; 34 | } 35 | 36 | void CFilterDirty::Set(float cutoff, float q) 37 | { 38 | if(cutoff < 0.f) 39 | cutoff = 0.f; 40 | else if(cutoff > 20000.f) 41 | cutoff = 20000.f; 42 | 43 | if(q < 0.f) 44 | q = 0.f; 45 | else if(q > 1.f) 46 | q = 1.f; 47 | 48 | #if ANALOGUE_BEHAVIOR > 0 49 | q *= DIRTY_Q_MAX; 50 | #endif 51 | 52 | this->f = cutoff * CCetoneSynth::SampleRate2_1; 53 | if (this->f == 1.f) 54 | this->f = 0.99999f; 55 | 56 | this->fb = q + q / (1.f - this->f); 57 | 58 | this->CutOff = cutoff; 59 | this->Q = q; 60 | } 61 | 62 | float CFilterDirty::Run(float val) 63 | { 64 | float hp = val - this->buf0; 65 | float bp = this->buf0 - this->buf1; 66 | 67 | this->buf0 += this->f * (hp + this->fb * bp); 68 | this->buf1 += this->f * (this->buf0 - this->buf1); 69 | 70 | switch (this->Mode) 71 | { 72 | default: 73 | return 0.f; 74 | case FMODE_LOW: 75 | return this->buf1; 76 | case FMODE_HIGH: 77 | return hp; 78 | case FMODE_BAND: 79 | return bp; 80 | case FMODE_NOTCH: 81 | return this->buf1 + hp; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /cetonesynth2/arp.cpp: -------------------------------------------------------------------------------- 1 | #include "arp.h" 2 | #include 3 | 4 | ARP::ARP() 5 | { 6 | int i; 7 | for(i = 0; i < 128; i++) 8 | { 9 | float f = (float)(i + 10) / 128.0f; 10 | f *= f; 11 | this->m2f[127 - i] = powf(2.0f, f * 3.0f) - 1.0f; 12 | } 13 | 14 | for(i = 0; i < 8; i++) 15 | this->Notes[i] = 0; 16 | 17 | this->SetLoop(1); 18 | this->SetSync(1); 19 | this->SetTempo(0); 20 | this->SetSpeed(0); 21 | this->SetLength(0); 22 | this->Retrigger(); 23 | } 24 | 25 | ARP::~ARP() 26 | { 27 | } 28 | 29 | void ARP::Retrigger() 30 | { 31 | this->Samples = 0; 32 | this->Pos = -1; 33 | this->fPos = 0; 34 | } 35 | 36 | void ARP::SetTempo(float f) 37 | { 38 | if(this->Tempo == f) 39 | return; 40 | 41 | this->Tempo = f; 42 | if(this->Sync) 43 | this->SetSpeed(this->Speed); 44 | } 45 | 46 | void ARP::SetSpeed(int speed) 47 | { 48 | this->Speed = speed; 49 | if(this->Sync) 50 | { 51 | float t = this->Tempo * g_syncSpeed[speed]; 52 | this->Delay = truncate(t); 53 | this->fDelay = truncate((t - (float)this->Delay) * 65536.0f); 54 | } 55 | else 56 | { 57 | float t = this->FS * this->m2f[speed]; 58 | this->Delay = truncate(t); 59 | this->fDelay = truncate((t - (float)this->Delay) * 65536.0f); 60 | } 61 | } 62 | 63 | void ARP::SetSync(int sync) 64 | { 65 | this->Sync = (sync) ? true : false; 66 | this->SetSpeed(this->Speed); 67 | } 68 | 69 | void ARP::SetLoop(int loop) 70 | { 71 | this->Loop = (loop) ? true : false; 72 | } 73 | 74 | void ARP::SetLength(int len) 75 | { 76 | this->Length = len; 77 | } 78 | 79 | void ARP::SetNote(int idx, int note) 80 | { 81 | this->Notes[idx] = note * 100; 82 | } 83 | 84 | void ARP::SetSampleRate(float fs) 85 | { 86 | if(this->FS == fs) 87 | return; 88 | this->FS = fs; 89 | if(!this->Sync) 90 | this->SetSpeed(this->Speed); 91 | } 92 | -------------------------------------------------------------------------------- /cetonesynth/Filter8580.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include 3 | #include "Filter8580.h" 4 | 5 | CFilter8580::CFilter8580(void) 6 | { 7 | this->Reset(); 8 | this->CalcClock(); 9 | 10 | this->SetMode(FMODE_LOW); 11 | this->Set(CCetoneSynth::SampleRate2, 0.f); 12 | } 13 | 14 | CFilter8580::~CFilter8580(void) 15 | { 16 | } 17 | 18 | void CFilter8580::Reset() 19 | { 20 | this->Vlp = 0.0; 21 | this->Vbp = 0.0; 22 | this->Vhp = 0.0; 23 | } 24 | 25 | void CFilter8580::CalcClock() 26 | { 27 | this->Clock = (int)(200000.f / CCetoneSynth::SampleRate + 0.5f); 28 | } 29 | 30 | void CFilter8580::Set(float cutoff, float q) 31 | { 32 | if (cutoff < 0.f) 33 | cutoff = 0.f; 34 | else if (cutoff > 12000.f) 35 | cutoff = 12000.f; 36 | 37 | if (q < 0.f) 38 | q = 0.f; 39 | else if (q > 1.f) 40 | q = 1.f; 41 | 42 | this->w0 = 2.f * CCetoneSynth::Pi * cutoff * 0.000005f; 43 | this->q_par = 1.f / (0.707f + q); 44 | 45 | this->CutOff = cutoff; 46 | this->Q = q; 47 | } 48 | 49 | void CFilter8580::SetMode(int mode) 50 | { 51 | this->Mode = mode; 52 | } 53 | 54 | int CFilter8580::GetMode() 55 | { 56 | return this->Mode; 57 | } 58 | 59 | float CFilter8580::Run(float val) 60 | { 61 | float output = 0.f; 62 | 63 | float w0_ = this->w0; 64 | float Vbp_ = this->Vbp; 65 | float Vhp_ = this->Vhp; 66 | float Vlp_ = this->Vlp; 67 | float q_par_ = this->q_par; 68 | 69 | for(int i = 0; i < this->Clock; i++) 70 | { 71 | Vlp_ -= w0_ * Vbp_; 72 | Vbp_ -= w0_ * Vhp_; 73 | Vhp_ = (Vbp_ * q_par_) - Vlp_ - val; 74 | } 75 | 76 | this->Vlp = Vlp_; 77 | this->Vhp = Vhp_; 78 | this->Vbp = Vbp_; 79 | 80 | switch(this->Mode) 81 | { 82 | default: 83 | return 0.f; 84 | case FMODE_LOW: 85 | return Vlp_; 86 | case FMODE_BAND: 87 | return Vbp_; 88 | case FMODE_HIGH: 89 | return Vhp_; 90 | case FMODE_NOTCH: 91 | return Vhp_ + Vlp_; 92 | } 93 | } -------------------------------------------------------------------------------- /cetonesynthlight/Filter8580.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include 3 | #include "Filter8580.h" 4 | 5 | CFilter8580::CFilter8580(void) 6 | { 7 | this->Reset(); 8 | this->CalcClock(); 9 | 10 | this->SetMode(FMODE_LOW); 11 | this->Set(1.f, 0.f); 12 | } 13 | 14 | CFilter8580::~CFilter8580(void) 15 | { 16 | } 17 | 18 | void CFilter8580::Reset() 19 | { 20 | this->Vlp = 0.0; 21 | this->Vbp = 0.0; 22 | this->Vhp = 0.0; 23 | } 24 | 25 | void CFilter8580::CalcClock() 26 | { 27 | this->Clock = (int)(1000000.f / CCetoneSynth::SampleRate + 0.5f); 28 | } 29 | 30 | void CFilter8580::Set(float cutoff, float q) 31 | { 32 | if (cutoff < 0.f) 33 | cutoff = 0.f; 34 | else if (cutoff > 0.5f) 35 | cutoff = 0.5f; 36 | 37 | if (q < 0.f) 38 | q = 0.f; 39 | else if (q > 1.f) 40 | q = 1.f; 41 | 42 | this->w0 = 2.f * CCetoneSynth::Pi * cutoff * 0.000001f * CCetoneSynth::SampleRate2; 43 | this->q_par = 1.f / (0.707f + q); 44 | 45 | this->CutOff = cutoff; 46 | this->Q = q; 47 | } 48 | 49 | void CFilter8580::SetMode(int mode) 50 | { 51 | this->Mode = mode; 52 | } 53 | 54 | int CFilter8580::GetMode() 55 | { 56 | return this->Mode; 57 | } 58 | 59 | float CFilter8580::Run(float val) 60 | { 61 | float output = 0.f; 62 | 63 | float w0_ = this->w0; 64 | float Vbp_ = this->Vbp; 65 | float Vhp_ = this->Vhp; 66 | float Vlp_ = this->Vlp; 67 | float q_par_ = this->q_par; 68 | 69 | for(int i = 0; i < this->Clock; i++) 70 | { 71 | Vlp_ -= w0_ * Vbp_; 72 | Vbp_ -= w0_ * Vhp_; 73 | Vhp_ = (Vbp_ * q_par_) - Vlp_ - val; 74 | } 75 | 76 | this->Vlp = Vlp_; 77 | this->Vhp = Vhp_; 78 | this->Vbp = Vbp_; 79 | 80 | switch(this->Mode) 81 | { 82 | default: 83 | return 0.f; 84 | case FMODE_LOW: 85 | return Vlp_; 86 | case FMODE_BAND: 87 | return Vbp_; 88 | case FMODE_HIGH: 89 | return Vhp_; 90 | case FMODE_NOTCH: 91 | return Vhp_ + Vlp_; 92 | } 93 | } -------------------------------------------------------------------------------- /cetonesynthlight/FilterMoog.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "FilterMoog.h" 3 | #include 4 | 5 | CFilterMoog::CFilterMoog(void) 6 | { 7 | this->Reset(); 8 | 9 | this->Set(1.f, 0.f); 10 | } 11 | 12 | CFilterMoog::~CFilterMoog(void) 13 | { 14 | } 15 | 16 | void CFilterMoog::Reset() 17 | { 18 | this->y1 = 0.f; 19 | this->y2 = 0.f; 20 | this->y3 = 0.f; 21 | this->y4 = 0.f; 22 | this->oldx = 0.f; 23 | this->oldy1 = 0.f; 24 | this->oldy3 = 0.f; 25 | this->oldy2 = 0.f; 26 | } 27 | 28 | void CFilterMoog::Set(float cutoff, float q) 29 | { 30 | if (cutoff < 0.f) 31 | cutoff = 0.f; 32 | else if (cutoff > 1.f) 33 | cutoff = 1.f; 34 | 35 | if (q < 0.f) 36 | q = 0.f; 37 | else if (q > 1.f) 38 | q = 1.f; 39 | 40 | #if ANALOGUE_BEHAVIOR > 0 41 | q *= MOOG_Q_MAX; 42 | #endif 43 | 44 | float f = cutoff; 45 | this->k = 3.6f * f - 1.6f * f * f - 1.f; 46 | this->p = (this->k + 1.f) * 0.5f; 47 | float scale = expf((1.f - this->p) * 1.386249f); 48 | this->r = q * scale; 49 | 50 | this->CutOff = cutoff; 51 | this->Q = q; 52 | 53 | } 54 | 55 | void CFilterMoog::SetMode(int mode) 56 | { 57 | // Nothing here 58 | } 59 | 60 | int CFilterMoog::GetMode() 61 | { 62 | return FMODE_LOW; 63 | } 64 | 65 | float CFilterMoog::Run(float val) 66 | { 67 | float x = val - this->r * this->y4; 68 | 69 | this->y1 = x * this->p + this->oldx * this->p - this->k * this->y1; 70 | this->y2 = this->y1 * this->p + this->oldy1 * this->p - this->k * this->y2; 71 | this->y3 = this->y2 * this->p + this->oldy2 * this->p - this->k * this->y3; 72 | this->y4 = this->y3 * this->p + this->oldy3 * this->p - this->k * this->y4; 73 | 74 | this->y4 = this->y4 - this->y4 * this->y4 * this->y4 * 0.1666667f; 75 | 76 | this->oldx = x; 77 | this->oldy1 = this->y1; 78 | this->oldy2 = this->y2; 79 | this->oldy3 = this->y3; 80 | 81 | return this->y4; 82 | } -------------------------------------------------------------------------------- /cetonesynth2/statics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | 5 | #define RANDa 1664525 6 | #define RANDc 1013904223 7 | 8 | extern float g_sine[WAVETABLE_LENGTH]; 9 | extern float g_freqtab[PITCH_MAX + 1]; 10 | extern __int32 g_lookup[65536]; 11 | extern float g_saw[(NOTE_MAX + 25) * WAVETABLE_LENGTH * 2]; 12 | extern float g_parabola[(NOTE_MAX + 25) * WAVETABLE_LENGTH * 2]; 13 | extern __int32 g_step[PITCH_MAX]; 14 | 15 | extern __int32 g_semi[128]; 16 | extern __int32 g_fine[128]; 17 | extern float g_m2f0[128]; 18 | extern float g_m2f1[128]; 19 | extern float g_m2co[128]; 20 | extern float g_m2vol[128]; 21 | extern float g_m2fgain[128]; 22 | extern float g_m2fenv[128]; 23 | extern float g_m2mod[128]; 24 | 25 | extern int g_osc_pw[128 * 16]; 26 | extern float g_osc_pwo[128 * 16]; 27 | extern float g_osc_tris[128 * 16]; 28 | 29 | extern unsigned __int32 _RND; 30 | extern __int32 _RND1, _RND2; 31 | 32 | extern double g_fsin[32768]; 33 | extern double g_fcos[32768]; 34 | 35 | extern float g_lfo_saw[WAVETABLE_LENGTH * 2]; 36 | extern float g_lfo_tri[WAVETABLE_LENGTH * 2]; 37 | extern __int32 g_lfo_step[4096]; 38 | 39 | extern const float g_syncSpeed[132]; 40 | 41 | void initStatics(float fs); 42 | float spline(float t, float* ps); 43 | float ntanh(float x); 44 | int irand(); 45 | 46 | __forceinline float nrand() 47 | { 48 | 49 | _RND1 ^= _RND2; 50 | float ret = _RND2 * (2.0f / 0xffffffff); 51 | _RND2 += _RND1; 52 | return ret; 53 | 54 | /* 55 | _RND = (_RND * RANDa) + RANDc; 56 | return g_i2f2[_RND >> 16]; 57 | */ 58 | } 59 | 60 | /* 61 | __forceinline float ntanh(float x) 62 | { 63 | int ix; 64 | 65 | if(x < 0.0f) 66 | { 67 | x *= -200.0f; 68 | ix = truncate(x); 69 | return -(_tanh[ix] + (x - (float)ix) * (_tanh[ix + 1] - _tanh[ix])); 70 | } 71 | else 72 | { 73 | x *= 200.0f; 74 | ix = truncate(x); 75 | return (_tanh[ix] + (x - (float)ix) * (_tanh[ix + 1] - _tanh[ix])); 76 | } 77 | } 78 | */ -------------------------------------------------------------------------------- /cetone033/globalfunctions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "cetone033.h" 5 | 6 | void wave2str(int wave, char* text) 7 | { 8 | switch(wave) 9 | { 10 | case WAVE_SAW: vst_strncpy (text, "Saw", kVstMaxParamStrLen); break; 11 | case WAVE_PULSE: vst_strncpy (text, "Pulse", kVstMaxParamStrLen); break; 12 | case WAVE_TRI: vst_strncpy (text, "Tri", kVstMaxParamStrLen); break; 13 | default: text[0] = 0; break; 14 | } 15 | } 16 | 17 | void myfloat2string(float val, char* text) 18 | { 19 | char tmp[256]; 20 | sprintf(tmp, "%f", val); 21 | vst_strncpy(text, tmp, kVstMaxParamStrLen); 22 | } 23 | 24 | void bool2string(bool val, char* text) 25 | { 26 | vst_strncpy (text, (val) ? "On" : "Off", kVstMaxParamStrLen); 27 | } 28 | 29 | float c_val2cutoff(float value) 30 | { 31 | float tmp = floor(value * 1000.f) / 1000.f; 32 | 33 | return tmp * CCetone033::SampleRate2; 34 | } 35 | 36 | float c_cutoff2val(float value) 37 | { 38 | float tmp = value / CCetone033::SampleRate2; 39 | 40 | tmp = floor(tmp * 1000.f) / 1000.f; 41 | 42 | return tmp; 43 | } 44 | 45 | bool c_val2bool(float value) 46 | { 47 | return (value < 0.5f) ? false : true; 48 | } 49 | 50 | float c_bool2val(bool value) 51 | { 52 | return (value) ? 1.f : 0.f; 53 | } 54 | 55 | int c_val2coarse(float value) 56 | { 57 | return (int)(value * 100.f + 0.5f) - 50; 58 | } 59 | 60 | float c_coarse2val(int value) 61 | { 62 | return (float)(value + 50) / 100.f; 63 | } 64 | 65 | int c_val2fine(float value) 66 | { 67 | return (int)(value * 200.f + 0.5f) - 100; 68 | } 69 | 70 | float c_fine2val(int value) 71 | { 72 | return (float)(value + 100) / 200.f; 73 | } 74 | 75 | int pf2i(float val, int max) 76 | { 77 | int tmp = (int)floor(((float)(max + 1) * (float)val) + 0.5f); 78 | 79 | if(tmp < 0) 80 | tmp = 0; 81 | else if(tmp > max) 82 | tmp = max; 83 | 84 | return tmp; 85 | } 86 | 87 | float pi2f(int val, int max) 88 | { 89 | return (float)val / (float)(max + 1); 90 | } -------------------------------------------------------------------------------- /cetonesynth/FilterMoog.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "FilterMoog.h" 3 | #include 4 | 5 | CFilterMoog::CFilterMoog(void) 6 | { 7 | this->Reset(); 8 | 9 | this->Set(CCetoneSynth::SampleRate2, 0.f); 10 | } 11 | 12 | CFilterMoog::~CFilterMoog(void) 13 | { 14 | } 15 | 16 | void CFilterMoog::Reset() 17 | { 18 | this->y1 = 0.f; 19 | this->y2 = 0.f; 20 | this->y3 = 0.f; 21 | this->y4 = 0.f; 22 | this->oldx = 0.f; 23 | this->oldy1 = 0.f; 24 | this->oldy3 = 0.f; 25 | this->oldy2 = 0.f; 26 | } 27 | 28 | void CFilterMoog::Set(float cutoff, float q) 29 | { 30 | if (cutoff < 0.f) 31 | cutoff = 0.f; 32 | else if (cutoff > CCetoneSynth::SampleRate2) 33 | cutoff = CCetoneSynth::SampleRate2; 34 | 35 | if (q < 0.f) 36 | q = 0.f; 37 | else if (q > 1.f) 38 | q = 1.f; 39 | 40 | #if ANALOGUE_BEHAVIOR > 0 41 | q *= MOOG_Q_MAX; 42 | #endif 43 | 44 | float f = cutoff * CCetoneSynth::SampleRate2_1; 45 | this->k = 3.6f * f - 1.6f * f * f - 1.f; 46 | this->p = (this->k + 1.f) * 0.5f; 47 | float scale = expf((1.f - this->p) * 1.386249f); 48 | this->r = q * scale; 49 | 50 | this->CutOff = cutoff; 51 | this->Q = q; 52 | 53 | } 54 | 55 | void CFilterMoog::SetMode(int mode) 56 | { 57 | // Nothing here 58 | } 59 | 60 | int CFilterMoog::GetMode() 61 | { 62 | return FMODE_LOW; 63 | } 64 | 65 | float CFilterMoog::Run(float val) 66 | { 67 | float x = val - this->r * this->y4; 68 | 69 | this->y1 = x * this->p + this->oldx * this->p - this->k * this->y1; 70 | this->y2 = this->y1 * this->p + this->oldy1 * this->p - this->k * this->y2; 71 | this->y3 = this->y2 * this->p + this->oldy2 * this->p - this->k * this->y3; 72 | this->y4 = this->y3 * this->p + this->oldy3 * this->p - this->k * this->y4; 73 | 74 | this->y4 = this->y4 - this->y4 * this->y4 * this->y4 * 0.1666667f; 75 | 76 | this->oldx = x; 77 | this->oldy1 = this->y1; 78 | this->oldy2 = this->y2; 79 | this->oldy3 = this->y3; 80 | 81 | return this->y4; 82 | } -------------------------------------------------------------------------------- /cetoneorg/defines.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#define CODEBUG 4 | 5 | #ifdef CODEBUG 6 | #include "log.h" 7 | #endif 8 | 9 | #define nCLAMP(min, val, max) ((val > max) ? max : ((val < min) ? min : val)) 10 | 11 | #define PI 3.14159265f 12 | #define PId 3.14159265358979323846 13 | #define UNDENORM(v) if( (*((unsigned __int32*)&v) & 0x7f800000) == 0) v = 0 14 | #define DENORM_CONST 1e-15f 15 | 16 | #define SINE_SIZE 2048 17 | #define SINE_SIZEf 2048.0f 18 | 19 | #define EFFECT_NAME "CetoneOrg" 20 | #define CLASS_NAME "CetoneOrg" 21 | #define VENDOR_NAME "Neotec Software" 22 | #define PRODUCT_NAME "CetoneOrg" 23 | #define VERSION_NUMBER 5 24 | #define REAL_VERSION 0x006000 25 | 26 | typedef struct 27 | { 28 | unsigned __int16 frac; 29 | __int16 index; 30 | } sFIXED; 31 | 32 | typedef union 33 | { 34 | sFIXED fixed; 35 | __int32 int32; 36 | } sSTEP; 37 | 38 | #if _M_IX86_FP > 0 39 | #define truncate(x) ((int)(x)) 40 | #else 41 | __forceinline int truncate(float flt) 42 | { 43 | int i; 44 | _asm 45 | { 46 | fld flt 47 | fistp i 48 | } 49 | return i; 50 | } 51 | #endif 52 | 53 | enum kParams 54 | { 55 | pDb0, pDb1, pDb2, pDb3, pDb4, pDb5, pDb6, pDb7, pDb8, 56 | pTone, pClick, pVolume, 57 | pLfoSpeed, pVibDepth, pPanPhase, pPanDepth, 58 | pChDelayL, pChDelayR, pChDepth, pChSpeed, pChFeedback, pChMix, 59 | pRevDamp, pRevRoom, pRevWidth, pRevWet, pRevDry, 60 | pOutVol, 61 | 62 | pNumParameters 63 | }; 64 | 65 | #define UINT8 unsigned __int8 66 | 67 | typedef struct 68 | { 69 | int version; 70 | char name[26]; 71 | UINT8 bars[9]; 72 | UINT8 volume; 73 | UINT8 tone; 74 | UINT8 vibDepth; 75 | UINT8 lfoSpeed; 76 | UINT8 panPhase; 77 | UINT8 panDepth; 78 | UINT8 click; 79 | UINT8 c_delayl; 80 | UINT8 c_delayr; 81 | UINT8 c_depth; 82 | UINT8 c_speed; 83 | UINT8 c_mix; 84 | UINT8 r_damp; 85 | UINT8 r_room; 86 | UINT8 r_width; 87 | UINT8 r_dry; 88 | UINT8 r_wet; 89 | UINT8 outvol; 90 | UINT8 c_feedback; 91 | UINT8 pad[6]; 92 | } PROGRAM; 93 | -------------------------------------------------------------------------------- /cetonesynth2/Synth.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | #include "svoice.h" 5 | 6 | class MidiStack 7 | { 8 | public: 9 | MidiStack() 10 | { 11 | this->StackLow = 0; 12 | this->StackHigh = 0; 13 | }; 14 | ~MidiStack() { }; 15 | 16 | bool IsEmpty() 17 | { 18 | return (this->StackLow == this->StackHigh) ? true : false; 19 | }; 20 | 21 | void Push(int p0, int p1, int p2, int delta) 22 | { 23 | this->P0[this->StackHigh] = p0; 24 | this->P1[this->StackHigh] = p1; 25 | this->P2[this->StackHigh] = p2; 26 | this->Delta[this->StackHigh] = delta; 27 | 28 | this->StackHigh++; 29 | this->StackHigh &= 4095; 30 | }; 31 | 32 | void Pop(int* p0, int* p1, int* p2, int* delta) 33 | { 34 | *p0 = this->P0[this->StackLow]; 35 | *p1 = this->P1[this->StackLow]; 36 | *p2 = this->P2[this->StackLow]; 37 | *delta = this->Delta[this->StackLow]; 38 | 39 | this->StackLow++; 40 | this->StackLow &= 4095; 41 | }; 42 | private: 43 | int P0[4096]; 44 | int P1[4096]; 45 | int P2[4096]; 46 | int Delta[4096]; 47 | int StackLow; 48 | int StackHigh; 49 | }; 50 | 51 | class Synth 52 | { 53 | public: 54 | Synth(sPRG* ps); 55 | ~Synth(); 56 | void InitRender(); 57 | void Render(int frames, float **inputs); 58 | void SetBlockSize(int size); 59 | void SetSampleRate(float fs); 60 | void NoteOn(int note, int vel); 61 | void NoteOff(int note); 62 | void Reset(); 63 | 64 | void SetParameter(int id, int val); 65 | int GetParameter(int id); 66 | void NotifyVoices(int id, int val); 67 | 68 | void SetGuiFlag(bool flag) { this->guiOpen = flag; }; 69 | 70 | void ChangeVoices(int nr); 71 | int GetVoices(); 72 | int GetLFOPos(int lfo); 73 | 74 | void SetTempo(float bpm); 75 | 76 | void SetProgram(int prg); 77 | void Store(); 78 | void Recall(); 79 | bool HasPrgChanged(); 80 | void ReadProgram(); 81 | 82 | float* fRight; 83 | float* fLeft; 84 | sPRG sPrg; 85 | int _CPU; 86 | private: 87 | void VoiceOn(int v, int note, int vel); 88 | float spq, FS, oBpm; 89 | SVoice* Voices[16]; 90 | int iBlockSize, lastNote; 91 | int midiMap[128]; 92 | int iFramePos; 93 | int curProgram; 94 | sPRG* programs; 95 | LFO* rlfo[2]; 96 | bool guiOpen; 97 | }; 98 | -------------------------------------------------------------------------------- /cetonesynthlight/FilterMoog2.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "FilterMoog2.h" 3 | #include 4 | 5 | CFilterMoog2::CFilterMoog2(void) 6 | { 7 | this->Reset(); 8 | 9 | this->Set(1.f, 0.f); 10 | this->SetMode(FMODE_LOW); 11 | } 12 | 13 | CFilterMoog2::~CFilterMoog2(void) 14 | { 15 | } 16 | 17 | void CFilterMoog2::Reset() 18 | { 19 | this->b0 = 0.f; 20 | this->b1 = 0.f; 21 | this->b2 = 0.f; 22 | this->b3 = 0.f; 23 | this->b4 = 0.f; 24 | } 25 | 26 | void CFilterMoog2::Set(float cutoff, float q) 27 | { 28 | if(cutoff < 0.f) 29 | cutoff = 0.f; 30 | else if(cutoff > 1.f) 31 | cutoff = 1.f; 32 | 33 | if(q < 0.f) 34 | q = 0.f; 35 | else if(q > 1.f) 36 | q = 1.f; 37 | 38 | #if ANALOGUE_BEHAVIOR > 0 39 | q *= MOOG2_Q_MAX; 40 | #endif 41 | 42 | float frequency = cutoff; 43 | 44 | this->q2 = 1.f - frequency; 45 | this->p = frequency + 0.8f * frequency * this->q2; 46 | this->f = this->p + this->p - 1.f; 47 | this->q2 = q * (1.f + 0.5f * this->q2 * (1.f - this->q2 + 5.6f * this->q2 * this->q2)); 48 | 49 | this->CutOff = cutoff; 50 | this->Q = q; 51 | } 52 | 53 | void CFilterMoog2::SetMode(int mode) 54 | { 55 | this->Mode = mode; 56 | } 57 | 58 | int CFilterMoog2::GetMode() 59 | { 60 | return this->Mode; 61 | } 62 | 63 | float CFilterMoog2::Run(float val) 64 | { 65 | float t1, t2; 66 | 67 | val -= this->q2 * this->b4; //feedback 68 | t1 = this->b1; 69 | this->b1 = (val + this->b0) * this->p - this->b1 * this->f; 70 | t2 = this->b2; 71 | this->b2 = (this->b1 + t1) * this->p - this->b2 * this->f; 72 | t1 = this->b3; 73 | this->b3 = (this->b2 + t2) * this->p - this->b3 * this->f; 74 | this->b4 = (this->b3 + t1) * this->p - this->b4 * this->f; 75 | this->b4 = this->b4 - this->b4 * this->b4 * this->b4 * 0.1666667f; //clipping 76 | this->b0 = val; 77 | 78 | switch (this->Mode) 79 | { 80 | default: 81 | return 0.f; 82 | case FMODE_LOW: 83 | return this->b4; 84 | case FMODE_HIGH: 85 | return val - this->b4; 86 | case FMODE_BAND: 87 | return 3.f * (this->b3 - this->b4); 88 | case FMODE_NOTCH: 89 | return this->b4 + (val - this->b4); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /cetonesynth2/lfo.cpp: -------------------------------------------------------------------------------- 1 | #include "lfo.h" 2 | #include 3 | 4 | LFO::LFO() 5 | { 6 | int i; 7 | for(i = 0; i < 128; i++) 8 | { 9 | float f = (float)(i + 10) / 128.0f; 10 | f *= f; 11 | this->m2f[i] = powf(2.0f, f * 3.0f) - 1.0f; 12 | } 13 | 14 | this->mDelay = 0; 15 | this->Speed = 0; 16 | this->SetSampleRate(44100.0f); 17 | this->SetTempo(0); 18 | this->SetPW(64); 19 | this->SetSpeed(0); 20 | this->SetRetrigger(0); 21 | this->SetSNH(0); 22 | this->SetDelay(0); 23 | this->SetWave(OSCW_SAW); 24 | this->SetSync(0); 25 | this->Reset(); 26 | } 27 | 28 | LFO::~LFO() 29 | { 30 | } 31 | 32 | void LFO::SetPW(int pw) 33 | { 34 | if(pw < 1) 35 | pw = 1; 36 | else if(pw > 126) 37 | pw = 126; 38 | this->PW = pw * (WAVETABLE_LENGTH / 128); 39 | } 40 | 41 | void LFO::SetWave(int wave) 42 | { 43 | this->Wave = wave; 44 | } 45 | 46 | void LFO::Reset() 47 | { 48 | this->Index.int32 = 0; 49 | this->lastNoise = 0.0f; 50 | this->SampleOutput = 0.0f; 51 | } 52 | 53 | void LFO::SetSampleRate(float fs) 54 | { 55 | this->FS = fs; 56 | this->SetDelay(this->mDelay); 57 | this->SetSpeed(this->Speed); 58 | } 59 | 60 | void LFO::Retrigger() 61 | { 62 | this->Gate = true; 63 | if(this->mDelay) 64 | this->Delay = this->DelayLen; 65 | else 66 | this->Delay = 0; 67 | if(this->isRetrigger) 68 | this->Index.int32 = 0; 69 | } 70 | 71 | void LFO::SetTempo(float f) 72 | { 73 | if(this->Tempo == f) 74 | return; 75 | 76 | this->Tempo = f; 77 | if(this->Sync) 78 | this->SetSpeed(this->Speed); 79 | } 80 | 81 | void LFO::SetSync(int sync) 82 | { 83 | this->Sync = (sync) ? true : false; 84 | this->SetSpeed(this->Speed); 85 | } 86 | 87 | void LFO::SetSNH(int snh) 88 | { 89 | this->SNH = (snh) ? true : false; 90 | if(this->SNH) 91 | { 92 | this->SampleOutput = 0; 93 | this->Gate = false; 94 | } 95 | } 96 | 97 | void LFO::SetRetrigger(int retrig) 98 | { 99 | this->isRetrigger = (retrig) ? true : false; 100 | } 101 | 102 | void LFO::SetDelay(int delay) 103 | { 104 | this->mDelay = delay; 105 | this->DelayLen = truncate(this->FS * this->m2f[delay]); 106 | if(!delay) 107 | this->Delay = 0; 108 | } 109 | 110 | -------------------------------------------------------------------------------- /cetonesynth/FilterMoog2.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "FilterMoog2.h" 3 | #include 4 | 5 | CFilterMoog2::CFilterMoog2(void) 6 | { 7 | this->Reset(); 8 | 9 | this->Set(CCetoneSynth::SampleRate2, 0.f); 10 | this->SetMode(FMODE_LOW); 11 | } 12 | 13 | CFilterMoog2::~CFilterMoog2(void) 14 | { 15 | } 16 | 17 | void CFilterMoog2::Reset() 18 | { 19 | this->b0 = 0.f; 20 | this->b1 = 0.f; 21 | this->b2 = 0.f; 22 | this->b3 = 0.f; 23 | this->b4 = 0.f; 24 | } 25 | 26 | void CFilterMoog2::Set(float cutoff, float q) 27 | { 28 | if(cutoff < 0.f) 29 | cutoff = 0.f; 30 | else if(cutoff > CCetoneSynth::SampleRate2) 31 | cutoff = CCetoneSynth::SampleRate2; 32 | 33 | if(q < 0.f) 34 | q = 0.f; 35 | else if(q > 1.f) 36 | q = 1.f; 37 | 38 | #if ANALOGUE_BEHAVIOR > 0 39 | q *= MOOG2_Q_MAX; 40 | #endif 41 | 42 | float frequency = cutoff * CCetoneSynth::SampleRate2_1; 43 | 44 | this->q2 = 1.f - frequency; 45 | this->p = frequency + 0.8f * frequency * this->q2; 46 | this->f = this->p + this->p - 1.f; 47 | this->q2 = q * (1.f + 0.5f * this->q2 * (1.f - this->q2 + 5.6f * this->q2 * this->q2)); 48 | 49 | this->CutOff = cutoff; 50 | this->Q = q; 51 | } 52 | 53 | void CFilterMoog2::SetMode(int mode) 54 | { 55 | this->Mode = mode; 56 | } 57 | 58 | int CFilterMoog2::GetMode() 59 | { 60 | return this->Mode; 61 | } 62 | 63 | float CFilterMoog2::Run(float val) 64 | { 65 | float t1, t2; 66 | 67 | val -= this->q2 * this->b4; //feedback 68 | t1 = this->b1; 69 | this->b1 = (val + this->b0) * this->p - this->b1 * this->f; 70 | t2 = this->b2; 71 | this->b2 = (this->b1 + t1) * this->p - this->b2 * this->f; 72 | t1 = this->b3; 73 | this->b3 = (this->b2 + t2) * this->p - this->b3 * this->f; 74 | this->b4 = (this->b3 + t1) * this->p - this->b4 * this->f; 75 | this->b4 = this->b4 - this->b4 * this->b4 * this->b4 * 0.1666667f; //clipping 76 | this->b0 = val; 77 | 78 | switch (this->Mode) 79 | { 80 | default: 81 | return 0.f; 82 | case FMODE_LOW: 83 | return this->b4; 84 | case FMODE_HIGH: 85 | return val - this->b4; 86 | case FMODE_BAND: 87 | return 3.f * (this->b3 - this->b4); 88 | case FMODE_NOTCH: 89 | return this->b4 + (val - this->b4); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /cetone033/CetoneLpFilter.cpp: -------------------------------------------------------------------------------- 1 | #include "cetone033.h" 2 | #include "CetoneLpFilter.h" 3 | 4 | CCetoneLpFilter::CCetoneLpFilter(void) 5 | { 6 | this->FilterBiquad = new CFilterBiquad(); 7 | this->FilterMoog = new CFilterMoog(); 8 | 9 | this->Type = 0; 10 | this->Set(1.f, 0.f); 11 | } 12 | 13 | CCetoneLpFilter::~CCetoneLpFilter(void) 14 | { 15 | if(this->FilterMoog != NULL) 16 | delete this->FilterMoog; 17 | if(this->FilterBiquad != NULL) 18 | delete this->FilterBiquad; 19 | 20 | this->FilterMoog = NULL; 21 | this->FilterBiquad = NULL; 22 | this->Type = -1; 23 | } 24 | 25 | int CCetoneLpFilter::GetType() 26 | { 27 | return this->Type; 28 | } 29 | 30 | void CCetoneLpFilter::Reset() 31 | { 32 | if (this->Type == -1) 33 | return; 34 | 35 | this->FilterBiquad->Reset(); 36 | this->FilterMoog->Reset(); 37 | } 38 | 39 | void CCetoneLpFilter::SetSampleRate(float fs) 40 | { 41 | if (this->Type == -1) 42 | return; 43 | 44 | this->FilterBiquad->SetSampleRate(fs); 45 | } 46 | 47 | void CCetoneLpFilter::SetType(int type) 48 | { 49 | if(type < 0) 50 | type = 0; 51 | else if(type > FILTER_TYPE_MAX) 52 | type = FILTER_TYPE_MAX; 53 | 54 | this->Type = type; 55 | 56 | this->Set(this->Cutoff, this->Resonance); 57 | } 58 | 59 | void CCetoneLpFilter::Set(float cutoff, float q) 60 | { 61 | this->Cutoff = cutoff; 62 | this->Resonance = q; 63 | 64 | switch(this->Type) 65 | { 66 | case FILTER_TYPE_BIQUAD: 67 | this->FilterBiquad->Set(cutoff, q); 68 | break; 69 | case FILTER_TYPE_MOOG: 70 | this->FilterMoog->Set(cutoff, q); 71 | break; 72 | } 73 | } 74 | 75 | float CCetoneLpFilter::Run(float inputout) 76 | { 77 | 78 | switch(this->Type) 79 | { 80 | case FILTER_TYPE_BIQUAD: 81 | inputout = this->FilterBiquad->Run(inputout); 82 | break; 83 | case FILTER_TYPE_MOOG: 84 | inputout = this->FilterMoog->Run(inputout); 85 | break; 86 | } 87 | 88 | return inputout; 89 | } 90 | 91 | void CCetoneLpFilter::Name(int type, char* text) 92 | { 93 | switch(type) 94 | { 95 | case FILTER_TYPE_BIQUAD: vst_strncpy (text, "Biquad", kVstMaxParamStrLen); break; 96 | case FILTER_TYPE_MOOG: vst_strncpy (text, "Moogle", kVstMaxParamStrLen); break; 97 | default: text[0] = 0; break; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /cetonesynth2/CetoneSynth2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "aeffeditor.h" 5 | #include "audioeffectx.h" 6 | #include "Synth.h" 7 | 8 | class CS2 : public AudioEffectX 9 | { 10 | public: 11 | CS2(audioMasterCallback audioMaster); 12 | ~CS2(); 13 | void process(float **inputs, float **outputs, VstInt32 sampleFrames); 14 | void processReplacing(float** inputs, float** outputs, VstInt32 sampleFrames); 15 | VstInt32 getVendorVersion (); 16 | bool getEffectName(char* name); 17 | bool getVendorString(char* text); 18 | bool getProductString(char* text); 19 | void setSampleRate(float sampleRate); 20 | void setBlockSize(VstInt32 blockSize); 21 | void setBlockSizeAndSampleRate(VstInt32 blockSize, float sampleRate) { this->setSampleRate(sampleRate); this->setBlockSize(blockSize); } 22 | VstInt32 getNumMidiInputChannels() { return 1; }; 23 | VstInt32 getNumMidiOutputChannels() { return 1; }; 24 | VstInt32 canDo(char* text); 25 | VstInt32 processEvents(VstEvents *events); 26 | void HandleMidi(int p0, int p1, int p2); 27 | 28 | void setParameter(VstInt32 index, float value); 29 | float getParameter(VstInt32 index); 30 | void getParameterLabel(VstInt32 index, char* label); 31 | void getParameterDisplay(VstInt32 index, char* text); 32 | void getParameterName(VstInt32 index, char* text); 33 | void getProgramName(char* name); 34 | bool getProgramNameIndexed(VstInt32 category, VstInt32 index, char* name); 35 | void setProgramName(char* name); 36 | void setProgram(VstInt32 program); 37 | VstInt32 getChunk(void **data, bool isPreset = false); 38 | VstInt32 setChunk(void *data, VstInt32 byteSize, bool isPreset = false); 39 | void CreateEmptyPrg(sPRG* p, int nr = -1); 40 | void resume(); 41 | void suspend(); 42 | void LoadPresets(char* name); 43 | char* GetFileName(char* name); 44 | void GuiUpdater(int ctrl); 45 | void CCDispatcher(int ctrl, int val); 46 | private: 47 | void CheckPrg(); 48 | void CheckPrg(int i); 49 | void SetVersion(); 50 | void SetVersion(int i); 51 | char path[512]; 52 | char tempname[512]; 53 | LARGE_INTEGER perfFreq; 54 | void myProcess(float **inputs, float **outputs, VstInt32 sampleFrames, bool replace); 55 | int np0, np1, np2, cdelta; 56 | Synth* _Synth; 57 | MidiStack* mStack; 58 | sPRG programs[128]; 59 | sPRG emptyPrg; 60 | }; 61 | -------------------------------------------------------------------------------- /cetonesynth2/envelope.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | 5 | enum envState 6 | { 7 | sOff, sAttack, sHold, sDecay, sSustain, sRelease, sPreAttack 8 | }; 9 | 10 | class Envelope 11 | { 12 | public: 13 | Envelope(); 14 | ~Envelope(); 15 | void SetSampleRate(float fs); 16 | void Attack(int val); 17 | void Hold(int val); 18 | void Decay(int val); 19 | void Sustain(int val); 20 | void Release(int val); 21 | void GateOn(); 22 | void GateOff(); 23 | __forceinline float Process() 24 | { 25 | float val = this->Value; 26 | switch(this->state) 27 | { 28 | case sOff: 29 | val = 0.0f; 30 | break; 31 | case sAttack: 32 | val += this->step; 33 | if(--this->samples <= 0) 34 | { 35 | val = 1.0f; 36 | this->state = sHold; 37 | this->samples = truncate(this->H * this->FS); 38 | } 39 | else 40 | { 41 | if(val > 1.0f) 42 | val = 1.0f; 43 | } 44 | break; 45 | case sHold: 46 | if(--this->samples <= 0) 47 | { 48 | this->state = sDecay; 49 | this->samples = truncate(this->D * this->FS); 50 | this->step = (1.0f - this->S) / (float)this->samples; 51 | } 52 | break; 53 | case sDecay: 54 | val -= this->step; 55 | if(--this->samples <= 0) 56 | { 57 | val = this->S; 58 | this->state = sSustain; 59 | } 60 | else 61 | { 62 | if(val < this->S) 63 | val = this->S; 64 | } 65 | break; 66 | case sSustain: 67 | break; 68 | case sRelease: 69 | val -= this->step; 70 | if(--this->samples <= 0) 71 | { 72 | val = 0.0f; 73 | this->state = sOff; 74 | } 75 | else 76 | { 77 | if(val < 0.0f) 78 | val = 0.0f; 79 | } 80 | break; 81 | case sPreAttack: 82 | val -= this->step; 83 | if(--this->samples <= 0) 84 | { 85 | this->state = sAttack; 86 | this->samples = truncate(this->A * this->FS); 87 | this->step = 1.0f / (float)this->samples; 88 | val = 0.0f; 89 | } 90 | else 91 | { 92 | if(val < 0.0f) 93 | val = 0.0f; 94 | } 95 | break; 96 | } 97 | 98 | this->Value = val; 99 | return val; 100 | } 101 | 102 | void Reset(); 103 | int state; 104 | private: 105 | float Value; 106 | float FS; 107 | float A, H, D, S, R; 108 | float step; 109 | int samples; 110 | float m2f[128]; 111 | }; 112 | -------------------------------------------------------------------------------- /cetonesynth/Filter303.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "cetonesynth.h" 4 | 5 | #include "Filter303.h" 6 | 7 | CFilter303::CFilter303(void) 8 | { 9 | this->Reset(); 10 | 11 | this->Q = 1.0; 12 | 13 | this->Set(CCetoneSynth::SampleRate2, 0.f, 0.f); 14 | } 15 | 16 | CFilter303::~CFilter303(void) 17 | { 18 | 19 | } 20 | 21 | void CFilter303::Reset() 22 | { 23 | this->a = 0.f; 24 | this->b = 0.f; 25 | this->c = 0.f; 26 | this->d1 = 0.f; 27 | this->d2 = 0.f; 28 | } 29 | 30 | void CFilter303::Set(float cutoff, float q, float mod) 31 | { 32 | if (cutoff < 0.f) 33 | cutoff = 0.f; 34 | else if (cutoff > CCetoneSynth::SampleRate2) 35 | cutoff = CCetoneSynth::SampleRate2; 36 | 37 | if (q < 0.f) 38 | q = 0.f; 39 | else if (q > 1.f) 40 | q = 1.f; 41 | 42 | if (mod < -1.f) 43 | mod = -1.f; 44 | else if(mod > 1.f) 45 | mod = 1.f; 46 | 47 | this->CutOff = cutoff; 48 | if(q != this->Q) 49 | { 50 | this->Q = q; 51 | this->res_coef = expf(-1.2f + 3.455f * q); 52 | } 53 | 54 | float w = expf(6.109f + 1.5876f * mod + 2.1553f * (cutoff * CCetoneSynth::SampleRate2_1) - 1.2f * (1.f - q)) * CCetoneSynth::SampleRatePi; 55 | float k = expf(-w / this->res_coef); 56 | 57 | this->a = 2.f * cosf(2.f * w) * k; 58 | this->b = -k * k; 59 | this->c = 1.f - this->a - this->b; 60 | 61 | /* 62 | vcf_e1 = exp(6.109 + 1.5876*vcf_envmod + 2.1553*vcf_cutoff - 1.2*(1.0-vcf_reso)); 63 | vcf_e0 = exp(5.613 - 0.8*vcf_envmod + 2.1553*vcf_cutoff - 0.7696*(1.0-vcf_reso)); 64 | vcf_e0*=M_PI/44100.0; 65 | vcf_e1*=M_PI/44100.0; 66 | vcf_e1 -= vcf_e0; 67 | vcf_envpos = ENVINC; 68 | 69 | w = vcf_e0 + vcf_c0; 70 | k = exp(-w/vcf_rescoeff); 71 | //vcf_c0 *= vcf_envdecay; 72 | vcf_a = 2.0*cos(2.0*w) * k; 73 | vcf_b = -k*k; 74 | vcf_c = 1.0 - vcf_a - vcf_b; 75 | vcf_envpos = 0; 76 | */ 77 | } 78 | 79 | void CFilter303::SetMode(int mode) 80 | { 81 | // Nothing here 82 | } 83 | 84 | int CFilter303::GetMode() 85 | { 86 | return FMODE_LOW; 87 | } 88 | 89 | float CFilter303::Run(float val) 90 | { 91 | float output; 92 | 93 | output = this->a * this->d1 + this->b * this->d2 + this->c * val; 94 | this->d2 = this->d1; 95 | this->d1 = output; 96 | 97 | /* 98 | // compute sample 99 | outbuf[i]=vcf_a*vcf_d1 + vcf_b*vcf_d2 + vcf_c*vco_k*vca_a; 100 | vcf_d2=vcf_d1; 101 | vcf_envpos++; 102 | vcf_d1=outbuf[i]; 103 | */ 104 | 105 | return output; 106 | } 107 | -------------------------------------------------------------------------------- /cetonesynth2/lfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | #include "statics.h" 5 | 6 | class LFO 7 | { 8 | public: 9 | LFO(); 10 | ~LFO(); 11 | void SetWave(int wave); 12 | void SetPW(int pw); 13 | void SetTempo(float tempo); 14 | void SetSync(int sync); 15 | void SetRetrigger(int retrig); 16 | void SetSNH(int snh); 17 | void SetDelay(int delay); 18 | void Reset(); 19 | void Retrigger(); 20 | void SetSampleRate(float fs); 21 | int GetPos() { return this->Index.fixed.index; }; 22 | __forceinline float Process() 23 | { 24 | if(!this->Wave) 25 | return 0.0f; 26 | 27 | if(this->Delay) 28 | { 29 | this->Delay--; 30 | return 0.0f; 31 | } 32 | 33 | float output = 0.0f; 34 | 35 | switch(this->Wave) 36 | { 37 | case OSCW_SAW: 38 | output = g_lfo_saw[this->Index.fixed.index]; 39 | break; 40 | case OSCW_PULSE: 41 | if(this->Index.fixed.index < this->PW) 42 | output = -1.0f; 43 | else 44 | output = 1.0f; 45 | break; 46 | case OSCW_TRI: 47 | output = g_lfo_tri[this->Index.fixed.index]; 48 | break; 49 | case OSCW_NOISE: 50 | output = this->lastNoise; 51 | break; 52 | } 53 | 54 | int old = this->Index.int32; 55 | this->Index.int32 = (this->Index.int32 + this->Step.int32) & (WAVETABLE_MASK * 0x10000 + 0xffff); 56 | if(old > this->Index.int32) 57 | this->lastNoise = nrand(); 58 | 59 | if(this->SNH) 60 | { 61 | if(this->Gate) 62 | { 63 | this->Gate = false; 64 | this->SampleOutput = output; 65 | } 66 | 67 | return this->SampleOutput; 68 | } 69 | else 70 | return output; 71 | } 72 | 73 | __forceinline void SetSpeed(int speed) 74 | { 75 | if(speed < 0) 76 | speed = 0; 77 | else if(speed > 4095) 78 | speed = 4095; 79 | this->Speed = speed; 80 | if(this->Sync) 81 | { 82 | if(this->Tempo) 83 | this->Step.int32 = truncate((WAVETABLE_LENGTHf * 65536.0f) / (this->Tempo * g_syncSpeed[(speed >> 5) + 1]) + 0.5f); 84 | else 85 | this->Step.int32 = 0; 86 | } 87 | else 88 | this->Step.int32 = g_lfo_step[speed]; 89 | } 90 | 91 | private: 92 | float m2f[4096]; 93 | float FS; 94 | float Tempo; 95 | float SampleOutput; 96 | float lastNoise; 97 | int Wave; 98 | int PW; 99 | int Speed; 100 | int mDelay; 101 | int DelayLen; 102 | int Delay; 103 | oSTEP Index; 104 | oSTEP Step; 105 | bool Sync; 106 | bool isRetrigger; 107 | bool SNH; 108 | bool Gate; 109 | }; 110 | -------------------------------------------------------------------------------- /cetoneorg/statics.cpp: -------------------------------------------------------------------------------- 1 | #include "defines.h" 2 | #include "statics.h" 3 | #include 4 | 5 | #define RANDa 1664525 6 | #define RANDc 1013904223 7 | 8 | int g_all_sizes[4] = {556, 441, 341, 225}; 9 | int g_comb_sizes[8] = {1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617}; 10 | float g_sine[SINE_SIZE * 3 * 128]; 11 | GENERATOR g_generators[61]; 12 | 13 | unsigned __int32 _RND; 14 | 15 | static float g_sampleRate = 0.0f; 16 | 17 | int irand() 18 | { 19 | _RND = (_RND * RANDa) + RANDc; 20 | return _RND >> 16; 21 | } 22 | 23 | void initStatics(float fs) 24 | { 25 | int i, n, m; 26 | float sine[SINE_SIZE]; 27 | float para[SINE_SIZE]; 28 | float tri[SINE_SIZE]; 29 | int offs[9] = { -12, -5, 0, 12, 19, 24, 28, 31, 36 }; 30 | 31 | if(g_sampleRate == fs) 32 | return; 33 | 34 | g_sampleRate = fs; 35 | 36 | for(i = 0; i < 61; i++) 37 | { 38 | for(n = 0; n < 9; n++) 39 | { 40 | int v = i + 12 + offs[n]; 41 | while(v > 88) 42 | v -= 12; 43 | g_generators[i].offset[n] = v; 44 | } 45 | } 46 | 47 | for(i = 0; i < SINE_SIZE; i++) 48 | { 49 | sine[i] = sinf(2.0f * PI * (float)i / SINE_SIZEf); 50 | para[i] = (PI * PI / 3.0f); 51 | } 52 | 53 | int harms = truncate((fs * 0.49f) / 5273.6f); 54 | float tharm = (PI * 0.5f) / (float)harms; 55 | 56 | float sign = -1.f; 57 | for (n = 0; n < harms; n++) 58 | { 59 | float t; 60 | int harmonic = n + 1; 61 | t = cosf((float)n * tharm); 62 | t *= t; 63 | t /= (float)(harmonic * harmonic); 64 | t *= 4.f * sign; 65 | 66 | for (m = 0; m < SINE_SIZE; m++) 67 | para[m] += t * sine[(m * harmonic + (SINE_SIZE / 4)) & (SINE_SIZE - 1)]; 68 | sign = -sign; 69 | } 70 | float max = 0.0f; 71 | 72 | for (i = 0; i < SINE_SIZE; i++) 73 | { 74 | if (fabs(para[i]) > max) 75 | max = fabs(para[i]); 76 | } 77 | 78 | max /= 2.f; 79 | 80 | for (i = 0; i < SINE_SIZE; i++) 81 | { 82 | para[i] /= max; 83 | para[i] -= 1.f; 84 | } 85 | 86 | max = 1.0f / 2.25f; 87 | for(i = 0; i < SINE_SIZE; i++) 88 | tri[i] = (para[i] - para[(i + (SINE_SIZE / 2)) & (SINE_SIZE - 1)]) * max; 89 | 90 | for(i = 0; i < 128; i++) 91 | { 92 | float mix1 = (float)i / 127.0f; 93 | float mix0 = 1.0f - mix1; 94 | float *ptr = g_sine + i * SINE_SIZE * 3; 95 | 96 | for(n = 0; n < SINE_SIZE; n++) 97 | { 98 | ptr[n + SINE_SIZE] = 99 | ptr[n + 2 * SINE_SIZE] = 100 | ptr[n] = sine[n] * mix0 + tri[n] * mix1; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /cetonesynthlight/Structures.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct SynthVoice 4 | { 5 | float Volume; 6 | int Coarse; 7 | int Fine; 8 | int Wave; 9 | int Pw; 10 | bool Ring; 11 | bool Sync; 12 | }; 13 | 14 | struct SynthModulation 15 | { 16 | int Source; 17 | int Destination; 18 | float Amount; 19 | float Multiplicator; 20 | }; 21 | 22 | struct SynthProgram 23 | { 24 | char Name[64]; 25 | 26 | // Global 27 | 28 | float Volume; 29 | float Panning; 30 | 31 | int Coarse; 32 | int Fine; 33 | 34 | // Filter 35 | 36 | float Cutoff; 37 | float Resonance; 38 | int FilterType; 39 | int FilterMode; 40 | 41 | // C64er Arpeggio 42 | 43 | int ArpMode; 44 | int ArpSpeed; 45 | 46 | // Portamento 47 | 48 | bool PortaMode; 49 | float PortaSpeed; 50 | 51 | // Envelopes 52 | 53 | float Attack[2]; 54 | float Hold[2]; 55 | float Decay[2]; 56 | float Sustain[2]; 57 | float Release[2]; 58 | 59 | // LFO's 60 | 61 | float LfoSpeed; 62 | int LfoWave; 63 | int LfoPw; 64 | bool LfoTrigger; 65 | 66 | // Voices 67 | 68 | SynthVoice Voice[4]; 69 | 70 | // Modulations 71 | 72 | SynthModulation Modulations[4]; 73 | 74 | float EnvMod; 75 | }; 76 | 77 | enum PARAMETERS 78 | { 79 | pVolume = 0, 80 | pPanning, 81 | pCoarse, 82 | pFine, 83 | 84 | pFilterType, // 4 85 | pFilterMode, 86 | pCutoff, 87 | pResonance, 88 | 89 | pPortaMode, // 8 90 | pPortaSpeed, 91 | 92 | pArpMode, // 10 93 | pArpSpeed, 94 | 95 | pOsc1Coarse, // 12 96 | pOsc1Fine, 97 | pOsc1Wave, 98 | pOsc1Pw, 99 | pOsc1Volume, 100 | pOsc1Ring, 101 | pOsc1Sync, 102 | 103 | pOsc2Coarse, // 19 104 | pOsc2Fine, 105 | pOsc2Wave, 106 | pOsc2Pw, 107 | pOsc2Volume, 108 | pOsc2Ring, 109 | pOsc2Sync, 110 | 111 | pOsc3Coarse, // 26 112 | pOsc3Fine, 113 | pOsc3Wave, 114 | pOsc3Pw, 115 | pOsc3Volume, 116 | pOsc3Ring, 117 | pOsc3Sync, 118 | 119 | pEnv1A, // 34 120 | pEnv1H, 121 | pEnv1D, 122 | pEnv1S, 123 | pEnv1R, 124 | 125 | pEnv2A, // 38 126 | pEnv2H, 127 | pEnv2D, 128 | pEnv2S, 129 | pEnv2R, 130 | 131 | pLfo1Speed, // 43 132 | pLfo1Wave, 133 | pLfo1Pw, 134 | pLfo1Trig, 135 | 136 | pMod1Src, // 47 137 | pMod1Dest, 138 | pMod1Amount, 139 | pMod1Mul, 140 | 141 | pMod2Src, 142 | pMod2Dest, 143 | pMod2Amount, 144 | pMod2Mul, 145 | 146 | pMod3Src, 147 | pMod3Dest, 148 | pMod3Amount, 149 | pMod3Mul, 150 | 151 | pMod4Src, 152 | pMod4Dest, 153 | pMod4Amount, 154 | pMod4Mul, 155 | 156 | pFilterMod, 157 | 158 | pParameters 159 | }; -------------------------------------------------------------------------------- /cetonesynthlight/Defines.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define FILTER_DELAY 128 4 | 5 | #define ACCURATE_SHIFTREG 0 6 | 7 | #define ANALOGUE_BEHAVIOR 1 8 | 9 | #define NOTE_RANGE 1 10 | 11 | #define MOD_CHANGE_SPEED 0.05f 12 | 13 | #if NOTE_RANGE == 1 14 | #define NOTE_MAX 144 15 | #define NOTE_MAX1 143 16 | #define PITCH_MAX 14400 17 | #define PITCH_MAX1 14399 18 | #define BASE_FREQUENCE 6.875f 19 | #define NOTE_OFFSET 3 20 | #elif NOTE_RANGE == 2 21 | #define NOTE_MAX 156 22 | #define NOTE_MAX1 15 23 | #define PITCH_MAX 15600 24 | #define PITCH_MAX1 15599 25 | #define BASE_FREQUENCE 3.4375f 26 | #define NOTE_OFFSET 15 27 | #endif 28 | 29 | #if ANALOGUE_BEHAVIOR > 0 30 | #define ANALOGUE_ENVELOPES 1 31 | 32 | #define MOOG_Q_MAX 0.95f 33 | #define MOOG2_Q_MAX 0.95f 34 | #define CH12DB_Q_MAX 0.95f 35 | #define DIRTY_Q_MAX 0.985f 36 | #else 37 | #define ANALOGUE_ENVELOPES 0 38 | #endif 39 | 40 | #define WAVETABLE_LENGTH 2048 41 | #define WAVETABLE_LENGTHf 2048.f 42 | #define WAVETABLE_LENGTH2 1024 43 | #define WAVETABLE_LENGTH4 512 44 | #define WAVETABLE_MASK 2047 45 | 46 | #define EFFECT_NAME "CetoneLight" 47 | #define VENDOR_NAME "Neotec Software" 48 | #define PRODUCT_NAME "CetoneLight" 49 | #define VERSION_NUMBER 1000; 50 | 51 | #define WAVE_SAW 0 52 | #define WAVE_PULSE 1 53 | #define WAVE_TRI 2 54 | #define WAVE_SINE 3 55 | #define WAVE_C64NOISE 4 56 | 57 | #define WAVE_MAX 4 58 | 59 | #define OWAVE_SAW 0 60 | #define OWAVE_PULSE 1 61 | #define OWAVE_TRI 2 62 | #define OWAVE_SINE 3 63 | #define OWAVE_C64NOISE 4 64 | 65 | #define OWAVE_MAX 4 66 | 67 | #define FMODE_LOW 0 68 | #define FMODE_BAND 1 69 | #define FMODE_HIGH 2 70 | #define FMODE_NOTCH 3 71 | 72 | #define FMODE_MAX 3 73 | 74 | #define FTYPE_NONE 0 75 | #define FTYPE_DIRTY 1 76 | #define FTYPE_MOOG 2 77 | #define FTYPE_MOOG2 3 78 | #define FTYPE_CH12DB 4 79 | #define FTYPE_303 5 80 | #define FTYPE_8580 6 81 | #define FTYPE_BUDDA 7 82 | 83 | #define FTYPE_MAX 7 84 | 85 | #define MOD_SRC_NONE 0 86 | #define MOD_SRC_VEL 1 87 | #define MOD_SRC_CTRL1 2 88 | #define MOD_SRC_MENV1 3 89 | #define MOD_SRC_LFO1 4 90 | #define MOD_SRC_MENV1xLFO1 5 91 | 92 | #define MOD_SRC_MAX 5 93 | 94 | #define MOD_DEST_MAINVOL 0 95 | #define MOD_DEST_PANNING 1 96 | #define MOD_DEST_CUTOFF 2 97 | #define MOD_DEST_RESONANCE 3 98 | #define MOD_DEST_MAINPITCH 4 99 | #define MOD_DEST_OSC1VOL 5 100 | #define MOD_DEST_OSC2VOL 6 101 | #define MOD_DEST_OSC3VOL 7 102 | #define MOD_DEST_OSC1PITCH 8 103 | #define MOD_DEST_OSC2PITCH 9 104 | #define MOD_DEST_OSC3PITCH 10 105 | #define MOD_DEST_OSC1PW 11 106 | #define MOD_DEST_OSC2PW 12 107 | #define MOD_DEST_OSC3PW 13 108 | #define MOD_DEST_LFO1SPEED 14 109 | #define MOD_DEST_ENVMOD 15 110 | 111 | #define MOD_DEST_MAX 15 112 | 113 | #define ARP_MAX 7 114 | -------------------------------------------------------------------------------- /cetonesynth/Defines.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define FILTER_DELAY 128 4 | 5 | #define ACCURATE_SHIFTREG 0 6 | 7 | #define ANALOGUE_BEHAVIOR 1 8 | 9 | #define NOTE_RANGE 1 10 | 11 | #define MOD_CHANGE_SPEED 0.05f 12 | 13 | #if NOTE_RANGE == 1 14 | #define NOTE_MAX 144 15 | #define NOTE_MAX1 143 16 | #define PITCH_MAX 14400 17 | #define PITCH_MAX1 14399 18 | #define BASE_FREQUENCE 6.875f 19 | #define NOTE_OFFSET 3 20 | #elif NOTE_RANGE == 2 21 | #define NOTE_MAX 156 22 | #define NOTE_MAX1 15 23 | #define PITCH_MAX 15600 24 | #define PITCH_MAX1 15599 25 | #define BASE_FREQUENCE 3.4375f 26 | #define NOTE_OFFSET 15 27 | #endif 28 | 29 | #if ANALOGUE_BEHAVIOR > 0 30 | #define ANALOGUE_ENVELOPES 1 31 | 32 | #define MOOG_Q_MAX 0.95f 33 | #define MOOG2_Q_MAX 0.95f 34 | #define CH12DB_Q_MAX 0.95f 35 | #define DIRTY_Q_MAX 0.985f 36 | #else 37 | #define ANALOGUE_ENVELOPES 0 38 | #endif 39 | 40 | #define WAVETABLE_LENGTH 4096 41 | #define WAVETABLE_LENGTHf 4096.f 42 | #define WAVETABLE_LENGTH2 2048 43 | #define WAVETABLE_LENGTH4 1024 44 | #define WAVETABLE_MASK 4095 45 | 46 | #define EFFECT_NAME "CetoneSynth" 47 | #define VENDOR_NAME "Neotec Software" 48 | #define PRODUCT_NAME "CetoneSynth" 49 | #define VERSION_NUMBER 1000; 50 | 51 | #define WAVE_SAW 0 52 | #define WAVE_PULSE 1 53 | #define WAVE_TRI 2 54 | #define WAVE_SINE 3 55 | #define WAVE_C64NOISE 4 56 | 57 | #define WAVE_MAX 4 58 | 59 | #define OWAVE_SAW 0 60 | #define OWAVE_PULSE 1 61 | #define OWAVE_TRI 2 62 | #define OWAVE_SINE 3 63 | #define OWAVE_C64NOISE 4 64 | 65 | #define OWAVE_MAX 4 66 | 67 | #define FMODE_LOW 0 68 | #define FMODE_BAND 1 69 | #define FMODE_HIGH 2 70 | #define FMODE_NOTCH 3 71 | 72 | #define FMODE_MAX 3 73 | 74 | #define FTYPE_NONE 0 75 | #define FTYPE_DIRTY 1 76 | #define FTYPE_MOOG 2 77 | #define FTYPE_MOOG2 3 78 | #define FTYPE_CH12DB 4 79 | #define FTYPE_303 5 80 | #define FTYPE_8580 6 81 | #define FTYPE_BUDDA 7 82 | 83 | #define FTYPE_MAX 7 84 | 85 | #define MOD_SRC_NONE 0 86 | #define MOD_SRC_VEL 1 87 | #define MOD_SRC_CTRL1 2 88 | #define MOD_SRC_MENV1 3 89 | #define MOD_SRC_MENV2 4 90 | #define MOD_SRC_LFO1 5 91 | #define MOD_SRC_LFO2 6 92 | #define MOD_SRC_HFO 7 93 | #define MOD_SRC_MENV1xLFO1 8 94 | #define MOD_SRC_LFO1xLFO2 9 95 | 96 | #define MOD_SRC_MAX 9 97 | 98 | #define MOD_DEST_MAINVOL 0 99 | #define MOD_DEST_PANNING 1 100 | #define MOD_DEST_CUTOFF 2 101 | #define MOD_DEST_RESONANCE 3 102 | #define MOD_DEST_MAINPITCH 4 103 | #define MOD_DEST_OSC1VOL 5 104 | #define MOD_DEST_OSC2VOL 6 105 | #define MOD_DEST_OSC3VOL 7 106 | #define MOD_DEST_OSC1PITCH 8 107 | #define MOD_DEST_OSC2PITCH 9 108 | #define MOD_DEST_OSC3PITCH 10 109 | #define MOD_DEST_OSC1PW 11 110 | #define MOD_DEST_OSC2PW 12 111 | #define MOD_DEST_OSC3PW 13 112 | #define MOD_DEST_LFO1SPEED 14 113 | #define MOD_DEST_LFO2SPEED 15 114 | #define MOD_DEST_ENVMOD 16 115 | 116 | #define MOD_DEST_MAX 16 117 | 118 | #define ARP_MAX 7 119 | -------------------------------------------------------------------------------- /cetonesynth2/svoice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "osc.h" 5 | #include "lfo.h" 6 | #include "filter.h" 7 | #include "envelope.h" 8 | #include "arp.h" 9 | 10 | #define iSPEED 0.004f 11 | 12 | #define iOSC1VOL 0 13 | #define iOSC2VOL 1 14 | #define iOSC3VOL 2 15 | #define iMAINVOL 3 16 | #define iFGAIN 4 17 | #define iPAN 5 18 | #define iCUTOFF 6 19 | #define iQ 7 20 | #define iAUDIOVOL 8 21 | #define iAUDIOPAN 9 22 | #define iPW1 10 23 | #define iPW2 11 24 | #define iPW3 12 25 | 26 | typedef struct 27 | { 28 | float current, step, dest; 29 | __int32 running; 30 | } vINTERPOLATE; 31 | 32 | class SVoice 33 | { 34 | public: 35 | SVoice(sPRG* p); 36 | ~SVoice(); 37 | void Reset(); 38 | 39 | void Render(float* left, float* right, float* inl, float* inr, int frames); 40 | 41 | void NoteOn(int note, int vel, int last); 42 | void NoteOff(); 43 | 44 | void UpdateValue(int id, int val); 45 | 46 | void SetTempo(float tempo); 47 | void SetSampleRate(float fs); 48 | 49 | bool IsDone(); 50 | bool IsRelease(); 51 | unsigned __int32 GetTime(); 52 | 53 | private: 54 | 55 | __forceinline void iReset(int idx) 56 | { 57 | this->inter[idx].current = 58 | this->inter[idx].step = 59 | this->inter[idx].dest = 0.0f; 60 | this->inter[idx].running = 0; 61 | } 62 | 63 | __forceinline void iSet(int idx, float val) 64 | { 65 | if(val != this->inter[idx].dest) 66 | { 67 | float delta = val - this->inter[idx].current; 68 | if(delta != 0) 69 | { 70 | this->inter[idx].dest = val; 71 | this->inter[idx].step = delta / this->iSamples; 72 | this->inter[idx].running = -1; 73 | } 74 | } 75 | } 76 | 77 | __forceinline float iGet(int idx) 78 | { 79 | return this->inter[idx].current; 80 | } 81 | 82 | __forceinline void iDo(int idx) 83 | { 84 | if(this->inter[idx].running) 85 | { 86 | this->inter[idx].current += this->inter[idx].step; 87 | if(this->inter[idx].step < 0.0f) 88 | { 89 | if(this->inter[idx].current < this->inter[idx].dest) 90 | { 91 | this->inter[idx].current = this->inter[idx].dest; 92 | this->inter[idx].running = 0; 93 | } 94 | } 95 | else 96 | { 97 | if(this->inter[idx].current > this->inter[idx].dest) 98 | { 99 | this->inter[idx].current = this->inter[idx].dest; 100 | this->inter[idx].running = 0; 101 | } 102 | } 103 | } 104 | } 105 | 106 | vINTERPOLATE inter[13]; 107 | sPRG* prg; 108 | OSC* osc[3]; 109 | Filter* filter; 110 | Envelope* env[3]; 111 | LFO* lfo[2]; 112 | ARP* arp; 113 | int glides[128]; 114 | unsigned __int32 time; 115 | float velocity; 116 | float coVel; 117 | float modwheel; 118 | float aftertouch; 119 | int mvolVel; 120 | int npitch; 121 | int currentNote; 122 | oSTEP gStep; 123 | oSTEP gIndex; 124 | __int16 gDest, gPad; 125 | int pitch0, pitch1, pitch2; 126 | bool oscAM1, oscAM2, oscAM3; 127 | bool oscKT1, oscKT2, oscKT3; 128 | bool filtExp, doGlide; 129 | float iSamples; 130 | float FS; 131 | }; 132 | -------------------------------------------------------------------------------- /cetonesynth/Structures.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct SynthVoice 4 | { 5 | float Volume; 6 | int Coarse; 7 | int Fine; 8 | int Wave; 9 | int Pw; 10 | bool Ring; 11 | bool Sync; 12 | }; 13 | 14 | struct SynthModulation 15 | { 16 | int Source; 17 | int Destination; 18 | float Amount; 19 | float Multiplicator; 20 | }; 21 | 22 | struct SynthProgram 23 | { 24 | char Name[64]; 25 | 26 | // Global 27 | 28 | float Volume; 29 | float Panning; 30 | 31 | int Coarse; 32 | int Fine; 33 | 34 | // Filter 35 | 36 | float Cutoff; 37 | float Resonance; 38 | int FilterType; 39 | int FilterMode; 40 | 41 | // C64er Arpeggio 42 | 43 | int ArpMode; 44 | int ArpSpeed; 45 | 46 | // Portamento 47 | 48 | bool PortaMode; 49 | float PortaSpeed; 50 | 51 | // Envelopes 52 | 53 | float Attack[3]; 54 | float Hold[3]; 55 | float Decay[3]; 56 | float Sustain[3]; 57 | float Release[3]; 58 | 59 | // LFO's 60 | 61 | float LfoSpeed[2]; 62 | int LfoWave[2]; 63 | int LfoPw[2]; 64 | bool LfoTrigger[2]; 65 | 66 | // Voices 67 | 68 | SynthVoice Voice[4]; 69 | 70 | // Modulations 71 | 72 | SynthModulation Modulations[8]; 73 | 74 | float EnvMod; 75 | }; 76 | 77 | enum PARAMETERS 78 | { 79 | pMidiChan = 0, 80 | pVolume, 81 | pPanning, 82 | pCoarse, 83 | pFine, 84 | 85 | pFilterType, // 5 86 | pFilterMode, 87 | pCutoff, 88 | pResonance, 89 | 90 | pPortaMode, // 9 91 | pPortaSpeed, 92 | 93 | pArpMode, // 11 94 | pArpSpeed, 95 | 96 | pOsc1Coarse, // 13 97 | pOsc1Fine, 98 | pOsc1Wave, 99 | pOsc1Pw, 100 | pOsc1Volume, 101 | pOsc1Ring, 102 | pOsc1Sync, 103 | 104 | pOsc2Coarse, // 20 105 | pOsc2Fine, 106 | pOsc2Wave, 107 | pOsc2Pw, 108 | pOsc2Volume, 109 | pOsc2Ring, 110 | pOsc2Sync, 111 | 112 | pOsc3Coarse, // 27 113 | pOsc3Fine, 114 | pOsc3Wave, 115 | pOsc3Pw, 116 | pOsc3Volume, 117 | pOsc3Ring, 118 | pOsc3Sync, 119 | 120 | pEnv1A, // 34 121 | pEnv1H, 122 | pEnv1D, 123 | pEnv1S, 124 | pEnv1R, 125 | 126 | pEnv2A, // 39 127 | pEnv2H, 128 | pEnv2D, 129 | pEnv2S, 130 | pEnv2R, 131 | 132 | pEnv3A, // 44 133 | pEnv3H, 134 | pEnv3D, 135 | pEnv3S, 136 | pEnv3R, 137 | 138 | pLfo1Speed, // 49 139 | pLfo1Wave, 140 | pLfo1Pw, 141 | pLfo1Trig, 142 | 143 | pLfo2Speed, // 53 144 | pLfo2Wave, 145 | pLfo2Pw, 146 | pLfo2Trig, 147 | 148 | pHfoCoarse, // 57 149 | pHfoFine, 150 | pHfoWave, 151 | pHfoPw, 152 | 153 | pMod1Src, // 61 154 | pMod1Dest, 155 | pMod1Amount, 156 | pMod1Mul, 157 | 158 | pMod2Src, 159 | pMod2Dest, 160 | pMod2Amount, 161 | pMod2Mul, 162 | 163 | pMod3Src, 164 | pMod3Dest, 165 | pMod3Amount, 166 | pMod3Mul, 167 | 168 | pMod4Src, 169 | pMod4Dest, 170 | pMod4Amount, 171 | pMod4Mul, 172 | 173 | pMod5Src, 174 | pMod5Dest, 175 | pMod5Amount, 176 | pMod5Mul, 177 | 178 | pMod6Src, 179 | pMod6Dest, 180 | pMod6Amount, 181 | pMod6Mul, 182 | 183 | pMod7Src, 184 | pMod7Dest, 185 | pMod7Amount, 186 | pMod7Mul, 187 | 188 | pMod8Src, 189 | pMod8Dest, 190 | pMod8Amount, 191 | pMod8Mul, 192 | 193 | pFilterMod, 194 | 195 | pParameters 196 | }; -------------------------------------------------------------------------------- /cetoneorg/CetoneOrg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | #include "audioeffectx.h" 5 | #include "Synth.h" 6 | 7 | class MidiStack 8 | { 9 | public: 10 | MidiStack() 11 | { 12 | this->StackLow = 0; 13 | this->StackHigh = 0; 14 | }; 15 | ~MidiStack() { }; 16 | 17 | bool IsEmpty() 18 | { 19 | return (this->StackLow == this->StackHigh) ? true : false; 20 | }; 21 | 22 | void Push(int p0, int p1, int p2, int delta) 23 | { 24 | this->P0[this->StackHigh] = p0; 25 | this->P1[this->StackHigh] = p1; 26 | this->P2[this->StackHigh] = p2; 27 | this->Delta[this->StackHigh] = delta; 28 | 29 | this->StackHigh++; 30 | this->StackHigh &= 4095; 31 | }; 32 | 33 | void Pop(int* p0, int* p1, int* p2, int* delta) 34 | { 35 | *p0 = this->P0[this->StackLow]; 36 | *p1 = this->P1[this->StackLow]; 37 | *p2 = this->P2[this->StackLow]; 38 | *delta = this->Delta[this->StackLow]; 39 | 40 | this->StackLow++; 41 | this->StackLow &= 4095; 42 | }; 43 | private: 44 | int P0[4096]; 45 | int P1[4096]; 46 | int P2[4096]; 47 | int Delta[4096]; 48 | int StackLow; 49 | int StackHigh; 50 | }; 51 | 52 | class CO : public AudioEffectX 53 | { 54 | public: 55 | CO(audioMasterCallback audioMaster); 56 | ~CO(); 57 | void process(float **inputs, float **outputs, VstInt32 sampleFrames); 58 | void processReplacing(float** inputs, float** outputs, VstInt32 sampleFrames); 59 | VstInt32 getVendorVersion (); 60 | bool getEffectName(char* name); 61 | bool getVendorString(char* text); 62 | bool getProductString(char* text); 63 | void setSampleRate(float sampleRate); 64 | void setBlockSize(VstInt32 blockSize); 65 | void setBlockSizeAndSampleRate(VstInt32 blockSize, float sampleRate) { this->setSampleRate(sampleRate); this->setBlockSize(blockSize); } 66 | VstInt32 getNumMidiInputChannels() { return 1; }; 67 | VstInt32 getNumMidiOutputChannels() { return 0; }; 68 | VstInt32 canDo(char* text); 69 | VstInt32 processEvents(VstEvents *events); 70 | 71 | void setParameter(VstInt32 index, float value); 72 | float getParameter(VstInt32 index); 73 | void getParameterLabel(VstInt32 index, char* label); 74 | void getParameterDisplay(VstInt32 index, char* text); 75 | void getParameterName(VstInt32 index, char* text); 76 | 77 | void getProgramName(char* name); 78 | bool getProgramNameIndexed(VstInt32 category, VstInt32 index, char* name); 79 | void setProgramName(char* name); 80 | void setProgram(VstInt32 program); 81 | VstInt32 getChunk(void **data, bool isPreset = false); 82 | VstInt32 setChunk(void *data, VstInt32 byteSize, bool isPreset = false); 83 | void suspend() { AudioEffectX::suspend(); }; 84 | void resume() { AudioEffectX::resume(); }; 85 | 86 | private: 87 | void CreateEmptyPrg(PROGRAM* p, int nr = -1); 88 | void LoadPresets(char* name); 89 | char* GetFileName(char* name); 90 | void SetVersion(); 91 | void SetVersion(int i); 92 | void ReadProgram(); 93 | void HandleMidi(int p0, int p1, int p2); 94 | void myProcess(float **inputs, float **outputs, VstInt32 sampleFrames, bool replace); 95 | int np0, np1, np2, cdelta; 96 | Synth* _Synth; 97 | MidiStack* mStack; 98 | PROGRAM _prg[128]; 99 | char path[512]; 100 | char tempname[512]; 101 | 102 | }; 103 | -------------------------------------------------------------------------------- /cetoneorg/tonewheel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | #include "statics.h" 5 | 6 | class ToneWheel 7 | { 8 | public: 9 | ToneWheel(int mul, int f0, int f1) 10 | { 11 | int i; 12 | this->Frequency = (float)mul * (20.0f / (float)f1) * (float)f0; 13 | for(i = 0; i < 61; i++) 14 | this->Volumes[i] = 0.0f; 15 | this->Volume = this->destVolume = 0.0f; 16 | this->Index.int32 = 0; 17 | this->Envelope = 0; 18 | this->Attack = 0.0001f; 19 | }; 20 | 21 | ~ToneWheel() 22 | { 23 | }; 24 | 25 | void setWave(float* wave) 26 | { 27 | this->Sine = wave; 28 | } 29 | 30 | void setSampleRate(float fs) 31 | { 32 | this->FS = fs; 33 | this->Step.int32 = truncate( ((this->Frequency * SINE_SIZEf) / fs) * 65536.0f + 0.5f); 34 | this->volStep = 1.0f / (fs * this->Attack); 35 | this->volDownStep = 1.0f / (fs * 0.025f); 36 | }; 37 | 38 | void setAttack(float val) 39 | { 40 | this->Attack = val; 41 | this->volStep = 1.0f / (this->FS * this->Attack); 42 | } 43 | 44 | void NoteOn(int note, float vol, int delay) 45 | { 46 | int i; 47 | float v = 0.0; 48 | 49 | if(vol == 0.0f) 50 | return; 51 | 52 | if(this->Volume == 0.0f) 53 | { 54 | this->Index.fixed.index = irand() & (SINE_SIZE - 1); 55 | this->Delay = delay; 56 | } 57 | else 58 | this->Delay = 0; 59 | 60 | this->Volumes[note] = vol; 61 | 62 | for(i = 0; i < 61; i++) 63 | { 64 | if(this->Volumes[i] > v) 65 | v = this->Volumes[i]; 66 | } 67 | 68 | this->destVolume = v; 69 | this->Envelope = -1; 70 | } 71 | 72 | void NoteOff(int note) 73 | { 74 | int i; 75 | float v = 0.0; 76 | 77 | this->Volumes[note] = 0.0f; 78 | 79 | for(i = 0; i < 61; i++) 80 | { 81 | if(this->Volumes[i] > v) 82 | v = this->Volumes[i]; 83 | } 84 | 85 | this->destVolume = v; 86 | this->Envelope = -1; 87 | } 88 | 89 | __forceinline void Render(float* out, int samples, int* vibrato) 90 | { 91 | if(this->Volume || this->destVolume) 92 | { 93 | int i; 94 | for(i = 0; i < samples; i++) 95 | { 96 | if(this->Delay) 97 | { 98 | this->Delay--; 99 | continue; 100 | } 101 | 102 | out[i] += spline((float)this->Index.fixed.frac / 65536.0f, this->Sine + this->Index.fixed.index - 1) * this->Volume; 103 | 104 | this->Index.int32 = (this->Index.int32 + this->Step.int32 + vibrato[i]) & (((SINE_SIZE - 1) * 0x10000) | 0xffff); 105 | 106 | if(this->Envelope) 107 | { 108 | if(this->Volume < this->destVolume) 109 | { 110 | this->Volume += this->volStep; 111 | if(this->Volume > this->destVolume) 112 | { 113 | this->Volume = this->destVolume; 114 | this->Envelope = 0; 115 | } 116 | } 117 | else 118 | { 119 | this->Volume -= this->volDownStep; 120 | if(this->Volume < this->destVolume) 121 | { 122 | this->Volume = this->destVolume; 123 | this->Envelope = 0; 124 | } 125 | } 126 | } 127 | } 128 | } 129 | } 130 | private: 131 | float* Sine; 132 | float Frequency; 133 | float FS; 134 | float Volume; 135 | float destVolume; 136 | float volStep; 137 | float volDownStep; 138 | float Volumes[61]; 139 | float Attack; 140 | int Delay; 141 | int Envelope; 142 | sSTEP Step; 143 | sSTEP Index; 144 | }; 145 | -------------------------------------------------------------------------------- /cetone033/SynthOscillator.cpp: -------------------------------------------------------------------------------- 1 | #include "Cetone033.h" 2 | #include "SynthOscillator.h" 3 | 4 | CSynthOscillator::CSynthOscillator(void) 5 | { 6 | this->SetPitch(7200); 7 | 8 | this->SetPw(0.5f); 9 | this->SetWave(WAVE_SAW); 10 | 11 | this->IndexInt = 0; 12 | this->IndexFrac = 0; 13 | } 14 | 15 | CSynthOscillator::~CSynthOscillator(void) 16 | { 17 | } 18 | 19 | void CSynthOscillator::Set(float pw, int wave) 20 | { 21 | if(pw < 0.01f) 22 | pw = 0.01f; 23 | else if(pw > 0.99f) 24 | pw = 0.99f; 25 | 26 | this->PwOffset = truncate(pw * WAVETABLE_LENGTHf); 27 | float f = (float)this->PwOffset / WAVETABLE_LENGTHf; 28 | this->PwWaveOffset = 1.f - (2.f * f); 29 | this->TriWaveScale = 1.f / (8.f * (f - f * f)); 30 | 31 | if(wave < 0) 32 | wave = 0; 33 | else if(wave > WAVE_MAX) 34 | wave = WAVE_MAX; 35 | 36 | this->Waveform = wave; 37 | } 38 | 39 | void CSynthOscillator::SetPitch(int pitch) 40 | { 41 | if(pitch < 0) 42 | pitch = 0; 43 | else if(pitch > PITCH_MAX1) 44 | pitch = PITCH_MAX1; 45 | 46 | this->StepInt = CCetone033::FreqStepInt[pitch]; 47 | this->StepFrac = CCetone033::FreqStepFrac[pitch]; 48 | 49 | int t = CCetone033::LookupTable[CCetone033::FreqTableInt[pitch]] * WAVETABLE_LENGTH; 50 | 51 | this->SawPtr = &(CCetone033::SawTable[t]); 52 | this->ParabolaPtr = &(CCetone033::ParabolaTable[t]); 53 | } 54 | 55 | void CSynthOscillator::SetPw(float pw) 56 | { 57 | if(pw < 0.01f) 58 | pw = 0.01f; 59 | else if(pw > 0.99f) 60 | pw = 0.99f; 61 | 62 | this->PwOffset = truncate(pw * WAVETABLE_LENGTHf); 63 | float f = (float)this->PwOffset / WAVETABLE_LENGTHf; 64 | this->PwWaveOffset = 1.f - (2.f * f); 65 | this->TriWaveScale = 1.f / (8.f * (f - f * f)); 66 | } 67 | 68 | void CSynthOscillator::SetWave(int wave) 69 | { 70 | if(wave < 0) 71 | wave = 0; 72 | else if(wave > WAVE_MAX) 73 | wave = WAVE_MAX; 74 | 75 | this->Waveform = wave; 76 | } 77 | 78 | float CSynthOscillator::Run() 79 | { 80 | int sample0, sample1; 81 | float interpolate, out0, out1; 82 | 83 | float output = 0.f; 84 | 85 | sample0 = this->IndexInt; 86 | sample1 = (sample0 + 1) & WAVETABLE_MASK; 87 | interpolate = CCetone033::Int2FloatTab[this->IndexFrac]; 88 | 89 | switch (this->Waveform) 90 | { 91 | case WAVE_SAW: 92 | out0 = this->SawPtr[sample0]; 93 | out1 = this->SawPtr[sample1]; 94 | output = (1.f - interpolate) * out0 + interpolate * out1; 95 | break; 96 | case WAVE_PULSE: 97 | out0 = this->SawPtr[sample0]; 98 | out1 = this->SawPtr[sample1]; 99 | 100 | sample0 += this->PwOffset; 101 | sample1 += this->PwOffset; 102 | sample0 &= WAVETABLE_MASK; 103 | sample1 &= WAVETABLE_MASK; 104 | 105 | out0 -= this->SawPtr[sample0]; 106 | out1 -= this->SawPtr[sample1]; 107 | 108 | output = (1.f - interpolate) * out0 + interpolate * out1; 109 | output += this->PwWaveOffset; 110 | break; 111 | case WAVE_TRI: 112 | out0 = this->ParabolaPtr[sample0]; 113 | out1 = this->ParabolaPtr[sample1]; 114 | 115 | sample0 += this->PwOffset; 116 | sample1 += this->PwOffset; 117 | sample0 &= WAVETABLE_MASK; 118 | sample1 &= WAVETABLE_MASK; 119 | 120 | out0 -= this->ParabolaPtr[sample0]; 121 | out1 -= this->ParabolaPtr[sample1]; 122 | 123 | output = (1.f - interpolate) * out0 + interpolate * out1; 124 | output *= this->TriWaveScale; 125 | break; 126 | } 127 | 128 | this->IndexFrac += this->StepFrac; 129 | 130 | if (this->IndexFrac > 65535) 131 | { 132 | this->IndexFrac &= 65535; 133 | this->IndexInt++; 134 | } 135 | 136 | this->IndexInt += this->StepInt; 137 | this->IndexInt &= WAVETABLE_MASK; 138 | 139 | return output; 140 | } -------------------------------------------------------------------------------- /cetonesynth/SynthLfo.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "SynthLfo.h" 3 | #include 4 | 5 | CSynthLfo::CSynthLfo(void) 6 | { 7 | this->SetSpeed(0.05f); 8 | this->SetPw(32768); 9 | this->SetTrigger(false); 10 | this->SetWave(WAVE_SAW); 11 | 12 | this->Reset(); 13 | } 14 | 15 | CSynthLfo::~CSynthLfo(void) 16 | { 17 | } 18 | 19 | void CSynthLfo::Reset() 20 | { 21 | this->OscNow = 0; 22 | this->Value = 0.f; 23 | this->ShiftRegister = 0x7ffff8; 24 | } 25 | 26 | void CSynthLfo::Set(float speed, int pw, int wave, bool trig) 27 | { 28 | if(speed < 0.00001f) 29 | speed = 0.00001f; 30 | 31 | this->Pitch = speed; 32 | 33 | float t2; 34 | t2 = (speed * 65536.f) / CCetoneSynth::SampleRate; 35 | this->OscStep = truncate(t2 * 16384.f + 0.5f); 36 | 37 | if (pw < 0) 38 | pw = 0; 39 | else if(pw > 65536) 40 | pw = 65536; 41 | 42 | this->PulseWidth = pw; 43 | 44 | if (wave < 0) 45 | wave = 0; 46 | else if(wave > WAVE_MAX) 47 | wave = WAVE_MAX; 48 | 49 | this->Waveform = wave; 50 | 51 | this->DoTrigger = trig; 52 | } 53 | 54 | void CSynthLfo::SetSpeed(float speed) 55 | { 56 | if(speed < 0.00001f) 57 | speed = 0.00001f; 58 | 59 | this->Pitch = speed; 60 | 61 | float t2; 62 | t2 = (speed * 65536.f) / CCetoneSynth::SampleRate; 63 | this->OscStep = truncate(t2 * 16384.f + 0.5f); 64 | } 65 | 66 | float CSynthLfo::GetSpeed() 67 | { 68 | return this->Pitch; 69 | } 70 | 71 | void CSynthLfo::SetPw(int pw) 72 | { 73 | if (pw < 0) 74 | pw = 0; 75 | else if(pw > 65536) 76 | pw = 65536; 77 | 78 | this->PulseWidth = pw; 79 | } 80 | 81 | int CSynthLfo::GetPw() 82 | { 83 | return this->PulseWidth; 84 | } 85 | 86 | void CSynthLfo::SetWave(int wave) 87 | { 88 | if (wave < 0) 89 | wave = 0; 90 | else if(wave > WAVE_MAX) 91 | wave = WAVE_MAX; 92 | 93 | this->Waveform = wave; 94 | } 95 | 96 | int CSynthLfo::GetWave() 97 | { 98 | return this->Waveform; 99 | } 100 | 101 | void CSynthLfo::SetTrigger(bool trig) 102 | { 103 | this->DoTrigger = trig; 104 | } 105 | 106 | bool CSynthLfo::GetTrigger() 107 | { 108 | return this->DoTrigger; 109 | } 110 | 111 | void CSynthLfo::Trigger() 112 | { 113 | if (this->DoTrigger) 114 | { 115 | this->ShiftRegister = 0x7ffff8; 116 | this->OscNow = 0; 117 | } 118 | } 119 | 120 | float CSynthLfo::Run() 121 | { 122 | int sr = this->ShiftRegister; 123 | int ret; 124 | int osc = this->OscNow >> 14; 125 | 126 | float output = 0.f; 127 | 128 | switch(this->Waveform) 129 | { 130 | case WAVE_SAW: 131 | output = CCetoneSynth::Int2FloatTab2[osc]; 132 | break; 133 | case WAVE_PULSE: 134 | if (osc < this->PulseWidth) 135 | output = -1.f; 136 | else 137 | output = 1.f; 138 | break; 139 | case WAVE_TRI: 140 | if (osc < 0x8000) 141 | ret = osc << 1; 142 | else 143 | ret = 131071 - (osc << 1); 144 | output = CCetoneSynth::Int2FloatTab2[ret]; 145 | break; 146 | case WAVE_SINE: 147 | output = CCetoneSynth::SineTable[osc]; 148 | break; 149 | case WAVE_C64NOISE: 150 | ret = ((sr & 0x400000) >> 11) | 151 | ((sr & 0x100000) >> 10) | 152 | ((sr & 0x010000) >> 7) | 153 | ((sr & 0x002000) >> 5) | 154 | ((sr & 0x000800) >> 4) | 155 | ((sr & 0x000080) >> 1) | 156 | ((sr & 0x000010) << 1) | 157 | ((sr & 0x000004) << 2); 158 | output = CCetoneSynth::Int2FloatTab2[ret << 4]; 159 | break; 160 | default: 161 | break; 162 | } 163 | 164 | this->OscNow += this->OscStep; 165 | 166 | if (this->OscNow > 0x3fffffff) 167 | { 168 | int bit0 = ((sr >> 22) ^ (sr >> 17)) & 0x1; 169 | sr <<= 1; 170 | sr &= 0x7fffff; 171 | sr |= bit0; 172 | this->OscNow &= 0x3fffffff; 173 | } 174 | 175 | this->Value = output; 176 | 177 | return output; 178 | } 179 | -------------------------------------------------------------------------------- /cetonesynthlight/SynthLfo.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "SynthLfo.h" 3 | #include 4 | 5 | CSynthLfo::CSynthLfo(void) 6 | { 7 | this->SetSpeed(0.05f); 8 | this->SetPw(32768); 9 | this->SetTrigger(false); 10 | this->SetWave(WAVE_SAW); 11 | 12 | this->Reset(); 13 | } 14 | 15 | CSynthLfo::~CSynthLfo(void) 16 | { 17 | } 18 | 19 | void CSynthLfo::Reset() 20 | { 21 | this->OscNow = 0; 22 | this->Value = 0.f; 23 | this->ShiftRegister = 0x7ffff8; 24 | } 25 | 26 | void CSynthLfo::Set(float speed, int pw, int wave, bool trig) 27 | { 28 | if(speed < 0.00001f) 29 | speed = 0.00001f; 30 | 31 | this->Pitch = speed; 32 | 33 | float t2; 34 | t2 = (speed * 65536.f) / CCetoneSynth::SampleRate; 35 | this->OscStep = truncate(t2 * 16384.f + 0.5f); 36 | 37 | if (pw < 0) 38 | pw = 0; 39 | else if(pw > 65536) 40 | pw = 65536; 41 | 42 | this->PulseWidth = pw; 43 | 44 | if (wave < 0) 45 | wave = 0; 46 | else if(wave > WAVE_MAX) 47 | wave = WAVE_MAX; 48 | 49 | this->Waveform = wave; 50 | 51 | this->DoTrigger = trig; 52 | } 53 | 54 | void CSynthLfo::SetSpeed(float speed) 55 | { 56 | if(speed < 0.00001f) 57 | speed = 0.00001f; 58 | 59 | this->Pitch = speed; 60 | 61 | float t2; 62 | t2 = (speed * 65536.f) / CCetoneSynth::SampleRate; 63 | this->OscStep = truncate(t2 * 16384.f + 0.5f); 64 | } 65 | 66 | float CSynthLfo::GetSpeed() 67 | { 68 | return this->Pitch; 69 | } 70 | 71 | void CSynthLfo::SetPw(int pw) 72 | { 73 | if (pw < 0) 74 | pw = 0; 75 | else if(pw > 65536) 76 | pw = 65536; 77 | 78 | this->PulseWidth = pw; 79 | } 80 | 81 | int CSynthLfo::GetPw() 82 | { 83 | return this->PulseWidth; 84 | } 85 | 86 | void CSynthLfo::SetWave(int wave) 87 | { 88 | if (wave < 0) 89 | wave = 0; 90 | else if(wave > WAVE_MAX) 91 | wave = WAVE_MAX; 92 | 93 | this->Waveform = wave; 94 | } 95 | 96 | int CSynthLfo::GetWave() 97 | { 98 | return this->Waveform; 99 | } 100 | 101 | void CSynthLfo::SetTrigger(bool trig) 102 | { 103 | this->DoTrigger = trig; 104 | } 105 | 106 | bool CSynthLfo::GetTrigger() 107 | { 108 | return this->DoTrigger; 109 | } 110 | 111 | void CSynthLfo::Trigger() 112 | { 113 | if (this->DoTrigger) 114 | { 115 | this->ShiftRegister = 0x7ffff8; 116 | this->OscNow = 0; 117 | } 118 | } 119 | 120 | float CSynthLfo::Run() 121 | { 122 | int sr = this->ShiftRegister; 123 | int ret; 124 | int osc = this->OscNow >> 14; 125 | 126 | float output = 0.f; 127 | 128 | switch(this->Waveform) 129 | { 130 | case WAVE_SAW: 131 | output = CCetoneSynth::Int2FloatTab2[osc]; 132 | break; 133 | case WAVE_PULSE: 134 | if (osc < this->PulseWidth) 135 | output = -1.f; 136 | else 137 | output = 1.f; 138 | break; 139 | case WAVE_TRI: 140 | if (osc < 0x8000) 141 | ret = osc << 1; 142 | else 143 | ret = 131071 - (osc << 1); 144 | output = CCetoneSynth::Int2FloatTab2[ret]; 145 | break; 146 | case WAVE_SINE: 147 | output = CCetoneSynth::SineTable[osc]; 148 | break; 149 | case WAVE_C64NOISE: 150 | ret = ((sr & 0x400000) >> 11) | 151 | ((sr & 0x100000) >> 10) | 152 | ((sr & 0x010000) >> 7) | 153 | ((sr & 0x002000) >> 5) | 154 | ((sr & 0x000800) >> 4) | 155 | ((sr & 0x000080) >> 1) | 156 | ((sr & 0x000010) << 1) | 157 | ((sr & 0x000004) << 2); 158 | output = CCetoneSynth::Int2FloatTab2[ret << 4]; 159 | break; 160 | default: 161 | break; 162 | } 163 | 164 | this->OscNow += this->OscStep; 165 | 166 | if (this->OscNow > 0x3fffffff) 167 | { 168 | int bit0 = ((sr >> 22) ^ (sr >> 17)) & 0x1; 169 | sr <<= 1; 170 | sr &= 0x7fffff; 171 | sr |= bit0; 172 | this->ShiftRegister = sr; 173 | this->OscNow &= 0x3fffffff; 174 | } 175 | 176 | this->Value = output; 177 | 178 | return output; 179 | } 180 | -------------------------------------------------------------------------------- /cetonesynth2/defines.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#define CS2DEBUG 4 | 5 | #ifdef CS2DEBUG 6 | #include "log.h" 7 | #endif 8 | 9 | #define nCLAMP(min, val, max) ((val > max) ? max : ((val < min) ? min : val)) 10 | 11 | #define PI 3.14159265f 12 | #define PId 3.14159265358979323846 13 | #define UNDENORM(v) if( (*((unsigned __int32*)&v) & 0x7f800000) == 0) v = 0 14 | 15 | #define NOTE_MAX 120 16 | #define NOTE_MAX1 (NOTE_MAX-1) 17 | #define PITCH_MAX 12000 18 | #define PITCH_MAX1 (PITCH_MAX-1) 19 | 20 | #define WAVETABLE_LENGTH 2048 21 | #define WAVETABLE_LENGTHf 2048.0f 22 | #define WAVETABLE_LENGTH1 (WAVETABLE_LENGTH-1) 23 | #define WAVETABLE_LENGTH2 (WAVETABLE_LENGTH/2) 24 | #define WAVETABLE_LENGTH4 (WAVETABLE_LENGTH/4) 25 | #define WAVETABLE_MASK (WAVETABLE_LENGTH-1) 26 | 27 | #define OSCW_OFF 0 28 | #define OSCW_SAW 1 29 | #define OSCW_PULSE 2 30 | #define OSCW_TRI 4 31 | #define OSCW_NOISE 8 32 | 33 | #define OSCM_NORMAL 0 34 | #define OSCM_ADD 1 35 | #define OSCM_MUL 2 36 | #define OSCM_SUPER 3 37 | 38 | #define EFFECT_NAME "CetoneSynth2" 39 | #define CLASS_NAME "CetoneSynth2" 40 | #define VENDOR_NAME "Neotec Software" 41 | #define PRODUCT_NAME "CetoneSynth2" 42 | #define VERSION_NUMBER 6 43 | #define REAL_VERSION 0x007500 44 | 45 | typedef struct 46 | { 47 | unsigned __int16 frac; 48 | __int16 index; 49 | } sFIXED; 50 | 51 | typedef union 52 | { 53 | sFIXED fixed; 54 | __int32 int32; 55 | } oSTEP; 56 | 57 | typedef struct 58 | { 59 | unsigned __int8 semi; 60 | unsigned __int8 fine; 61 | unsigned __int8 morph; 62 | unsigned __int8 flags; 63 | unsigned __int8 wave; 64 | unsigned __int8 mode; 65 | unsigned __int8 spread; 66 | unsigned __int8 pad; 67 | } sOSC; // 8 68 | 69 | typedef struct 70 | { 71 | unsigned __int8 a, h, d, s, r; 72 | unsigned __int8 pad[3]; 73 | } sENV; // 8 74 | 75 | typedef struct 76 | { 77 | unsigned __int8 speed; 78 | unsigned __int8 delay; 79 | unsigned __int8 pw; 80 | unsigned __int8 keytrack; 81 | unsigned __int8 wave; 82 | unsigned __int8 sync; 83 | unsigned __int8 snh; 84 | unsigned __int8 retrig; 85 | } sLFO; // 8 86 | 87 | typedef struct 88 | { 89 | unsigned __int8 source; 90 | unsigned __int8 amount; 91 | unsigned __int8 dest; 92 | unsigned __int8 pad[1]; 93 | } sMOD; // 4 94 | 95 | typedef struct 96 | { 97 | unsigned __int8 cutoff; 98 | unsigned __int8 q; 99 | unsigned __int8 gain; 100 | unsigned __int8 velsens; 101 | unsigned __int8 env2; 102 | unsigned __int8 db; 103 | unsigned __int8 mode; 104 | unsigned __int8 exp; 105 | } sFILT; // 8 106 | 107 | typedef struct 108 | { 109 | unsigned __int8 volume; 110 | unsigned __int8 velsens; 111 | unsigned __int8 panning; 112 | unsigned __int8 osc1; 113 | unsigned __int8 osc2; 114 | unsigned __int8 osc3; 115 | unsigned __int8 pad[2]; 116 | } sMIX; // 8 117 | 118 | typedef struct 119 | { 120 | unsigned __int8 flags; 121 | unsigned __int8 speed; 122 | unsigned __int8 length; 123 | unsigned __int8 loop; 124 | unsigned __int8 sync; 125 | unsigned __int8 note[8]; 126 | unsigned __int8 pad[3]; 127 | } sARP; // 16 128 | 129 | typedef struct 130 | { 131 | __int32 version; // 4 132 | char name[26]; // + 26 = 30 133 | sOSC osc[3]; // + 3 * 8 = 54 134 | sLFO lfo[2]; // + 2 * 8 = 70 135 | sENV env[3]; // + 3 * 8 = 94 136 | sFILT filter; // + 8 = 102 137 | sMIX mixer; // + 8 = 110 138 | sMOD mod[6]; // + 6 * 4 = 134 139 | sARP arp; // + 16 = 150 140 | unsigned __int8 voices; // 151 141 | unsigned __int8 glide; // 152 142 | unsigned __int8 audioVol; 143 | unsigned __int8 audioPan; 144 | unsigned __int8 pad[102]; 145 | } sPRG; 146 | 147 | #if _M_IX86_FP > 0 148 | #define truncate(x) ((int)(x)) 149 | #else 150 | __forceinline int truncate(float flt) 151 | { 152 | int i; 153 | _asm 154 | { 155 | fld flt 156 | fistp i 157 | } 158 | return i; 159 | } 160 | #endif 161 | -------------------------------------------------------------------------------- /cetonesynth/FilterButterworth24db.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "cetonesynth.h" 3 | 4 | #define BUDDA_Q_SCALE 40.f 5 | 6 | #include "FilterButterworth24db.h" 7 | 8 | CFilterButterworth24db::CFilterButterworth24db(void) 9 | { 10 | this->Reset(); 11 | 12 | this->SetSampleRate(CCetoneSynth::SampleRate); 13 | this->Set(CCetoneSynth::SampleRate2, 0.0); 14 | } 15 | 16 | CFilterButterworth24db::~CFilterButterworth24db(void) 17 | { 18 | } 19 | 20 | void CFilterButterworth24db::Reset() 21 | { 22 | this->history1 = 0.f; 23 | this->history2 = 0.f; 24 | this->history3 = 0.f; 25 | this->history4 = 0.f; 26 | } 27 | 28 | void CFilterButterworth24db::SetSampleRate(float fs) 29 | { 30 | /* No damn optimizations here, 'cause this func should 31 | get called only once, so ... who cares!? 32 | */ 33 | 34 | float pi = 4.f * atanf(1.f); 35 | 36 | this->t0 = 4.f * fs * fs; 37 | this->t1 = 8.f * fs * fs; 38 | this->t2 = 2.f * fs; 39 | this->t3 = pi / fs; 40 | 41 | this->min_cutoff = fs * 0.0005f; 42 | this->max_cutoff = fs * 0.45f; 43 | } 44 | 45 | void CFilterButterworth24db::Set(float cutoff, float q) 46 | { 47 | if (cutoff < this->min_cutoff) 48 | cutoff = this->min_cutoff; 49 | else if(cutoff > this->max_cutoff) 50 | cutoff = this->max_cutoff; 51 | 52 | if(q < 0.f) 53 | q = 0.f; 54 | else if(q > 1.f) 55 | q = 1.f; 56 | 57 | float wp = this->t2 * tanf(this->t3 * cutoff); 58 | float bd, bd_tmp, b1, b2; 59 | 60 | q *= BUDDA_Q_SCALE; 61 | q += 1.f; 62 | 63 | b1 = (0.765367f / q) / wp; 64 | b2 = 1.f / (wp * wp); 65 | 66 | bd_tmp = this->t0 * b2 + 1.f; 67 | 68 | bd = 1.f / (bd_tmp + this->t2 * b1); 69 | 70 | this->gain = bd; 71 | 72 | this->coef2 = (2.f - this->t1 * b2); 73 | 74 | this->coef0 = this->coef2 * bd; 75 | this->coef1 = (bd_tmp - this->t2 * b1) * bd; 76 | 77 | b1 = (1.847759f / q) / wp; 78 | 79 | bd = 1.f / (bd_tmp + this->t2 * b1); 80 | 81 | this->gain *= bd; 82 | this->coef2 *= bd; 83 | this->coef3 = (bd_tmp - this->t2 * b1) * bd; 84 | } 85 | 86 | float CFilterButterworth24db::Run(float input) 87 | { 88 | float output = input * this->gain; 89 | float new_hist; 90 | 91 | output -= this->history1 * this->coef0; 92 | new_hist = output - this->history2 * this->coef1; 93 | 94 | output = new_hist + this->history1 * 2.f; 95 | output += this->history2; 96 | 97 | this->history2 = this->history1; 98 | this->history1 = new_hist; 99 | 100 | output -= this->history3 * this->coef2; 101 | new_hist = output - this->history4 * this->coef3; 102 | 103 | output = new_hist + this->history3 * 2.f; 104 | output += this->history4; 105 | 106 | this->history4 = this->history3; 107 | this->history3 = new_hist; 108 | 109 | return output; 110 | } 111 | /* 112 | 113 | float wp = t2 * tanf(t3 * fc); 114 | float bd, bd_tmp; 115 | 116 | // Section 1 117 | 118 | b1 = (0.765367f / Q) / wp; 119 | b2 = 1.f / (wp * wp); 120 | 121 | bd_tmp = t0 * b2 + 1.f; 122 | 123 | bd = 1.f / (bd_tmp + t2 * b1); 124 | gain *= bd; 125 | 126 | coef[2] = (2.f - t1 * b2); 127 | 128 | coef[0] = coef[2] * bd; 129 | coef[1] = (bd_tmp - t2 * b1) * bd; 130 | 131 | // Section 2 132 | 133 | b1 = (1.847759f / Q) / wp; 134 | 135 | bd = 1.f / (bd_tmp + t2 * b1); 136 | 137 | gain *= bd; 138 | coef[2] *= bd; 139 | coef[3] = (bd_tmp - t2 * b1) * bd; 140 | 141 | // Compute filter 142 | 143 | 144 | float output = input * gain; 145 | float new_hist; 146 | 147 | output -= history1 * coef[0] 148 | new_hist = output - history2 * coef[1]; 149 | 150 | output = new_hist + history1 * 2.f; 151 | output += history2; 152 | 153 | history2 = history1; 154 | histroy1 = new_hist; 155 | 156 | output -= history3 * coef[2] 157 | new_hist = output - history4 * coef[3]; 158 | 159 | output = new_hist + history3 * 2.f; 160 | output += history4; 161 | 162 | history4 = history3; 163 | histroy3 = new_hist; 164 | 165 | return output; 166 | */ -------------------------------------------------------------------------------- /cetonesynth2/parameters.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum kParameters 4 | { 5 | kCutoff = 0, 6 | kReso, 7 | kFGain, 8 | kFVel, 9 | kFEnv, 10 | kF12dB, 11 | kF24dB, 12 | kFLP, 13 | kFBP, 14 | kFHP, 15 | kFBR, 16 | kFExp, 17 | 18 | kSemi1, kFine1, kMorph1, kOKTrk1, kOSync1, kOAM1, kONormal1, 19 | kOAdd1, kOMul1, kOSuper1, kOOff1, kOSaw1, kOPulse1, kOTri1, 20 | kONoise1, kOSpread1, 21 | 22 | kSemi2, kFine2, kMorph2, kOKTrk2, kOSync2, kOAM2, kONormal2, 23 | kOAdd2, kOMul2, kOSuper2, kOOff2, kOSaw2, kOPulse2, kOTri2, 24 | kONoise2, kOSpread2, 25 | 26 | kSemi3, kFine3, kMorph3, kOKTrk3, kOSync3, kOAM3, kONormal3, 27 | kOAdd3, kOMul3, kOSuper3, kOOff3, kOSaw3, kOPulse3, kOTri3, 28 | kONoise3, kOSpread3, 29 | 30 | kMixVol, 31 | kMixVel, 32 | kMixPan, 33 | kMixVol1, 34 | kMixVol2, 35 | kMixVol3, 36 | 37 | kVoices, 38 | kGlide, 39 | 40 | kAttack1, 41 | kHold1, 42 | kDecay1, 43 | kSustain1, 44 | kRelease1, 45 | 46 | kAttack2, 47 | kHold2, 48 | kDecay2, 49 | kSustain2, 50 | kRelease2, 51 | 52 | kAttack3, 53 | kHold3, 54 | kDecay3, 55 | kSustain3, 56 | kRelease3, 57 | 58 | kL1Speed, 59 | kL1Delay, 60 | kL1PW, 61 | kL1KTrack, 62 | kL1Off, 63 | kL1Saw, 64 | kL1Pulse, 65 | kL1Tri, 66 | kL1Noise, 67 | kL1Sync, 68 | kL1SNH, 69 | kL1Retrig, 70 | 71 | kL2Speed, 72 | kL2Delay, 73 | kL2PW, 74 | kL2KTrack, 75 | kL2Off, 76 | kL2Saw, 77 | kL2Pulse, 78 | kL2Tri, 79 | kL2Noise, 80 | kL2Sync, 81 | kL2SNH, 82 | kL2Retrig, 83 | 84 | kM1Source, 85 | kM1Amount, 86 | kM1Dest, 87 | 88 | kM2Source, 89 | kM2Amount, 90 | kM2Dest, 91 | 92 | kM3Source, 93 | kM3Amount, 94 | kM3Dest, 95 | 96 | kM4Source, 97 | kM4Amount, 98 | kM4Dest, 99 | 100 | kM5Source, 101 | kM5Amount, 102 | kM5Dest, 103 | 104 | kM6Source, 105 | kM6Amount, 106 | kM6Dest, 107 | 108 | kArpSpeed, 109 | kArpLength, 110 | kArpNote1, 111 | kArpNote2, 112 | kArpNote3, 113 | kArpNote4, 114 | kArpNote5, 115 | kArpNote6, 116 | kArpNote7, 117 | kArpNote8, 118 | kArpSync, 119 | kArpLoop, 120 | 121 | kPanic, 122 | kPatchStore, 123 | kPatchRecall, 124 | kPatchChaos, 125 | 126 | kAudioVol, 127 | kAudioPan, 128 | 129 | kNumParameters 130 | }; 131 | 132 | enum pParameters 133 | { 134 | pOSemi1, 135 | pOFine1, 136 | pOMorph1, 137 | pOWave1, 138 | pOMode1, 139 | pOFlags1, 140 | pOSpread1, 141 | 142 | pOSemi2, 143 | pOFine2, 144 | pOMorph2, 145 | pOWave2, 146 | pOMode2, 147 | pOFlags2, 148 | pOSpread2, 149 | 150 | pOSemi3, 151 | pOFine3, 152 | pOMorph3, 153 | pOWave3, 154 | pOMode3, 155 | pOFlags3, 156 | pOSpread3, 157 | 158 | pAttack1, 159 | pHold1, 160 | pDecay1, 161 | pSustain1, 162 | pRelease1, 163 | 164 | pAttack2, 165 | pHold2, 166 | pDecay2, 167 | pSustain2, 168 | pRelease2, 169 | 170 | pAttack3, 171 | pHold3, 172 | pDecay3, 173 | pSustain3, 174 | pRelease3, 175 | 176 | pMixVol, 177 | pMixPan, 178 | pMixVelsens, 179 | pMixVol1, 180 | pMixVol2, 181 | pMixVol3, 182 | 183 | pFCutoff, 184 | pFQ, 185 | pFVelsens, 186 | pFGain, 187 | pFEnv2, 188 | pFMode, 189 | pFType, 190 | pFExp, 191 | 192 | pVoices, 193 | pGlide, 194 | 195 | pArpSpeed, 196 | pArpLength, 197 | pArpNote1, 198 | pArpNote2, 199 | pArpNote3, 200 | pArpNote4, 201 | pArpNote5, 202 | pArpNote6, 203 | pArpNote7, 204 | pArpNote8, 205 | pArpSync, 206 | pArpLoop, 207 | 208 | pL1Speed, 209 | pL1Delay, 210 | pL1PW, 211 | pL1Keytrack, 212 | pL1Wave, 213 | pL1Sync, 214 | pL1Retrig, 215 | pL1SNH, 216 | 217 | pL2Speed, 218 | pL2Delay, 219 | pL2PW, 220 | pL2Keytrack, 221 | pL2Wave, 222 | pL2Sync, 223 | pL2Retrig, 224 | pL2SNH, 225 | 226 | pM1Source, 227 | pM1Amount, 228 | pM1Dest, 229 | 230 | pM2Source, 231 | pM2Amount, 232 | pM2Dest, 233 | 234 | pM3Source, 235 | pM3Amount, 236 | pM3Dest, 237 | 238 | pM4Source, 239 | pM4Amount, 240 | pM4Dest, 241 | 242 | pM5Source, 243 | pM5Amount, 244 | pM5Dest, 245 | 246 | pM6Source, 247 | pM6Amount, 248 | pM6Dest, 249 | 250 | pAftertouch, 251 | pModwheel, 252 | 253 | pAudioVol, 254 | pAudioPan, 255 | 256 | pNumParameters 257 | }; 258 | 259 | #define OBJ_COUNT kNumParameters 260 | -------------------------------------------------------------------------------- /cetoneorg/Synth.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | #include "statics.h" 5 | #include "tonewheel.h" 6 | #include "lfo.h" 7 | #include "chorus.h" 8 | #include "reverb.h" 9 | 10 | class Synth 11 | { 12 | public: 13 | Synth(); 14 | ~Synth(); 15 | void NoteOn(int note, int vel); 16 | void NoteOff(int note); 17 | void InitRender(); 18 | void FinishRender(int samples); 19 | void Render(int frames); 20 | void setSampleRate(float fs); 21 | void setBlockSize(int size); 22 | 23 | void Reset() 24 | { 25 | this->buffer[0] = 26 | this->buffer[1] = 27 | this->buffer[2] = 28 | this->buffer[3] = 29 | this->buffer[4] = 30 | this->buffer[5] = 0.0f; 31 | this->buffer1[0] = 32 | this->buffer1[1] = 33 | this->buffer1[2] = 34 | this->buffer1[3] = 35 | this->buffer1[4] = 36 | this->buffer1[5] = 0.0f; 37 | this->_Chorus->Reset(); 38 | this->_Reverb->Reset(); 39 | } 40 | 41 | void setTone(int val) 42 | { 43 | int i; 44 | for(i = 0; i < 89; i++) 45 | this->Wheels[i]->setWave(g_sine + val * SINE_SIZE * 3 + SINE_SIZE); 46 | } 47 | 48 | void setLfoSpeed(int val) 49 | { 50 | float v = (float)val / 127.0f; 51 | this->_LFO->setSpeed(v * v * 32.0f); 52 | } 53 | 54 | void setLfoPhase(int phase) 55 | { 56 | this->_LFO->setPhase(phase); 57 | } 58 | 59 | void setVolume(int val) 60 | { 61 | float v = (float)val / 127.0f; 62 | this->Volume = v * v * 4.0f; 63 | } 64 | 65 | void setDrawbars(int idx, int val) 66 | { 67 | this->volumes[idx] = ((float)val / 8.0f) * 0.5f; 68 | } 69 | 70 | void setVibDepth(int val) 71 | { 72 | this->VibDepth = (float)val / 127.0f * 0.95f; 73 | } 74 | 75 | void setPanDepth(int val) 76 | { 77 | this->PanDepth = (float)val / 127.0f * 0.48f; 78 | } 79 | 80 | void setChorusDelayL(int val) 81 | { 82 | this->_Chorus->setDelayL(val); 83 | } 84 | 85 | void setChorusDelayR(int val) 86 | { 87 | this->_Chorus->setDelayR(val); 88 | } 89 | 90 | void setChorusSpeed(int val) 91 | { 92 | this->_Chorus->setLfoSpeed(val); 93 | } 94 | 95 | void setChorusDepth(int val) 96 | { 97 | this->_Chorus->setDepth(val); 98 | } 99 | 100 | void setChorusMix(int val) 101 | { 102 | float v = (float)val / 127.0f; 103 | this->Chorus_dry = 1.0f - v; 104 | this->Chorus_wet = v; 105 | 106 | if(val > 0) 107 | { 108 | if(!this->isChorus) 109 | this->_Chorus->Reset(); 110 | this->isChorus = -1; 111 | } 112 | else 113 | this->isChorus = 0; 114 | } 115 | 116 | void setChorusFeedback(int val) 117 | { 118 | this->_Chorus->setFeedback((float)(val - 64) / 65.0f); 119 | } 120 | 121 | void setClickAmount(int val) 122 | { 123 | int i; 124 | float v = (float)(127 - val) / 127.0f; 125 | float click = v * v * 0.005f + 0.00001f; 126 | for(i = 0; i < 89; i++) 127 | this->Wheels[i]->setAttack(click); 128 | } 129 | 130 | void setRevDamp(int val) 131 | { 132 | this->_Reverb->setDamp((float)val / 127.0f); 133 | } 134 | 135 | void setRevRoom(int val) 136 | { 137 | this->_Reverb->setRoomsize((float)val / 127.0f); 138 | } 139 | 140 | void setRevWidth(int val) 141 | { 142 | this->_Reverb->setWidth((float)val / 127.0f); 143 | } 144 | 145 | void setRevDry(int val) 146 | { 147 | this->_Reverb->setDry((float)val / 127.0f); 148 | } 149 | 150 | void setRevWet(int val) 151 | { 152 | this->_Reverb->setWet((float)val / 127.0f); 153 | if(val > 0) 154 | { 155 | if(!this->isReverb) 156 | this->_Reverb->Reset(); 157 | this->isReverb = -1; 158 | } 159 | else 160 | this->isReverb = 0; 161 | } 162 | 163 | void setOutVol(int val) 164 | { 165 | float v = (float)val / 127.0f; 166 | this->OutVol = v * v * 4.0f; 167 | } 168 | 169 | float *fLeft; 170 | float *fRight; 171 | 172 | float volumes[9]; 173 | float Volume; 174 | float VibDepth; 175 | float PanDepth; 176 | private: 177 | ToneWheel *Wheels[89]; 178 | float FS; 179 | float *mixBuf; 180 | float *lfo1; 181 | float *lfo2; 182 | int *vibrato; 183 | LFO *_LFO; 184 | Chorus *_Chorus; 185 | Reverb *_Reverb; 186 | int iBlockSize; 187 | int iFramePos; 188 | int isChorus; 189 | int isReverb; 190 | float OutVol; 191 | float a1, a2; 192 | float b0, b1, b2; 193 | float buffer[6]; 194 | float buffer1[6]; 195 | float Chorus_wet, Chorus_dry; 196 | }; 197 | -------------------------------------------------------------------------------- /cetoneorg/chorus.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "defines.h" 4 | #include "statics.h" 5 | #include 6 | #include 7 | #include 8 | 9 | // Chorus/Flanger Effect 10 | /* 11 | Parameters: 12 | Depth Delay L/R 13 | Feedback 14 | LFO Speed 15 | */ 16 | class Chorus 17 | { 18 | public: 19 | Chorus() 20 | { 21 | this->FS = 0.0f; 22 | this->Size = 0; 23 | this->bufl = this->bufr = 0; 24 | this->lfoPos.int32 = this->lfoStep.int32 = 0; 25 | this->Position = 0; 26 | this->params[0] = 18; 27 | this->params[1] = 19; 28 | this->params[2] = 50; 29 | this->params[3] = 7; 30 | 31 | int i; 32 | for(i = 0; i < 16384; i++) 33 | this->l_sine[i] = (sinf(PI * (float)i / 8192) + 1.0f) * 0.5f; 34 | } 35 | 36 | ~Chorus() 37 | { 38 | if(this->bufl) free(this->bufl); 39 | if(this->bufr) free(this->bufr); 40 | } 41 | 42 | void Reset() 43 | { 44 | this->Position = 0; 45 | this->lfoPos.int32 = 0; 46 | memset(this->bufl, 0, this->Size * sizeof(float)); 47 | memset(this->bufr, 0, this->Size * sizeof(float)); 48 | } 49 | 50 | void setDelayL(int val) 51 | { 52 | this->params[0] = val; 53 | float v = (float)val / 127.0f; 54 | this->DelayL = this->FS * (0.04f * v * v + 0.001f); 55 | } 56 | 57 | void setDelayR(int val) 58 | { 59 | this->params[1] = val; 60 | float v = (float)val / 127.0f; 61 | this->DelayR = this->FS * (0.04f * v * v + 0.001f); 62 | } 63 | 64 | void setDepth(int val) 65 | { 66 | this->params[2] = val; 67 | float v = (float)val / 127.0f; 68 | this->Depth = this->FS * 0.02f * v * v; 69 | } 70 | 71 | void setFeedback(float val) 72 | { 73 | this->Feedback = val; 74 | } 75 | 76 | void setLfoSpeed(int val) 77 | { 78 | this->params[3] = val; 79 | float v = (float)val / 127.0f; 80 | this->lfoStep.int32 = truncate(((16384.0f * v * v * 4.0f + 0.005f) / this->FS) * 65536.0f); 81 | } 82 | 83 | void setSampleRate(float fs) 84 | { 85 | int size = truncate(fs * 0.5f); 86 | if(size != this->Size || this->FS != fs) 87 | { 88 | this->FS = fs; 89 | this->Size = size; 90 | if(this->bufl != 0) 91 | { 92 | this->bufl = (float*)realloc(this->bufl, size * sizeof(float)); 93 | this->bufr = (float*)realloc(this->bufr, size * sizeof(float)); 94 | } 95 | else 96 | { 97 | this->bufl = (float*)malloc(size * sizeof(float)); 98 | this->bufr = (float*)malloc(size * sizeof(float)); 99 | } 100 | memset(this->bufl, 0, size * sizeof(float)); 101 | memset(this->bufr, 0, size * sizeof(float)); 102 | 103 | this->setDelayL(this->params[0]); 104 | this->setDelayR(this->params[1]); 105 | this->setDepth(this->params[2]); 106 | this->setLfoSpeed(this->params[3]); 107 | } 108 | } 109 | 110 | void Render(float *inl, float* inr, int samples, float dry, float wet) 111 | { 112 | int i; 113 | for(i = 0; i < samples; i++) 114 | { 115 | float dd, f0, ol, or, tmp; 116 | int d, d0, d1; 117 | float lfo = this->ProcessLFO() * this->Depth; 118 | 119 | dd = lfo + this->DelayL; 120 | d = truncate(floorf(dd)); 121 | 122 | d0 = (this->Position - d + this->Size - 1) % this->Size; 123 | d1 = (d0 + 1) % this->Size; 124 | f0 = dd - (float)d; 125 | 126 | ol = this->bufl[d1] + f0 * (this->bufl[d0] - this->bufl[d1]); 127 | 128 | dd = lfo + this->DelayR; 129 | d = truncate(floorf(dd)); 130 | 131 | d0 = (this->Position - d + this->Size - 1) % this->Size; 132 | d1 = (d0 + 1) % this->Size; 133 | f0 = dd - (float)d; 134 | 135 | or = this->bufr[d1] + f0 * (this->bufr[d0] - this->bufr[d1]); 136 | 137 | tmp = inl[i] + this->Feedback * ol; 138 | UNDENORM(tmp); 139 | this->bufl[this->Position] = tanhf(tmp); 140 | 141 | tmp = inr[i] + this->Feedback * or; 142 | UNDENORM(tmp); 143 | this->bufr[this->Position] = tanhf(tmp); 144 | 145 | inl[i] = ol * wet + inl[i] * dry; 146 | inr[i] = or * wet + inr[i] * dry; 147 | 148 | this->Position = (this->Position + 1) % this->Size; 149 | } 150 | } 151 | 152 | private: 153 | float ProcessLFO() 154 | { 155 | float s0 = this->l_sine[this->lfoPos.fixed.index]; 156 | float s1 = this->l_sine[(this->lfoPos.fixed.index + 1) & 16383]; 157 | float out = s0 + ((float)this->lfoPos.fixed.frac / 65536.0f) * (s1 - s0); 158 | this->lfoPos.int32 += this->lfoStep.int32; 159 | this->lfoPos.fixed.index &= 16383; 160 | return out; 161 | } 162 | 163 | int params[8]; 164 | float FS; 165 | int Size; 166 | int Position; 167 | float* bufl; 168 | float *bufr; 169 | float DelayL, DelayR; 170 | float Depth; 171 | float Feedback; 172 | sSTEP lfoPos; 173 | sSTEP lfoStep; 174 | float l_sine[16384]; 175 | }; 176 | -------------------------------------------------------------------------------- /cetone033/Cetone033.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "audioeffectx.h" 4 | 5 | #include "defines.h" 6 | #include "structures.h" 7 | #include "globalfunctions.h" 8 | #include "midistack.h" 9 | #include "synthoscillator.h" 10 | 11 | #include "cetonelpfilter.h" 12 | 13 | class CCetone033 : public AudioEffectX 14 | { 15 | public: 16 | CCetone033(audioMasterCallback audioMaster); 17 | ~CCetone033(void); 18 | 19 | // Plugin interface 20 | 21 | virtual void resume(); 22 | 23 | virtual VstInt32 processEvents(VstEvents* events); 24 | virtual void process(float **inputs, float **outputs, VstInt32 sampleFrames); 25 | virtual void processReplacing(float** inputs, float** outputs, VstInt32 sampleFrames); 26 | 27 | virtual VstInt32 getChunk(void** data, bool isPreset = false); 28 | virtual VstInt32 setChunk(void* data, VstInt32 byteSize, bool isPreset = false); 29 | 30 | virtual void setProgram(VstInt32 program); 31 | virtual VstInt32 getProgram(); 32 | virtual void setProgramName(char* name); 33 | virtual void getProgramName(char* name); 34 | virtual bool getProgramNameIndexed(VstInt32 category, VstInt32 index, char* text); 35 | 36 | virtual VstInt32 getNumMidiInputChannels(); 37 | virtual VstInt32 getNumMidiOutputChannels(); 38 | 39 | virtual void setSampleRate (float sampleRate); 40 | virtual void setBlockSize (VstInt32 blockSize); 41 | 42 | virtual VstInt32 getVendorVersion (); 43 | virtual bool getEffectName(char* name); 44 | virtual bool getVendorString(char* text); 45 | virtual bool getProductString(char* text); 46 | 47 | virtual VstInt32 canDo(char* text); 48 | 49 | virtual void setParameter(VstInt32 index, float value); 50 | virtual float getParameter(VstInt32 index); 51 | virtual void getParameterLabel(VstInt32 index, char* label); 52 | virtual void getParameterDisplay(VstInt32 index, char* text); 53 | virtual void getParameterName(VstInt32 index, char* text); 54 | 55 | static float SampleRate; 56 | static float SampleRate2; 57 | static float SampleRateEnv; 58 | static float SampleRateVel; 59 | static float Pi; 60 | 61 | static float SmallSineTable[WAVETABLE_LENGTH]; 62 | static float FreqTable[PITCH_MAX]; 63 | static int FreqTableInt[PITCH_MAX]; 64 | 65 | static int LookupTable[65536]; 66 | static float SawTable[NOTE_MAX * WAVETABLE_LENGTH]; 67 | static float ParabolaTable[NOTE_MAX * WAVETABLE_LENGTH]; 68 | static int FreqStepInt[PITCH_MAX]; 69 | static int FreqStepFrac[PITCH_MAX]; 70 | 71 | static float Int2FloatTab[65536]; 72 | static float Int2FloatTab2[65536]; 73 | 74 | private: 75 | CMidiStack* MidiStack; 76 | CCetoneLpFilter* Filter; 77 | 78 | CSynthOscillator* Oscs[2]; 79 | 80 | SynthProgram Programs[128]; 81 | SynthProgramOld OldPrograms[128]; 82 | 83 | int CurrentNote; 84 | int CurrentVelocity; 85 | int CurrentDelta; 86 | int CurrentProgram; 87 | int CurrentPitch; 88 | 89 | float VelocityMod; 90 | float VelocityModStep; 91 | float VelocityModEnd; 92 | 93 | int LastP0; 94 | int NextP0; 95 | int NextP1; 96 | int NextP2; 97 | 98 | int FilterCounter; 99 | 100 | float GlideSamples; 101 | 102 | // Program 103 | 104 | int Coarse[2]; 105 | int Fine[2]; 106 | int Wave[2]; 107 | float Morph[2]; 108 | float Volume[2]; 109 | 110 | float Attack[2]; 111 | float Decay[2]; 112 | 113 | float ModEnv; 114 | float ModVel; 115 | float ModRes; 116 | 117 | float Cutoff; 118 | float Resonance; 119 | int FilterType; 120 | 121 | bool GlideState; 122 | float GlideSpeed; 123 | 124 | bool ClipState; 125 | float MainVolume; 126 | 127 | float CutoffDest; 128 | float CutoffStep; 129 | 130 | float ResonanceDest; 131 | float ResonanceStep; 132 | 133 | // 134 | 135 | float AttackFactor[2]; 136 | float DecayFactor[2]; 137 | float VoiceVolume[2]; 138 | int EnvPos[2]; 139 | float DecayResonance; 140 | 141 | bool DoGlide; 142 | int GlidePitch; 143 | int GlideStep; 144 | int GlideFrac; 145 | float ModChangeSamples; 146 | float ModResValue; 147 | 148 | void ReadProgram(int prg); 149 | void WriteProgram(int prg); 150 | 151 | void SynthProcess(float **inputs, float **outputs, VstInt32 sampleFrames, bool replace); 152 | void HandleMidi(int p0, int p1, int p2); 153 | 154 | void NoteOn(int note, int vel); 155 | void NoteOff(int note, int vel); 156 | void InitFreqTables(float fs); 157 | void InitParameters(); 158 | void UpdateEnvelopes(); 159 | void SetGlideSpeed(float speed); 160 | void SetGlideState(bool state); 161 | void SetModRes(float value); 162 | 163 | void SetCutoffSave(float value); 164 | void SetResonanceSave(float value); 165 | 166 | void ImportProgram(SynthProgramOld* src, SynthProgram* dest); 167 | }; 168 | -------------------------------------------------------------------------------- /cetone033/FilterBiquad.cpp: -------------------------------------------------------------------------------- 1 | #include "cetone033.h" 2 | #include "FilterBiquad.h" 3 | #include 4 | 5 | // Interpolates between ps[1] and ps[2] 6 | static float spline(float t, float* ps) 7 | { 8 | return ( 9 | (((-t + 3.0f) * t - 3.0f) * t + 1.0f) * ps[0] 10 | + (((3.0f * t - 6.0f) * t) * t + 4.0f) * ps[1] 11 | + (((-3.0f * t + 3.0f) * t + 3.0f) * t + 1.0f) * ps[2] 12 | + (t * t * t) * ps[3] 13 | ) / 6.0f; 14 | } 15 | 16 | CFilterBiquad::CFilterBiquad() 17 | { 18 | int i; 19 | float points[5] = {-1.2f, 0.0f, 1.2f, 1.5f, 1.2f}; 20 | this->min_fc = 0.0025f; 21 | 22 | this->Reset(); 23 | 24 | this->SetSampleRate(CCetone033::SampleRate); 25 | this->Set(1.f, 0.f); 26 | 27 | for(i = 0; i < 8192; i++) 28 | { 29 | this->waveshaper[i] = spline((float)i / 8192.0f, &(points[0])); 30 | this->waveshaper[i + 8192] = spline((float)i / 8192.0f, &(points[1])); 31 | } 32 | } 33 | 34 | CFilterBiquad::~CFilterBiquad() 35 | { 36 | } 37 | 38 | void CFilterBiquad::Reset() 39 | { 40 | for(int i = 0; i < 6; i++) 41 | { 42 | this->buffer0[i] = 0.f; 43 | this->buffer1[i] = 0.f; 44 | this->buffer2[i] = 0.f; 45 | } 46 | } 47 | 48 | void CFilterBiquad::Set(float cutoff, float q) 49 | { 50 | // Just to give some more control in the lower regions 51 | 52 | cutoff *= cutoff; 53 | //q *= q; 54 | 55 | if(cutoff < this->min_fc) 56 | cutoff = this->min_fc; 57 | else if(cutoff > 1.0f) 58 | cutoff = 1.0f; 59 | cutoff *= 0.5f; 60 | 61 | if(q < 0.f) 62 | q = 0.f; 63 | else if(q > 1.f) 64 | q = 1.f; 65 | 66 | q = 1.f + q * 15.f; 67 | 68 | float omega = this->t1 * cutoff; 69 | float cs = cosf(omega); 70 | float alpha = sinf(omega) / q; 71 | 72 | float a0 = 1.0f + alpha; 73 | this->b0 = (1.0f - cs) / (2.f * a0); 74 | this->b1 = (1.0f - cs) / a0; 75 | this->b2 = this->b0; 76 | this->a1 = (-2.f * cs) / a0; 77 | this->a2 = (1.0f - alpha) / a0; 78 | } 79 | 80 | void CFilterBiquad::SetSampleRate(float fs) 81 | { 82 | float pi = 4.f * atanf(1.f); 83 | this->t0 = pi * fs; 84 | this->t1 = pi;// * 0.5f; 85 | 86 | float omega = this->t1 * 880.0f / CCetone033::SampleRate2; 87 | float cs = cosf(omega); 88 | float sn = sinf(omega) / 6.0f; 89 | 90 | float a0 = 1.0f + sn; 91 | this->b0b = sn / a0; 92 | this->b1b = 0.0f; 93 | this->b2b = -this->b0b; 94 | this->a1b = (-2.f * cs) / a0; 95 | this->a2b = (1.0f - sn) / a0; 96 | } 97 | 98 | // Oversampled, 24dB 99 | /* 100 | Well, my first aproach using standard biquads just sounded ... sounded ... 101 | hmm ... well, no-good. This one is much more CPU consuming (5 biquad sections) 102 | but sounds really nice. 103 | A Neotec-filter ... my own ... no other filter sounds like this^^ 104 | */ 105 | float CFilterBiquad::Run(float inputout) 106 | { 107 | float* buf; 108 | float frac; 109 | int pos; 110 | 111 | // Short explan~s coming up 112 | 113 | // A band-pass filter with Q == 6 and FS == 880 Hz 114 | buf = this->buffer2; 115 | buf[2] = buf[1]; buf[1] = buf[0]; buf[0] = inputout; 116 | buf[5] = buf[4]; buf[4] = buf[3]; 117 | buf[3] = this->b0b * buf[0] + this->b1b * buf[1] + this->b2b * buf[2] 118 | - this->a1b * buf[4] - this->a2b * buf[5]; 119 | UNDENORM(buf[3]); 120 | 121 | // Mix "dry" and "wet" 122 | inputout = 0.7f * inputout + 0.3f * buf[3]; 123 | 124 | // This is the first 12dB biquad filter section 125 | buf = this->buffer0; 126 | buf[2] = buf[1]; buf[1] = buf[0]; buf[0] = inputout; 127 | buf[5] = buf[4]; buf[4] = buf[3]; 128 | buf[3] = this->b0 * buf[0] + this->b1 * buf[1] + this->b2 * buf[2] 129 | - this->a1 * buf[4] - this->a2 * buf[5]; 130 | // Jap, UNDENORM ... needed^^ 131 | UNDENORM(buf[3]); 132 | 133 | // Oversample, pad with NULL 134 | buf[2] = buf[1]; buf[1] = buf[0]; buf[0] = 0.0f; 135 | buf[5] = buf[4]; buf[4] = buf[3]; 136 | buf[3] = this->b1 * buf[1] + this->b2 * buf[2] 137 | - this->a1 * buf[4] - this->a2 * buf[5]; 138 | UNDENORM(buf[3]); 139 | 140 | inputout = buf[3]; 141 | 142 | // This is the second 12dB biquad filter section 143 | buf = this->buffer1; 144 | buf[2] = buf[1]; buf[1] = buf[0]; buf[0] = inputout; 145 | buf[5] = buf[4]; buf[4] = buf[3]; 146 | buf[3] = this->b0 * buf[0] + this->b1 * buf[1] + this->b2 * buf[2] 147 | - this->a1 * buf[4] - this->a2 * buf[5]; 148 | UNDENORM(buf[3]); 149 | 150 | // Oversample, pad with NULL 151 | buf[2] = buf[1]; buf[1] = buf[0]; buf[0] = 0.0f; 152 | buf[5] = buf[4]; buf[4] = buf[3]; 153 | buf[3] = this->b1 * buf[1] + this->b2 * buf[2] 154 | - this->a1 * buf[4] - this->a2 * buf[5]; 155 | UNDENORM(buf[3]); 156 | 157 | inputout = buf[3]; 158 | 159 | // Waveshaping (spline table) 160 | if(inputout < 0.0f) 161 | { 162 | inputout *= -8192.0f; 163 | if(inputout > 16382.0f) 164 | inputout = -this->waveshaper[16383]; 165 | else 166 | { 167 | pos = truncate(inputout); frac = inputout - (float)pos; 168 | inputout = -(this->waveshaper[pos] 169 | + frac * (this->waveshaper[pos + 1] - this->waveshaper[pos])); 170 | } 171 | } 172 | else 173 | { 174 | inputout *= 8192.0f; 175 | if(inputout > 16382.0f) 176 | inputout = this->waveshaper[16383]; 177 | else 178 | { 179 | pos = truncate(inputout); frac = inputout - (float)pos; 180 | inputout = this->waveshaper[pos] 181 | + frac * (this->waveshaper[pos + 1] - this->waveshaper[pos]); 182 | } 183 | } 184 | 185 | // done ... finally 186 | return inputout; 187 | } 188 | -------------------------------------------------------------------------------- /cetonesynth/SynthOscillator.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "SynthOscillator.h" 3 | 4 | CSynthOscillator::CSynthOscillator(void) 5 | { 6 | #if NOTE_RANGE == 1 7 | this->SetPitch(7200); 8 | #else 9 | this->SetPitch(8400); 10 | #endif 11 | 12 | this->SetPw(32768); 13 | this->SetWave(WAVE_SAW); 14 | 15 | this->Reset(); 16 | 17 | this->SyncOsc = NULL; 18 | this->DoSync = false; 19 | } 20 | 21 | CSynthOscillator::~CSynthOscillator(void) 22 | { 23 | } 24 | 25 | void CSynthOscillator::Reset() 26 | { 27 | this->Value = 0; 28 | this->ShiftRegister = 0x7ffff8; 29 | this->IndexInt = 0; 30 | this->IndexFrac = 0; 31 | } 32 | 33 | void CSynthOscillator::Set(int pw, int wave, bool sync) 34 | { 35 | if(pw < 0) 36 | pw = 0; 37 | else if(pw > 65535) 38 | pw = 65535; 39 | 40 | this->PulseWidth = pw; 41 | 42 | pw >>= 4; 43 | 44 | this->PwFloat = CCetoneSynth::Pw2Float[pw]; 45 | this->PwOffset = CCetoneSynth::Pw2Offset[pw]; 46 | this->PwWaveOffset = CCetoneSynth::Pw2WaveOffset[pw]; 47 | 48 | if(wave < 0) 49 | wave = 0; 50 | else if(wave > OWAVE_MAX) 51 | wave = OWAVE_MAX; 52 | 53 | this->Waveform = wave; 54 | 55 | this->DoSync = sync; 56 | } 57 | 58 | void CSynthOscillator::SetPitch(int pitch) 59 | { 60 | if(pitch < 0) 61 | pitch = 0; 62 | else if(pitch > PITCH_MAX1) 63 | pitch = PITCH_MAX1; 64 | 65 | this->Pitch = pitch; 66 | 67 | this->StepInt = CCetoneSynth::FreqStepInt[pitch]; 68 | this->StepFrac = CCetoneSynth::FreqStepFrac[pitch]; 69 | 70 | int t = CCetoneSynth::LookupTable[CCetoneSynth::FreqTableInt[pitch]] * WAVETABLE_LENGTH; 71 | 72 | this->SawPtr = &(CCetoneSynth::SawTable[t]); 73 | this->ParabolaPtr = &(CCetoneSynth::ParabolaTable[t]); 74 | } 75 | 76 | int CSynthOscillator::GetPitch() 77 | { 78 | return this->Pitch; 79 | } 80 | 81 | void CSynthOscillator::SetPw(int pw) 82 | { 83 | if(pw < 0) 84 | pw = 0; 85 | else if(pw > 65535) 86 | pw = 65535; 87 | 88 | this->PulseWidth = pw; 89 | 90 | pw >>= 4; 91 | 92 | this->PwFloat = CCetoneSynth::Pw2Float[pw]; 93 | this->PwOffset = CCetoneSynth::Pw2Offset[pw]; 94 | this->PwWaveOffset = CCetoneSynth::Pw2WaveOffset[pw]; 95 | } 96 | 97 | int CSynthOscillator::GetPw() 98 | { 99 | return this->PulseWidth; 100 | } 101 | 102 | void CSynthOscillator::SetWave(int wave) 103 | { 104 | if(wave < 0) 105 | wave = 0; 106 | else if(wave > OWAVE_MAX) 107 | wave = OWAVE_MAX; 108 | 109 | this->Waveform = wave; 110 | } 111 | 112 | int CSynthOscillator::GetWave() 113 | { 114 | return this->Waveform; 115 | } 116 | 117 | void CSynthOscillator::Sync() 118 | { 119 | } 120 | 121 | void CSynthOscillator::SetSync(bool sync) 122 | { 123 | this->DoSync = sync; 124 | } 125 | 126 | void CSynthOscillator::SetSyncDest(CSynthOscillator *osc) 127 | { 128 | this->SyncOsc = osc; 129 | } 130 | 131 | float CSynthOscillator::Run() 132 | { 133 | int sr = this->ShiftRegister; 134 | 135 | int sample0, sample1, onow; 136 | float interpolate, out0, out1; 137 | 138 | float output = 0.0; 139 | 140 | sample0 = this->IndexInt; 141 | sample1 = (sample0 + 1) & WAVETABLE_MASK; 142 | interpolate = CCetoneSynth::Int2FloatTab[this->IndexFrac]; 143 | 144 | switch (this->Waveform) 145 | { 146 | case OWAVE_SAW: 147 | out0 = this->SawPtr[sample0]; 148 | out1 = this->SawPtr[sample1]; 149 | output = (1.f - interpolate) * out0 + interpolate * out1; 150 | break; 151 | case OWAVE_PULSE: 152 | out0 = this->SawPtr[sample0]; 153 | out1 = this->SawPtr[sample1]; 154 | 155 | sample0 += this->PwOffset; 156 | sample1 += this->PwOffset; 157 | sample0 &= WAVETABLE_MASK; 158 | sample1 &= WAVETABLE_MASK; 159 | 160 | out0 -= this->SawPtr[sample0]; 161 | out1 -= this->SawPtr[sample1]; 162 | 163 | output = (1.f - interpolate) * out0 + interpolate * out1; 164 | output += this->PwWaveOffset; 165 | break; 166 | case OWAVE_TRI: 167 | out0 = this->ParabolaPtr[sample0]; 168 | out1 = this->ParabolaPtr[sample1]; 169 | 170 | sample0 += WAVETABLE_LENGTH2; 171 | sample1 += WAVETABLE_LENGTH2; 172 | sample0 &= WAVETABLE_MASK; 173 | sample1 &= WAVETABLE_MASK; 174 | 175 | out0 -= this->ParabolaPtr[sample0]; 176 | out1 -= this->ParabolaPtr[sample1]; 177 | 178 | output = (1.f - interpolate) * out0 + interpolate * out1; 179 | output *= 0.5f; 180 | break; 181 | case OWAVE_C64NOISE: 182 | onow = ((sr & 0x400000) >> 11) | 183 | ((sr & 0x100000) >> 10) | 184 | ((sr & 0x010000) >> 7) | 185 | ((sr & 0x002000) >> 5) | 186 | ((sr & 0x000800) >> 4) | 187 | ((sr & 0x000080) >> 1) | 188 | ((sr & 0x000010) << 1) | 189 | ((sr & 0x000004) << 2); 190 | output = CCetoneSynth::Int2FloatTab2[onow << 4]; 191 | break; 192 | case OWAVE_SINE: 193 | onow = (this->IndexInt << 4) + (this->IndexFrac >> 12); 194 | out0 = CCetoneSynth::SineTable[onow]; 195 | out1 = CCetoneSynth::SineTable[(onow + 1) & 65535]; 196 | output = (1.f - interpolate) * out0 + interpolate * out1; 197 | break; 198 | } 199 | 200 | this->IndexFrac += this->StepFrac; 201 | 202 | if (this->IndexFrac > 65535) 203 | { 204 | this->IndexFrac &= 65535; 205 | this->IndexInt++; 206 | } 207 | 208 | this->IndexInt += this->StepInt; 209 | 210 | if((this->IndexInt >> 12) != 0) 211 | { 212 | int bit0 = ((sr >> 22) ^ (sr >> 17)) & 0x1; 213 | sr <<= 1; 214 | sr &= 0x7fffff; 215 | sr |= bit0; 216 | this->ShiftRegister = sr; 217 | } 218 | 219 | this->IndexInt &= WAVETABLE_MASK; 220 | return output; 221 | } -------------------------------------------------------------------------------- /cetonesynth2/filter.cpp: -------------------------------------------------------------------------------- 1 | #include "filter.h" 2 | #include "statics.h" 3 | #include 4 | 5 | Filter::Filter() 6 | { 7 | this->Reset(); 8 | 9 | this->SetSampleRate(44100); 10 | this->SetMode(FILTM_12DB); 11 | this->SetType(FILTT_LP); 12 | this->Set(1.0f, 0.0f); 13 | this->SetGain(1.0f); 14 | } 15 | 16 | Filter::~Filter() 17 | { 18 | } 19 | 20 | void Filter::Reset() 21 | { 22 | this->lastIn = this->lastIn2 = 0.0; 23 | for(int i = 0; i < 6; i++) 24 | { 25 | this->buffer0[i] = 0.0; 26 | this->buffer1[i] = 0.0; 27 | this->buffer2[i] = 0.0; 28 | } 29 | } 30 | 31 | void Filter::SetMode(int mode) 32 | { 33 | #ifdef FILTER_INLINE 34 | this->modus = mode; 35 | #else 36 | if(mode) 37 | this->Process = &Filter::Process24; 38 | else 39 | this->Process = &Filter::Process12; 40 | #endif 41 | } 42 | 43 | void Filter::SetType(int type) 44 | { 45 | if(type != this->type) 46 | { 47 | this->Reset(); 48 | this->type = type; 49 | } 50 | } 51 | 52 | void Filter::SetSampleRate(float fs) 53 | { 54 | double omega = PId * BPCO / (double)(fs * 0.5f); 55 | double cs = cos(omega); 56 | double sn = sin(omega); 57 | 58 | double a0 = 1.0 + sn; 59 | this->b0b = sn / a0; 60 | this->b1b = 0.0; 61 | this->b2b = -this->b0b; 62 | this->a1b = (2.0 * cs) / a0; 63 | this->a2b = (sn - 1.0) / a0; 64 | 65 | this->Reset(); 66 | } 67 | 68 | // Oversampled, 24dB 69 | /* 70 | Well, my first aproach using standard biquads just sounded ... sounded ... 71 | hmm ... well, no-good. This one is much more CPU consuming (5 biquad sections) 72 | but sounds really nice. 73 | A Neotec-filter ... my own ... no other filter sounds like this^^ 74 | */ 75 | 76 | #ifndef FILTER_INLINE 77 | float Filter::Process24(float _inputout) 78 | { 79 | double inputout = (double)_inputout; 80 | this->buffer2[2] = this->buffer2[1]; 81 | this->buffer2[1] = this->buffer2[0]; 82 | this->buffer2[0] = inputout; 83 | this->buffer2[5] = this->buffer2[4]; 84 | this->buffer2[4] = this->buffer2[3]; 85 | this->buffer2[3] = 86 | this->b0b * this->buffer2[0] 87 | + this->b1b * this->buffer2[1] 88 | + this->b2b * this->buffer2[2] 89 | + this->a1b * this->buffer2[4] 90 | + this->a2b * this->buffer2[5] + DENORM_CONST; 91 | 92 | inputout = DRY * inputout + WET * this->buffer2[3]; 93 | 94 | this->buffer0[2] = this->buffer0[1]; 95 | this->buffer0[1] = this->buffer0[0]; 96 | this->buffer0[0] = (this->lastIn + inputout) * 0.5; 97 | this->buffer0[5] = this->buffer0[4]; 98 | this->buffer0[4] = this->buffer0[3]; 99 | this->buffer0[3] = 100 | this->b0 * this->buffer0[0] 101 | + this->b1 * this->buffer0[1] 102 | + this->b2 * this->buffer0[2] 103 | + this->a1 * this->buffer0[4] 104 | + this->a2 * this->buffer0[5] + DENORM_CONST; 105 | 106 | this->buffer0[2] = this->buffer0[1]; 107 | this->buffer0[1] = this->buffer0[0]; 108 | this->lastIn = this->buffer0[0] = inputout; 109 | this->buffer0[5] = this->buffer0[4]; 110 | this->buffer0[4] = this->buffer0[3]; 111 | this->buffer0[3] = 112 | this->b0 * this->buffer0[0] 113 | + this->b1 * this->buffer0[1] 114 | + this->b2 * this->buffer0[2] 115 | + this->a1 * this->buffer0[4] 116 | + this->a2 * this->buffer0[5] + DENORM_CONST; 117 | 118 | this->buffer1[2] = this->buffer1[1]; 119 | this->buffer1[1] = this->buffer1[0]; 120 | this->buffer1[0] = (this->lastIn2 + this->buffer0[3]) * 0.5; 121 | this->buffer1[5] = this->buffer1[4]; 122 | this->buffer1[4] = this->buffer1[3]; 123 | this->buffer1[3] = 124 | this->b0 * this->buffer1[0] 125 | + this->b1 * this->buffer1[1] 126 | + this->b2 * this->buffer1[2] 127 | + this->a1 * this->buffer1[4] 128 | + this->a2 * this->buffer1[5] + DENORM_CONST; 129 | 130 | this->buffer1[2] = this->buffer1[1]; 131 | this->buffer1[1] = this->buffer1[0]; 132 | this->lastIn2 = this->buffer1[0] = this->buffer0[3]; 133 | this->buffer1[5] = this->buffer1[4]; 134 | this->buffer1[4] = this->buffer1[3]; 135 | this->buffer1[3] = 136 | this->b0 * this->buffer1[0] 137 | + this->b1 * this->buffer1[1] 138 | + this->b2 * this->buffer1[2] 139 | + this->a1 * this->buffer1[4] 140 | + this->a2 * this->buffer1[5] + DENORM_CONST; 141 | 142 | if(this->buffer1[3] > 15.0) 143 | this->Reset(); 144 | 145 | return ntanh((float)this->buffer1[3] * this->gain); 146 | } 147 | 148 | float Filter::Process12(float _inputout) 149 | { 150 | double inputout = (double)_inputout; 151 | this->buffer2[2] = this->buffer2[1]; 152 | this->buffer2[1] = this->buffer2[0]; 153 | this->buffer2[0] = inputout; 154 | this->buffer2[5] = this->buffer2[4]; 155 | this->buffer2[4] = this->buffer2[3]; 156 | this->buffer2[3] = 157 | this->b0b * this->buffer2[0] 158 | + this->b1b * this->buffer2[1] 159 | + this->b2b * this->buffer2[2] 160 | + this->a1b * this->buffer2[4] 161 | + this->a2b * this->buffer2[5] + DENORM_CONST; 162 | 163 | inputout = DRY * inputout + WET * this->buffer2[3]; 164 | 165 | this->buffer0[2] = this->buffer0[1]; 166 | this->buffer0[1] = this->buffer0[0]; 167 | this->buffer0[0] = (this->lastIn + inputout) * 0.5; 168 | this->buffer0[5] = this->buffer0[4]; 169 | this->buffer0[4] = this->buffer0[3]; 170 | this->buffer0[3] = 171 | this->b0 * this->buffer0[0] 172 | + this->b1 * this->buffer0[1] 173 | + this->b2 * this->buffer0[2] 174 | + this->a1 * this->buffer0[4] 175 | + this->a2 * this->buffer0[5] + DENORM_CONST; 176 | 177 | this->buffer0[2] = this->buffer0[1]; 178 | this->buffer0[1] = this->buffer0[0]; 179 | this->lastIn = this->buffer0[0] = inputout; 180 | this->buffer0[5] = this->buffer0[4]; 181 | this->buffer0[4] = this->buffer0[3]; 182 | this->buffer0[3] = 183 | this->b0 * this->buffer0[0] 184 | + this->b1 * this->buffer0[1] 185 | + this->b2 * this->buffer0[2] 186 | + this->a1 * this->buffer0[4] 187 | + this->a2 * this->buffer0[5] + DENORM_CONST; 188 | 189 | if(this->buffer0[3] > 15.0) 190 | this->Reset(); 191 | 192 | return ntanh((float)this->buffer0[3] * this->gain); 193 | } 194 | #endif 195 | -------------------------------------------------------------------------------- /cetonesynthlight/SynthEnvelope.cpp: -------------------------------------------------------------------------------- 1 | #include "defines.h" 2 | 3 | #include "CetoneSynth.h" 4 | #include "SynthEnvelope.h" 5 | 6 | CSynthEnvelope::CSynthEnvelope(void) 7 | { 8 | this->Reset(); 9 | 10 | this->SetPreAttack(0.015f); 11 | this->Set(0.01f, 0.f, 0.25f, 0.5f, 0.4f); 12 | } 13 | 14 | CSynthEnvelope::~CSynthEnvelope(void) 15 | { 16 | this->LastPhase = -1; 17 | this->Phase = -1; 18 | this->VolNow = 0.f; 19 | } 20 | 21 | void CSynthEnvelope::Reset() 22 | { 23 | this->LastPhase = -1; 24 | this->Phase = -1; 25 | this->VolNow = 0.f; 26 | } 27 | 28 | void CSynthEnvelope::Gate(bool gate) 29 | { 30 | if (gate) 31 | { 32 | this->LastPhase = -1; 33 | 34 | #if ANALOGUE_ENVELOPES != 0 35 | #pragma message("SynthEnvelope: Analogue mode") 36 | this->Phase = 0; 37 | #else 38 | #pragma message("SynthEnvelope: Digital mode") 39 | if (this->Phase == -1) 40 | this->Phase = 0; 41 | else 42 | this->Phase = 5; 43 | #endif 44 | } 45 | else 46 | { 47 | this->LastPhase = -1; 48 | this->Phase = 4; 49 | } 50 | } 51 | 52 | float CSynthEnvelope::TimeValue(float val) 53 | { 54 | if(val <= 8.f) 55 | return val; 56 | else 57 | return val * 26.f - 200.f; 58 | } 59 | 60 | void CSynthEnvelope::Set(float a, float h, float d, float s, float r) 61 | { 62 | if(a < 0.005f) 63 | a = 0.005f; 64 | 65 | if(d < 0.005f) 66 | d = 0.005f; 67 | 68 | if(r < 0.005f) 69 | r = 0.005f; 70 | 71 | this->Attack = this->TimeValue(a); 72 | this->sAttack = truncate(a * CCetoneSynth::SampleRate + 0.5f); 73 | this->sAttackf = (float)this->sAttack; 74 | 75 | this->Hold = this->TimeValue(h); 76 | this->sHold = truncate(h * CCetoneSynth::SampleRate + 0.5f); 77 | this->sHoldf = (float)this->sHold; 78 | 79 | this->Decay = this->TimeValue(d); 80 | this->sDecay = truncate(d * CCetoneSynth::SampleRate + 0.5f); 81 | this->sDecayf = (float)this->sDecay; 82 | 83 | this->Sustain = s; 84 | 85 | this->Release = this->TimeValue(r); 86 | this->sRelease = truncate(r * CCetoneSynth::SampleRate + 0.5f); 87 | this->sReleasef = (float)this->sRelease; 88 | } 89 | 90 | void CSynthEnvelope::SetPreAttack(float val) 91 | { 92 | this->PreAttack = val; 93 | this->sPreAttack = truncate(val * CCetoneSynth::SampleRate + 0.5f); 94 | this->sPreAttackf = (float)this->sPreAttack; 95 | } 96 | 97 | float CSynthEnvelope::GetAttack() 98 | { 99 | return this->Attack; 100 | } 101 | 102 | float CSynthEnvelope::GetHold() 103 | { 104 | return this->Hold; 105 | } 106 | 107 | float CSynthEnvelope::GetDecay() 108 | { 109 | return this->Decay; 110 | } 111 | 112 | float CSynthEnvelope::GetSustain() 113 | { 114 | return this->Sustain; 115 | } 116 | 117 | float CSynthEnvelope::GetRelease() 118 | { 119 | return this->Release; 120 | } 121 | 122 | float CSynthEnvelope::Run() 123 | { 124 | float vol = this->VolNow; 125 | 126 | switch (this->Phase) 127 | { 128 | case 0: 129 | if (this->LastPhase != 0) 130 | { 131 | this->LastPhase = 0; 132 | 133 | if (this->sAttack != 0) 134 | this->VolStep = 1.f / this->sAttackf; 135 | else 136 | { 137 | vol = 1.f; 138 | this->Phase = 1; 139 | break; 140 | } 141 | } 142 | 143 | vol += this->VolStep; 144 | 145 | if(vol >= 1.f) 146 | { 147 | vol = 1.f; 148 | this->Phase = 1; 149 | } 150 | break; 151 | case 1: 152 | if (this->LastPhase != 1) 153 | { 154 | this->LastPhase = 1; 155 | this->Samples = this->sHold; 156 | this->Counter = 0; 157 | } 158 | 159 | vol = 1.f; 160 | this->Counter++; 161 | 162 | if (this->Counter >= this->Samples) 163 | this->Phase = 2; 164 | break; 165 | case 2: 166 | if (this->LastPhase != 2) 167 | { 168 | this->LastPhase = 2; 169 | 170 | if (this->sDecay != 0) 171 | #if ANALOGUE_ENVELOPES != 0 172 | this->VolStep = 1.f / this->sDecayf; 173 | #else 174 | this->VolStep = (1.f - this->Sustain) / this->sDecayf; 175 | #endif 176 | else 177 | { 178 | vol = this->Sustain; 179 | this->Phase = 3; 180 | break; 181 | } 182 | } 183 | 184 | vol -= this->VolStep; 185 | 186 | if (vol <= this->Sustain) 187 | { 188 | vol = this->Sustain; 189 | this->Phase = 3; 190 | } 191 | break; 192 | case 3: 193 | vol = (float)this->Sustain; 194 | break; 195 | case 4: 196 | if (this->LastPhase != 4) 197 | { 198 | this->LastPhase = 4; 199 | 200 | if (this->sRelease != 0) 201 | #if ANALOGUE_ENVELOPES != 0 202 | this->VolStep = 1.f / this->sReleasef; 203 | #else 204 | this->VolStep = this->VolNow / this->sReleasef; 205 | #endif 206 | else 207 | { 208 | vol = 0.f; 209 | this->Phase = -1; 210 | break; 211 | } 212 | } 213 | 214 | vol -= this->VolStep; 215 | 216 | if(vol <= 0.f) 217 | { 218 | vol = 0.f; 219 | this->Phase = -1; 220 | } 221 | break; 222 | #if ANALOGUE_ENVELOPES == 0 223 | case 5: 224 | if (this->LastPhase != 5) 225 | { 226 | this->LastPhase = 5; 227 | 228 | if (this->sPreAttack != 0) 229 | this->VolStep = this->VolNow / this->sPreAttackf; 230 | else 231 | { 232 | vol = 0.f; 233 | this->Phase = 0; 234 | break; 235 | } 236 | } 237 | 238 | vol -= this->VolStep; 239 | 240 | if(vol <= 0.f) 241 | { 242 | vol = 0.f; 243 | this->Phase = 0; 244 | } 245 | break; 246 | #endif 247 | default: 248 | vol = 0.f; 249 | break; 250 | } 251 | 252 | this->VolNow = vol; 253 | 254 | return vol; 255 | } 256 | -------------------------------------------------------------------------------- /cetoneorg/Synth.cpp: -------------------------------------------------------------------------------- 1 | #include "Synth.h" 2 | #include "data.h" 3 | #include 4 | #include 5 | #include 6 | 7 | Synth::Synth() 8 | { 9 | int i; 10 | for(i = 0; i < 89; i++) 11 | { 12 | this->Wheels[i] = new ToneWheel(g_rotors[i * 3], g_rotors[i * 3 + 1], g_rotors[i * 3 + 2]); 13 | this->Wheels[i]->setWave(g_sine + 127 * SINE_SIZE * 3 + SINE_SIZE); 14 | } 15 | 16 | this->_LFO = new LFO(); 17 | this->_Chorus = new Chorus(); 18 | this->_Reverb = new Reverb(); 19 | this->isChorus = 0; 20 | this->isReverb = 0; 21 | this->iBlockSize = 0; 22 | this->fLeft = this->fRight = this->mixBuf = this->lfo1 = this->lfo2 = 0; 23 | this->vibrato = 0; 24 | this->VibDepth = 0.0f; 25 | this->PanDepth = 0.0f; 26 | this->Chorus_dry = 1.0f; 27 | this->Chorus_wet = 0.0f; 28 | this->Volume = 0.2f; 29 | this->OutVol = 0.5f; 30 | 31 | this->volumes[0] = 0.5f; 32 | this->volumes[1] = 0.5f; 33 | this->volumes[2] = 0.5f; 34 | this->volumes[3] = 0.5f; 35 | this->volumes[4] = 0.5f; 36 | this->volumes[5] = 0.5f; 37 | this->volumes[6] = 0.5f; 38 | this->volumes[7] = 0.5f; 39 | this->volumes[8] = 0.5f; 40 | 41 | this->Reset(); 42 | } 43 | 44 | Synth::~Synth() 45 | { 46 | int i; 47 | for(i = 0; i < 89; i++) 48 | delete this->Wheels[i]; 49 | 50 | delete this->_LFO; 51 | delete this->_Chorus; 52 | delete this->_Reverb; 53 | 54 | if(this->fLeft) free(this->fLeft); 55 | if(this->fRight) free(this->fRight); 56 | if(this->mixBuf) free(this->mixBuf); 57 | if(this->lfo1) free(this->lfo1); 58 | if(this->lfo2) free(this->lfo2); 59 | if(this->vibrato) free(this->vibrato); 60 | } 61 | 62 | void Synth::setSampleRate(float fs) 63 | { 64 | int i; 65 | for(i = 0; i < 89; i++) 66 | this->Wheels[i]->setSampleRate(fs); 67 | this->FS = fs; 68 | 69 | float omega = 2.0f * PI * 2900.0f / fs; 70 | float cs = cosf(omega); 71 | float sn = sinf(omega); 72 | float a0 = 1.0f / (1.0f + sn); 73 | 74 | this->b2 = this->b0 = (1.0f - cs) * (0.5f * a0); 75 | this->b1 = (1.0f - cs) * a0; 76 | this->a1 = (2.0f * cs) * a0; 77 | this->a2 = (sn - 1.0f) * a0; 78 | 79 | this->_Chorus->setSampleRate(fs); 80 | this->_LFO->setSampleRate(fs); 81 | this->_Reverb->setSampleRate(fs); 82 | } 83 | 84 | void Synth::setBlockSize(int size) 85 | { 86 | if(size > this->iBlockSize) 87 | { 88 | if(this->fLeft != 0) 89 | { 90 | this->fLeft = (float*)realloc(this->fLeft, sizeof(float) * size); 91 | this->fRight = (float*)realloc(this->fLeft, sizeof(float) * size); 92 | this->mixBuf = (float*)realloc(this->mixBuf, sizeof(float) * size); 93 | this->lfo1 = (float*)realloc(this->lfo1, sizeof(float) * size); 94 | this->lfo2 = (float*)realloc(this->lfo2, sizeof(float) * size); 95 | this->vibrato = (int*)realloc(this->vibrato, sizeof(int) * size); 96 | } 97 | else 98 | { 99 | this->fLeft = (float*)malloc(sizeof(float) * size); 100 | this->fRight = (float*)malloc(sizeof(float) * size); 101 | this->mixBuf = (float*)malloc(sizeof(float) * size); 102 | this->lfo1 = (float*)malloc(sizeof(float) * size); 103 | this->lfo2 = (float*)malloc(sizeof(float) * size); 104 | this->vibrato = (int*)malloc(sizeof(int) * size); 105 | } 106 | this->iBlockSize = size; 107 | } 108 | } 109 | 110 | void Synth::InitRender() 111 | { 112 | memset(this->mixBuf, 0, this->iBlockSize * sizeof(float)); 113 | this->iFramePos = 0; 114 | } 115 | 116 | void Synth::FinishRender(int samples) 117 | { 118 | int i; 119 | for(i = 0; i < samples; i++) 120 | { 121 | float v = tanhf(this->mixBuf[i] * this->Volume); 122 | float pan = this->lfo2[i] * this->PanDepth + 0.5f; 123 | this->fLeft[i] = v * sqrtf(1.0f - pan); 124 | this->fRight[i] = v * sqrtf(pan); 125 | } 126 | 127 | if(this->isChorus) 128 | this->_Chorus->Render(this->fLeft, this->fRight, samples, this->Chorus_dry, this->Chorus_wet); 129 | 130 | if(this->isReverb) 131 | this->_Reverb->Render(this->fLeft, this->fRight, samples); 132 | 133 | for(i = 0; i < samples; i++) 134 | { 135 | this->buffer[2] = this->buffer[1]; 136 | this->buffer[1] = this->buffer[0]; 137 | this->buffer[0] = this->fLeft[i]; 138 | this->buffer[5] = this->buffer[4]; 139 | this->buffer[4] = this->buffer[3]; 140 | this->buffer[3] = 141 | this->b0 * this->buffer[0] 142 | + this->b1 * this->buffer[1] 143 | + this->b2 * this->buffer[2] 144 | + this->a1 * this->buffer[4] 145 | + this->a2 * this->buffer[5]; 146 | 147 | UNDENORM(this->buffer[3]); 148 | this->fLeft[i] = this->buffer[3] * this->OutVol; 149 | 150 | this->buffer1[2] = this->buffer1[1]; 151 | this->buffer1[1] = this->buffer1[0]; 152 | this->buffer1[0] = this->fRight[i]; 153 | this->buffer1[5] = this->buffer1[4]; 154 | this->buffer1[4] = this->buffer1[3]; 155 | this->buffer1[3] = 156 | this->b0 * this->buffer1[0] 157 | + this->b1 * this->buffer1[1] 158 | + this->b2 * this->buffer1[2] 159 | + this->a1 * this->buffer1[4] 160 | + this->a2 * this->buffer1[5]; 161 | 162 | UNDENORM(this->buffer1[3]); 163 | this->fRight[i] = this->buffer1[3] * this->OutVol; 164 | } 165 | } 166 | 167 | void Synth::NoteOn(int note, int vel) 168 | { 169 | int i; 170 | float v = ((float)(127 - vel) * 0.00003f + 0.00008f) * this->FS; 171 | for(i = 0; i < 9; i++) 172 | this->Wheels[g_generators[note].offset[i]]->NoteOn(note, this->volumes[i], truncate(v * (float)i)); 173 | } 174 | 175 | void Synth::NoteOff(int note) 176 | { 177 | int i; 178 | for(i = 0; i < 9; i++) 179 | this->Wheels[g_generators[note].offset[i]]->NoteOff(note); 180 | } 181 | 182 | void Synth::Render(int frames) 183 | { 184 | int i; 185 | float* l = this->mixBuf + this->iFramePos; 186 | float* l1 = this->lfo1 + this->iFramePos; 187 | float* l2 = this->lfo2 + this->iFramePos; 188 | int* vib = this->vibrato + this->iFramePos; 189 | 190 | this->_LFO->Render(l1, l2, frames); 191 | 192 | for(i = 0; i < frames; i++) 193 | vib[i] = truncate((l1[i] * this->VibDepth) * 65536.0f); 194 | 195 | for(i = 0; i < 89; i++) 196 | this->Wheels[i]->Render(l, frames, vib); 197 | 198 | this->iFramePos += frames; 199 | } 200 | -------------------------------------------------------------------------------- /cetonesynthlight/CetoneSynth.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma warning (disable: 4996) 3 | 4 | #include "audioeffectx.h" 5 | 6 | #include "defines.h" 7 | #include "structures.h" 8 | #include "globalfunctions.h" 9 | 10 | #include "synthoscillator.h" 11 | #include "synthenvelope.h" 12 | #include "synthlfo.h" 13 | 14 | #include "filtermoog.h" 15 | #include "filtermoog2.h" 16 | #include "filterdirty.h" 17 | #include "filterch12db.h" 18 | #include "filter303.h" 19 | #include "filter8580.h" 20 | #include "filterbiquad.h" 21 | #include "midistack.h" 22 | 23 | class CCetoneSynth : public AudioEffectX 24 | { 25 | public: 26 | CCetoneSynth(audioMasterCallback audioMaster); 27 | ~CCetoneSynth(void); 28 | 29 | // Plugin interface 30 | 31 | virtual void resume(); 32 | 33 | virtual VstInt32 processEvents(VstEvents* events); 34 | virtual void process(float **inputs, float **outputs, VstInt32 sampleFrames); 35 | virtual void processReplacing(float** inputs, float** outputs, VstInt32 sampleFrames); 36 | 37 | virtual VstInt32 getChunk(void** data, bool isPreset = false); 38 | virtual VstInt32 setChunk(void* data, VstInt32 byteSize, bool isPreset = false); 39 | 40 | virtual void setProgram(VstInt32 program); 41 | virtual VstInt32 getProgram(); 42 | virtual void setProgramName(char* name); 43 | virtual void getProgramName(char* name); 44 | virtual bool getProgramNameIndexed(VstInt32 category, VstInt32 index, char* text); 45 | 46 | virtual VstInt32 getNumMidiInputChannels(); 47 | virtual VstInt32 getNumMidiOutputChannels(); 48 | 49 | virtual void setSampleRate (float sampleRate); 50 | virtual void setBlockSize (VstInt32 blockSize); 51 | 52 | virtual VstInt32 getVendorVersion (); 53 | virtual bool getEffectName(char* name); 54 | virtual bool getVendorString(char* text); 55 | virtual bool getProductString(char* text); 56 | 57 | virtual VstInt32 canDo(char* text); 58 | 59 | virtual void setParameter(VstInt32 index, float value); 60 | virtual float getParameter(VstInt32 index); 61 | virtual void getParameterLabel(VstInt32 index, char* label); 62 | virtual void getParameterDisplay(VstInt32 index, char* text); 63 | virtual void getParameterName(VstInt32 index, char* text); 64 | 65 | // Public statics 66 | 67 | static float SineTable[65536]; 68 | static float SmallSineTable[WAVETABLE_LENGTH]; 69 | static float FreqTable[PITCH_MAX]; 70 | static int FreqTableInt[PITCH_MAX]; 71 | 72 | static int LookupTable[65536]; 73 | static float SawTable[NOTE_MAX * WAVETABLE_LENGTH]; 74 | static float ParabolaTable[NOTE_MAX * WAVETABLE_LENGTH]; 75 | static int FreqStepInt[PITCH_MAX]; 76 | static int FreqStepFrac[PITCH_MAX]; 77 | 78 | static float Pw2Float[4096]; 79 | static int Pw2Offset[4096]; 80 | static float Pw2WaveOffset[4096]; 81 | 82 | static float Int2FloatTab[65536]; 83 | static float Int2FloatTab2[65536]; 84 | 85 | static float SampleRate; 86 | static float SampleRate2; 87 | static float SampleRate_1; 88 | static float SampleRate2_1; 89 | static float SampleRatePi; 90 | static float Pi; 91 | static int C64Arps[8][16]; 92 | 93 | private: 94 | 95 | // Classes 96 | 97 | CSynthOscillator* Oscs[3]; 98 | CSynthEnvelope* Envs[2]; 99 | CSynthLfo* Lfo; 100 | 101 | CMidiStack* MidiStack; 102 | CFilterDirty* FilterDirty; 103 | CFilterMoog* FilterMoog; 104 | CFilterMoog2* FilterMoog2; 105 | CFilterCh12db* FilterCh12db; 106 | CFilter303* Filter303; 107 | CFilter8580* Filter8580; 108 | CFilterBiquad* FilterBiquad; 109 | 110 | // Variables 111 | 112 | SynthProgram Programs[129]; 113 | 114 | // Program variables 115 | 116 | float Volume; 117 | float Panning; 118 | 119 | int MainCoarse; 120 | int MainFine; 121 | 122 | int FilterType; 123 | int FilterMode; 124 | float Cutoff; 125 | float Resonance; 126 | 127 | int ArpMode; 128 | int ArpSpeed; 129 | 130 | bool PortaMode; 131 | float PortaSpeed; 132 | 133 | SynthVoice Voice[3]; 134 | 135 | float EnvAttack[2]; 136 | float EnvHold[2]; 137 | float EnvDecay[2]; 138 | float EnvSustain[2]; 139 | float EnvRelease[2]; 140 | 141 | float LfoSpeed; 142 | int LfoWave; 143 | int LfoPw; 144 | bool LfoTrigger; 145 | 146 | SynthModulation Modulations[4]; 147 | 148 | float EnvMod; 149 | 150 | // Runtime variables 151 | 152 | float ModChangeSamples; 153 | 154 | int CurrentNote; 155 | int CurrentVelocity; 156 | int CurrentDelta; 157 | int CurrentCtrl1; 158 | int CurrentProgram; 159 | 160 | float VelocityMod; 161 | float Ctrl1Mod; 162 | 163 | float VelocityModStep; 164 | float Ctrl1ModStep; 165 | 166 | float VelocityModEnd; 167 | float Ctrl1ModEnd; 168 | 169 | int LastP0; 170 | int NextP0; 171 | int NextP1; 172 | int NextP2; 173 | 174 | int FilterCounter; 175 | 176 | int ArpPos; 177 | int ArpDelay; 178 | int ArpCounter; 179 | 180 | int CurrentPitch; 181 | int PortaStep; 182 | int PortaPitch; 183 | int PortaFrac; 184 | float PortaSamples; 185 | bool DoPorta; 186 | 187 | float CutoffDest; 188 | float CutoffStep; 189 | 190 | int VoicePulsewidth[3]; 191 | 192 | float LfoPitch; 193 | 194 | // Init functions 195 | 196 | void InitSineTable(); 197 | void InitFreqTable(); 198 | void InitParameters(); 199 | 200 | // Programs 201 | 202 | void ReadProgram(int prg); 203 | void WriteProgram(int prg); 204 | 205 | // Synthesizer functions (CetoneSynthMain.cpp) 206 | 207 | void SynthProcess(float **inputs, float **outputs, VstInt32 sampleFrames, bool replace); 208 | void HandleMidi(int p0, int p1, int p2); 209 | 210 | void NoteOn(int note, int vel); 211 | void NoteOff(int note, int vel); 212 | 213 | void UpdateFilters(); 214 | void UpdateFilters(float cutoff, float q, float mode); 215 | void SetFilterMode(int mode); 216 | 217 | void SetArpSpeed(int ms); 218 | void SetPortaSpeed(float speed); 219 | void UpdateEnvelopes(); 220 | void SetCutoffSave(float value); 221 | }; 222 | -------------------------------------------------------------------------------- /cetonesynth/CetoneSynth.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma warning (disable: 4996) 3 | 4 | #include "audioeffectx.h" 5 | 6 | #include "defines.h" 7 | #include "structures.h" 8 | #include "globalfunctions.h" 9 | 10 | #include "synthoscillator.h" 11 | #include "synthenvelope.h" 12 | #include "synthlfo.h" 13 | 14 | #include "filtermoog.h" 15 | #include "filtermoog2.h" 16 | #include "filterdirty.h" 17 | #include "filterch12db.h" 18 | #include "filter303.h" 19 | #include "filter8580.h" 20 | #include "filterbutterworth24db.h" 21 | #include "midistack.h" 22 | 23 | class CCetoneSynth : public AudioEffectX 24 | { 25 | public: 26 | CCetoneSynth(audioMasterCallback audioMaster); 27 | ~CCetoneSynth(void); 28 | 29 | // Plugin interface 30 | 31 | virtual void resume(); 32 | 33 | virtual VstInt32 processEvents(VstEvents* events); 34 | virtual void process(float **inputs, float **outputs, VstInt32 sampleFrames); 35 | virtual void processReplacing(float** inputs, float** outputs, VstInt32 sampleFrames); 36 | 37 | virtual VstInt32 getChunk(void** data, bool isPreset = false); 38 | virtual VstInt32 setChunk(void* data, VstInt32 byteSize, bool isPreset = false); 39 | 40 | virtual void setProgram(VstInt32 program); 41 | virtual VstInt32 getProgram(); 42 | virtual void setProgramName(char* name); 43 | virtual void getProgramName(char* name); 44 | virtual bool getProgramNameIndexed(VstInt32 category, VstInt32 index, char* text); 45 | 46 | virtual VstInt32 getNumMidiInputChannels(); 47 | virtual VstInt32 getNumMidiOutputChannels(); 48 | 49 | virtual void setSampleRate (float sampleRate); 50 | virtual void setBlockSize (VstInt32 blockSize); 51 | 52 | virtual VstInt32 getVendorVersion (); 53 | virtual bool getEffectName(char* name); 54 | virtual bool getVendorString(char* text); 55 | virtual bool getProductString(char* text); 56 | 57 | virtual VstInt32 canDo(char* text); 58 | 59 | virtual void setParameter(VstInt32 index, float value); 60 | virtual float getParameter(VstInt32 index); 61 | virtual void getParameterLabel(VstInt32 index, char* label); 62 | virtual void getParameterDisplay(VstInt32 index, char* text); 63 | virtual void getParameterName(VstInt32 index, char* text); 64 | 65 | // Public statics 66 | 67 | static float SineTable[65536]; 68 | static float SmallSineTable[WAVETABLE_LENGTH]; 69 | static float FreqTable[PITCH_MAX]; 70 | static int FreqTableInt[PITCH_MAX]; 71 | 72 | static int LookupTable[65536]; 73 | static float SawTable[NOTE_MAX * WAVETABLE_LENGTH]; 74 | static float ParabolaTable[NOTE_MAX * WAVETABLE_LENGTH]; 75 | static int FreqStepInt[PITCH_MAX]; 76 | static int FreqStepFrac[PITCH_MAX]; 77 | 78 | static float Pw2Float[4096]; 79 | static int Pw2Offset[4096]; 80 | static float Pw2WaveOffset[4096]; 81 | 82 | static float Int2FloatTab[65536]; 83 | static float Int2FloatTab2[65536]; 84 | 85 | static float SampleRate; 86 | static float SampleRate2; 87 | static float SampleRate_1; 88 | static float SampleRate2_1; 89 | static float SampleRatePi; 90 | static float Pi; 91 | static int C64Arps[8][16]; 92 | 93 | private: 94 | 95 | // Classes 96 | 97 | CSynthOscillator* Oscs[4]; 98 | CSynthEnvelope* Envs[3]; 99 | CSynthLfo* Lfos[2]; 100 | 101 | CMidiStack* MidiStack; 102 | CFilterDirty* FilterDirty; 103 | CFilterMoog* FilterMoog; 104 | CFilterMoog2* FilterMoog2; 105 | CFilterCh12db* FilterCh12db; 106 | CFilter303* Filter303; 107 | CFilter8580* Filter8580; 108 | CFilterButterworth24db* FilterBuddawert; 109 | 110 | // Variables 111 | 112 | int MidiChannel; 113 | 114 | SynthProgram Programs[129]; 115 | 116 | // Program variables 117 | 118 | float Volume; 119 | float Panning; 120 | 121 | int MainCoarse; 122 | int MainFine; 123 | 124 | int FilterType; 125 | int FilterMode; 126 | float Cutoff; 127 | float Resonance; 128 | 129 | int ArpMode; 130 | int ArpSpeed; 131 | 132 | bool PortaMode; 133 | float PortaSpeed; 134 | 135 | SynthVoice Voice[4]; 136 | 137 | float EnvAttack[3]; 138 | float EnvHold[3]; 139 | float EnvDecay[3]; 140 | float EnvSustain[3]; 141 | float EnvRelease[3]; 142 | 143 | float LfoSpeed[2]; 144 | int LfoWave[2]; 145 | int LfoPw[2]; 146 | bool LfoTrigger[2]; 147 | 148 | SynthModulation Modulations[8]; 149 | 150 | float EnvMod; 151 | 152 | // Runtime variables 153 | 154 | float ModChangeSamples; 155 | 156 | int CurrentNote; 157 | int CurrentVelocity; 158 | int CurrentDelta; 159 | int CurrentCtrl1; 160 | int CurrentProgram; 161 | 162 | float VelocityMod; 163 | float Ctrl1Mod; 164 | 165 | float VelocityModStep; 166 | float Ctrl1ModStep; 167 | 168 | float VelocityModEnd; 169 | float Ctrl1ModEnd; 170 | 171 | int LastP0; 172 | int NextP0; 173 | int NextP1; 174 | int NextP2; 175 | 176 | int FilterCounter; 177 | 178 | int ArpPos; 179 | int ArpDelay; 180 | int ArpCounter; 181 | 182 | int CurrentPitch; 183 | int PortaStep; 184 | int PortaPitch; 185 | int PortaFrac; 186 | float PortaSamples; 187 | bool DoPorta; 188 | 189 | float CutoffDest; 190 | float CutoffStep; 191 | 192 | int VoicePulsewidth[4]; 193 | 194 | float LfoPitch[2]; 195 | 196 | // Init functions 197 | 198 | void InitSineTable(); 199 | void InitFreqTable(); 200 | void InitParameters(); 201 | 202 | // Programs 203 | 204 | void ReadProgram(int prg); 205 | void WriteProgram(int prg); 206 | 207 | // Synthesizer functions (CetoneSynthMain.cpp) 208 | 209 | void SynthProcess(float **inputs, float **outputs, VstInt32 sampleFrames, bool replace); 210 | void Run(float* left, float* right); 211 | void HandleMidi(int p0, int p1, int p2); 212 | 213 | void NoteOn(int note, int vel); 214 | void NoteOff(int note, int vel); 215 | 216 | void TriggerFilterCounter(); 217 | void UpdateFilters(); 218 | void UpdateFilters(float cutoff, float q, float mode); 219 | void SetFilterMode(int mode); 220 | 221 | void SetArpSpeed(int ms); 222 | void SetPortaSpeed(float speed); 223 | void UpdateEnvelopes(); 224 | void SetCutoffSave(float value); 225 | }; 226 | -------------------------------------------------------------------------------- /cetonesynthlight/SynthOscillator.cpp: -------------------------------------------------------------------------------- 1 | #include "CetoneSynth.h" 2 | #include "SynthOscillator.h" 3 | 4 | CSynthOscillator::CSynthOscillator(void) 5 | { 6 | this->SyncOsc = NULL; 7 | this->DoSync = false; 8 | 9 | #if NOTE_RANGE == 1 10 | this->SyncPitch = 7200; 11 | this->SetPitch(7200); 12 | #else 13 | this->SyncPitch = 8400; 14 | this->SetPitch(8400); 15 | #endif 16 | 17 | this->SetPw(32768); 18 | this->SetWave(OWAVE_SAW); 19 | 20 | this->Reset(); 21 | } 22 | 23 | CSynthOscillator::~CSynthOscillator(void) 24 | { 25 | } 26 | 27 | void CSynthOscillator::Reset() 28 | { 29 | this->Value = 0; 30 | this->ShiftRegister = 0x7ffff8; 31 | this->IndexInt = 0; 32 | this->IndexFrac = 0; 33 | this->WasPeriod = false; 34 | } 35 | 36 | void CSynthOscillator::Set(int pw, int wave, bool sync) 37 | { 38 | if(pw < 0) 39 | pw = 0; 40 | else if(pw > 65535) 41 | pw = 65535; 42 | 43 | this->PulseWidth = pw; 44 | 45 | pw >>= 4; 46 | 47 | this->PwFloat = CCetoneSynth::Pw2Float[pw]; 48 | this->PwOffset = CCetoneSynth::Pw2Offset[pw]; 49 | this->PwWaveOffset = CCetoneSynth::Pw2WaveOffset[pw]; 50 | 51 | if(wave < 0) 52 | wave = 0; 53 | else if(wave > OWAVE_MAX) 54 | wave = OWAVE_MAX; 55 | 56 | this->Waveform = wave; 57 | 58 | this->DoSync = sync; 59 | } 60 | 61 | void CSynthOscillator::SetPitch(int pitch) 62 | { 63 | if(pitch < 0) 64 | pitch = 0; 65 | else if(pitch > PITCH_MAX1) 66 | pitch = PITCH_MAX1; 67 | 68 | this->Pitch = pitch; 69 | 70 | if(this->SyncOsc != NULL) 71 | this->SyncOsc->SetSyncPitch(pitch); 72 | 73 | this->StepInt = CCetoneSynth::FreqStepInt[pitch]; 74 | this->StepFrac = CCetoneSynth::FreqStepFrac[pitch]; 75 | 76 | if(this->DoSync) 77 | { 78 | if(this->SyncPitch > this->Pitch) 79 | pitch = this->SyncPitch; 80 | } 81 | 82 | int t = CCetoneSynth::LookupTable[CCetoneSynth::FreqTableInt[pitch]] * WAVETABLE_LENGTH; 83 | 84 | this->SawPtr = &(CCetoneSynth::SawTable[t]); 85 | this->ParabolaPtr = &(CCetoneSynth::ParabolaTable[t]); 86 | } 87 | 88 | int CSynthOscillator::GetPitch() 89 | { 90 | return this->Pitch; 91 | } 92 | 93 | void CSynthOscillator::SetPw(int pw) 94 | { 95 | if(pw < 0) 96 | pw = 0; 97 | else if(pw > 65535) 98 | pw = 65535; 99 | 100 | this->PulseWidth = pw; 101 | 102 | pw >>= 4; 103 | 104 | this->PwFloat = CCetoneSynth::Pw2Float[pw]; 105 | this->PwOffset = CCetoneSynth::Pw2Offset[pw]; 106 | this->PwWaveOffset = CCetoneSynth::Pw2WaveOffset[pw]; 107 | } 108 | 109 | int CSynthOscillator::GetPw() 110 | { 111 | return this->PulseWidth; 112 | } 113 | 114 | void CSynthOscillator::SetWave(int wave) 115 | { 116 | if(wave < 0) 117 | wave = 0; 118 | else if(wave > OWAVE_MAX) 119 | wave = OWAVE_MAX; 120 | 121 | this->Waveform = wave; 122 | } 123 | 124 | int CSynthOscillator::GetWave() 125 | { 126 | return this->Waveform; 127 | } 128 | 129 | void CSynthOscillator::Sync() 130 | { 131 | if(this->DoSync) 132 | { 133 | this->IndexInt = 0; 134 | this->IndexFrac = 0; 135 | } 136 | } 137 | 138 | void CSynthOscillator::ProcessSync() 139 | { 140 | if(this->WasPeriod && (this->SyncOsc != NULL)) 141 | this->SyncOsc->Sync(); 142 | } 143 | 144 | void CSynthOscillator::SetSyncPitch(int pitch) 145 | { 146 | this->SyncPitch = pitch; 147 | } 148 | 149 | void CSynthOscillator::SetSync(bool sync) 150 | { 151 | this->DoSync = sync; 152 | } 153 | 154 | void CSynthOscillator::SetSyncDest(CSynthOscillator *osc) 155 | { 156 | this->SyncOsc = osc; 157 | } 158 | 159 | float CSynthOscillator::Run() 160 | { 161 | int sr = this->ShiftRegister; 162 | 163 | int sample0, sample1, onow; 164 | float interpolate, out0, out1; 165 | 166 | float output = 0.0; 167 | 168 | sample0 = this->IndexInt; 169 | sample1 = (sample0 + 1) & WAVETABLE_MASK; 170 | interpolate = CCetoneSynth::Int2FloatTab[this->IndexFrac]; 171 | 172 | switch (this->Waveform) 173 | { 174 | case OWAVE_SAW: 175 | out0 = this->SawPtr[sample0]; 176 | out1 = this->SawPtr[sample1]; 177 | output = (1.f - interpolate) * out0 + interpolate * out1; 178 | break; 179 | case OWAVE_PULSE: 180 | out0 = this->SawPtr[sample0]; 181 | out1 = this->SawPtr[sample1]; 182 | 183 | sample0 += this->PwOffset; 184 | sample1 += this->PwOffset; 185 | sample0 &= WAVETABLE_MASK; 186 | sample1 &= WAVETABLE_MASK; 187 | 188 | out0 -= this->SawPtr[sample0]; 189 | out1 -= this->SawPtr[sample1]; 190 | 191 | output = (1.f - interpolate) * out0 + interpolate * out1; 192 | output += this->PwWaveOffset; 193 | break; 194 | case OWAVE_TRI: 195 | out0 = this->ParabolaPtr[sample0]; 196 | out1 = this->ParabolaPtr[sample1]; 197 | 198 | sample0 += WAVETABLE_LENGTH2; 199 | sample1 += WAVETABLE_LENGTH2; 200 | sample0 &= WAVETABLE_MASK; 201 | sample1 &= WAVETABLE_MASK; 202 | 203 | out0 -= this->ParabolaPtr[sample0]; 204 | out1 -= this->ParabolaPtr[sample1]; 205 | 206 | output = (1.f - interpolate) * out0 + interpolate * out1; 207 | output *= 0.5f; 208 | break; 209 | case OWAVE_C64NOISE: 210 | onow = ((sr & 0x400000) >> 11) | 211 | ((sr & 0x100000) >> 10) | 212 | ((sr & 0x010000) >> 7) | 213 | ((sr & 0x002000) >> 5) | 214 | ((sr & 0x000800) >> 4) | 215 | ((sr & 0x000080) >> 1) | 216 | ((sr & 0x000010) << 1) | 217 | ((sr & 0x000004) << 2); 218 | output = CCetoneSynth::Int2FloatTab2[onow << 4]; 219 | break; 220 | case OWAVE_SINE: 221 | onow = (this->IndexInt << 4) + (this->IndexFrac >> 12); 222 | out0 = CCetoneSynth::SineTable[onow]; 223 | out1 = CCetoneSynth::SineTable[(onow + 1) & 65535]; 224 | output = (1.f - interpolate) * out0 + interpolate * out1; 225 | break; 226 | } 227 | 228 | this->IndexFrac += this->StepFrac; 229 | 230 | if (this->IndexFrac > 65535) 231 | { 232 | this->IndexFrac &= 65535; 233 | this->IndexInt++; 234 | } 235 | 236 | this->IndexInt += this->StepInt; 237 | 238 | if(this->IndexInt >= WAVETABLE_LENGTH) 239 | { 240 | int bit0 = ((sr >> 22) ^ (sr >> 17)) & 0x1; 241 | sr <<= 1; 242 | sr &= 0x7fffff; 243 | sr |= bit0; 244 | this->ShiftRegister = sr; 245 | this->IndexInt &= WAVETABLE_MASK; 246 | this->WasPeriod = true; 247 | } 248 | else 249 | this->WasPeriod = false; 250 | 251 | return output; 252 | } 253 | -------------------------------------------------------------------------------- /cetoneorg/reverb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "defines.h" 3 | #include "statics.h" 4 | #include 5 | #include 6 | 7 | #define FIXED_GAIN 0.015f 8 | #define SCALE_WET 2.0f 9 | #define SCALE_DAMP 0.4f 10 | #define SCALE_ROOM 0.28f 11 | #define OFFSET_ROOM 0.7f 12 | #define INITIAL_ROOM 0.5f 13 | #define INITIAL_DAMP 0.5f 14 | #define INITIAL_WET (0.5f / SCALE_WET) 15 | #define INITIAL_DRY 0.5f 16 | #define INITIAL_WIDTH 1.0f 17 | #define STEREO_SPREAD 23 18 | 19 | class CombFilter 20 | { 21 | public: 22 | CombFilter() 23 | { 24 | this->Reset(); 25 | } 26 | 27 | ~CombFilter() 28 | { 29 | } 30 | 31 | void Reset() 32 | { 33 | this->_History = 0.0f; 34 | memset(this->_Buffer, 0, 8192 * sizeof(float)); 35 | } 36 | 37 | void setSize(int size) 38 | { 39 | this->_Size = size; 40 | this->Reset(); 41 | } 42 | 43 | void setFeedback(float value) 44 | { 45 | this->_Feedback = value; 46 | } 47 | 48 | void setDamp(float value) 49 | { 50 | this->_Damp1 = value; 51 | this->_Damp2 = 1.0f - value; 52 | } 53 | 54 | __forceinline float Process(float input) 55 | { 56 | float output; 57 | 58 | output = this->_Buffer[this->_Pos]; 59 | 60 | this->_History = (output * this->_Damp2) + (this->_History * this->_Damp1); 61 | UNDENORM(this->_History); 62 | 63 | this->_Buffer[this->_Pos] = input + (this->_History * this->_Feedback); 64 | UNDENORM(this->_Buffer[this->_Pos]); 65 | 66 | this->_Pos = (this->_Pos + 1) % this->_Size; 67 | 68 | return output; 69 | } 70 | private: 71 | float _Buffer[8192]; 72 | int _Size; 73 | float _Damp1; 74 | float _Damp2; 75 | float _Feedback; 76 | int _Pos; 77 | float _History; 78 | }; 79 | 80 | class AllPassFilter 81 | { 82 | public: 83 | AllPassFilter() 84 | { 85 | this->Reset(); 86 | } 87 | 88 | ~AllPassFilter() 89 | { 90 | } 91 | 92 | void setSize(int size) 93 | { 94 | this->_Size = size; 95 | this->Reset(); 96 | } 97 | 98 | void Reset() 99 | { 100 | memset(this->_Buffer, 0, 3072 * sizeof(float)); 101 | } 102 | 103 | __forceinline float Process(float input) 104 | { 105 | float output, buf; 106 | 107 | buf = this->_Buffer[this->_Pos]; 108 | output = buf - input; 109 | 110 | this->_Buffer[this->_Pos] = input + (buf * 0.5f); 111 | UNDENORM(this->_Buffer[this->_Pos]); 112 | 113 | this->_Pos = (this->_Pos + 1) % this->_Size; 114 | 115 | return output; 116 | } 117 | private: 118 | float _Buffer[3072]; 119 | int _Size; 120 | int _Pos; 121 | }; 122 | 123 | class Reverb 124 | { 125 | public: 126 | Reverb() 127 | { 128 | int i; 129 | for(i = 0; i < 16; i++) 130 | { 131 | this->_combs[i] = new CombFilter(); 132 | if(i < 8) 133 | this->_alls[i] = new AllPassFilter(); 134 | } 135 | 136 | this->setWet(INITIAL_WET); 137 | this->setDry(INITIAL_DRY); 138 | this->setDamp(INITIAL_DAMP); 139 | this->setWidth(INITIAL_WIDTH); 140 | this->setRoomsize(INITIAL_ROOM); 141 | 142 | this->Update(); 143 | } 144 | 145 | ~Reverb() 146 | { 147 | int i; 148 | for(i = 0; i < 16; i++) 149 | { 150 | delete this->_combs[i]; 151 | if(i < 8) 152 | delete this->_alls[i]; 153 | } 154 | } 155 | 156 | void Reset() 157 | { 158 | int i; 159 | for(i = 0; i < 16; i++) 160 | { 161 | this->_combs[i]->Reset(); 162 | if(i < 8) 163 | this->_alls[i]->Reset(); 164 | } 165 | } 166 | 167 | void setDamp(float val) 168 | { 169 | this->_Damp = val * SCALE_DAMP; 170 | this->Update(); 171 | } 172 | 173 | void setRoomsize(float val) 174 | { 175 | this->_Roomsize = val * SCALE_ROOM + OFFSET_ROOM; 176 | this->Update(); 177 | } 178 | 179 | void setWet(float val) 180 | { 181 | this->_Wet = val * SCALE_WET; 182 | this->Update(); 183 | } 184 | 185 | void setDry(float val) 186 | { 187 | this->_Dry = val; 188 | } 189 | 190 | void setWidth(float val) 191 | { 192 | this->_Width = val; 193 | this->Update(); 194 | } 195 | 196 | void setSampleRate(float fs) 197 | { 198 | int i; 199 | float fac = fs / 44100.0f; 200 | for(i = 0; i < 8; i++) 201 | { 202 | this->_combs[i * 2]->setSize(truncate((float)g_comb_sizes[i] * fac)); 203 | this->_combs[i * 2 + 1]->setSize(truncate(((float)g_comb_sizes[i] + (float)STEREO_SPREAD) * fac)); 204 | } 205 | for(i = 0; i < 4; i++) 206 | { 207 | this->_alls[i * 2]->setSize(truncate((float)g_all_sizes[i] * fac)); 208 | this->_alls[i * 2 + 1]->setSize(truncate(((float)g_all_sizes[i] + (float)STEREO_SPREAD) * fac)); 209 | } 210 | } 211 | 212 | void Render(float *left, float* right, int samples) 213 | { 214 | float ol, or; 215 | int i; 216 | for(i = 0; i < samples; i++) 217 | { 218 | 219 | float input = (left[i] + right[i]) * FIXED_GAIN; 220 | 221 | ol = this->_combs[0]->Process(input) 222 | + this->_combs[2]->Process(input) 223 | + this->_combs[4]->Process(input) 224 | + this->_combs[6]->Process(input) 225 | + this->_combs[8]->Process(input) 226 | + this->_combs[10]->Process(input) 227 | + this->_combs[12]->Process(input) 228 | + this->_combs[14]->Process(input); 229 | 230 | or = this->_combs[1]->Process(input) 231 | + this->_combs[3]->Process(input) 232 | + this->_combs[5]->Process(input) 233 | + this->_combs[7]->Process(input) 234 | + this->_combs[9]->Process(input) 235 | + this->_combs[11]->Process(input) 236 | + this->_combs[13]->Process(input) 237 | + this->_combs[15]->Process(input); 238 | 239 | ol = this->_alls[0]->Process(ol); 240 | ol = this->_alls[2]->Process(ol); 241 | ol = this->_alls[4]->Process(ol); 242 | ol = this->_alls[6]->Process(ol); 243 | or = this->_alls[1]->Process(or); 244 | or = this->_alls[3]->Process(or); 245 | or = this->_alls[5]->Process(or); 246 | or = this->_alls[7]->Process(or); 247 | 248 | left[i] = ol * this->_Wet1 + or * this->_Wet2 + left[i] * this->_Dry; 249 | right[i] = or * this->_Wet1 + ol * this->_Wet2 + right[i] * this->_Dry; 250 | } 251 | } 252 | private: 253 | void Update() 254 | { 255 | int i; 256 | this->_Wet1 = this->_Wet * (this->_Width / 2.0f + 0.5f); 257 | this->_Wet2 = this->_Wet * ((1.0f - this->_Width) / 2.0f); 258 | 259 | for (i = 0; i < 16; i++) 260 | { 261 | this->_combs[i]->setFeedback(this->_Roomsize); 262 | this->_combs[i]->setDamp(this->_Damp); 263 | } 264 | } 265 | 266 | AllPassFilter* _alls[8]; 267 | CombFilter* _combs[16]; 268 | 269 | float _Roomsize; 270 | float _Dry; 271 | float _Wet; 272 | float _Wet1; 273 | float _Wet2; 274 | float _Damp; 275 | float _Width; 276 | }; 277 | -------------------------------------------------------------------------------- /cetonesynth/SynthEnvelope.cpp: -------------------------------------------------------------------------------- 1 | #include "defines.h" 2 | 3 | #include "CetoneSynth.h" 4 | #include "SynthEnvelope.h" 5 | 6 | CSynthEnvelope::CSynthEnvelope(void) 7 | { 8 | this->Reset(); 9 | 10 | this->SetPreAttack(0.015f); 11 | this->SetAttack(0.01f); 12 | this->SetHold(0.0f); 13 | this->SetDecay(0.25f); 14 | this->SetSustain(0.5f); 15 | this->SetRelease(0.4f); 16 | } 17 | 18 | CSynthEnvelope::~CSynthEnvelope(void) 19 | { 20 | this->LastPhase = -1; 21 | this->Phase = -1; 22 | this->VolNow = 0.f; 23 | } 24 | 25 | void CSynthEnvelope::Reset() 26 | { 27 | this->LastPhase = -1; 28 | this->Phase = -1; 29 | this->VolNow = 0.f; 30 | } 31 | 32 | void CSynthEnvelope::Gate(bool gate) 33 | { 34 | if (gate) 35 | { 36 | this->LastPhase = -1; 37 | 38 | #if ANALOGUE_ENVELOPES != 0 39 | #pragma message("SynthEnvelope: Analogue mode") 40 | this->Phase = 0; 41 | #else 42 | #pragma message("SynthEnvelope: Digital mode") 43 | if (this->Phase == -1) 44 | this->Phase = 0; 45 | else 46 | this->Phase = 5; 47 | #endif 48 | } 49 | else 50 | { 51 | this->LastPhase = -1; 52 | this->Phase = 4; 53 | } 54 | } 55 | 56 | void CSynthEnvelope::Set(float a, float h, float d, float s, float r) 57 | { 58 | if(a == 0.f) 59 | a = 0.005f; 60 | 61 | this->Attack = a; 62 | this->sAttack = truncate(a * CCetoneSynth::SampleRate + 0.5f); 63 | this->sAttackf = (float)this->sAttack; 64 | 65 | this->Hold = h; 66 | this->sHold = truncate(h * CCetoneSynth::SampleRate + 0.5f); 67 | this->sHoldf = (float)this->sHold; 68 | 69 | this->Decay = d; 70 | this->sDecay = truncate(d * CCetoneSynth::SampleRate + 0.5f); 71 | this->sDecayf = (float)this->sDecay; 72 | 73 | this->Sustain = s; 74 | 75 | this->Release = r; 76 | this->sRelease = truncate(r * CCetoneSynth::SampleRate + 0.5f); 77 | this->sReleasef = (float)this->sRelease; 78 | } 79 | 80 | void CSynthEnvelope::SetPreAttack(float val) 81 | { 82 | this->PreAttack = val; 83 | this->sPreAttack = truncate(val * CCetoneSynth::SampleRate + 0.5f); 84 | this->sPreAttackf = (float)this->sPreAttack; 85 | } 86 | 87 | void CSynthEnvelope::SetAttack(float val) 88 | { 89 | if(val == 0.f) 90 | val = 0.001f; 91 | 92 | this->Attack = val; 93 | this->sAttack = truncate(val * CCetoneSynth::SampleRate + 0.5f); 94 | this->sAttackf = (float)this->sAttack; 95 | } 96 | 97 | float CSynthEnvelope::GetAttack() 98 | { 99 | return this->Attack; 100 | } 101 | 102 | void CSynthEnvelope::SetHold(float val) 103 | { 104 | this->Hold = val; 105 | this->sHold = truncate(val * CCetoneSynth::SampleRate + 0.5f); 106 | this->sHoldf = (float)this->sHold; 107 | } 108 | 109 | float CSynthEnvelope::GetHold() 110 | { 111 | return this->Hold; 112 | } 113 | 114 | void CSynthEnvelope::SetDecay(float val) 115 | { 116 | this->Decay = val; 117 | this->sDecay = truncate(val * CCetoneSynth::SampleRate + 0.5f); 118 | this->sDecayf = (float)this->sDecay; 119 | } 120 | 121 | float CSynthEnvelope::GetDecay() 122 | { 123 | return this->Decay; 124 | } 125 | 126 | void CSynthEnvelope::SetSustain(float val) 127 | { 128 | this->Sustain = val; 129 | } 130 | 131 | float CSynthEnvelope::GetSustain() 132 | { 133 | return this->Sustain; 134 | } 135 | 136 | void CSynthEnvelope::SetRelease(float val) 137 | { 138 | this->Release = val; 139 | this->sRelease = truncate(val * CCetoneSynth::SampleRate + 0.5f); 140 | this->sReleasef = (float)this->sRelease; 141 | } 142 | 143 | float CSynthEnvelope::GetRelease() 144 | { 145 | return this->Release; 146 | } 147 | 148 | float CSynthEnvelope::Run() 149 | { 150 | float vol = this->VolNow; 151 | 152 | switch (this->Phase) 153 | { 154 | case 0: 155 | if (this->LastPhase != 0) 156 | { 157 | this->LastPhase = 0; 158 | 159 | if (this->sAttack != 0) 160 | this->VolStep = 1.f / this->sAttackf; 161 | else 162 | { 163 | vol = 1.f; 164 | this->Phase = 1; 165 | break; 166 | } 167 | } 168 | 169 | vol += this->VolStep; 170 | 171 | if(vol >= 1.f) 172 | { 173 | vol = 1.f; 174 | this->Phase = 1; 175 | } 176 | break; 177 | case 1: 178 | if (this->LastPhase != 1) 179 | { 180 | this->LastPhase = 1; 181 | this->Samples = this->sHold; 182 | this->Counter = 0; 183 | } 184 | 185 | vol = 1.f; 186 | this->Counter++; 187 | 188 | if (this->Counter >= this->Samples) 189 | this->Phase = 2; 190 | break; 191 | case 2: 192 | if (this->LastPhase != 2) 193 | { 194 | this->LastPhase = 2; 195 | 196 | if (this->sDecay != 0) 197 | #if ANALOGUE_ENVELOPES != 0 198 | this->VolStep = 1.f / this->sDecayf; 199 | #else 200 | this->VolStep = (1.f - this->Sustain) / this->sDecayf; 201 | #endif 202 | else 203 | { 204 | vol = this->Sustain; 205 | this->Phase = 3; 206 | break; 207 | } 208 | } 209 | 210 | vol -= this->VolStep; 211 | 212 | if (vol <= this->Sustain) 213 | { 214 | vol = this->Sustain; 215 | this->Phase = 3; 216 | } 217 | break; 218 | case 3: 219 | vol = (float)this->Sustain; 220 | break; 221 | case 4: 222 | if (this->LastPhase != 4) 223 | { 224 | this->LastPhase = 4; 225 | 226 | if (this->sRelease != 0) 227 | #if ANALOGUE_ENVELOPES != 0 228 | this->VolStep = 1.f / this->sReleasef; 229 | #else 230 | this->VolStep = this->VolNow / this->sReleasef; 231 | #endif 232 | else 233 | { 234 | vol = 0.f; 235 | this->Phase = -1; 236 | break; 237 | } 238 | } 239 | 240 | vol -= this->VolStep; 241 | 242 | if(vol <= 0.f) 243 | { 244 | vol = 0.f; 245 | this->Phase = -1; 246 | } 247 | break; 248 | #if ANALOGUE_ENVELOPES == 0 249 | case 5: 250 | if (this->LastPhase != 5) 251 | { 252 | this->LastPhase = 5; 253 | 254 | if (this->sPreAttack != 0) 255 | this->VolStep = this->VolNow / this->sPreAttackf; 256 | else 257 | { 258 | vol = 0.f; 259 | this->Phase = 0; 260 | break; 261 | } 262 | } 263 | 264 | vol -= this->VolStep; 265 | 266 | if(vol <= 0.f) 267 | { 268 | vol = 0.f; 269 | this->Phase = 0; 270 | } 271 | break; 272 | #endif 273 | default: 274 | vol = 0.f; 275 | break; 276 | } 277 | 278 | this->VolNow = vol; 279 | 280 | return vol; 281 | } 282 | -------------------------------------------------------------------------------- /cetonesynth2/filter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "defines.h" 5 | #include "statics.h" 6 | 7 | #define FILTER_INLINE 8 | 9 | #define FILTM_12DB 0 10 | #define FILTM_24DB 1 11 | 12 | #define FILTT_LP 0 13 | #define FILTT_BP 1 14 | #define FILTT_HP 2 15 | #define FILTT_BR 3 16 | 17 | #define DRY 0.65 18 | #define WET 0.35 19 | #define BPCO 440.0 20 | #define DENORM_CONST 1e-20 21 | 22 | class Filter 23 | { 24 | public: 25 | Filter(); 26 | ~Filter(); 27 | void Reset(); 28 | void SetSampleRate(float fs); 29 | void SetType(int type); 30 | void SetMode(int mode); 31 | 32 | __forceinline void SetGain(float gain) 33 | { 34 | this->gain = gain * 0.5f; 35 | } 36 | 37 | __forceinline void Set(float cutoff, float q) 38 | { 39 | int co = truncate(cutoff * 32768.0f); 40 | if(co < 0) 41 | co = 0; 42 | else if(co > 32767) 43 | co = 32767; 44 | 45 | if(q < 0.f) 46 | q = 0.f; 47 | else if(q > 1.f) 48 | q = 1.f; 49 | 50 | q = 1.f + q * 9.f; 51 | 52 | double cs = g_fcos[co]; 53 | double alpha = g_fsin[co] / q; 54 | double a0 = 1.0 / (1.0 + alpha); 55 | 56 | switch(this->type) 57 | { 58 | case FILTT_LP: 59 | this->b2 = this->b0 = (1.0 - cs) * (0.5 * a0); 60 | this->b1 = (1.0 - cs) * a0; 61 | this->a1 = (2.0 * cs) * a0; 62 | this->a2 = (alpha - 1.0) * a0; 63 | break; 64 | case FILTT_HP: 65 | this->b2 = this->b0 = (1.0 + cs) * (0.5 * a0); 66 | this->b1 = -((1.0 + cs) * a0); 67 | this->a1 = (2.0 * cs) * a0; 68 | this->a2 = (alpha - 1.0) * a0; 69 | break; 70 | case FILTT_BP: 71 | this->b0 = alpha * a0; 72 | this->b1 = 0.0; 73 | this->b2 = -this->b0; 74 | this->a1 = (2.0 * cs) * a0; 75 | this->a2 = (alpha - 1.0) * a0; 76 | break; 77 | case FILTT_BR: 78 | this->b2 = this->b0 = a0; 79 | this->b1 = (-2.0 * cs) * a0; 80 | this->a1 = -this->b1; 81 | this->a2 = (alpha - 1.0) * a0; 82 | break; 83 | } 84 | } 85 | 86 | #ifdef FILTER_INLINE 87 | __forceinline float CallProcess(float _inputout) 88 | { 89 | if(this->modus) 90 | { 91 | double inputout = (double)_inputout; 92 | this->buffer2[2] = this->buffer2[1]; 93 | this->buffer2[1] = this->buffer2[0]; 94 | this->buffer2[0] = inputout; 95 | this->buffer2[5] = this->buffer2[4]; 96 | this->buffer2[4] = this->buffer2[3]; 97 | this->buffer2[3] = 98 | this->b0b * this->buffer2[0] 99 | + this->b1b * this->buffer2[1] 100 | + this->b2b * this->buffer2[2] 101 | + this->a1b * this->buffer2[4] 102 | + this->a2b * this->buffer2[5] + DENORM_CONST; 103 | 104 | inputout = DRY * inputout + WET * this->buffer2[3]; 105 | 106 | this->buffer0[2] = this->buffer0[1]; 107 | this->buffer0[1] = this->buffer0[0]; 108 | this->buffer0[0] = (this->lastIn + inputout) * 0.5; 109 | this->buffer0[5] = this->buffer0[4]; 110 | this->buffer0[4] = this->buffer0[3]; 111 | this->buffer0[3] = 112 | this->b0 * this->buffer0[0] 113 | + this->b1 * this->buffer0[1] 114 | + this->b2 * this->buffer0[2] 115 | + this->a1 * this->buffer0[4] 116 | + this->a2 * this->buffer0[5] + DENORM_CONST; 117 | 118 | this->buffer0[2] = this->buffer0[1]; 119 | this->buffer0[1] = this->buffer0[0]; 120 | this->lastIn = this->buffer0[0] = inputout; 121 | this->buffer0[5] = this->buffer0[4]; 122 | this->buffer0[4] = this->buffer0[3]; 123 | this->buffer0[3] = 124 | this->b0 * this->buffer0[0] 125 | + this->b1 * this->buffer0[1] 126 | + this->b2 * this->buffer0[2] 127 | + this->a1 * this->buffer0[4] 128 | + this->a2 * this->buffer0[5] + DENORM_CONST; 129 | 130 | this->buffer1[2] = this->buffer1[1]; 131 | this->buffer1[1] = this->buffer1[0]; 132 | this->buffer1[0] = (this->lastIn2 + this->buffer0[3]) * 0.5; 133 | this->buffer1[5] = this->buffer1[4]; 134 | this->buffer1[4] = this->buffer1[3]; 135 | this->buffer1[3] = 136 | this->b0 * this->buffer1[0] 137 | + this->b1 * this->buffer1[1] 138 | + this->b2 * this->buffer1[2] 139 | + this->a1 * this->buffer1[4] 140 | + this->a2 * this->buffer1[5] + DENORM_CONST; 141 | 142 | this->buffer1[2] = this->buffer1[1]; 143 | this->buffer1[1] = this->buffer1[0]; 144 | this->lastIn2 = this->buffer1[0] = this->buffer0[3]; 145 | this->buffer1[5] = this->buffer1[4]; 146 | this->buffer1[4] = this->buffer1[3]; 147 | this->buffer1[3] = 148 | this->b0 * this->buffer1[0] 149 | + this->b1 * this->buffer1[1] 150 | + this->b2 * this->buffer1[2] 151 | + this->a1 * this->buffer1[4] 152 | + this->a2 * this->buffer1[5] + DENORM_CONST; 153 | 154 | if(this->buffer0[3] > 320.0) 155 | this->Reset(); 156 | 157 | return tanhf((float)this->buffer1[3] * this->gain); 158 | } 159 | else 160 | { 161 | double inputout = (double)_inputout; 162 | this->buffer2[2] = this->buffer2[1]; 163 | this->buffer2[1] = this->buffer2[0]; 164 | this->buffer2[0] = inputout; 165 | this->buffer2[5] = this->buffer2[4]; 166 | this->buffer2[4] = this->buffer2[3]; 167 | this->buffer2[3] = 168 | this->b0b * this->buffer2[0] 169 | + this->b1b * this->buffer2[1] 170 | + this->b2b * this->buffer2[2] 171 | + this->a1b * this->buffer2[4] 172 | + this->a2b * this->buffer2[5] + DENORM_CONST; 173 | 174 | inputout = DRY * inputout + WET * this->buffer2[3]; 175 | 176 | this->buffer0[2] = this->buffer0[1]; 177 | this->buffer0[1] = this->buffer0[0]; 178 | this->buffer0[0] = (this->lastIn + inputout) * 0.5; 179 | this->buffer0[5] = this->buffer0[4]; 180 | this->buffer0[4] = this->buffer0[3]; 181 | this->buffer0[3] = 182 | this->b0 * this->buffer0[0] 183 | + this->b1 * this->buffer0[1] 184 | + this->b2 * this->buffer0[2] 185 | + this->a1 * this->buffer0[4] 186 | + this->a2 * this->buffer0[5] + DENORM_CONST; 187 | 188 | this->buffer0[2] = this->buffer0[1]; 189 | this->buffer0[1] = this->buffer0[0]; 190 | this->lastIn = this->buffer0[0] = inputout; 191 | this->buffer0[5] = this->buffer0[4]; 192 | this->buffer0[4] = this->buffer0[3]; 193 | this->buffer0[3] = 194 | this->b0 * this->buffer0[0] 195 | + this->b1 * this->buffer0[1] 196 | + this->b2 * this->buffer0[2] 197 | + this->a1 * this->buffer0[4] 198 | + this->a2 * this->buffer0[5] + DENORM_CONST; 199 | 200 | if(this->buffer0[3] > 320.0) 201 | this->Reset(); 202 | 203 | return tanhf((float)this->buffer0[3] * this->gain); 204 | } 205 | }; 206 | #else 207 | __forceinline float CallProcess(float input) { return (this->*Process)(input); }; 208 | float (Filter::*Process)(float); 209 | 210 | float Process12(float inputout); 211 | float Process24(float inputout); 212 | #endif 213 | private: 214 | double a1, a2; 215 | double b0, b1, b2; 216 | double buffer0[6]; 217 | double buffer1[6]; 218 | double a1b, a2b; 219 | double b0b, b1b, b2b; 220 | double buffer2[6]; 221 | double lastIn, lastIn2; 222 | 223 | int type; 224 | int modus; 225 | float gain; 226 | }; 227 | --------------------------------------------------------------------------------