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 all commits
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
74 changes: 48 additions & 26 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 @@ -1910,13 +1910,26 @@ void FoaAsymmetry_next_k(FoaAsymmetry *unit, int inNumSamples)


///////////////////////////////////////////////////////////////////////////////////////////////////////
// FoaNFC -
// FoaNFC
void FoaNFC_Ctor(FoaNFC* unit)
{
int numChannels = unit->mNumInputs;

unit->m_y1x = 0.0f;
unit->m_y1y = 0.0f;
unit->m_y1z = 0.0f;
unit->m_distanceStart = IN0(4);
/*
maintain backwards compatibility w/ atk-sc3 quark <= v5.0.3
https://github.com/ambisonictoolkit/atk-sc3
*/
if (numChannels == 6) {
unit->m_speedOfSound = IN0(5);
} else {
// previous (equivalent) value
unit->m_speedOfSound = 333.0;
}

if (INRATE(4) == calc_FullRate) {
SETCALC(FoaNFC_next_a);
} else {
Expand All @@ -1937,19 +1950,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++){
float freq = 53.0 / distanceStart;
float wc = (twopi * freq) * SAMPLEDUR;

// a0 = (1 + (wc.cos.neg * 2 + 2).sqrt).reciprocal;
for(int i = 0; i < inNumSamples; i++){
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 @@ -1990,14 +2001,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++){
float freq = 53.0 / 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 @@ -2027,10 +2038,23 @@ void FoaNFC_next_a(FoaNFC *unit, int inNumSamples)

void FoaProximity_Ctor(FoaProximity* unit)
{
int numChannels = unit->mNumInputs;

unit->m_y1x = 0.0f;
unit->m_y1y = 0.0f;
unit->m_y1z = 0.0f;
unit->m_distanceStart = IN0(4);
/*
maintain backwards compatibility w/ atk-sc3 quark <= v5.0.3
https://github.com/ambisonictoolkit/atk-sc3
*/
if (numChannels == 6) {
unit->m_speedOfSound = IN0(5);
} else {
// previous (equivalent) value
unit->m_speedOfSound = 333.0;
}

if (INRATE(4) == calc_FullRate) {
SETCALC(FoaProximity_next_a);
} else {
Expand All @@ -2051,19 +2075,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++){
float freq = 53.0 / distanceStart;
float wc = (twopi * freq) * SAMPLEDUR;

// a0 = 1 + (wc.cos.neg * 2 + 2).sqrt;
for(int i = 0; i < inNumSamples;i++){
float wc = (speedOfSound / distanceStart) * SAMPLEDUR;
float a0 = 1 + sqrt((cos(wc) * -2) + 2);

// W is passed straight out
Expand Down Expand Up @@ -2104,14 +2126,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++){
float freq = 53.0 / distance[i];
float wc = (twopi * freq) * SAMPLEDUR;

for(int i = 0; i < inNumSamples; i++){
float wc = (speedOfSound / distance[i]) * SAMPLEDUR;
float a0 = 1 + sqrt((cos(wc) * -2) + 2);

// W is passed straight out
Expand Down
146 changes: 95 additions & 51 deletions source/ATK/sc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@ ATK UGens for SuperCollider3 : Read Me

This is the unit generator plugin (UGen) component of the SuperCollider3 version
of the Ambisonic Toolkit (ATK), which is distributed via the
[sc3-plugins](https://github.com/supercollider/sc3-plugins) project. It can be
used with [SuperCollider3](http://supercollider.github.io/) on OSX, Linux and
Windows.
[sc3-plugins](https://github.com/supercollider/sc3-plugins) project. It can be used with [SuperCollider](http://supercollider.github.io/) on OSX,
Linux and Windows, and is distributed as a
[Quark package](https://github.com/ambisonictoolkit/atk-sc3) with [sc3-plugins](https://github.com/supercollider/sc3-plugins) components, and
[other dependencies](http://www.ambisonictoolkit.net/download/supercollider/).


The Ambisonic Toolkit (ATK) is intended to bring together a number of
tools and methods for working with Ambisonic surround sound. The intention
is for the toolset to be both ergonomic and comprehensive, providing both
classic and novel algorithms to creatively manipulate and synthesise
complex Ambisonic soundfields.
complex Ambisonic soundfields.

Tools are offered in two sets:
* The first of these is modeled after the hardware and software
tools offered in the world of classic, aka Gerzonic, First Order
Ambisonics (FOA).
* The second is framed as a modern Near-Field Controlled Higher Order
Ambisonic (NFC-HOA) solution.

The tools are framed for the user to think in terms of the soundfield
kernel. By this, it is meant the ATK addresses the holistic problem of
Expand All @@ -24,11 +33,11 @@ technique.

We hope you enjoy the ATK!

For more information please visit the
[Ambisonic Toolkit website](http:www.ambisonictoolkit.net) or send us an
For more information please visit the [Ambisonic Toolkit
website](http:www.ambisonictoolkit.net/) or send us an
[e-mail](mailto:info[at]ambisonictoolkit.net). See also
[Introducing the Ambisonic Toolkit](http://doc.sccode.org/Guides/Intro-to-the-ATK.html)
for an overview on working with the ATK for SuperCollider3.
[ABCs of the ATK](http://doc.sccode.org/Tutorials/ABCs-of-the-ATK.html)
for an overview on working with the ATK for SuperCollider.



Expand All @@ -44,7 +53,7 @@ Installing
Requirements
------------

* ATK for [SuperCollider3](http://supercollider.github.io) requires version 3.5
ATK for [SuperCollider](http://supercollider.github.io) requires version 3.10
or later. Download the latest version
[here](http://supercollider.github.io/download), or fork the source code at
[GitHub](http://supercollider.github.io/).
Expand All @@ -54,9 +63,9 @@ or later. Download the latest version
atk-sc3 Quark
-----------

The ATK for [SuperCollider3](http://supercollider.github.io)'s classes,
The ATK for [SuperCollider](http://supercollider.github.io)'s classes,
extension methods and documentation are distributed via the
[atk-sc3 Quark](https://github.com/ambisonictoolkit/atk-sc3). Start by reviewing
[atk-sc3 quark](https://github.com/ambisonictoolkit/atk-sc3). Start by reviewing
the Quark installation instructions
[found here](https://github.com/supercollider-quarks/quarks#installing). See
also [Using Quarks](http://doc.sccode.org/Guides/UsingQuarks.html).
Expand All @@ -65,7 +74,16 @@ With [git](https://git-scm.com/) installed, you can easily install the
[atk-sc3 Quark](https://github.com/ambisonictoolkit/atk-sc3) directly by
running the following line of code in SuperCollider:

Quarks.install("https://github.com/ambisonictoolkit/atk-sc3.git");
```supercollider
Quarks.install("https://github.com/ambisonictoolkit/atk-sc3.git");
```

If you've previously installed the ATK, you'll want to update all the dependencies
to their current versions. The easiest way to do so is via the Quarks GUI:

```supercollider
QuarksGui.new;
```


sc3-plugins
Expand All @@ -85,43 +103,58 @@ You may need to create the `Extensions` folder if it does not already exist.
On other platforms, you can find where this is by running the following line of
code in SuperCollider:

(
// post the directory in which to move the SC3Plugins folder
Platform.userExtensionDir.postln;
)
(
// alternatively, SC can open it for you
// (assuming it already exists! - you may need to create /Extensions)
Platform.userExtensionDir.openOS;
)
```supercollider
(
// post the directory in which to move the SC3Plugins folder
Platform.userExtensionDir.postln;
)
(
// alternatively, SC can open it for you
// (assuming it already exists! - you may need to create /Extensions)
Platform.userExtensionDir.openOS;
)
```

If you've previously installed the ATK, you'll want to be sure to install the
version of [sc3-plugins](https://github.com/supercollider/sc3-plugins/releases)
that is compatible with your installed version of [SuperCollider](http://supercollider.github.io/download).

Kernels & Recordings
--------------------

Additionally, the SuperCollider3 version of the ATK has further dependencies:
Kernels, Matrices & Soundfiles
--------------------

* Download and install [ATK Kernels](http://www.ambisonictoolkit.net/download/kernels/).
* Download and install [ATK Sound File Example Recordings](http://www.ambisonictoolkit.net/download/recordings/).
Additionally, the SuperCollider version of the ATK has further dependencies:

* [ATK Kernels](http://www.ambisonictoolkit.net/download/kernels/)
* [ATK Matrices](http://www.ambisonictoolkit.net/download/matrices/)
* [ATK Soundfiles](http://www.ambisonictoolkit.net/download/recordings/)

&nbsp;
Install Kernels, Matrices, and Soundfiles by running the following code:

### Source code
```supercollider
Atk.downloadKernels;
Atk.downloadMatrices;
Atk.downloadSounds;
```

You can build the ATK for SuperCollider UGen components from the [sc3-plugins](https://github.com/supercollider/sc3-plugins) source-code.
If successful, these three dependencies are installed here:

```supercollider
(
// post the kernel, matrix and sounds directories
Atk.userKernelDir.postln;
Atk.userMatrixDir.postln;
Atk.userSoundsDir.postln;
)
```

&nbsp;

If you are using Ambisonic Toolkit with Reaper as well,
the convolution kernels are installed in the same place and have
the exact same content. We do not expect this to cause any conflicts.
Source code
-----------

You can build the ATK for SuperCollider UGen components from the [sc3-plugins](https://github.com/supercollider/sc3-plugins) source-code.

If you want to take a look at the installed files and do not see the
Library folder in Finder, please press the ALT button while clicking
the "Go" menu in Finder. The Library folder will show up as an
additional option.

&nbsp;

Expand All @@ -136,10 +169,9 @@ You can find a collection of sound files here. (Download as part of installation

Additional sound files can be grabbed from these fine sources:

* [http://ambisonia.com/](http://ambisonia.com/).
* [http://www.freesound.org/browse/tags/B-format/](http://www.freesound.org/browse/tags/B-format/).
* [http://www.surround-library.com/](http://www.surround-library.com/) (commercial library ambisonic sound effects).
* [http://www.spheric-collection.com/](http://www.spheric-collection.com/) (commercial library ambisonic sound effects).
* [Ambisonic Sound Library](https://library.soundfield.com/).
* [Ambisonia](http://ambisonia.com/).
* [Freesound](http://www.freesound.org/browse/tags/B-format/).

&nbsp;

Expand All @@ -157,23 +189,32 @@ Feedback and Bug Reports
Known issues are logged at
[GitHub](https://github.com/ambisonictoolkit/atk-sc3/issues).

If you experience problems or have questions pertaining to the ATK for Reaper
plugins, please create an issue in the
[ATK-Reaper issue tracker](https://github.com/ambisonictoolkit/atk-sc3/issues).
If you experience problems or have questions pertaining to the ATK for
SuperCollider, please create an issue in the
[atk-sc3 issue tracker](https://github.com/ambisonictoolkit/atk-sc3/issues).

Experienced users and the developers are active participants on
the [sc-users mailing list](http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml).
Questions posted here are usually answered fairly quickly.

If you use the plugins for some project, please
[let us know](mailto:info[at]ambisonictoolkit.net). We
[plan on](https://github.com/ambisonictoolkit/ambisonictoolkit.github.io/issues/9)
adding a gallery of example artistic and creative projects that make use of the
Ambisonic Toolkit.
An archive of this list can be searched from
[this page](http://www.listarc.bham.ac.uk/lists/sc-users/search/).

If need be, the developers can be contacted directly via
[this address](info@ambisonictoolkit.net).

&nbsp;


List of Changes
---------------

Unreleased 3.9.0
Version 3.12.0

* Refactoring:
* Update (AtkFoa.speedOfSound == AtkHoa.speedOfSound) & user settable

Version 3.9.0

* Refactoring:
* Quark-ify: classes, extension methods & documentation moved to
Expand Down Expand Up @@ -291,7 +332,7 @@ Credits
&nbsp;

Copyright the ATK Community, Joseph Anderson, and Joshua Parmenter, 2011,
2016-17.
2016-21.

* J Anderson : [[e-mail]](mailto:j.anderson[at]ambisonictoolkit.net)
* J Parmenter : [[e-mail]](mailto:j.parmenter[at]ambisonictoolkit.net)
Expand All @@ -309,7 +350,10 @@ are copyright the Ambisonic Toolkit Community and Joseph Anderson,
Contributors
------------

Unreleased 3.9.0
Version 3.12.0
* Joseph Anderson (@joslloand)

Version 3.9.0
* Joseph Anderson (@joslloand)
* Julian Rohrhuber (@telephon)
* Michael McCrea (@mtmccrea)
Expand Down