Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic/atk fix speed of sound #319

Merged
merged 5 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions source/ATK/AtkUGens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ struct FoaDominateZ : FoaDominateX { };

struct FoaNFC : public Unit
{
float m_distanceStart, m_y1x, m_y1y, m_y1z;
float m_distanceStart, m_speedOfSound, m_y1x, m_y1y, m_y1z;
};

struct FoaProximity : public Unit
{
float m_distanceStart, m_y1x, m_y1y, m_y1z;
float m_distanceStart, m_speedOfSound, m_y1x, m_y1y, m_y1z;
};

struct FoaPsychoShelf : public Unit
Expand Down Expand Up @@ -1917,6 +1917,7 @@ void FoaNFC_Ctor(FoaNFC* unit)
unit->m_y1y = 0.0f;
unit->m_y1z = 0.0f;
unit->m_distanceStart = IN0(4);
unit->m_speedOfSound = IN0(5);
if (INRATE(4) == calc_FullRate) {
SETCALC(FoaNFC_next_a);
} else {
Expand All @@ -1937,20 +1938,17 @@ void FoaNFC_next_k(FoaNFC *unit, int inNumSamples)
float *Yin = IN(2);
float *Zin = IN(3);
float distanceEnd = IN0(4);
float speedOfSound = unit->m_speedOfSound;

float distanceStart = unit->m_distanceStart;

float distanceInc = CALCSLOPE(distanceEnd, distanceStart);

float y1x = unit->m_y1x;
float y1y = unit->m_y1y;
float y1z = unit->m_y1z;

for(int i = 0; i < inNumSamples; i++){
// AtkFoa.speedOfSound = 343.0 --> 343.0 / 2pi --> 54.59014548052
float freq = 54.59014548052 / distanceStart;
float wc = (twopi * freq) * SAMPLEDUR;

// a0 = (1 + (wc.cos.neg * 2 + 2).sqrt).reciprocal;
float wc = (speedOfSound / distanceStart) * SAMPLEDUR;
joslloand marked this conversation as resolved.
Show resolved Hide resolved
float a0 = 1 / (sqrt((cos(wc) * -2) + 2) + 1);

// W is passed straight out
Expand Down Expand Up @@ -1991,15 +1989,14 @@ void FoaNFC_next_a(FoaNFC *unit, int inNumSamples)
float *Yin = IN(2);
float *Zin = IN(3);
float *distance = IN(4);

float speedOfSound = unit->m_speedOfSound;

float y1x = unit->m_y1x;
float y1y = unit->m_y1y;
float y1z = unit->m_y1z;

for(int i = 0; i < inNumSamples; i++){
// AtkFoa.speedOfSound = 343.0 --> 343.0 / 2pi --> 54.59014548052
float freq = 54.59014548052 / distance[i];
float wc = (twopi * freq) * SAMPLEDUR;
float wc = (speedOfSound / distance[i]) * SAMPLEDUR;
float a0 = 1 / (sqrt((cos(wc) * -2) + 2) + 1);

// W is passed straight out
Expand Down Expand Up @@ -2033,6 +2030,7 @@ void FoaProximity_Ctor(FoaProximity* unit)
unit->m_y1y = 0.0f;
unit->m_y1z = 0.0f;
unit->m_distanceStart = IN0(4);
unit->m_speedOfSound = IN0(5);
if (INRATE(4) == calc_FullRate) {
SETCALC(FoaProximity_next_a);
} else {
Expand All @@ -2053,20 +2051,17 @@ void FoaProximity_next_k(FoaProximity *unit, int inNumSamples)
float *Yin = IN(2);
float *Zin = IN(3);
float distanceEnd = IN0(4);
float speedOfSound = unit->m_speedOfSound;

float distanceStart = unit->m_distanceStart;

float distanceInc = CALCSLOPE(distanceEnd, distanceStart);

float y1x = unit->m_y1x;
float y1y = unit->m_y1y;
float y1z = unit->m_y1z;

for(int i = 0; i < inNumSamples;i++){
// AtkFoa.speedOfSound = 343.0 --> 343.0 / 2pi --> 54.59014548052
float freq = 54.59014548052 / distance[i];
float wc = (twopi * freq) * SAMPLEDUR;

// a0 = 1 + (wc.cos.neg * 2 + 2).sqrt;
float wc = (speedOfSound / distanceStart) * SAMPLEDUR;
float a0 = 1 + sqrt((cos(wc) * -2) + 2);

// W is passed straight out
Expand Down Expand Up @@ -2107,15 +2102,14 @@ void FoaProximity_next_a(FoaProximity *unit, int inNumSamples)
float *Yin = IN(2);
float *Zin = IN(3);
float *distance = IN(4);

float speedOfSound = unit->m_speedOfSound;

float y1x = unit->m_y1x;
float y1y = unit->m_y1y;
float y1z = unit->m_y1z;

for(int i = 0; i < inNumSamples; i++){
// AtkFoa.speedOfSound = 343.0 --> 343.0 / 2pi --> 54.59014548052
float freq = 54.59014548052 / distance[i];
float wc = (twopi * freq) * SAMPLEDUR;
float wc = (speedOfSound / distance[i]) * SAMPLEDUR;
float a0 = 1 + sqrt((cos(wc) * -2) + 2);

// W is passed straight out
Expand Down
2 changes: 1 addition & 1 deletion source/ATK/sc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ List of Changes
Version 3.12.0

* Refactoring:
* Update AtkFoa.speedOfSound == AtkHoa.speedOfSound == 343.0 m/s
* Update (AtkFoa.speedOfSound == AtkHoa.speedOfSound) & user settable

Version 3.9.0

Expand Down