JackTrip
Compressor.h
Go to the documentation of this file.
1//*****************************************************************
2/*
3 JackTrip: A System for High-Quality Audio Network Performance
4 over the Internet
5
6 Copyright (c) 2020 Julius Smith, Juan-Pablo Caceres, Chris Chafe.
7 SoundWIRE group at CCRMA, Stanford University.
8
9 Permission is hereby granted, free of charge, to any person
10 obtaining a copy of this software and associated documentation
11 files (the "Software"), to deal in the Software without
12 restriction, including without limitation the rights to use,
13 copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the
15 Software is furnished to do so, subject to the following
16 conditions:
17
18 The above copyright notice and this permission notice shall be
19 included in all copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 OTHER DEALINGS IN THE SOFTWARE.
29*/
30//*****************************************************************
31
42#ifndef __COMPRESSOR_H__
43#define __COMPRESSOR_H__
44
45#include "ProcessPlugin.h"
46#include "compressordsp.h"
47#include "CompressorPresets.h"
48#include <vector>
49
54{
55public:
57 Compressor(int numchans, // xtor
58 bool verboseIn = false,
59 float ratioIn = 2.0f,
60 float thresholdDBIn = -24.0f,
61 float attackMSIn = 15.0f,
62 float releaseMSIn = 40.0f,
63 float makeUpGainDBIn = 2.0f)
64 : mNumChannels(numchans)
65 , ratio(ratioIn)
66 , thresholdDB(thresholdDBIn)
67 , attackMS(attackMSIn)
68 , releaseMS(releaseMSIn)
69 , makeUpGainDB(makeUpGainDBIn)
70 {
71 setVerbose(verboseIn);
72 // presets.push_back(std::make_unique<CompressorPreset>(ratio,thresholdDB,attackMS,releaseMS,makeUpGainDB));
73 for ( int i = 0; i < mNumChannels; i++ ) {
74 compressorP.push_back(new compressordsp);
75 compressorUIP.push_back(new APIUI); // #included in compressordsp.h
76 compressorP[i]->buildUserInterface(compressorUIP[i]);
77 }
78 }
79
80 Compressor(int numchans, // xtor
81 bool verboseIn = false,
83 Compressor(numchans,verboseIn,
84 preset.ratio,
85 preset.thresholdDB,
86 preset.attackMS,
87 preset.releaseMS,
88 preset.makeUpGainDB)
89 {}
91 virtual ~Compressor() {
92 for ( int i = 0; i < mNumChannels; i++ ) {
93 delete compressorP[i];
94 delete compressorUIP[i];
95 }
96 compressorP.clear();
97 compressorUIP.clear();
98 }
99
100 // void setParamAllChannels(std::string& pName, float p) {
101 void setParamAllChannels(const char pName[], float p) {
102 for ( int i = 0; i < mNumChannels; i++ ) {
103 int ndx = compressorUIP[i]->getParamIndex(pName);
104 if (ndx >= 0) {
105 compressorUIP[i]->setParamValue(ndx, p);
106 if (verbose) {
107 std::cout << "Compressor.h: parameter " << pName << " set to " << p << " on audio channel " << i << "\n";
108 }
109 } else {
110 std::cerr << "*** Compressor.h: Could not find parameter named " << pName << "\n";
111 }
112 }
113 }
114
115 void init(int samplingRate) override {
116 ProcessPlugin::init(samplingRate);
117 if (samplingRate != fSamplingFreq) {
118 std::cerr << "Sampling rate not set by superclass!\n";
119 std::exit(1); }
120 fs = float(fSamplingFreq);
121 for ( int i = 0; i < mNumChannels; i++ ) {
122 compressorP[i]->init(fs); // compression filter parameters depend on sampling rate
123 }
124 setParamAllChannels("Ratio", ratio);
125 setParamAllChannels("Threshold", thresholdDB);
126 setParamAllChannels("Attack", attackMS);
127 setParamAllChannels("Release", releaseMS);
128 setParamAllChannels("MakeUpGain", makeUpGainDB);
129 inited = true;
130 }
131
132 int getNumInputs() override { return(mNumChannels); }
133 int getNumOutputs() override { return(mNumChannels); }
134 void compute(int nframes, float** inputs, float** outputs) override;
135
136private:
137 float fs;
138 int mNumChannels;
139 std::vector<compressordsp*> compressorP;
140 std::vector<APIUI*> compressorUIP;
141 float ratio;
142 float thresholdDB;
143 float attackMS;
144 float releaseMS;
145 float makeUpGainDB;
146};
147
148#endif
Definition: compressordsp.h:1031
Applies compressor_mono from the faustlibraries distribution, compressors.lib.
Definition: Compressor.h:54
virtual ~Compressor()
The class destructor.
Definition: Compressor.h:91
void compute(int nframes, float **inputs, float **outputs) override
Compute process.
Definition: Compressor.cpp:44
int getNumOutputs() override
Return Number of Output Channels.
Definition: Compressor.h:133
int getNumInputs() override
Return Number of Input Channels.
Definition: Compressor.h:132
Compressor(int numchans, bool verboseIn=false, CompressorPreset preset=CompressorPresets::voice)
Definition: Compressor.h:80
void init(int samplingRate) override
Do proper Initialization of members and class instances. By default this initializes the Sampling Fre...
Definition: Compressor.h:115
Compressor(int numchans, bool verboseIn=false, float ratioIn=2.0f, float thresholdDBIn=-24.0f, float attackMSIn=15.0f, float releaseMSIn=40.0f, float makeUpGainDBIn=2.0f)
The class constructor sets the number of audio channels and default parameters.
Definition: Compressor.h:57
void setParamAllChannels(const char pName[], float p)
Definition: Compressor.h:101
Interface for the process plugins to add to the JACK callback process in JackAudioInterface.
Definition: ProcessPlugin.h:53
virtual void setVerbose(bool v)
Definition: ProcessPlugin.h:86
int fSamplingFreq
Faust Data member, Sampling Rate.
Definition: ProcessPlugin.h:92
virtual void init(int samplingRate)
Do proper Initialization of members and class instances. By default this initializes the Sampling Fre...
Definition: ProcessPlugin.h:78
bool inited
Definition: ProcessPlugin.h:93
bool verbose
Definition: ProcessPlugin.h:94
Definition: compressordsp.h:1575
const CompressorPreset voice
Definition: CompressorPresets.h:24
Definition: CompressorPresets.h:5