Browse Source

Import roth-air plugin

Signed-off-by: falkTX <falktx@falktx.com>
master
falkTX 1 month ago
parent
commit
bc55bda1fa
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
73 changed files with 17873 additions and 0 deletions
  1. +1
    -0
      libs/juce6.0/meson.build
  2. +1
    -0
      libs/juce6.1/meson.build
  3. +1
    -0
      meson_options.txt
  4. +1
    -0
      ports-juce6.1/meson.build
  5. +4945
    -0
      ports-juce6.1/roth-air/BinaryData.cpp
  6. +63
    -0
      ports-juce6.1/roth-air/BinaryData.h
  7. +295
    -0
      ports-juce6.1/roth-air/Compressor.cpp
  8. +103
    -0
      ports-juce6.1/roth-air/Compressor.h
  9. +485
    -0
      ports-juce6.1/roth-air/DspFilters/Bessel.h
  10. +232
    -0
      ports-juce6.1/roth-air/DspFilters/Biquad.h
  11. +436
    -0
      ports-juce6.1/roth-air/DspFilters/Butterworth.h
  12. +181
    -0
      ports-juce6.1/roth-air/DspFilters/Cascade.h
  13. +465
    -0
      ports-juce6.1/roth-air/DspFilters/ChebyshevI.h
  14. +466
    -0
      ports-juce6.1/roth-air/DspFilters/ChebyshevII.h
  15. +66
    -0
      ports-juce6.1/roth-air/DspFilters/Common.h
  16. +177
    -0
      ports-juce6.1/roth-air/DspFilters/Custom.h
  17. +64
    -0
      ports-juce6.1/roth-air/DspFilters/Design.h
  18. +62
    -0
      ports-juce6.1/roth-air/DspFilters/Dsp.h
  19. +359
    -0
      ports-juce6.1/roth-air/DspFilters/Elliptic.h
  20. +269
    -0
      ports-juce6.1/roth-air/DspFilters/Filter.h
  21. +170
    -0
      ports-juce6.1/roth-air/DspFilters/Layout.h
  22. +417
    -0
      ports-juce6.1/roth-air/DspFilters/Legendre.h
  23. +154
    -0
      ports-juce6.1/roth-air/DspFilters/MathSupplement.h
  24. +244
    -0
      ports-juce6.1/roth-air/DspFilters/Params.h
  25. +217
    -0
      ports-juce6.1/roth-air/DspFilters/PoleFilter.h
  26. +335
    -0
      ports-juce6.1/roth-air/DspFilters/RBJ.h
  27. +129
    -0
      ports-juce6.1/roth-air/DspFilters/RootFinder.h
  28. +155
    -0
      ports-juce6.1/roth-air/DspFilters/SmoothedFilter.h
  29. +323
    -0
      ports-juce6.1/roth-air/DspFilters/State.h
  30. +139
    -0
      ports-juce6.1/roth-air/DspFilters/Types.h
  31. +730
    -0
      ports-juce6.1/roth-air/DspFilters/Utilities.h
  32. +224
    -0
      ports-juce6.1/roth-air/DspFilters/source/Bessel.cpp
  33. +236
    -0
      ports-juce6.1/roth-air/DspFilters/source/Biquad.cpp
  34. +212
    -0
      ports-juce6.1/roth-air/DspFilters/source/Butterworth.cpp
  35. +118
    -0
      ports-juce6.1/roth-air/DspFilters/source/Cascade.cpp
  36. +272
    -0
      ports-juce6.1/roth-air/DspFilters/source/ChebyshevI.cpp
  37. +271
    -0
      ports-juce6.1/roth-air/DspFilters/source/ChebyshevII.cpp
  38. +66
    -0
      ports-juce6.1/roth-air/DspFilters/source/Custom.cpp
  39. +41
    -0
      ports-juce6.1/roth-air/DspFilters/source/Design.cpp
  40. +456
    -0
      ports-juce6.1/roth-air/DspFilters/source/Documentation.cpp
  41. +384
    -0
      ports-juce6.1/roth-air/DspFilters/source/Elliptic.cpp
  42. +117
    -0
      ports-juce6.1/roth-air/DspFilters/source/Filter.cpp
  43. +344
    -0
      ports-juce6.1/roth-air/DspFilters/source/Legendre.cpp
  44. +309
    -0
      ports-juce6.1/roth-air/DspFilters/source/Param.cpp
  45. +337
    -0
      ports-juce6.1/roth-air/DspFilters/source/PoleFilter.cpp
  46. +207
    -0
      ports-juce6.1/roth-air/DspFilters/source/RBJ.cpp
  47. +188
    -0
      ports-juce6.1/roth-air/DspFilters/source/RootFinder.cpp
  48. +43
    -0
      ports-juce6.1/roth-air/DspFilters/source/State.cpp
  49. BIN
      ports-juce6.1/roth-air/Graphics/airText.png
  50. BIN
      ports-juce6.1/roth-air/Graphics/bigKnob.png
  51. BIN
      ports-juce6.1/roth-air/Graphics/bigKnob_light.png
  52. BIN
      ports-juce6.1/roth-air/Graphics/bigKnob_red.png
  53. BIN
      ports-juce6.1/roth-air/Graphics/label_freq.png
  54. BIN
      ports-juce6.1/roth-air/Graphics/label_gain.png
  55. BIN
      ports-juce6.1/roth-air/Graphics/label_mix.png
  56. BIN
      ports-juce6.1/roth-air/Graphics/label_thresh.png
  57. BIN
      ports-juce6.1/roth-air/Graphics/smallKnob.png
  58. BIN
      ports-juce6.1/roth-air/Graphics/smallKnob_light.png
  59. BIN
      ports-juce6.1/roth-air/Graphics/title.png
  60. BIN
      ports-juce6.1/roth-air/Graphics/website.png
  61. +33
    -0
      ports-juce6.1/roth-air/JuceHeader.h
  62. +151
    -0
      ports-juce6.1/roth-air/JucePluginCharacteristics.h
  63. +621
    -0
      ports-juce6.1/roth-air/LICENSE
  64. +289
    -0
      ports-juce6.1/roth-air/PluginEditor.cpp
  65. +171
    -0
      ports-juce6.1/roth-air/PluginEditor.h
  66. +439
    -0
      ports-juce6.1/roth-air/PluginProcessor.cpp
  67. +143
    -0
      ports-juce6.1/roth-air/PluginProcessor.h
  68. +8
    -0
      ports-juce6.1/roth-air/README.md
  69. +312
    -0
      ports-juce6.1/roth-air/SideChain.cpp
  70. +81
    -0
      ports-juce6.1/roth-air/SideChain.h
  71. +57
    -0
      ports-juce6.1/roth-air/WaveShaper.cpp
  72. +37
    -0
      ports-juce6.1/roth-air/WaveShaper.h
  73. +21
    -0
      ports-juce6.1/roth-air/meson.build

