Skip to content

Commit

Permalink
Move 'Averaging Functions' from maths.lib to filters.lib, cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Jan 11, 2021
1 parent 403f6d5 commit 4a41355
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 129 deletions.
16 changes: 8 additions & 8 deletions analyzers.lib
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ declare abs_envelope_rect copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare abs_envelope_rect license "MIT-style STK-4.3 license";
abs_envelope_rect(period, x) = abs(x) : ma.avg_rect(period);
abs_envelope_rect(period, x) = abs(x) : fi.avg_rect(period);



Expand All @@ -70,7 +70,7 @@ declare abs_envelope_tau copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare abs_envelope_tau license "MIT-style STK-4.3 license";
abs_envelope_tau(period, x) = abs(x) : ma.avg_tau(period);
abs_envelope_tau(period, x) = abs(x) : fi.avg_tau(period);


//------------------`(an.)abs_envelope_t60`------------------------------------
Expand All @@ -92,7 +92,7 @@ declare abs_envelope_t60 copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare abs_envelope_t60 license "MIT-style STK-4.3 license";
abs_envelope_t60(period, x) = abs(x) : ma.avg_t60(period);
abs_envelope_t60(period, x) = abs(x) : fi.avg_t60(period);


//------------------`(an.)abs_envelope_t19`------------------------------------
Expand All @@ -114,7 +114,7 @@ declare abs_envelope_t19 copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare abs_envelope_t19 license "MIT-style STK-4.3 license";
abs_envelope_t19(period, x) = abs(x) : ma.avg_t19(period);
abs_envelope_t19(period, x) = abs(x) : fi.avg_t19(period);


//---------------------------`(an.)amp_follower`---------------------------
Expand Down Expand Up @@ -210,7 +210,7 @@ declare ms_envelope_rect copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare ms_envelope_rect license "MIT-style STK-4.3 license";
ms_envelope_rect(period, x) = x * x : ma.avg_rect(period);
ms_envelope_rect(period, x) = x * x : fi.avg_rect(period);


//------------------`(an.)ms_envelope_tau`-------------------------------------
Expand All @@ -232,7 +232,7 @@ declare ms_envelope_tau copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare ms_envelope_tau license "MIT-style STK-4.3 license";
ms_envelope_tau(period, x) = x * x : ma.avg_tau(period);
ms_envelope_tau(period, x) = x * x : fi.avg_tau(period);


//------------------`(an.)ms_envelope_t60`-------------------------------------
Expand All @@ -254,7 +254,7 @@ declare ms_envelope_t60 copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare ms_envelope_t60 license "MIT-style STK-4.3 license";
ms_envelope_t60(period, x) = x * x : ma.avg_t60(period);
ms_envelope_t60(period, x) = x * x : fi.avg_t60(period);


//------------------`(an.)ms_envelope_t19`-------------------------------------
Expand All @@ -276,7 +276,7 @@ declare ms_envelope_t19 copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare ms_envelope_t19 license "MIT-style STK-4.3 license";
ms_envelope_t19(period, x) = x * x : ma.avg_t19(period);
ms_envelope_t19(period, x) = x * x : fi.avg_t19(period);


//------------------`(an.)rms_envelope_rect`-----------------------------------
Expand Down
2 changes: 1 addition & 1 deletion basics.lib
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ closed source license or any other license if you decide so.

ma = library("maths.lib");
ro = library("routes.lib");
ba = library("basics.lib"); // so functions here can be copy/pasted out
ba = library("basics.lib"); // for compatible copy/paste out of this file
fi = library("filters.lib");
si = library("signals.lib");

Expand Down
115 changes: 114 additions & 1 deletion filters.lib
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ si = library("signals.lib");
fi = library("filters.lib"); // for compatible copy/paste out of this file

declare name "Faust Filters Library";
declare version "0.2";
declare version "0.3";

//===============================Basic Filters============================================
//========================================================================================
Expand Down Expand Up @@ -2660,6 +2660,119 @@ svf = environment {
};


//============================Averaging Functions==============================
//=============================================================================
//
// These are a set of samplerate independent averaging functions based on
// moving-average and one-pole filters with specific response characteristics.

