Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
suzumushi0 authored Mar 23, 2024
1 parent 28840e6 commit bfaf933
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 97 deletions.
20 changes: 10 additions & 10 deletions source/SO2ndordIIRfilters.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Copyright (c) 2021-2023 suzumushi
// Copyright (c) 2021-2024 suzumushi
//
// 2023-4-13 SO2ndordIIRfilters.h
// 2024-3-10 SO2ndordIIRfilters.h
//
// Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0).
//
Expand Down Expand Up @@ -58,7 +58,7 @@ template <typename TYPE>
void SOsphere_scattering <TYPE>:: setup (const TYPE cT, const TYPE a)
{
TYPE omega_a = tan (cT / (2.0 * a)); // omega_a = tan (c * T / (2 * a))
TYPE omega_a_2 = 2.0 * pow (omega_a, 2.0); // omega_a_2 = 2 * omega_a^2
TYPE omega_a_2 = 2.0 * omega_a * omega_a; // omega_a_2 = 2 * omega_a^2
this->a [0] = omega_a_2 + 2.0 * omega_a + 1.0; // a [0] = 2 * omega_a^2 + 2 * omega_a + 1
this->a [1] = -2.0 * (omega_a_2 - 1.0) / this->a [0]; // a [1] = -2 * (2 * omega_a^2 - 1) / a [0]
this->a [2] = - (omega_a_2 - 2.0 * omega_a + 1.0) / this->a [0]; // a [2] = -(2 * omega_a^2 - 2 * omega_a + 1) / a [0]
Expand Down Expand Up @@ -101,7 +101,7 @@ void SOLPF <TYPE, FC_MAX>:: setup (const TYPE SR, const TYPE fc, const TYPE Q)
} else {
pass_through = false;
TYPE omega_a = tan (pi * fc / SR);
TYPE omega_a_2 = pow (omega_a, 2.0); // omega_a_2 = omega_a^2
TYPE omega_a_2 = omega_a * omega_a; // omega_a_2 = omega_a^2
TYPE omega_a_Q = omega_a / Q; // omega_a_Q = omega_a / Q
this->a [0] = omega_a_2 + omega_a_Q + 1.0; // a [0] = omega_a^2 + omega_a / Q + 1
this->a [1] = -2.0 * (omega_a_2 - 1.0) / this->a [0]; // a [1] = -2 * (omega_a^2 - 1) / a [0]
Expand Down Expand Up @@ -140,7 +140,7 @@ void SOHPF <TYPE, MUTE_LEN>:: setup (const TYPE SR, const TYPE fc, const TYPE Q)
mute_timer = (int)(SR + 0.5) * MUTE_LEN / 1000;

TYPE omega_a = tan (pi * fc / SR);
TYPE omega_a_2 = pow (omega_a, 2.0); // omega_a_2 = omega_a^2
TYPE omega_a_2 = omega_a * omega_a; // omega_a_2 = omega_a^2
TYPE omega_a_Q = omega_a / Q; // omega_a_Q = omega_a / Q
this->a [0] = omega_a_2 + omega_a_Q + 1.0; // a [0] = omega_a^2 + omega_a / Q + 1
this->a [1] = -2.0 * (omega_a_2 - 1.0) / this->a [0]; // a [1] = -2 * (omega_a^2 - 1) / a [0]
Expand Down Expand Up @@ -180,7 +180,7 @@ template <typename TYPE>
void SOBPF_G <TYPE>:: setup (const TYPE SR, const TYPE fc, const TYPE Q)
{
TYPE omega_a = tan (pi * fc / SR);
TYPE omega_a_2 = pow (omega_a, 2.0); // omega_a_2 = omega_a^2
TYPE omega_a_2 = omega_a * omega_a; // omega_a_2 = omega_a^2
TYPE omega_a_Q = omega_a / Q; // omega_a_Q = omega_a / Q
this->a [0] = omega_a_2 + omega_a_Q + 1.0; // a [0] = omega_a^2 + omega_a / Q + 1
this->a [1] = -2.0 * (omega_a_2 - 1.0) / this->a [0]; // a [1] = -2 * (omega_a^2 - 1) / a [0]
Expand All @@ -202,7 +202,7 @@ template <typename TYPE>
void SOBPF_B <TYPE>:: setup (const TYPE SR, const TYPE fc, const TYPE Q)
{
TYPE omega_a = tan (pi * fc / SR);
TYPE omega_a_2 = pow (omega_a, 2.0); // omega_a_2 = omega_a^2
TYPE omega_a_2 = omega_a * omega_a; // omega_a_2 = omega_a^2
TYPE omega_a_Q = omega_a / Q; // omega_a_Q = omega_a / Q
this->a [0] = omega_a_2 + omega_a_Q + 1.0; // a [0] = omega_a^2 + omega_a / Q + 1
this->a [1] = -2.0 * (omega_a_2 - 1.0) / this->a [0]; // a [1] = -2 * (omega_a^2 - 1) / a [0]
Expand All @@ -224,8 +224,8 @@ template <typename TYPE>
void SOBPF_E <TYPE>:: setup (const TYPE SR, const TYPE fc, const TYPE Q)
{
TYPE omega_a = tan (pi * fc / SR);
TYPE omega_a_2 = pow (omega_a, 2.0); // omega_a_2 = omega_a^2
TYPE omega_a_Q2 = omega_a / pow (Q, 2.0); // omega_a_Q2 = omega_a / Q^2
TYPE omega_a_2 = omega_a * omega_a; // omega_a_2 = omega_a^2
TYPE omega_a_Q2 = omega_a / (Q * Q); // omega_a_Q2 = omega_a / Q^2
this->a [0] = omega_a_2 + omega_a_Q2 + 1.0; // a [0] = omega_a^2 + omega_a / Q^2 + 1
this->a [1] = -2.0 * (omega_a_2 - 1.0) / this->a [0]; // a [1] = -2 * (omega_a^2 - 1) / a [0]
this->a [2] = - (omega_a_2 - omega_a_Q2 + 1.0) / this->a [0]; // a [2] = -(omega_a^2 - omega_a / Q^2 + 1) / a [0]
Expand All @@ -246,7 +246,7 @@ template <typename TYPE>
void SOPFE <TYPE>:: setup (const TYPE SR, const TYPE fc, const TYPE Q, const TYPE A)
{
TYPE omega_a = tan (pi * fc / SR);
TYPE omega_a_2 = pow (omega_a, 2.0); // omega_a_2 = omega_a^2
TYPE omega_a_2 = omega_a * omega_a; // omega_a_2 = omega_a^2
TYPE omega_a_AQ = omega_a / (A * Q); // omega_a_AQ = omega_a / (AQ)
TYPE omega_a_A_Q = omega_a * A / Q; // omega_a_A_Q = omega_a * A / Q
this->a [0] = omega_a_2 + omega_a_AQ + 1.0; // a [0] = omega_a^2 + omega_a / (AQ) + 1
Expand Down
100 changes: 60 additions & 40 deletions source/SODSPparam.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//
// Copyright (c) 2021-2024 suzumushi
//
// 2024-1-3 SODSPparam.cpp
// 2024-3-21 SODSPparam.cpp
//
// Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0).
//
// https://creativecommons.org/licenses/by-nc-sa/4.0/
//

#include "SODSPparam.h"
#include "SOXYPad.h"


namespace suzumushi {
Expand Down Expand Up @@ -58,8 +59,8 @@ void SODSPparam:: rt_param_update (struct GUI_param &gp, IParameterChanges* outP
gp.s_z = std::min (std::max (gp.s_z, edge [5]), edge [4]);

// re-calculate positions
double gp_s_x_2_y_2 = pow (gp.s_x, 2.0) + pow (gp.s_y, 2.0);
gp.r = sqrt (gp_s_x_2_y_2 + pow (gp.s_z, 2.0));
double gp_s_x_2_y_2 = gp.s_x * gp.s_x + gp.s_y * gp.s_y;
gp.r = sqrt (gp_s_x_2_y_2 + gp.s_z * gp.s_z);
if (gp.r != 0.0) {
gp.theta = asin (gp.s_z / gp.r) * 180.0 / pi;
gp.phi= acos (gp.s_x / sqrt (gp_s_x_2_y_2)) * 180.0 / pi;
Expand Down Expand Up @@ -106,20 +107,24 @@ void SODSPparam:: rt_param_update (struct GUI_param &gp, IParameterChanges* outP
double s_y = gp.s_y;
double s_z = gp.s_z;
if (! gp.reset) {
double v = sqrt (pow (gp.s_x - prev_s_x, 2.0) + pow (gp.s_y - prev_s_y, 2.0) + pow (gp.s_z - prev_s_z, 2.0));
double d_s_x = s_x - prev_s_x;
double d_s_y = s_y - prev_s_y;
double d_s_z = s_z - prev_s_z;
double v = sqrt (d_s_x * d_s_x + d_s_y * d_s_y + d_s_z * d_s_z);
if (v > v_limit) {
s_x = (gp.s_x - prev_s_x) * v_limit / v + prev_s_x;
s_y = (gp.s_y - prev_s_y) * v_limit / v + prev_s_y;
s_z = (gp.s_z - prev_s_z) * v_limit / v + prev_s_z;
double cof = v_limit / v;
s_x = d_s_x * cof + prev_s_x;
s_y = d_s_y * cof + prev_s_y;
s_z = d_s_z * cof + prev_s_z;
gp.param_changed = true;
}
}
prev_s_x = s_x;
prev_s_y = s_y;
prev_s_z = s_z;
double s_x_2 = pow (s_x, 2.0);
double s_y_2 = pow (s_y, 2.0);
double s_z_2 = pow (s_z, 2.0);
double s_x_2 = s_x * s_x;
double s_y_2 = s_y * s_y;
double s_z_2 = s_z * s_z;


// update of direct wave parameters
Expand Down Expand Up @@ -156,33 +161,41 @@ void SODSPparam:: rt_param_update (struct GUI_param &gp, IParameterChanges* outP


// update of reflected waves parameters
valarray <double> v_s_x {2.0 * edge [0] - s_x, 2.0 * edge [1] - s_x, s_x, s_x, s_x, s_x};
valarray <double> v_s_y {s_y, s_y, 2.0 * edge [2] - s_y, 2.0 * edge [3] - s_y, s_y, s_y};
valarray <double> v_s_z {s_z, s_z, s_z, s_z, 2.0 * edge [4] - s_z, 2.0 * edge [5] - s_z};
valarray <double> v_s_x_2 {pow (v_s_x [0], 2.0), pow (v_s_x [1], 2.0), s_x_2, s_x_2, s_x_2, s_x_2};
valarray <double> v_s_y_2 {s_y_2, s_y_2, pow (v_s_y [2], 2.0), pow (v_s_y [3], 2.0), s_y_2, s_y_2};
valarray <double> v_s_z_2 {s_z_2, s_z_2, s_z_2, s_z_2, pow (v_s_z [4], 2.0), pow (v_s_z [5], 2.0)};
valarray <double> v_s_x_2_z_2 = v_s_x_2 + v_s_z_2;
valarray <double> v_med_r = sqrt (v_s_x_2_z_2);
valarray <double> v_r = sqrt (v_s_x_2_z_2 + v_s_y_2);
double v_s_x [] {2.0 * edge [0] - s_x, 2.0 * edge [1] - s_x, s_x, s_x, s_x, s_x};
double v_s_y [] {s_y, s_y, 2.0 * edge [2] - s_y, 2.0 * edge [3] - s_y, s_y, s_y};
double v_s_z [] {s_z, s_z, s_z, s_z, 2.0 * edge [4] - s_z, 2.0 * edge [5] - s_z};
double v_s_x_2 [] {v_s_x [0] * v_s_x [0], v_s_x [1] * v_s_x [1], s_x_2, s_x_2, s_x_2, s_x_2};
double v_s_y_2 [] {s_y_2, s_y_2, v_s_y [2] * v_s_y [2], v_s_y [3] * v_s_y [3], s_y_2, s_y_2};
double v_s_z_2 [] {s_z_2, s_z_2, s_z_2, s_z_2, v_s_z [4] * v_s_z [4], v_s_z [5] * v_s_z [5]};

double v_s_x_2_z_2 [6];
for (int i = 0; i < 6; i++)
v_s_x_2_z_2 [i] = v_s_x_2 [i] + v_s_z_2 [i];
double v_med_r [6];
for (int i = 0; i < 6; i++)
v_med_r [i] = sqrt (v_s_x_2_z_2 [i]);

for (int i = 0; i < 6; i++) {
if (v_med_r [i] != 0.0)
v_theta_p [i] = v_s_x [i] / v_med_r [i];
v_theta_p [i] = acos (v_s_x [i] / v_med_r [i]);
else
v_theta_p [i] = 1.0;
}
v_theta_p = acos (v_theta_p);
for (int i = 0; i < 6; i++) {
v_theta_p [i] = 0.0;
if (v_s_z [i] < 0.0)
v_theta_p [i] = - v_theta_p [i];
}

valarray <double> v_next_cos_theta_o = v_s_y / v_r;
valarray <double> v_near_side = a_r * v_next_cos_theta_o;
valarray <double> v_far_side = acos (v_next_cos_theta_o);
v_far_side = a_r * v_far_side;
v_far_side = a_r * pi / 2.0 - v_far_side;
double v_r [6];
for (int i = 0; i < 6; i++)
v_r [i] = sqrt (v_s_x_2_z_2 [i] + v_s_y_2 [i]);
double v_next_cos_theta_o [6];
for (int i = 0; i < 6; i++)
v_next_cos_theta_o [i] = v_s_y [i] / v_r [i];
double v_near_side [6];
for (int i = 0; i < 6; i++)
v_near_side [i] = a_r * v_next_cos_theta_o [i];
double v_far_side [6];
for (int i = 0; i < 6; i++)
v_far_side [i] = a_r * (pi / 2.0 - acos (v_next_cos_theta_o [i]));

for (int i = 0; i < 6; i++) {
if (v_next_cos_theta_o [i] >= 0.0) {
Expand All @@ -194,11 +207,11 @@ void SODSPparam:: rt_param_update (struct GUI_param &gp, IParameterChanges* outP
}
}

valarray <double> v_next_decay = pow (v_r, d_att);
for (int i = 0; i < 6; i++)
v_next_decay [i] = std::max (v_next_decay [i], min_dist);
double ref = rangeParameter:: dB_to_ratio (gp.reflectance);
v_next_decay = ref / v_next_decay;
double v_next_decay [6];
for (int i = 0; i < 6; i++)
v_next_decay [i] = ref / std::max (pow (v_r [i], d_att), min_dist);


// update of parameter for crosstalk canceller
sin_phiL = sin (gp.phiL * pi / 180.0);
Expand All @@ -208,14 +221,18 @@ void SODSPparam:: rt_param_update (struct GUI_param &gp, IParameterChanges* outP
cos_theta_o = next_cos_theta_o;
decay_L = next_decay_L;
decay_R = next_decay_R;
v_cos_theta_o = v_next_cos_theta_o;
v_decay = v_next_decay;
for (int i = 0; i < 6; i++) {
v_cos_theta_o [i] = v_next_cos_theta_o [i];
v_decay [i] = v_next_decay [i];
}
} else {
delta_cos_theta_o = (next_cos_theta_o - cos_theta_o) / frame_len;
delta_decay_L = (next_decay_L - decay_L) / frame_len;
delta_decay_R = (next_decay_R - decay_R) / frame_len;
v_delta_cos_theta_o = (v_next_cos_theta_o - v_cos_theta_o) / frame_len;
v_delta_decay = (v_next_decay - v_decay) / frame_len;
for (int i = 0; i < 6; i++) {
v_delta_cos_theta_o [i] = (v_next_cos_theta_o [i] - v_cos_theta_o [i]) / frame_len;
v_delta_decay [i] = (v_next_decay [i] - v_decay [i]) / frame_len;
}
}
gp.reset = false;
}
Expand All @@ -227,7 +244,7 @@ void SODSPparam:: nrt_param_update (struct GUI_param &gp, IParameterChanges* out
inv_cT = sampleRate / gp.c;
v_limit = max_speed * frame_len / inv_cT;
a_r = gp.a / 1'000.0; // [mm] to [m]
a_2 = pow (a_r, 2.0);
a_2 = a_r * a_r;

// parameters range check
if (gp.r_x >= max_side_len / 2.0 + min_dist)
Expand Down Expand Up @@ -275,8 +292,11 @@ void SODSPparam:: param_smoothing ()
cos_theta_o += delta_cos_theta_o;
decay_L += delta_decay_L;
decay_R += delta_decay_R;
v_cos_theta_o += v_delta_cos_theta_o;
v_decay += v_delta_decay;
for (int i = 0; i < 6; i++) {
v_cos_theta_o [i] += v_delta_cos_theta_o [i];
v_decay [i] += v_delta_decay [i];
}

}
}

Expand Down
20 changes: 8 additions & 12 deletions source/SODSPparam.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Copyright (c) 2021-2024 suzumushi
//
// 2024-1-2 SODSPparam.h
// 2024-3-21 SODSPparam.h
//
// Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0).
//
Expand All @@ -11,14 +11,10 @@
#pragma once

#include "SOparam.h"
#include "SOXYPad.h"

#include "pluginterfaces/vst/ivstparameterchanges.h"
using namespace Steinberg;
using namespace Vst;

#include <valarray>
using std::valarray;
#ifdef _MSC_VER // Visual C++
#include <numbers>
using std::numbers::pi;
Expand All @@ -45,11 +41,11 @@ class SODSPparam {
double decay_L {1.0};
double decay_R {1.0};
// real-time parameters for reflected waves
valarray <double> v_cos_theta_o {valarray <double> (0.0, 6)};
valarray <double> v_theta_p {valarray <double> (0.0, 6)};
valarray <double> v_distance_L {valarray <double> (1.0, 6)};
valarray <double> v_distance_R {valarray <double> (1.0, 6)};
valarray <double> v_decay {valarray <double> (1.0, 6)};
double v_cos_theta_o [6];
double v_theta_p [6];
double v_distance_L [6];
double v_distance_R [6];
double v_decay [6];
// real-time parameter for crosstalk canceller
double sin_phiL {1.0};

Expand All @@ -73,8 +69,8 @@ class SODSPparam {
double delta_cos_theta_o {0.0};
double delta_decay_L {1.0};
double delta_decay_R {1.0};
valarray <double> v_delta_cos_theta_o {valarray <double> (0.0, 6)};
valarray <double> v_delta_decay {valarray <double> (1.0, 6)};
double v_delta_cos_theta_o [6];
double v_delta_decay [6];
};

} // namespace suzumushi
6 changes: 4 additions & 2 deletions source/SOXYPad.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Copyright (c) 2023 suzumushi
// Copyright (c) 2023-2024 suzumushi
//
// 2023-11-29 SOXYPad.cpp
// 2024-3-10 SOXYPad.cpp
//
// Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0).
//
Expand All @@ -12,6 +12,8 @@

#include "version.h"
#include "SOXYPad.h"
#include "SOconfig.h"


namespace VSTGUI {

Expand Down
6 changes: 3 additions & 3 deletions source/SOXYPad.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Copyright (c) 2023 suzumushi
// Copyright (c) 2023-2024 suzumushi
//
// 2023-11-25 SOXYPad.h
// 2024-3-10 SOXYPad.h
//
// Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0).
//
Expand All @@ -12,9 +12,9 @@

#include "vstgui4/vstgui/lib/controls/cxypad.h"

#include "SOconfig.h"
#include "SOparam.h"


namespace VSTGUI {

// XYPad for SoundObject
Expand Down
7 changes: 4 additions & 3 deletions source/SOcontroller.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//
// Copyright (c) 2021-2023 suzumushi
// Copyright (c) 2021-2024 suzumushi
//
// 2023-11-26 SOcontroller.cpp
// 2024-3-10 SOcontroller.cpp
//
// Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0).
//
// https://creativecommons.org/licenses/by-nc-sa/4.0/
//

#include "SOcontroller.h"
#include "SOcids.h"
#include "SOparam.h"
#include "SOvst3editor.h"
#include "vstgui/plugin-bindings/vst3editor.h"

// suzumushi:
Expand Down
8 changes: 2 additions & 6 deletions source/SOcontroller.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Copyright (c) 2021-2023 suzumushi
// Copyright (c) 2021-2024 suzumushi
//
// 2023-11-21 SOcontroller.h
// 2024-3-10 SOcontroller.h
//
// Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0).
//
Expand All @@ -12,10 +12,6 @@

#include "public.sdk/source/vst/vsteditcontroller.h"

// suzumushi:
#include "SOparam.h"
#include "SOextparam.h"
#include "SOvst3editor.h"

namespace suzumushi {

Expand Down
Loading

0 comments on commit bfaf933

Please sign in to comment.