+ 1
- 0
libs/juce6.0/meson.build View File

@@ -36,6 +36,7 @@ juce60_devices_srcs = [

juce60_extra_cpp_args = [
'-std=gnu++14',
'-Wno-free-nonheap-object',
'-Wno-non-virtual-dtor',
]
juce60_extra_include_dirs = []


+ 1
- 0
libs/juce6.1/meson.build View File

@@ -35,6 +35,7 @@ juce61_devices_srcs = [

juce61_extra_cpp_args = [
'-std=gnu++14',
'-Wno-free-nonheap-object',
'-Wno-non-virtual-dtor',
]
juce61_extra_include_dirs = []


+ 1
- 0
meson_options.txt View File

@@ -116,6 +116,7 @@ option('plugins',
# juce6.0
'vitalium',
# juce6.1
'roth-air',
'swankyamp',
# juce7
],


+ 1
- 0
ports-juce6.1/meson.build View File

@@ -7,6 +7,7 @@ if linux_headless
else
plugins = [
'chow',
'roth-air',
'swankyamp',
]
endif


+ 4945
- 0
ports-juce6.1/roth-air/BinaryData.cpp
File diff suppressed because it is too large
View File


+ 63
- 0
ports-juce6.1/roth-air/BinaryData.h View File

@@ -0,0 +1,63 @@
/* =========================================================================================
This is an auto-generated file: Any edits you make may be overwritten!
*/
#pragma once
namespace BinaryData
{
extern const char* airText_png;
const int airText_pngSize = 22392;
extern const char* bigKnob_light_png;
const int bigKnob_light_pngSize = 60475;
extern const char* bigKnob_red_png;
const int bigKnob_red_pngSize = 38916;
extern const char* bigKnob_png;
const int bigKnob_pngSize = 47504;
extern const char* label_freq_png;
const int label_freq_pngSize = 21456;
extern const char* label_gain_png;
const int label_gain_pngSize = 21661;
extern const char* label_mix_png;
const int label_mix_pngSize = 21577;
extern const char* label_thresh_png;
const int label_thresh_pngSize = 21704;
extern const char* smallKnob_light_png;
const int smallKnob_light_pngSize = 31141;
extern const char* smallKnob_png;
const int smallKnob_pngSize = 31445;
extern const char* title_png;
const int title_pngSize = 24948;
extern const char* website_png;
const int website_pngSize = 23975;
// Number of elements in the namedResourceList and originalFileNames arrays.
const int namedResourceListSize = 12;
// Points to the start of a list of resource names.
extern const char* namedResourceList[];
// Points to the start of a list of resource filenames.
extern const char* originalFilenames[];
// If you provide the name of one of the binary resource variables above, this function will
// return the corresponding data and its size (or a null pointer if the name isn't found).
const char* getNamedResource (const char* resourceNameUTF8, int& dataSizeInBytes);
// If you provide the name of one of the binary resource variables above, this function will
// return the corresponding original, non-mangled filename (or a null pointer if the name isn't found).
const char* getNamedResourceOriginalFilename (const char* resourceNameUTF8);
}

+ 295
- 0
ports-juce6.1/roth-air/Compressor.cpp View File

@@ -0,0 +1,295 @@
/*---------------------------------------------------

Compressor
==========
A simple feed forward compressor for use in AIR plugin
A simplified implementation of Martin Zuther's "Squeezer" with some modifications
https://github.com/mzuther/Squeezer

-----------------------------------------------------*/

#include <float.h>
#include "Compressor.h"

//====================================================

Compressor::Compressor(int channels, int sample_rate) :
// Set de-normalization params to float and double absolute minimum
fDeNormal(FLT_MIN),
dDeNormal(DBL_MIN),
dBufferLength(0.1),
nChannels(channels),
nSampleRate(sample_rate)
{
jassert((channels == 1) || (channels == 2));

bufInputSamples.clear();
bufSideChainSamples.clear();
bufOutputSamples.clear();

bufInputSamples.setSize(nChannels, 1);
bufSideChainSamples.setSize(nChannels, 1);
bufOutputSamples.setSize(nChannels, 1);
dCrestFactor = 20.0;
dReleaseCoefLinear = 26 * dBufferLength / 3.0;
setMakeupGain(0.0);
// Clear the sidechain array in case of junk
p_arrSideChain.clear();

// Add sidechain objects and add an entry for each channel into the sample buffers
for (int nChannel = 0; nChannel < 2; ++nChannel)
{
// Make a new sidechain element for each channel
p_arrSideChain.add(new SideChain(nSampleRate));
}
}

Compressor::~Compressor() {

}

double Compressor::getDetectorRmsFilter()
/* Get current detector RMS rate.

return value (double): returns current detector RMS rate*/
{
return p_arrSideChain[0]->getDetectorRmsFilter();
}

void Compressor::setDetectorRmsFilter(double dDetectorRateMsNew)
/* Set new detector RMS rate.

dDetectorRateMsNew (double): new detector RMS filter rate

return value: none*/
{
for (int nChannel = 0; nChannel < nChannels; ++nChannel)
{
p_arrSideChain[nChannel]->setDetectorRmsFilter(dDetectorRateMsNew);
}
}

double Compressor::getThreshold()
/* Get current threshold

return value (double): current threshold in dB*/
{
return p_arrSideChain[0]->getThreshold();
}

void Compressor::setThreshold(double dThresholdNew)
/* Set new threshold.

dThresholdNew (double): new threshold in dB

return value: none*/
{
for (int nChannel = 0; nChannel < nChannels; ++nChannel)
{
p_arrSideChain[nChannel]->setThreshold(dThresholdNew);
}
}

double Compressor::getRatio()
/* Get current comp ratio.

return value (double): returns current ratio*/
{
double dRatioNew = p_arrSideChain[0]->getRatio();

return dRatioNew;
}

void Compressor::setRatio(double dRatioNew)
/* Set new ratio.

dRatioNew (double): new ratio

return value: none*/
{
for (int nChannel = 0; nChannel < nChannels; ++nChannel)
{
p_arrSideChain[nChannel]->setRatio(dRatioNew);
}
}

int Compressor::getAttackRate()
/* Get current attack rate.

return value (int): returns the current attack rate in ms*/
{
return p_arrSideChain[0]->getAttackRate();
}

void Compressor::setAttackRate(int nAttackRateNew)
/* Set new attack rate.

nAttackRateNew (int): new attack rate in ms

return value: none*/
{
for (int nChannel = 0; nChannel < nChannels; ++nChannel)
{
p_arrSideChain[nChannel]->setAttackRate(nAttackRateNew);
}
}

int Compressor::getReleaseRate()
/* Get current release rate.

return value (int): returns the current release rate in ms*/
{
return p_arrSideChain[0]->getReleaseRate();
}

void Compressor::setReleaseRate(int nReleaseRateNew)
/* Set new release rate.

nReleaseRateNew (int): new release rate in ms

return value: none*/
{
for (int nChannel = 0; nChannel < nChannels; ++nChannel)
{
p_arrSideChain[nChannel]->setReleaseRate(nReleaseRateNew);
}
}

double Compressor::getMakeupGain()
/* Get current make-up gain.

return value (double): current make-up gain in dB*/
{
return dMakeupGainDb;
}

void Compressor::setMakeupGain(double dMakeupGainNew)
/* Set new make-up gain.

nMakeupGainNew (double): new makeup gain in dB
return value: none*/
{
dMakeupGainDb = dMakeupGainNew;
dMakeupGain = SideChain::dbtolvl(dMakeupGainDb);
}

double Compressor::getGainReduction(int nChannel)
/* Get current gain reduction.

nChannel (int): queried audio channel
return value (double): returns current gain reduction in dB*/
{
jassert(nChannel >= 0);
jassert(nChannel < nChannels);

return arrGainReduction[nChannel];
}

double Compressor::getGainReductionPeak(int nChannel)
/* Get current peak gain reduction

nChannel (int): queried audio channel
return value (double): returns current peak gain reduction in dB*/
{
jassert(nChannel >= 0);
jassert(nChannel < nChannels);

return arrGainReductionPeak[nChannel];
}

double Compressor::getSampleRate()
{
return p_arrSideChain[0]->getSampleRate();
}

void Compressor::setSampleRate(double newSampleRate)
{
if (newSampleRate != p_arrSideChain[0]->getSampleRate())
{
for (int nChannel = 0; nChannel < nChannels; ++nChannel)
{
p_arrSideChain[nChannel]->setSampleRate(newSampleRate);
}

nSampleRate = (int)newSampleRate;
}
}

void Compressor::resetSideChain() {
for (int nChannel = 0; nChannel < 2; ++nChannel)
{
p_arrSideChain[nChannel]->reset();
}
}

double Compressor::getTempGainReduction()
{
return tempGainReduction;
}

void Compressor::processBlock(AudioBuffer<float> &buffer)
{
int nNumSamples = buffer.getNumSamples();

// Loop through samples
for (int nSample = 0; nSample < nNumSamples; ++nSample)
{
// Get input samples, de-normalize and store in buffer
for (int nChannel = 0; nChannel < nChannels; ++nChannel)
{
// Get current input sample (both as float and as double)
float fInputSample = buffer.getSample(nChannel, nSample);
double dInputSample = (double) fInputSample;

// Remove denormal numbers input samples
fInputSample += fDeNormal;
dInputSample += dDeNormal;
fInputSample -= fDeNormal;
dInputSample -= dDeNormal;

// jassert(arrInputSamples.size() == 2 && arrSidechainSamples.size() == 2 && arrOutputSamples.size() == 2);

// Store de-normalized input sample
// arrInputSamples.set(nChannel, dInputSample);
bufInputSamples.setSample(nChannel, 0, dInputSample);

// Process each channel instead of stereo linking (for channel compability)
// arrSidechainSamples.set(nChannel, arrInputSamples[nChannel]);
bufSideChainSamples.setSample(nChannel, 0, bufInputSamples.getSample(nChannel, 0));

// Calculate level of sidechain sample
double dSideChainInputLevel = SideChain::lvltodb(fabs(bufSideChainSamples.getSample(nChannel, 0)));

// Apply crest factor
dSideChainInputLevel += dCrestFactor;

// Send current input sample to gain reduction
p_arrSideChain[nChannel]->processSample(dSideChainInputLevel);

// Store gain reduction (might only be for metering)
// arrGainReduction.set(nChannel, p_arrSideChain[nChannel]->getGainReduction());

// Apply gain reduction to current input sample
double dGainReduction = p_arrSideChain[nChannel]->getGainReduction();
tempGainReduction = dGainReduction;

// arrOutputSamples.set(nChannel, arrInputSamples[nChannel] / SideChain::dbtolvl(dGainReduction));
bufOutputSamples.setSample(nChannel, 0, bufInputSamples.getSample(nChannel, 0) / SideChain::dbtolvl(dGainReduction));

// arrOutputSamples.set(nChannel, arrOutputSamples[nChannel] * dMakeupGain);
bufOutputSamples.setSample(nChannel, 0, bufOutputSamples.getSample(nChannel, 0) * dMakeupGain);

// Set sample to output buffer
// float fOutput = arrOutputSamples[nChannel];
float fOutput = bufOutputSamples.getSample(nChannel, 0);
buffer.setSample(nChannel, nSample, fOutput);
}
}
}

+ 103
- 0
ports-juce6.1/roth-air/Compressor.h View File

@@ -0,0 +1,103 @@
/*---------------------------------------------------
Compressor
==========
A simple feed forward compressor for use in AIR plugin
A simplified implementation of Martin Zuther's "Squeezer" with some modifications
https://github.com/mzuther/Squeezer
-----------------------------------------------------*/

#ifndef __COMPRESSOR_H__
#define __COMPRESSOR_H__

class SideChain;

#include "JuceHeader.h"
#include "SideChain.h"

//=============================================================
class Compressor
{
public:
//=========================================================

// Constructor
Compressor(int channels, int sample_rate);
~Compressor();

// Declare functions for setting/getting comp parameters
double getDetectorRmsFilter();
void setDetectorRmsFilter(double dDetectorRateMsNew);

double getThreshold();
void setThreshold(double dThresholdNew);

double getRatio();
void setRatio(double dRatioNew);

int getAttackRate();
void setAttackRate(int nAttackRateNew);

int getReleaseRate();
void setReleaseRate(int nReleaseRateNew);

double getMakeupGain();
void setMakeupGain(double dMakeupGainNew);

double getGainReduction(int nChannel);
double getGainReductionPeak(int nChannel);
double getSampleRate();
void setSampleRate(double newSampleRate);
void resetSideChain();

double getTempGainReduction();

// Declare function for processing audio
void processBlock(AudioBuffer<float> &buffer);

private:
// Declare de-normalization variables
const float fDeNormal;
const double dDeNormal;
const double dBufferLength;

// Variables for keeping track of channels and sample rate
int nChannels;
int nSampleRate;

// Arrays for holding sample data
OwnedArray<SideChain> p_arrSideChain;

// Array<double> arrInputSamples;
// Array<double> arrSidechainSamples;
// Array<double> arrOutputSamples;

AudioSampleBuffer bufInputSamples;
AudioSampleBuffer bufSideChainSamples;
AudioSampleBuffer bufOutputSamples;

Array<double> arrGainReduction;
Array<double> arrGainReductionPeak;

AudioSampleBuffer bufGainReduction;
AudioSampleBuffer bufGainReductionPeak;

double dCrestFactor;

double dReleaseCoefLinear;

// Makeup gain variables
double dMakeupGain;
double dMakeupGainDb;

// Might also need this
double dGainNormalize;

double tempGainReduction;
};

#endif // __COMRESSOR_H__

+ 485
- 0
ports-juce6.1/roth-air/DspFilters/Bessel.h View File

@@ -0,0 +1,485 @@
/*******************************************************************************

"A Collection of Useful C++ Classes for Digital Signal Processing"
By Vincent Falco

Official project location:
http://code.google.com/p/dspfilterscpp/

See Documentation.cpp for contact information, notes, and bibliography.

--------------------------------------------------------------------------------

License: MIT License (http://www.opensource.org/licenses/mit-license.php)
Copyright (c) 2009 by Vincent Falco

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*******************************************************************************/

#ifndef DSPFILTERS_BESSEL_H
#define DSPFILTERS_BESSEL_H

#include "DspFilters/Common.h"
#include "DspFilters/Cascade.h"
#include "DspFilters/Design.h"
#include "DspFilters/Filter.h"
#include "DspFilters/PoleFilter.h"
#include "DspFilters/RootFinder.h"

namespace Dsp {

/*
* Filters with Bessel response characteristics
*
*/

namespace Bessel {

// A Workspace is necessary to find roots

struct WorkspaceBase
{
WorkspaceBase (RootFinderBase* rootsBase)
: roots (*rootsBase)
{
}

RootFinderBase& roots;

private:
WorkspaceBase (WorkspaceBase&);
WorkspaceBase& operator= (WorkspaceBase&);
};

template <int MaxOrder>
struct Workspace : WorkspaceBase
{
Workspace ()
: WorkspaceBase (&m_roots)
{
}

private:
RootFinder <MaxOrder> m_roots;
};

//------------------------------------------------------------------------------

// Half-band analog prototypes (s-plane)

class AnalogLowPass : public LayoutBase
{
public:
AnalogLowPass ();

void design (const int numPoles,
WorkspaceBase* w);

private:
int m_numPoles;
};

//------------------------------------------------------------------------------

class AnalogLowShelf : public LayoutBase
{
public:
AnalogLowShelf ();

void design (int numPoles,
double gainDb,
WorkspaceBase* w);

private:
int m_numPoles;
double m_gainDb;
};

//------------------------------------------------------------------------------

// Factored implementations to reduce template instantiations

struct LowPassBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double cutoffFrequency,
WorkspaceBase* w);
};

struct HighPassBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double cutoffFrequency,
WorkspaceBase* w);
};