//----------------------------`(fi.)avg_rect`----------------------------------
// Moving average.
//
// #### Usage
//
// ```
// _ : avg_rect(period) : _
// ```
//
// Where:
//
// * `period` is the averaging frame in seconds
//-----------------------------------------------------------------------------
declare avg_rect author "Dario Sanfilippo and Julius O. Smith III";
declare avg_rect copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare avg_rect license "MIT-style STK-4.3 license";
avg_rect(period, x) = x : ba.slidingMean(rint(period * ma.SR));


//----------------------------(fi.)avg_tau-------------------------------------
// Averaging function based on a one-pole filter and the tau response time.
// Tau represents the effective length of the one-pole impulse response,
// that is, tau is the integral of the filter's impulse response. This
// response is slower to reach the final value but has less ripples in
// non-steady signals.
//
// #### Usage
//
// ```
// _ avg_tau(period) : _
// ```
//
// Where:
//
// * `period` is the time, in seconds, for the system to decay by 1/e,
// or to reach 1-1/e of its final value.
//
// #### Reference
//
// <https://ccrma.stanford.edu/~jos/mdft/Exponentials.html>
//-----------------------------------------------------------------------------
declare avg_tau author "Dario Sanfilippo and Julius O. Smith III";
declare avg_tau copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare avg_tau license "MIT-style STK-4.3 license";
avg_tau(period, x) = fi.lptau(period, x);


//----------------------------(fi.)avg_t60-------------------------------------
// Averaging function based on a one-pole filter and the t60 response time.
// This response is particularly useful when the system is required to
// reach the final value after about `period` seconds.
//
// #### Usage
//
// ```
// _ avg_t60(period) : _
// ```
//
// Where:
//
// * `period` is the time, in seconds, for the system to decay by 1/1000,
// or to reach 1-1/1000 of its final value.
//
// #### Reference
//
// <https://ccrma.stanford.edu/~jos/mdft/Audio_Decay_Time_T60.html>
//-----------------------------------------------------------------------------
declare avg_t60 author "Dario Sanfilippo and Julius O. Smith III";
declare avg_t60 copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare avg_t60 license "MIT-style STK-4.3 license";
avg_t60(period, x) = fi.lpt60(period, x);


//----------------------------(fi.)avg_t19-------------------------------------
// Averaging function based on a one-pole filter and the t19 response time.
// This response is close to the moving-average algorithm as it roughly reaches
// the final value after `period` seconds and shows about the same
// oscillations for non-steady signals.
//
// #### Usage
//
// ```
// _ avg_t19(period) : _
// ```
//
// Where:
//
// * `period` is the time, in seconds, for the system to decay by 1/e^2.2,
// or to reach 1-1/e^2.2 of its final value.
//
// #### Reference
// Zölzer, U. (2008). Digital audio signal processing (Vol. 9). New York: Wiley.
//-----------------------------------------------------------------------------
declare avg_t19 author "Dario Sanfilippo and Julius O. Smith III";
declare avg_t19 copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare avg_t19 license "MIT-style STK-4.3 license";
avg_t19(period, x) = fi.lpt19(period, x);


