From 398a72ef13a90df135f4d72b432bfc67d5bc9a62 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 6 Dec 2015 09:49:12 -0800 Subject: [PATCH] semi-working MSVC support i gave up on gcc, it kept producing segfaults. --- build.bat | 33 ++++++++++ crap/delay_test.hpp | 24 ++++---- crap/eq.hpp | 22 +++---- crap/eq_const.hpp | 22 +++---- crap/eq_const_T420.hpp | 22 +++---- crap/eq_const_T420_svf.hpp | 22 +++---- crap/level.hpp | 51 +++++++-------- crap/mugi4.hpp | 56 ++++++++--------- crap/noise.hpp | 20 +++--- crap/tube.hpp | 25 ++++---- include/Buffer2.hpp | 4 +- include/Buffer2OS2.hpp | 4 +- include/biquad.hpp | 17 ++--- include/os2piir.hpp | 14 ++--- include/util.hpp | 16 +++++ include/vectors_simple.hpp | 123 +++++++++++++++++++++++++++++++++++++ template/vst.cpp | 6 +- util/generate.vbs | 18 ++++++ 18 files changed, 348 insertions(+), 151 deletions(-) create mode 100755 build.bat create mode 100755 include/vectors_simple.hpp create mode 100755 util/generate.vbs diff --git a/build.bat b/build.bat new file mode 100755 index 0000000..b21c68c --- /dev/null +++ b/build.bat @@ -0,0 +1,33 @@ +@ECHO OFF +call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" +cd bin + +set vst=../../../src/vstsdk2.4/ +set vst2x=%vst%public.sdk/source/vst2.x/ +set vstdef=%vst%public.sdk/samples/vst2.x/win/vstplug.def +set vst_c=/LD /I"%vst%" +set vst_ld=/DEF:"%vstdef%" +set vstsrc=%vst2x%audioeffect.cpp %vst2x%audioeffectx.cpp %vst2x%vstplugmain.cpp + +set wall=/Wall /wd4100 /wd4668 /wd4820 /wd4514 /wd4365 /wd4711 /wd4996 +REM the warning disabled below is function-not-inlined +set common_c=/I"../" /I"../include/" %wall% /wd4710 +set release_c=%common_c% /O2 /Oy- /GL /EHsc /fp:fast /analyze- /nologo +set release_ld= + +call:compile delay_test +call:compile eq +call:compile eq_const +call:compile eq_const_T420 +REM call:compile eq_const_T420_svf +call:compile level +call:compile mugi4 +call:compile noise +call:compile tube +goto:eof + +:compile +set crap=%~1 +cscript ..\util\generate.vbs %crap% +cl %release_c% %vst_c% ../crap/vst/%crap%.cpp %vstsrc% /link %release_ld% %vst_ld% /OUT:"vst/crap_%crap%.dll" +goto:eof diff --git a/crap/delay_test.hpp b/crap/delay_test.hpp index 2d6bdb3..361b00d 100644 --- a/crap/delay_test.hpp +++ b/crap/delay_test.hpp @@ -72,12 +72,12 @@ struct channel { struct Crap_delay_test :public AdjustAll { - static constexpr ulong id = 0xDEDEDEDE; - static constexpr char label[] = "crap_delay_test"; - static constexpr char name[] = "crap sample delay test"; - static constexpr char author[] = "Connor Olding"; - static constexpr char copyright[] = "MIT"; - static constexpr ulong parameters = 0; + static const ulong id = 0xDEDEDEDE; + static const char *label; + static const char *name; + static const char *author; + static const char *copyright; + static const ulong parameters = 0; channel c_L, c_R; @@ -100,8 +100,8 @@ struct Crap_delay_test ulong count) { for (ulong i = 0; i < count; i++) { - out_L[i] = c_L.process(in_L[i]); - out_R[i] = c_R.process(in_R[i]); + out_L[i] = (float)c_L.process(in_L[i]); + out_R[i] = (float)c_R.process(in_R[i]); } } @@ -131,7 +131,7 @@ struct Crap_delay_test } }; -constexpr char Crap_delay_test::label[]; -constexpr char Crap_delay_test::name[]; -constexpr char Crap_delay_test::author[]; -constexpr char Crap_delay_test::copyright[]; +const char *Crap_delay_test::label = "crap_delay_test"; +const char *Crap_delay_test::name = "crap sample delay test"; +const char *Crap_delay_test::author = "Connor Olding"; +const char *Crap_delay_test::copyright = "MIT"; diff --git a/crap/eq.hpp b/crap/eq.hpp index 89f3438..3fc368a 100644 --- a/crap/eq.hpp +++ b/crap/eq.hpp @@ -9,14 +9,14 @@ struct Crap_eq :public AdjustAll> { - static constexpr ulong id = 0x000CAFED; - static constexpr char label[] = "crap_eq"; - static constexpr char name[] = "crap Parametric Equalizer"; - static constexpr char author[] = "Connor Olding"; - static constexpr char copyright[] = "MIT"; + static const ulong bands = 4; - static constexpr ulong bands = 4; - static constexpr ulong parameters = bands*3; + static const ulong id = 0x000CAFED; + static const char *label; + static const char *name; + static const char *author; + static const char *copyright; + static const ulong parameters = bands*3; biquad filters_L[bands]; biquad filters_R[bands]; @@ -88,7 +88,7 @@ struct Crap_eq } }; -constexpr char Crap_eq::label[]; -constexpr char Crap_eq::name[]; -constexpr char Crap_eq::author[]; -constexpr char Crap_eq::copyright[]; +const char *Crap_eq::label = "crap_eq"; +const char *Crap_eq::name = "crap Parametric Equalizer"; +const char *Crap_eq::author = "Connor Olding"; +const char *Crap_eq::copyright = "MIT"; diff --git a/crap/eq_const.hpp b/crap/eq_const.hpp index 557a696..bf728a3 100644 --- a/crap/eq_const.hpp +++ b/crap/eq_const.hpp @@ -8,14 +8,14 @@ struct Crap_eq_const :public AdjustAll> { - static constexpr ulong id = 0x0DEFACED; - static constexpr char label[] = "crap_eq_const"; - static constexpr char name[] = "crap Constant Equalizer"; - static constexpr char author[] = "Connor Olding"; - static constexpr char copyright[] = "MIT"; + static const ulong id = 0x0DEFACED; + static const char *label; + static const char *name; + static const char *author; + static const char *copyright; + static const ulong parameters = 0; - static constexpr ulong bands = 12; - static constexpr ulong parameters = 0; + static const ulong bands = 12; biquad filters_L[bands]; biquad filters_R[bands]; @@ -71,7 +71,7 @@ struct Crap_eq_const } }; -constexpr char Crap_eq_const::label[]; -constexpr char Crap_eq_const::name[]; -constexpr char Crap_eq_const::author[]; -constexpr char Crap_eq_const::copyright[]; +const char *Crap_eq_const::label = "crap_eq_const"; +const char *Crap_eq_const::name = "crap Constant Equalizer"; +const char *Crap_eq_const::author = "Connor Olding"; +const char *Crap_eq_const::copyright = "MIT"; diff --git a/crap/eq_const_T420.hpp b/crap/eq_const_T420.hpp index 690ba75..3ffdff0 100644 --- a/crap/eq_const_T420.hpp +++ b/crap/eq_const_T420.hpp @@ -8,14 +8,14 @@ struct Crap_eq_const_T420 :public AdjustAll> { - static constexpr ulong id = 0x0DEFACED + 420; - static constexpr char label[] = "crap_eq_const_T420"; - static constexpr char name[] = "crap T420 Speaker Compensation"; - static constexpr char author[] = "Connor Olding"; - static constexpr char copyright[] = "MIT"; + static const ulong id = 0x0DEFACED + 420; + static const char *label; + static const char *name; + static const char *author; + static const char *copyright; + static const ulong parameters = 0; - static constexpr ulong bands = 16; - static constexpr ulong parameters = 0; + static const ulong bands = 16; biquad filters_L[bands]; biquad filters_R[bands]; @@ -75,7 +75,7 @@ struct Crap_eq_const_T420 } }; -constexpr char Crap_eq_const_T420::label[]; -constexpr char Crap_eq_const_T420::name[]; -constexpr char Crap_eq_const_T420::author[]; -constexpr char Crap_eq_const_T420::copyright[]; +const char *Crap_eq_const_T420::label = "crap_eq_const_T420"; +const char *Crap_eq_const_T420::name = "crap T420 Speaker Compensation"; +const char *Crap_eq_const_T420::author = "Connor Olding"; +const char *Crap_eq_const_T420::copyright = "MIT"; diff --git a/crap/eq_const_T420_svf.hpp b/crap/eq_const_T420_svf.hpp index 8a31d10..095bd0f 100644 --- a/crap/eq_const_T420_svf.hpp +++ b/crap/eq_const_T420_svf.hpp @@ -10,14 +10,14 @@ struct Crap_eq_const_T420_svf :public AdjustAll> { - static constexpr ulong id = 0x0DEFACED + 420 + 1337; - static constexpr char label[] = "crap_eq_const_T420_svf"; - static constexpr char name[] = "crap T420 Speaker Compensation (SVF)"; - static constexpr char author[] = "Connor Olding"; - static constexpr char copyright[] = "MIT"; + static const ulong id = 0x0DEFACED + 420 + 1337; + static const char *label; + static const char *name; + static const char *author; + static const char *copyright; + static const ulong parameters = 0; - static constexpr ulong bands = 16; - static constexpr ulong parameters = 0; + static const ulong bands = 16; svf_matrix filters_L[bands]; svf_matrix filters_R[bands]; @@ -83,7 +83,7 @@ struct Crap_eq_const_T420_svf } }; -constexpr char Crap_eq_const_T420_svf::label[]; -constexpr char Crap_eq_const_T420_svf::name[]; -constexpr char Crap_eq_const_T420_svf::author[]; -constexpr char Crap_eq_const_T420_svf::copyright[]; +const char *Crap_eq_const_T420_svf::label = "crap_eq_const_T420_svf"; +const char *Crap_eq_const_T420_svf::name = "crap T420 Speaker Compensation (SVF)"; +const char *Crap_eq_const_T420_svf::author = "Connor Olding"; +const char *Crap_eq_const_T420_svf::copyright = "MIT"; diff --git a/crap/level.hpp b/crap/level.hpp index 6a65f47..5922e77 100644 --- a/crap/level.hpp +++ b/crap/level.hpp @@ -12,7 +12,7 @@ static ulong global_delay = 0; TEMPLATE struct Delay { - static constexpr ulong size = 4096; + static const ulong size = 4096; // needs to be twice the size for a memcpy trick later T buf[size*2]; @@ -28,7 +28,7 @@ struct Delay { }; inline T - delay(T s) + delay(const T &s) { pos--; if (pos <= 0) { @@ -52,14 +52,13 @@ struct Delay { struct Crap_level :public AdjustAll> { - static constexpr ulong id = 0xAAAAAAAA; - static constexpr char label[] = "crap_level"; - static constexpr char name[] = "crap Leveller"; - static constexpr char author[] = "Connor Olding"; - static constexpr char copyright[] = "MIT"; - - static constexpr ulong bands = 2; - static constexpr ulong parameters = 0; + static const ulong id = 0xAAAAAAAA; + static const char *label; + static const char *name; + static const char *author; + static const char *copyright; + static const ulong bands = 2; + static const ulong parameters = 0; v2df sc[BLOCK_SIZE]; // sidechain biquad filters_L[bands]; @@ -80,7 +79,7 @@ struct Crap_level ~Crap_level() { if (window) - free(window); + delete window; } inline void @@ -89,20 +88,21 @@ struct Crap_level biquad *f0, *f1; f0 = filters_L; f1 = filters_R; - memcpy(sc, buf, rem*sizeof(v2df)); + for (ulong i = 0; i < rem; i++) + sc[i] = buf[i]; for (ulong i = 0; i < bands; i++) { biquad_run_block_stereo(f0, f1, sc, rem); f0++; f1++; } - double envs[rem]; + double envs[BLOCK_SIZE]; for (ulong i = 0; i < rem; i++) envs[i] = fabs(sc[i][0]) + fabs(sc[i][1]); for (ulong i = 0; i < rem; i++) envs[i] *= 0.5; // MaxFIR - double applied[window_size]; + double *applied = new double[window_size]; for (ulong i = 0; i < rem; i++) { window_delay.delay(envs[i]); for (ulong j = 0; j < window_size; j++) @@ -112,6 +112,7 @@ struct Crap_level max_ = fmax(max_, applied[j]); envs[i] = max_; } + delete applied; // Follower for (ulong i = 0; i < rem; i++) { @@ -119,7 +120,7 @@ struct Crap_level env = fmax(0.00001, env); envs[i] = env; } - double gains[rem]; + double gains[BLOCK_SIZE]; for (ulong i = 0; i < rem; i++) gains[i] = 0.3991 - 0.01769/(envs[i] + 0.044); for (ulong i = 0; i < rem; i++) @@ -153,7 +154,7 @@ struct Crap_level construct_params(Param *params) {} - virtual void + void adjust_all(Param *params) { biquad *f = filters_L; @@ -163,15 +164,15 @@ struct Crap_level filters_R[i] = filters_L[i]; double window_length = fs*0.010/0.60; - window_size = round(window_length); - lookahead = round(window_length*0.6); + window_size = (ulong) round(window_length); + lookahead = (ulong) round(window_length*0.6); global_delay = lookahead; if (window) - free(window); - window = (double *) calloc(window_size, sizeof(double)); + delete window; + window = new double[window_size]; - for (int i = 0; i < window_size; i++) { + for (ulong i = 0; i < window_size; i++) { double x = double(i)/window_size; double y = -(x - 0)*(x - 1)*(x + 0.6)/0.288; window[i] = y; @@ -184,7 +185,7 @@ struct Crap_level } }; -constexpr char Crap_level::label[]; -constexpr char Crap_level::name[]; -constexpr char Crap_level::author[]; -constexpr char Crap_level::copyright[]; +const char *Crap_level::label = "crap_level"; +const char *Crap_level::name = "crap Leveller"; +const char *Crap_level::author = "Connor Olding"; +const char *Crap_level::copyright = "MIT"; diff --git a/crap/mugi4.hpp b/crap/mugi4.hpp index 3aa3e4a..c384eba 100644 --- a/crap/mugi4.hpp +++ b/crap/mugi4.hpp @@ -21,10 +21,10 @@ https://aaltodoc.aalto.fi/bitstream/handle/123456789/14420/article6.pdf #define VT 0.026 #define N 4 -#define VT2 T(2.*VT) +#define VT2 2.*VT TEMPLATE INNER PURE T -tanh2(T x) +tanh2(const T &x) { //return T(tanh(x[0]), tanh(x[1])); T xx = x*x; @@ -47,12 +47,12 @@ struct stage { v2df sum, sumback, dout; TEMPLATE inline T - process(freqdata fd, T in) + process(const freqdata &fd, const T &in) { - T temp = (in + sumback)*VT2*fd.L_p0*fd.g; + T temp = (in + sumback)*T(VT2)*fd.L_p0*fd.g; T out = temp + sum; sum += T(2)*temp; - dout = tanh2(out/VT2); + dout = tanh2(out/T(VT2)); sumback = in*fd.L_r1 - dout*fd.L_q0; return out; } @@ -64,25 +64,26 @@ struct mugi4 { v2df sumback1, sumback2, sumback3, sumback4; v2df drive, feedback; - TEMPLATE inline T - process(T in) + inline v2df + process(const v2df &in_) { - in *= drive; + v2df in = in_*drive; - T sum = in + sumback1; - T pre = -fd.p0*sum; - s1.process(fd, tanh2(pre/VT2)); - s2.process(fd, s1.dout); - s3.process(fd, s2.dout); - T out = s4.process(fd, s3.dout); + v2df sum = in + sumback1; + v2df pre = -fd.p0*sum; + v2df temp = tanh2(pre/VT2); + s1.process(fd, temp); + s2.process(fd, s1.dout); + s3.process(fd, s2.dout); + v2df out = s4.process(fd, s3.dout); - T back = feedback*out; + v2df back = feedback*out; sumback1 = fd.r1*in + fd.q0*back + sumback2; sumback2 = fd.r2*in + fd.q1*back + sumback3; sumback3 = fd.r3*in + fd.q2*back + sumback4; sumback4 = fd.r4*in + fd.q3*back; - T compensate = -(feedback + T(1)); + v2df compensate = -(feedback + v2df(1)); return out/drive*compensate; } @@ -99,7 +100,7 @@ struct mugi4 { double bc4 = -1; //-binomial(N, 4); // apparently fd_set is used by some stdio implementations, so - #define crap_fd_set(L, R) double L = R; fd.L = (v2df){L, L} + #define crap_fd_set(L, R) double L = R; fd.L = v2df(L, L) crap_fd_set(g, tan(wc)); double gg1 = g/(g + 1); double gg1Nk = k*gg1*gg1*gg1*gg1; @@ -124,13 +125,12 @@ struct mugi4 { struct Crap_mugi4 :public AdjustAll> { - static constexpr ulong id = 0xD8D0D8D0; - static constexpr char label[] = "crap_mugi4"; - static constexpr char name[] = "crap mugi4 (moog-like)"; - static constexpr char author[] = "Connor Olding"; - static constexpr char copyright[] = "MIT"; - - static constexpr ulong parameters = 3; + static const ulong id = 0xD8D0D8D0; + static const char *label; + static const char *name; + static const char *author; + static const char *copyright; + static const ulong parameters = 3; mugi4 filter; @@ -196,7 +196,7 @@ struct Crap_mugi4 } }; -constexpr char Crap_mugi4::label[]; -constexpr char Crap_mugi4::name[]; -constexpr char Crap_mugi4::author[]; -constexpr char Crap_mugi4::copyright[]; +const char *Crap_mugi4::label = "crap_mugi4"; +const char *Crap_mugi4::name = "crap mugi4 (moog-like)"; +const char *Crap_mugi4::author = "Connor Olding"; +const char *Crap_mugi4::copyright = "MIT"; diff --git a/crap/noise.hpp b/crap/noise.hpp index c53c8e0..ef7981d 100644 --- a/crap/noise.hpp +++ b/crap/noise.hpp @@ -6,12 +6,12 @@ struct Crap_noise :public AdjustAll { - static constexpr ulong id = 0xEC57A71C; - static constexpr char label[] = "crap_noise"; - static constexpr char name[] = "crap noise generator"; - static constexpr char author[] = "Connor Olding"; - static constexpr char copyright[] = "MIT"; - static constexpr ulong parameters = 0; + static const ulong id = 0xEC57A71C; + static const char *label; + static const char *name; + static const char *author; + static const char *copyright; + static const ulong parameters = 0; unsigned int mirand_L, mirand_R; @@ -61,7 +61,7 @@ struct Crap_noise {} }; -constexpr char Crap_noise::label[]; -constexpr char Crap_noise::name[]; -constexpr char Crap_noise::author[]; -constexpr char Crap_noise::copyright[]; +const char *Crap_noise::label = "crap_noise"; +const char *Crap_noise::name = "crap noise generator"; +const char *Crap_noise::author = "Connor Olding"; +const char *Crap_noise::copyright = "MIT"; diff --git a/crap/tube.hpp b/crap/tube.hpp index 524d61e..923a37a 100644 --- a/crap/tube.hpp +++ b/crap/tube.hpp @@ -33,13 +33,13 @@ typedef struct { namespace Tube { TEMPLATE INNER CONST T - distort(T x) + distort(const T &x) { return (T(27.)*x + T(9.)) / (T(9.)*x*x + T(6.)*x + T(19.)) - T(9./19.); } TEMPLATE INNER CONST T - process(T x, T drive, T wet) + process(const T &x, const T &drive, const T &wet) { return (distort(x*drive)/drive*T(0.79) - x)*wet + x; } @@ -47,13 +47,12 @@ namespace Tube { struct Crap_tube :public Buffer2OS2 { - static constexpr ulong id = 0x50F7BA11; - static constexpr char label[] = "crap_tube"; - static constexpr char name[] = "crap Tube Distortion"; - static constexpr char author[] = "Connor Olding"; - static constexpr char copyright[] = "MIT"; - - static constexpr ulong parameters = 2; + static const ulong id = 0x50F7BA11; + static const char *label; + static const char *name; + static const char *author; + static const char *copyright; + static const ulong parameters = 2; smoothval drive, wet; @@ -121,7 +120,7 @@ struct Crap_tube } }; -constexpr char Crap_tube::label[]; -constexpr char Crap_tube::name[]; -constexpr char Crap_tube::author[]; -constexpr char Crap_tube::copyright[]; +const char *Crap_tube::label = "crap_tube"; +const char *Crap_tube::name = "crap Tube Distortion"; +const char *Crap_tube::author = "Connor Olding"; +const char *Crap_tube::copyright = "MIT"; diff --git a/include/Buffer2.hpp b/include/Buffer2.hpp index 4dbbcbd..636e887 100644 --- a/include/Buffer2.hpp +++ b/include/Buffer2.hpp @@ -23,8 +23,8 @@ struct Buffer2 : public Mixin { process2(buf, rem); for (ulong i = 0; i < rem; i++) { - out_L[i] = buf[i][0]; - out_R[i] = buf[i][1]; + out_L[i] = (T)buf[i][0]; + out_R[i] = (T)buf[i][1]; } in_L += BLOCK_SIZE; diff --git a/include/Buffer2OS2.hpp b/include/Buffer2OS2.hpp index b9547b2..52b50a9 100644 --- a/include/Buffer2OS2.hpp +++ b/include/Buffer2OS2.hpp @@ -37,8 +37,8 @@ struct Buffer2OS2 : public Mixin { } for (ulong i = 0; i < rem; i++) { - out_L[i] = buf[i][0]; - out_R[i] = buf[i][1]; + out_L[i] = (T)buf[i][0]; + out_R[i] = (T)buf[i][1]; } in_L += BLOCK_SIZE; diff --git a/include/biquad.hpp b/include/biquad.hpp index e741825..dc893e2 100644 --- a/include/biquad.hpp +++ b/include/biquad.hpp @@ -19,14 +19,15 @@ design(double cw, double sw, double num0, double num1, double num2, double den0, double den1, double den2) { - return (biquad_interim) { - .b0 = num0* (1 + cw) + num1*sw + num2* (1 - cw), - .b1 = num0*-2*(1 + cw) + num2*2*(1 - cw), - .b2 = num0* (1 + cw) - num1*sw + num2* (1 - cw), - .a0 = den0* (1 + cw) + den1*sw + den2* (1 - cw), - .a1 = den0*-2*(1 + cw) + den2*2*(1 - cw), - .a2 = den0* (1 + cw) - den1*sw + den2* (1 - cw), + const biquad_interim ret = { + num0* (1 + cw) + num1*sw + num2* (1 - cw), + num0*-2*(1 + cw) + num2*2*(1 - cw), + num0* (1 + cw) - num1*sw + num2* (1 - cw), + den0* (1 + cw) + den1*sw + den2* (1 - cw), + den0*-2*(1 + cw) + den2*2*(1 - cw), + den0* (1 + cw) - den1*sw + den2* (1 - cw), }; + return ret; } // TODO: rename to biquad_gen_raw, fix up parameters like you did with svf @@ -55,6 +56,8 @@ biquad_gen(filter_t type, double fc, double gain, double bw, double fs) case FILT_BANDPASS_2: d(0, 1/Q, 0, 1, 1/Q, 1); break; case FILT_NOTCH: d(1, 0, 1, 1, 1/Q, 1); break; case FILT_GAIN: d(A, A, A, 1/A, 1/A, 1/A); break; + // TODO: error or something + default: d(1, 1, 1, 1, 1, 1); break; } #undef d diff --git a/include/os2piir.hpp b/include/os2piir.hpp index 9a76d85..a809b54 100644 --- a/include/os2piir.hpp +++ b/include/os2piir.hpp @@ -17,7 +17,7 @@ struct halfband_t { }; TEMPLATE INNER void -halfband_a(T a[8], T ao[8], T x0, T x2) +halfband_a(T a[8], T ao[8], const T &x0, const T &x2) { a[0] = x2 + (x0 - ao[0])*T(0.006185967461045014); a[1] = ao[0] + (a[0] - ao[1])*T(0.054230780876613788); @@ -30,7 +30,7 @@ halfband_a(T a[8], T ao[8], T x0, T x2) } TEMPLATE INNER void -halfband_b(T b[8], T bo[8], T x1, T x3) +halfband_b(T b[8], T bo[8], const T &x1, const T &x3) { b[0] = x3 + (x1 - bo[0])*T(0.024499027624721819); b[1] = bo[0] + (b[0] - bo[1])*T(0.094283481125726432); @@ -43,7 +43,7 @@ halfband_b(T b[8], T bo[8], T x1, T x3) } TEMPLATE INNER T -halfband(halfband_t *h, T x0) +halfband(halfband_t *h, const T &x0) { T a[8], b[8]; halfband_a(a, h->ao, x0, h->x2); @@ -59,7 +59,7 @@ halfband(halfband_t *h, T x0) } TEMPLATE INNER T -decimate_a(halfband_t *h, T x0) +decimate_a(halfband_t *h, const T &x0) { T c[8]; halfband_b(c, h->bo, x0, h->x2); @@ -70,7 +70,7 @@ decimate_a(halfband_t *h, T x0) } TEMPLATE INNER T -decimate_b(halfband_t *h, T x0) +decimate_b(halfband_t *h, const T &x0) { T c[8]; halfband_a(c, h->ao, x0, h->x2); @@ -82,7 +82,7 @@ decimate_b(halfband_t *h, T x0) // note: do not zero-stuff! send the input each time. TEMPLATE INNER T -interpolate_a(halfband_t *h, T x0) +interpolate_a(halfband_t *h, const T &x0) { T c[8]; halfband_a(c, h->ao, x0, h->x1); @@ -92,7 +92,7 @@ interpolate_a(halfband_t *h, T x0) // note: do not zero-stuff! send the input each time. TEMPLATE INNER T -interpolate_b(halfband_t *h, T x0) +interpolate_b(halfband_t *h, const T &x0) { T c[8]; halfband_b(c, h->bo, x0, h->x1); diff --git a/include/util.hpp b/include/util.hpp index ded76cb..c7d7ee9 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -2,15 +2,27 @@ #include #include +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#define M_SQRT2 1.41421356237309504880 +#define M_SQRT1_2 0.707106781186547524401 +#endif + #ifdef __SSE2__ #include #endif #define TEMPLATE template #define INNER static inline +#ifdef _MSC_VER +#define PURE +#define CONST +#define RESTRICT +#else #define PURE __attribute__((pure)) #define CONST __attribute__((const)) #define RESTRICT __restrict__ +#endif typedef unsigned long ulong; // __attribute((aligned(16))); @@ -18,8 +30,12 @@ typedef unsigned long ulong; // __attribute((aligned(16))); #define BLOCK_SIZE 256 #endif +#ifdef _MSC_VER +#include "vectors_simple.hpp" +#else #include "Dumber.hpp" #include "vectors.hpp" +#endif #ifdef FORCE_SINGLE #define v2df v2sf diff --git a/include/vectors_simple.hpp b/include/vectors_simple.hpp new file mode 100755 index 0000000..c958bbc --- /dev/null +++ b/include/vectors_simple.hpp @@ -0,0 +1,123 @@ +#include +typedef __m128d _v2df; +typedef __m64 _v2sf; +typedef __m128 _v4sf; + +struct v2df { + _v2df v; + + v2df() + {} + + v2df(double d) + { v = _mm_set1_pd(d); } + + v2df(double d0, double d1) + { v = _mm_setr_pd(d0,d1); } + + friend inline v2df + operator-(const v2df &a) + { v2df c; c.v =_mm_sub_pd(_mm_setzero_pd(),a.v); return c; } + + friend inline v2df + operator+(const v2df &a, const v2df &b) + { v2df c; c.v = _mm_add_pd(a.v,b.v); return c; } + + friend inline v2df + operator-(const v2df &a, const v2df &b) + { v2df c; c.v = _mm_sub_pd(a.v,b.v); return c; } + + friend inline v2df + operator*(const v2df &a, const v2df &b) + { v2df c; c.v = _mm_mul_pd(a.v,b.v); return c; } + + friend inline v2df + operator/(const v2df &a, const v2df &b) + { v2df c; c.v = _mm_div_pd(a.v,b.v); return c; } + + friend inline v2df + sqrt(const v2df &a) + { v2df c; c.v = _mm_sqrt_pd(a.v); return c; } + + friend inline v2df + operator+(double a, const v2df &b) + { v2df c; c.v = _mm_add_pd(_mm_set1_pd(a),b.v); return c; } + + friend inline v2df + operator-(double a, const v2df &b) + { v2df c; c.v = _mm_sub_pd(_mm_set1_pd(a),b.v); return c; } + + friend inline v2df + operator*(double a, const v2df &b) + { v2df c; c.v = _mm_mul_pd(_mm_set1_pd(a),b.v); return c; } + + friend inline v2df + operator/(double a, const v2df &b) + { v2df c; c.v = _mm_div_pd(_mm_set1_pd(a),b.v); return c; } + + inline v2df & + operator+=(const v2df &a) + { v = _mm_add_pd(v,a.v); return *this; } + + inline v2df & + operator-=(const v2df &a) + { v = _mm_sub_pd(v,a.v); return *this; } + + inline v2df & + operator*=(const v2df &a) + { v = _mm_mul_pd(v,a.v); return *this; } + + inline v2df & + operator/=(const v2df &a) + { v = _mm_div_pd(v,a.v); return *this; } + + friend inline v2df + operator&(const v2df &a, const v2df &b) + { v2df c; c.v = _mm_and_pd(a.v,b.v); return c; } + + friend inline v2df + operator|(const v2df &a, const v2df &b) + { v2df c; c.v = _mm_or_pd(a.v,b.v); return c; } + + friend inline v2df + operator^(const v2df &a, const v2df &b) + { v2df c; c.v = _mm_xor_pd(a.v,b.v); return c; } + + friend inline v2df + andnot(const v2df &a, const v2df &b) + { v2df c; c.v = _mm_andnot_pd(a.v,b.v); return c; } + + friend inline v2df + operator<(const v2df &a, const v2df &b) + { v2df c; c.v = _mm_cmplt_pd(a.v,b.v); return c; } + + friend inline v2df + operator>(const v2df &a, const v2df &b) + { v2df c; c.v = _mm_cmpgt_pd(a.v,b.v); return c; } + + friend inline v2df + operator==(const v2df &a, const v2df &b) + { v2df c; c.v = _mm_cmpeq_pd(a.v,b.v); return c; } + + friend inline v2df + operator<(const v2df &a, double b) + { v2df c; c.v = _mm_cmplt_pd(a.v,_mm_set1_pd(b)); return c; } + + friend inline v2df + operator>(const v2df &a, double b) + { v2df c; c.v = _mm_cmpgt_pd(a.v,_mm_set1_pd(b)); return c; } + + friend inline v2df + max(const v2df &a, v2df &b) + { v2df c; c.v = _mm_max_pd(a.v,b.v); return c; } + + inline double & + operator[](int index) { + return ((double *)&v)[index]; + } + + inline const double & + operator[](int index) const { + return ((double *)&v)[index]; + } +}; diff --git a/template/vst.cpp b/template/vst.cpp index 5d5e7e2..7f456a9 100644 --- a/template/vst.cpp +++ b/template/vst.cpp @@ -37,7 +37,7 @@ struct plugin : public AudioEffectX char programName[kVstMaxProgNameLen]; - Param params[CrapPlug::parameters]; + Param *params; Crap *crap; }; @@ -53,6 +53,8 @@ plugin::plugin(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, 1, CrapPlug::parameters) { crap = new CrapPlug(); + if (CrapPlug::parameters) + params = new Param[CrapPlug::parameters]; setNumInputs(2); setNumOutputs(2); setUniqueID(CrapPlug::id); @@ -65,6 +67,8 @@ plugin::plugin(audioMasterCallback audioMaster) plugin::~plugin() { delete crap; + if (CrapPlug::parameters) + delete[] params; } void diff --git a/util/generate.vbs b/util/generate.vbs new file mode 100755 index 0000000..8ef9311 --- /dev/null +++ b/util/generate.vbs @@ -0,0 +1,18 @@ +Set FSO = CreateObject("Scripting.FileSystemObject") + +Name = WScript.Arguments(0) + +IPath = "../template/vst.cpp" +OPath = "../crap/vst/"&Name&".cpp" +Inc = "crap/"&Name&".hpp" + +Set File = FSO.OpenTextFile(IPath) +Text = File.ReadAll +File.Close + +Text = Replace(Text, "//#INCLUDE", "#include """&Inc&"""") +Text = Replace(Text, "//#REDEFINE", "#define CrapPlug Crap_"&Name) + +Set File = FSO.CreateTextFile(OPath, True) +File.Write Text +File.Close