struct BandPassBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double centerFrequency,
double widthFrequency,
WorkspaceBase* w);
};

struct BandStopBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double centerFrequency,
double widthFrequency,
WorkspaceBase* w);
};

struct LowShelfBase : PoleFilterBase <AnalogLowShelf>
{
void setup (int order,
double sampleRate,
double cutoffFrequency,
double gainDb,
WorkspaceBase* w);
};

//------------------------------------------------------------------------------

//
// Raw filters
//

template <int MaxOrder>
struct LowPass : PoleFilter <LowPassBase, MaxOrder>
{
void setup (int order,
double sampleRate,
double cutoffFrequency)
{
Workspace <MaxOrder> w;
LowPassBase::setup (order,
sampleRate,
cutoffFrequency,
&w);
}
};

template <int MaxOrder>
struct HighPass : PoleFilter <HighPassBase, MaxOrder>
{
void setup (int order,
double sampleRate,
double cutoffFrequency)
{
Workspace <MaxOrder> w;
HighPassBase::setup (order,
sampleRate,
cutoffFrequency,
&w);
}
};

template <int MaxOrder>
struct BandPass : PoleFilter <BandPassBase, MaxOrder, MaxOrder*2>
{
void setup (int order,
double sampleRate,
double centerFrequency,
double widthFrequency)
{
Workspace <MaxOrder> w;
BandPassBase::setup (order,
sampleRate,
centerFrequency,
widthFrequency,
&w);
}
};