/*******************************************************************************
# Licenses

Expand Down
115 changes: 0 additions & 115 deletions maths.lib
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ declare license "LGPL with exception";

// This library contains platform specific constants
pl = library("platform.lib");
ba = library("basics.lib");
si = library("signals.lib");
fi = library("filters.lib");
ma = library("maths.lib"); // for compatible copy/paste out of this file

//=============================Functions Reference========================================
Expand Down Expand Up @@ -723,115 +720,3 @@ nextpow2(x) = ceil(log(x)/log(2.0));
//-----------------------------------------------------------------------------
zc(x) = x * x' < 0;


//============================Averaging Functions==============================
//=============================================================================
//
// These are a set of samplerate independent averaging functions based on
// moving-average and one-pole filters with specific response characteristics.

//----------------------------`(ma.)avg_rect`----------------------------------
// Moving average.
//
// #### Usage
//
// ```
// _ : avg_rect(period) : _
// ```
//
// Where:
//
// * `period` is the averaging frame in seconds
//-----------------------------------------------------------------------------
declare avg_rect author "Dario Sanfilippo and Julius O. Smith III";
declare avg_rect copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare avg_rect license "MIT-style STK-4.3 license";
avg_rect(period, x) = x : ba.slidingMean(rint(period * ma.SR));


//----------------------------(ma.)avg_tau-------------------------------------
// Averaging function based on a one-pole filter and the tau response time.
// Tau represents the effective length of the one-pole impulse response,
// that is, tau is the integral of the filter's impulse response. This
// response is slower to reach the final value but has less ripples in
// non-steady signals.
//
// #### Usage
//
// ```
// _ avg_tau(period) : _
// ```
//
// Where:
//
// * `period` is the time, in seconds, for the system to decay by 1/e,
// or to reach 1-1/e of its final value.
//
// #### Reference
//
// <https://ccrma.stanford.edu/~jos/mdft/Exponentials.html>
//-----------------------------------------------------------------------------
declare avg_tau author "Dario Sanfilippo and Julius O. Smith III";
declare avg_tau copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare avg_tau license "MIT-style STK-4.3 license";
avg_tau(period, x) = fi.lptau(period, x);


//----------------------------(ma.)avg_t60-------------------------------------
// Averaging function based on a one-pole filter and the t60 response time.
// This response is particularly useful when the system is required to
// reach the final value after about `period` seconds.
//
// #### Usage
//
// ```
// _ avg_t60(period) : _
// ```
//
// Where:
//
// * `period` is the time, in seconds, for the system to decay by 1/1000,
// or to reach 1-1/1000 of its final value.
//
// #### Reference
//
// <https://ccrma.stanford.edu/~jos/mdft/Audio_Decay_Time_T60.html>
//-----------------------------------------------------------------------------
declare avg_t60 author "Dario Sanfilippo and Julius O. Smith III";
declare avg_t60 copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare avg_t60 license "MIT-style STK-4.3 license";
avg_t60(period, x) = fi.lpt60(period, x);


//----------------------------(ma.)avg_t19-------------------------------------
// Averaging function based on a one-pole filter and the t19 response time.
// This response is close to the moving-average algorithm as it roughly reaches
// the final value after `period` seconds and shows about the same
// oscillations for non-steady signals.
//
// #### Usage
//
// ```
// _ avg_t19(period) : _
// ```
//
// Where:
//
// * `period` is the time, in seconds, for the system to decay by 1/e^2.2,
// or to reach 1-1/e^2.2 of its final value.
//
// #### Reference
// Zölzer, U. (2008). Digital audio signal processing (Vol. 9). New York: Wiley.
//-----------------------------------------------------------------------------
declare avg_t19 author "Dario Sanfilippo and Julius O. Smith III";
declare avg_t19 copyright "Copyright (C) 2020 Dario Sanfilippo
<[email protected]> and
2003-2020 by Julius O. Smith III <[email protected]>";
declare avg_t19 license "MIT-style STK-4.3 license";
avg_t19(period, x) = fi.lpt19(period, x);
6 changes: 4 additions & 2 deletions tubes.lib
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
**
******************************************************************************/

fi = library("filters.lib");

/*******************************************************************************
* 1-dimensional function tables for linear interpolation
*******************************************************************************/
Expand Down Expand Up @@ -72,7 +74,7 @@ getFactor(low, step, size, x) =
******************************************************************************/

tubestageF(tb,vplus,divider,fck,Rk,Vk0) = tube : hpf with {
lpfk = library("filters.lib").lowpass(1,fck);
lpfk = fi.lowpass(1,fck);
Rp = 100.0e3;
VkC = Vk0 * (Rp/Rk);

Expand All @@ -83,7 +85,7 @@ tubestageF(tb,vplus,divider,fck,Rk,Vk0) = tube : hpf with {
size = 2000; // (real size = 2001, set the actual size at 2001-1 for interpolation to work at the last point)

tube = (+ : -(Vk0) : tubeF(tb, low, high, step, size) : +(VkC-vplus)) ~ (*(Rk/Rp) : lpfk) : /(divider);
hpf = library("filters.lib").highpass(1,31.0);
hpf = fi.highpass(1,31.0);
};

tubestage(tb,fck,Rk,Vk0) = tubestageF(tb,250.0,40.0,fck,Rk,Vk0);
Expand Down
4 changes: 2 additions & 2 deletions version.lib
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// ```
//
//------------------------------------------------------------
version = 1, // MAJOR version when we make incompatible API changes,
3, // MINOR version when we add functionality in a backwards compatible manner,
version = 2, // MAJOR version when we make incompatible API changes,
0, // MINOR version when we add functionality in a backwards compatible manner,
0; // PATCH version when we make backwards compatible bug fixes.


0 comments on commit 4a41355

Please sign in to comment.