template <int MaxOrder>
struct BandStop : PoleFilter <BandStopBase, MaxOrder, MaxOrder*2>
{
void setup (int order,
double sampleRate,
double centerFrequency,
double widthFrequency)
{
Workspace <MaxOrder> w;
BandStopBase::setup (order,
sampleRate,
centerFrequency,
widthFrequency,
&w);
}
};

template <int MaxOrder>
struct LowShelf : PoleFilter <LowShelfBase, MaxOrder, MaxOrder*2>
{
void setup (int order,
double sampleRate,
double cutoffFrequency,
double gainDb)
{
Workspace <MaxOrder> w;
LowShelfBase::setup (order,
sampleRate,
cutoffFrequency,
gainDb,
&w);
}
};

//------------------------------------------------------------------------------

//
// Gui-friendly Design layer
//

namespace Design {

struct TypeIBase : DesignBase
{
enum
{
NumParams = 3
};

static int getNumParams ()
{
return 3;
}

static const ParamInfo getParamInfo_2 ()
{
return ParamInfo::defaultCutoffFrequencyParam ();
}
};

template <class FilterClass>
struct TypeI : TypeIBase, FilterClass
{
void setParams (const Params& params)
{
FilterClass::setup (int(params[1]), params[0], params[2]);
}
};

struct TypeIIBase : DesignBase
{
enum
{
NumParams = 4
};

static int getNumParams ()
{
return 4;
}

static const ParamInfo getParamInfo_2 ()
{
return ParamInfo::defaultCenterFrequencyParam ();
}

static const ParamInfo getParamInfo_3 ()
{
return ParamInfo::defaultBandwidthHzParam ();
}
};

template <class FilterClass>
struct TypeII : TypeIIBase, FilterClass
{
void setParams (const Params& params)
{
FilterClass::setup (int(params[1]), params[0], params[2], params[3]);
}
};

struct TypeIIIBase : DesignBase
{
enum
{
NumParams = 4
};

static int getNumParams ()
{
return 4;
}

static const ParamInfo getParamInfo_2 ()
{
return ParamInfo::defaultCutoffFrequencyParam ();
}

static const ParamInfo getParamInfo_3 ()
{
return ParamInfo::defaultGainParam ();
}
};

template <class FilterClass>
struct TypeIII : TypeIIIBase, FilterClass
{
void setParams (const Params& params)
{
FilterClass::setup (int(params[1]),
params[0],
params[2],
params[3]);
}
};

struct TypeIVBase : DesignBase
{
enum
{
NumParams = 5
};

static int getNumParams ()
{
return 5;
}

static const ParamInfo getParamInfo_2 ()
{
return ParamInfo::defaultCenterFrequencyParam ();
}

static const ParamInfo getParamInfo_3 ()
{
return ParamInfo::defaultBandwidthHzParam ();
}

static const ParamInfo getParamInfo_4 ()
{
return ParamInfo::defaultGainParam ();
}
};

template <class FilterClass>
struct TypeIV : TypeIVBase, FilterClass
{
void setParams (const Params& params)
{
FilterClass::setup (int(params[1]), params[0], params[2], params[3], params[4]);
}
};

// Factored kind and name

struct LowPassDescription
{
static Kind getKind () { return kindLowPass; }
static const char* getName() { return "Bessel Low Pass"; }
};

struct HighPassDescription
{
static Kind getKind () { return kindHighPass; }
static const char* getName() { return "Bessel High Pass"; }
};

struct BandPassDescription
{
static Kind getKind () { return kindHighPass; }
static const char* getName() { return "Bessel Band Pass"; }
};

struct BandStopDescription
{
static Kind getKind () { return kindHighPass; }
static const char* getName() { return "Bessel Band Stop"; }
};

struct LowShelfDescription
{
static Kind getKind () { return kindLowShelf; }
static const char* getName() { return "Bessel Low Shelf"; }
};

// This glues on the Order parameter
template <int MaxOrder,
template <class> class TypeClass,
template <int> class FilterClass>
struct OrderBase : TypeClass <FilterClass <MaxOrder> >
{
const ParamInfo getParamInfo_1 () const
{
return ParamInfo (idOrder, "Order", "Order",
1, MaxOrder, 2,
&ParamInfo::Int_toControlValue,
&ParamInfo::Int_toNativeValue,
&ParamInfo::Int_toString);

}
};

//------------------------------------------------------------------------------

//
// Gui-friendly Design layer
//

template <int MaxOrder>
struct LowPass : OrderBase <MaxOrder, TypeI, Bessel::LowPass>,
LowPassDescription
{
};

template <int MaxOrder>
struct HighPass : OrderBase <MaxOrder, TypeI, Bessel::HighPass>,
HighPassDescription
{
};

template <int MaxOrder>
struct BandPass : OrderBase <MaxOrder, TypeII, Bessel::BandPass>,
BandPassDescription
{
};

template <int MaxOrder>
struct BandStop : OrderBase <MaxOrder, TypeII, Bessel::BandStop>,
BandStopDescription
{
};

/*
* NOT IMPLEMENTED
*
*/
template <int MaxOrder>
struct LowShelf : OrderBase <MaxOrder, TypeIII, Bessel::LowShelf>,
LowShelfDescription
{
};

}

}

}

#endif

/* This is a test of svn:external */

+ 232
- 0
ports-juce6.1/roth-air/DspFilters/Biquad.h View File

@@ -0,0 +1,232 @@
/*******************************************************************************

"A Collection of Useful C++ Classes for Digital Signal Processing"
By Vincent Falco

Official project location:
http://code.google.com/p/dspfilterscpp/

See Documentation.cpp for contact information, notes, and bibliography.

--------------------------------------------------------------------------------

License: MIT License (http://www.opensource.org/licenses/mit-license.php)
Copyright (c) 2009 by Vincent Falco

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*******************************************************************************/

#ifndef DSPFILTERS_BIQUAD_H
#define DSPFILTERS_BIQUAD_H

#include "DspFilters/Common.h"
#include "DspFilters/MathSupplement.h"
#include "DspFilters/Types.h"

namespace Dsp {

struct BiquadPoleState;

/*
* Holds coefficients for a second order Infinite Impulse Response
* digital filter. This is the building block for all IIR filters.
*
*/

// Factored interface to prevent outsiders from fiddling
class BiquadBase
{
public:
template <class StateType>
struct State : StateType, private DenormalPrevention
{
template <typename Sample>
inline Sample process (const Sample in, const BiquadBase& b)
{
return static_cast<Sample> (StateType::process1 (in, b, ac()));
}
};

public:
// Calculate filter response at the given normalized frequency.
complex_t response (double normalizedFrequency) const;

std::vector<PoleZeroPair> getPoleZeros () const;

double getA0 () const { return m_a0; }
double getA1 () const { return m_a1*m_a0; }
double getA2 () const { return m_a2*m_a0; }
double getB0 () const { return m_b0*m_a0; }
double getB1 () const { return m_b1*m_a0; }
double getB2 () const { return m_b2*m_a0; }

// Process a block of samples in the given form
template <class StateType, typename Sample>
void process (int numSamples, Sample* dest, StateType& state) const
{
while (--numSamples >= 0)
*dest++ = state.process (*dest, *this);
}

protected:
//
// These are protected so you can't mess with RBJ biquads
//

void setCoefficients (double a0, double a1, double a2,
double b0, double b1, double b2);

void setOnePole (complex_t pole, complex_t zero);

void setTwoPole (complex_t pole1, complex_t zero1,
complex_t pole2, complex_t zero2);

void setPoleZeroPair (const PoleZeroPair& pair)
{
if (pair.isSinglePole ())
setOnePole (pair.poles.first, pair.zeros.first);
else
setTwoPole (pair.poles.first, pair.zeros.first,
pair.poles.second, pair.zeros.second);
}

void setPoleZeroForm (const BiquadPoleState& bps);

void setIdentity ();

void applyScale (double scale);

public:
double m_a0;
double m_a1;
double m_a2;
double m_b1;
double m_b2;
double m_b0;
};

//------------------------------------------------------------------------------

// Expresses a biquad as a pair of pole/zeros, with gain
// values so that the coefficients can be reconstructed precisely.
struct BiquadPoleState : PoleZeroPair
{
BiquadPoleState () { }

explicit BiquadPoleState (const BiquadBase& s);

double gain;
};

// More permissive interface for fooling around
class Biquad : public BiquadBase
{
public:
Biquad ();

explicit Biquad (const BiquadPoleState& bps);

public:
// Process a block of samples, interpolating from the old section's coefficients
// to this section's coefficients, over numSamples. This implements smooth
// parameter changes.

template <class StateType, typename Sample>
void smoothProcess1 (int numSamples,
Sample* dest,
StateType& state,
Biquad sectionPrev) const
{
double t = 1. / numSamples;
double da1 = (m_a1 - sectionPrev.m_a1) * t;
double da2 = (m_a2 - sectionPrev.m_a2) * t;
double db0 = (m_b0 - sectionPrev.m_b0) * t;
double db1 = (m_b1 - sectionPrev.m_b1) * t;
double db2 = (m_b2 - sectionPrev.m_b2) * t;

while (--numSamples >= 0)
{
sectionPrev.m_a1 += da1;
sectionPrev.m_a2 += da2;
sectionPrev.m_b0 += db0;
sectionPrev.m_b1 += db1;
sectionPrev.m_b2 += db2;

*dest++ = state.process (*dest, sectionPrev);
}
}

// Process a block of samples, interpolating from the old section's pole/zeros
// to this section's pole/zeros, over numSamples. The interpolation is done
// in the z-plane using polar coordinates.
template <class StateType, typename Sample>
void smoothProcess2 (int numSamples,
Sample* dest,
StateType& state,
BiquadPoleState zPrev) const
{
BiquadPoleState z (*this);
double t = 1. / numSamples;
complex_t dp0 = (z.poles.first - zPrev.poles.first) * t;
complex_t dp1 = (z.poles.second - zPrev.poles.second) * t;
complex_t dz0 = (z.zeros.first - zPrev.zeros.first) * t;
complex_t dz1 = (z.zeros.second - zPrev.zeros.second) * t;
double dg = (z.gain - zPrev.gain) * t;

while (--numSamples >= 0)
{
zPrev.poles.first += dp0;
zPrev.poles.second += dp1;
zPrev.zeros.first += dz0;
zPrev.zeros.second += dz1;
zPrev.gain += dg;

*dest++ = state.process (*dest, Biquad (zPrev));
}
}

public:
// Export these as public

void setOnePole (complex_t pole, complex_t zero)
{
BiquadBase::setOnePole (pole, zero);
}

void setTwoPole (complex_t pole1, complex_t zero1,
complex_t pole2, complex_t zero2)
{
BiquadBase::setTwoPole (pole1, zero1, pole2, zero2);
}

void setPoleZeroPair (const PoleZeroPair& pair)
{
BiquadBase::setPoleZeroPair (pair);
}

void applyScale (double scale)
{
BiquadBase::applyScale (scale);
}
};

}

#endif

+ 436
- 0
ports-juce6.1/roth-air/DspFilters/Butterworth.h View File

@@ -0,0 +1,436 @@
/*******************************************************************************

"A Collection of Useful C++ Classes for Digital Signal Processing"
By Vincent Falco

Official project location:
http://code.google.com/p/dspfilterscpp/

See Documentation.cpp for contact information, notes, and bibliography.

--------------------------------------------------------------------------------

License: MIT License (http://www.opensource.org/licenses/mit-license.php)
Copyright (c) 2009 by Vincent Falco

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*******************************************************************************/

#ifndef DSPFILTERS_BUTTERWORTH_H
#define DSPFILTERS_BUTTERWORTH_H

#include "DspFilters/Common.h"
#include "DspFilters/Cascade.h"
#include "DspFilters/Design.h"
#include "DspFilters/Filter.h"
#include "DspFilters/PoleFilter.h"

namespace Dsp {

/*
* Filters with Butterworth response characteristics
*
*/

namespace Butterworth {

// Half-band analog prototypes (s-plane)

class AnalogLowPass : public LayoutBase
{
public:
AnalogLowPass ();

void design (const int numPoles);

private:
int m_numPoles;
};

//------------------------------------------------------------------------------

class AnalogLowShelf : public LayoutBase
{
public:
AnalogLowShelf ();

void design (int numPoles, double gainDb);

private:
int m_numPoles;
double m_gainDb;
};

//------------------------------------------------------------------------------

// Factored implementations to reduce template instantiations

struct LowPassBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double cutoffFrequency);
};

struct HighPassBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double cutoffFrequency);
};

struct BandPassBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double centerFrequency,
double widthFrequency);
};

struct BandStopBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double centerFrequency,
double widthFrequency);
};

struct LowShelfBase : PoleFilterBase <AnalogLowShelf>
{
void setup (int order,
double sampleRate,
double cutoffFrequency,
double gainDb);
};

struct HighShelfBase : PoleFilterBase <AnalogLowShelf>
{
void setup (int order,
double sampleRate,
double cutoffFrequency,
double gainDb);
};

struct BandShelfBase : PoleFilterBase <AnalogLowShelf>
{
void setup (int order,
double sampleRate,
double centerFrequency,
double widthFrequency,
double gainDb);
};

//------------------------------------------------------------------------------

//
// Raw filters
//

template <int MaxOrder>
struct LowPass : PoleFilter <LowPassBase, MaxOrder>
{
};

template <int MaxOrder>
struct HighPass : PoleFilter <HighPassBase, MaxOrder>
{
};

template <int MaxOrder>
struct BandPass : PoleFilter <BandPassBase, MaxOrder, MaxOrder*2>
{
};

template <int MaxOrder>
struct BandStop : PoleFilter <BandStopBase, MaxOrder, MaxOrder*2>
{
};

template <int MaxOrder>
struct LowShelf : PoleFilter <LowShelfBase, MaxOrder>
{
};

template <int MaxOrder>
struct HighShelf : PoleFilter <HighShelfBase, MaxOrder>
{
};

template <int MaxOrder>
struct BandShelf : PoleFilter <BandShelfBase, MaxOrder, MaxOrder*2>
{
};

//------------------------------------------------------------------------------

//
// Gui-friendly Design layer
//

namespace Design {

struct TypeIBase : DesignBase
{
enum
{
NumParams = 3
};

static int getNumParams ()
{
return 3;
}

static const ParamInfo getParamInfo_2 ()
{
return ParamInfo::defaultCutoffFrequencyParam ();
}
};

template <class FilterClass>
struct TypeI : TypeIBase, FilterClass
{
void setParams (const Params& params)
{
FilterClass::setup (int(params[1]), params[0], params[2]);
}
};

struct TypeIIBase : DesignBase
{
enum
{
NumParams = 4
};

static int getNumParams ()
{
return 4;
}

static const ParamInfo getParamInfo_2 ()
{
return ParamInfo::defaultCenterFrequencyParam ();
}

static const ParamInfo getParamInfo_3 ()
{
return ParamInfo::defaultBandwidthHzParam ();
}
};

template <class FilterClass>
struct TypeII : TypeIIBase, FilterClass
{
void setParams (const Params& params)
{
FilterClass::setup (int(params[1]), params[0], params[2], params[3]);
}
};

struct TypeIIIBase : DesignBase
{
enum
{
NumParams = 4
};

static int getNumParams ()
{
return 4;
}

static const ParamInfo getParamInfo_2 ()
{
return ParamInfo::defaultCutoffFrequencyParam ();
}

static const ParamInfo getParamInfo_3 ()
{
return ParamInfo::defaultGainParam ();
}
};

template <class FilterClass>
struct TypeIII : TypeIIIBase, FilterClass
{
void setParams (const Params& params)
{
FilterClass::setup (int(params[1]),
params[0],
params[2],
params[3]);
}
};

struct TypeIVBase : DesignBase
{
enum
{
NumParams = 5
};

static int getNumParams ()
{
return 5;
}

static const ParamInfo getParamInfo_2 ()
{
return ParamInfo::defaultCenterFrequencyParam ();
}

static const ParamInfo getParamInfo_3 ()
{
return ParamInfo::defaultBandwidthHzParam ();
}

static const ParamInfo getParamInfo_4 ()
{
return ParamInfo::defaultGainParam ();
}
};

template <class FilterClass>
struct TypeIV : TypeIVBase, FilterClass
{
void setParams (const Params& params)
{
FilterClass::setup (int(params[1]), params[0], params[2], params[3], params[4]);
}
};

// Factored kind and name

struct LowPassDescription
{
static Kind getKind () { return kindLowPass; }
static const char* getName() { return "Butterworth Low Pass"; }
};

struct HighPassDescription
{
static Kind getKind () { return kindHighPass; }
static const char* getName() { return "Butterworth High Pass"; }
};

struct BandPassDescription
{
static Kind getKind () { return kindHighPass; }
static const char* getName() { return "Butterworth Band Pass"; }
};

struct BandStopDescription
{
static Kind getKind () { return kindHighPass; }
static const char* getName() { return "Butterworth Band Stop"; }
};

struct LowShelfDescription
{
static Kind getKind () { return kindLowShelf; }
static const char* getName() { return "Butterworth Low Shelf"; }
};

struct HighShelfDescription
{
static Kind getKind () { return kindHighShelf; }
static const char* getName() { return "Butterworth High Shelf"; }
};

struct BandShelfDescription
{
static Kind getKind () { return kindBandShelf; }
static const char* getName() { return "Butterworth Band Shelf"; }
};

// This glues on the Order parameter
template <int MaxOrder,
template <class> class TypeClass,
template <int> class FilterClass>
struct OrderBase : TypeClass <FilterClass <MaxOrder> >
{
const ParamInfo getParamInfo_1 () const
{
return ParamInfo (idOrder, "Order", "Order",
1, MaxOrder, 2,
&ParamInfo::Int_toControlValue,
&ParamInfo::Int_toNativeValue,
&ParamInfo::Int_toString);

}
};

//------------------------------------------------------------------------------

//
// Design filters
//

template <int MaxOrder>
struct LowPass : OrderBase <MaxOrder, TypeI, Butterworth::LowPass>,
LowPassDescription
{
};

template <int MaxOrder>
struct HighPass : OrderBase <MaxOrder, TypeI, Butterworth::HighPass>,
HighPassDescription
{
};

template <int MaxOrder>
struct BandPass : OrderBase <MaxOrder, TypeII, Butterworth::BandPass>,
BandPassDescription
{
};

template <int MaxOrder>
struct BandStop : OrderBase <MaxOrder, TypeII, Butterworth::BandStop>,
BandStopDescription
{
};

template <int MaxOrder>
struct LowShelf : OrderBase <MaxOrder, TypeIII, Butterworth::LowShelf>,
LowShelfDescription
{
};

template <int MaxOrder>
struct HighShelf : OrderBase <MaxOrder, TypeIII, Butterworth::HighShelf>,
HighShelfDescription
{
};

template <int MaxOrder>
struct BandShelf : OrderBase <MaxOrder, TypeIV, Butterworth::BandShelf>,
BandShelfDescription
{
};

}

}

}

#endif


+ 181
- 0
ports-juce6.1/roth-air/DspFilters/Cascade.h View File

@@ -0,0 +1,181 @@
/*******************************************************************************

"A Collection of Useful C++ Classes for Digital Signal Processing"
By Vincent Falco

Official project location:
http://code.google.com/p/dspfilterscpp/

See Documentation.cpp for contact information, notes, and bibliography.

--------------------------------------------------------------------------------

License: MIT License (http://www.opensource.org/licenses/mit-license.php)
Copyright (c) 2009 by Vincent Falco

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*******************************************************************************/

#ifndef DSPFILTERS_CASCADE_H
#define DSPFILTERS_CASCADE_H

#include "DspFilters/Common.h"
#include "DspFilters/Biquad.h"
#include "DspFilters/Filter.h"
#include "DspFilters/Layout.h"
#include "DspFilters/MathSupplement.h"

namespace Dsp {

/*
* Holds coefficients for a cascade of second order sections.
*
*/

// Factored implementation to reduce template instantiations
class Cascade
{
public:
template <class StateType>
class StateBase : private DenormalPrevention
{
public:
template <typename Sample>
inline Sample process (const Sample in, const Cascade& c)
{
double out = in;
StateType* state = m_stateArray;
Biquad const* stage = c.m_stageArray;
const double vsa = ac();
int i = c.m_numStages - 1;
out = (state++)->process1 (out, *stage++, vsa);
for (; --i >= 0;)
out = (state++)->process1 (out, *stage++, 0);
//for (int i = c.m_numStages; --i >= 0; ++state, ++stage)
// out = state->process1 (out, *stage, vsa);
return static_cast<Sample> (out);
}

protected:
StateBase (StateType* stateArray)
: m_stateArray (stateArray)
{
}

protected:
StateType* m_stateArray;
};

struct Stage : Biquad
{
};

struct Storage
{
Storage (int maxStages_, Stage* stageArray_)
: maxStages (maxStages_)
, stageArray (stageArray_)
{
}

int maxStages;
Stage* stageArray;
};

int getNumStages () const
{
return m_numStages;
}

const Stage& operator[] (int index)
{
assert (index >= 0 && index <= m_numStages);
return m_stageArray[index];
}

public:
// Calculate filter response at the given normalized frequency.
complex_t response (double normalizedFrequency) const;

std::vector<PoleZeroPair> getPoleZeros () const;

// Process a block of samples in the given form
template <class StateType, typename Sample>
void process (int numSamples, Sample* dest, StateType& state) const
{
while (--numSamples >= 0)
*dest++ = state.process (*dest, *this);
}

protected:
Cascade ();

void setCascadeStorage (const Storage& storage);

void applyScale (double scale);
void setLayout (const LayoutBase& proto);

private:
int m_numStages;
int m_maxStages;
Stage* m_stageArray;
};

//------------------------------------------------------------------------------

// Storage for Cascade
template <int MaxStages>
class CascadeStages
{
public:
template <class StateType>
class State : public Cascade::StateBase <StateType>
{
public:
State() : Cascade::StateBase <StateType> (m_states)
{
Cascade::StateBase <StateType>::m_stateArray = m_states;
reset ();
}

void reset ()
{
StateType* state = m_states;
for (int i = MaxStages; --i >= 0; ++state)
state->reset();
}

private:
StateType m_states[MaxStages];
};

/*@Internal*/
Cascade::Storage getCascadeStorage()
{
return Cascade::Storage (MaxStages, m_stages);
}

private:
Cascade::Stage m_stages[MaxStages];
};

}

#endif

+ 465
- 0
ports-juce6.1/roth-air/DspFilters/ChebyshevI.h View File

@@ -0,0 +1,465 @@
/*******************************************************************************

"A Collection of Useful C++ Classes for Digital Signal Processing"
By Vincent Falco

Official project location:
http://code.google.com/p/dspfilterscpp/

See Documentation.cpp for contact information, notes, and bibliography.

--------------------------------------------------------------------------------

License: MIT License (http://www.opensource.org/licenses/mit-license.php)
Copyright (c) 2009 by Vincent Falco

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*******************************************************************************/

#ifndef DSPFILTERS_CHEBYSHEVI_H
#define DSPFILTERS_CHEBYSHEVI_H

#include "DspFilters/Common.h"
#include "DspFilters/Cascade.h"
#include "DspFilters/Design.h"
#include "DspFilters/Filter.h"
#include "DspFilters/PoleFilter.h"

namespace Dsp {

/*
* Filters with Chebyshev response characteristics
*
*/

namespace ChebyshevI {

// Half-band analog prototypes (s-plane)

class AnalogLowPass : public LayoutBase
{
public:
AnalogLowPass ();

void design (const int numPoles,
double rippleDb);

private:
int m_numPoles;
double m_rippleDb;
};

//------------------------------------------------------------------------------

class AnalogLowShelf : public LayoutBase
{
public:
AnalogLowShelf ();

void design (int numPoles,
double gainDb,
double rippleDb);

private:
int m_numPoles;
double m_rippleDb;
double m_gainDb;
};

//------------------------------------------------------------------------------

// Factored implementations to reduce template instantiations

struct LowPassBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double cutoffFrequency,
double rippleDb);
};

struct HighPassBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double cutoffFrequency,
double rippleDb);
};

struct BandPassBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double centerFrequency,
double widthFrequency,
double rippleDb);
};

struct BandStopBase : PoleFilterBase <AnalogLowPass>
{
void setup (int order,
double sampleRate,
double centerFrequency,
double widthFrequency,
double rippleDb);
};

struct LowShelfBase : PoleFilterBase <AnalogLowShelf>
{
void setup (int order,
double sampleRate,
double cutoffFrequency,
double gainDb,
double rippleDb);
};

struct HighShelfBase : PoleFilterBase <AnalogLowShelf>
{
void setup (int order,
double sampleRate,
double cutoffFrequency,
double gainDb,
double rippleDb);
};

struct BandShelfBase : PoleFilterBase <AnalogLowShelf>
{
void setup (int order,
double sampleRate,
double centerFrequency,
double widthFrequency,
double gainDb,
double rippleDb);
};

//------------------------------------------------------------------------------

//
// Raw filters
//

template <int MaxOrder>
struct LowPass : PoleFilter <LowPassBase, MaxOrder>
{
};

template <int MaxOrder>
struct HighPass : PoleFilter <HighPassBase, MaxOrder>
{
};

template <int MaxOrder>
struct BandPass : PoleFilter <BandPassBase, MaxOrder, MaxOrder*2>
{
};

template <int MaxOrder>
struct BandStop : PoleFilter <BandStopBase, MaxOrder, MaxOrder*2>
{
};

template <int MaxOrder>
struct LowShelf : PoleFilter <LowShelfBase, MaxOrder>
{
};

template <int MaxOrder>
struct HighShelf : PoleFilter <HighShelfBase, MaxOrder>
{
};

template <int MaxOrder>
struct BandShelf : PoleFilter <BandShelfBase, MaxOrder, MaxOrder*2>
{
};

//------------------------------------------------------------------------------

//
// Gui-friendly Design layer
//

namespace Design {

struct TypeIBase : DesignBase
{
enum
{
NumParams = 4
};

static int getNumParams ()
{
return 4;
}

static const ParamInfo getParamInfo_2 ()
{
return ParamInfo::defaultCutoffFrequencyParam ();
}

static const ParamInfo getParamInfo_3 ()
{
return ParamInfo::defaultRippleDbParam ();
}
};

template <class FilterClass>
struct TypeI : TypeIBase, FilterClass
{
void setParams (const Params& params)
{
FilterClass::setup (int(params[1]), params[0], params[2], params[3]);
}
};

struct TypeIIBase : DesignBase
{
enum
{
NumParams = 5
};

static int getNumParams ()
{
return 5;
}

static const ParamInfo getParamInfo_2 ()
{
return ParamInfo::defaultCenterFrequencyParam ();
}

static const ParamInfo getParamInfo_3 ()
{
return ParamInfo::defaultBandwidthHzParam ();
}

static const ParamInfo getParamInfo_4 ()
{
return ParamInfo::defaultRippleDbParam ();
}
};

template <class FilterClass>
struct TypeII : TypeIIBase, FilterClass
{
void setParams (const Params& params)
{
FilterClass::setup (int(params[1]), params[0], params[2], params[3], params[4]);
}
};

struct TypeIIIBase : DesignBase
{
enum
{
NumParams = 5
};

static int getNumParams ()
{
return 5;
}

static const ParamInfo getParamInfo_2 ()