JackTrip
Reverb.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 __REVERB_H__
43 #define __REVERB_H__
44 
45 //#define SINE_TEST
46 
47 #include "ProcessPlugin.h"
48 #include "freeverbdsp.h" // stereo in and out
49 #include "freeverbmonodsp.h" // mono in and out (there is no mono to stereo case in jacktrip as yet)
50 #include "zitarevdsp.h" // stereo in and out
51 #include "zitarevmonodsp.h" // mono in and out
52 
56 class Reverb : public ProcessPlugin
57 {
58 public:
60  Reverb(int numInChans, int numOutChans, float reverbLevel = 1.0, bool verboseFlag = false) // xtor
61  : mNumInChannels(numInChans), mNumOutChannels(numOutChans), mReverbLevel(reverbLevel)
62  {
63  setVerbose(verboseFlag);
64  if ( mNumInChannels < 1 ) {
65  std::cerr << "*** Reverb.h: must have at least one input audio channels\n";
66  mNumInChannels = 1;
67  }
68  if ( mNumInChannels > 2 ) {
69  std::cerr << "*** Reverb.h: limiting number of audio output channels to 2\n";
70  mNumInChannels = 2;
71  }
72 #if 0
73  std::cout << "Reverb: constructed for "
74  << mNumInChannels << " input channels and "
75  << mNumOutChannels << " output channels with reverb level = "
76  << mReverbLevel << "\n";
77 #endif
78 
79  if (mReverbLevel <= 1.0) { // freeverb:
80  freeverbStereoP = new freeverbdsp; // stereo input and output
81  freeverbMonoP = new freeverbmonodsp; // mono input, stereo output
82  freeverbStereoUIP = new APIUI; // #included in *dsp.h
83  freeverbMonoUIP = new APIUI;
84  freeverbStereoP->buildUserInterface(freeverbStereoUIP);
85  freeverbMonoP->buildUserInterface(freeverbMonoUIP);
86  // std::cout << "Using freeverb\n";
87  } else {
88  zitarevStereoP = new zitarevdsp; // stereo input and output
89  zitarevMonoP = new zitarevmonodsp; // mono input, stereo output
90  zitarevStereoUIP = new APIUI;
91  zitarevMonoUIP = new APIUI;
92  zitarevStereoP->buildUserInterface(zitarevStereoUIP);
93  zitarevMonoP->buildUserInterface(zitarevMonoUIP);
94  // std::cout << "Using zitarev\n";
95  }
96  }
97 
99  virtual ~Reverb() {
100  if (mReverbLevel <= 1.0) { // freeverb:
101  delete freeverbStereoP;
102  delete freeverbMonoP;
103  delete freeverbStereoUIP;
104  delete freeverbMonoUIP;
105  } else {
106  delete zitarevStereoP;
107  delete zitarevMonoP;
108  delete zitarevStereoUIP;
109  delete zitarevMonoUIP;
110  }
111  }
112 
113  void init(int samplingRate) override {
114  ProcessPlugin::init(samplingRate);
115  // std::cout << "Reverb: init(" << samplingRate << ")\n";
116  if (samplingRate != fSamplingFreq) {
117  std::cerr << "Sampling rate not set by superclass!\n";
118  std::exit(1); }
119  fs = float(fSamplingFreq);
120  if (mReverbLevel <= 1.0) { // freeverb:
121  freeverbStereoP->init(fs); // compression filter parameters depend on sampling rate
122  freeverbMonoP->init(fs); // compression filter parameters depend on sampling rate
123  int ndx = freeverbStereoUIP->getParamIndex("Wet");
124  freeverbStereoUIP->setParamValue(ndx, mReverbLevel);
125  freeverbMonoUIP->setParamValue(ndx, mReverbLevel);
126  } else { // zitarev:
127  zitarevStereoP->init(fs); // compression filter parameters depend on sampling rate
128  zitarevMonoP->init(fs); // compression filter parameters depend on sampling rate
129  int ndx = zitarevStereoUIP->getParamIndex("Wet");
130  float zitaLevel = mReverbLevel-1.0f; // range within zitarev is 0 to 1 (our version only)
131  zitarevStereoUIP->setParamValue(ndx, zitaLevel);
132  zitarevMonoUIP->setParamValue(ndx, zitaLevel);
133  }
134  inited = true;
135  }
136  int getNumInputs() override { return(mNumInChannels); }
137  int getNumOutputs() override { return(mNumOutChannels); }
138  void compute(int nframes, float** inputs, float** outputs) override;
139 
140 private:
141  float fs;
142  int mNumInChannels;
143  int mNumOutChannels;
144 
145  float mReverbLevel;
146 
147  freeverbdsp* freeverbStereoP;
148  freeverbmonodsp* freeverbMonoP;
149  APIUI* freeverbStereoUIP;
150  APIUI* freeverbMonoUIP;
151 
152  zitarevdsp* zitarevStereoP;
153  zitarevmonodsp* zitarevMonoP;
154  APIUI* zitarevStereoUIP;
155  APIUI* zitarevMonoUIP;
156 };
157 
158 #endif
Reverb::getNumInputs
int getNumInputs() override
Return Number of Input Channels.
Definition: Reverb.h:136
Reverb::compute
void compute(int nframes, float **inputs, float **outputs) override
Compute process.
Definition: Reverb.cpp:45
APIUI::getParamIndex
int getParamIndex(const char *path)
Definition: compressordsp.h:1338
zitarevdsp::buildUserInterface
virtual void buildUserInterface(UI *ui_interface)
Definition: zitarevdsp.h:2042
zitarevdsp::init
virtual void init(int sample_rate)
Definition: zitarevdsp.h:2024
freeverbmonodsp::buildUserInterface
virtual void buildUserInterface(UI *ui_interface)
Definition: freeverbmonodsp.h:1978
Reverb::~Reverb
virtual ~Reverb()
The class destructor.
Definition: Reverb.h:99
freeverbdsp.h
ProcessPlugin::inited
bool inited
Definition: ProcessPlugin.h:93
freeverbdsp::init
virtual void init(int sample_rate)
Definition: freeverbdsp.h:1970
Reverb::Reverb
Reverb(int numInChans, int numOutChans, float reverbLevel=1.0, bool verboseFlag=false)
The class constructor sets the number of channels to limit.
Definition: Reverb.h:60
ProcessPlugin
Interface for the process plugins to add to the JACK callback process in JackAudioInterface.
Definition: ProcessPlugin.h:53
freeverbmonodsp
Definition: freeverbmonodsp.h:1572
freeverbdsp
Definition: freeverbdsp.h:1575
ProcessPlugin::setVerbose
virtual void setVerbose(bool v)
Definition: ProcessPlugin.h:86
ProcessPlugin::init
virtual void init(int samplingRate)
Do proper Initialization of members and class instances. By default this initializes the Sampling Fre...
Definition: ProcessPlugin.h:78
freeverbmonodsp::init
virtual void init(int sample_rate)
Definition: freeverbmonodsp.h:1960
APIUI::setParamValue
void setParamValue(int p, FAUSTFLOAT v)
Definition: compressordsp.h:1371
zitarevmonodsp
Definition: zitarevmonodsp.h:1575
APIUI
Definition: compressordsp.h:1031
freeverbmonodsp.h
Reverb::getNumOutputs
int getNumOutputs() override
Return Number of Output Channels.
Definition: Reverb.h:137
ProcessPlugin.h
ProcessPlugin::fSamplingFreq
int fSamplingFreq
Faust Data member, Sampling Rate.
Definition: ProcessPlugin.h:92
freeverbdsp::buildUserInterface
virtual void buildUserInterface(UI *ui_interface)
Definition: freeverbdsp.h:1988
zitarevmonodsp::init
virtual void init(int sample_rate)
Definition: zitarevmonodsp.h:2012
zitarevdsp
Definition: zitarevdsp.h:1575
zitarevdsp.h
zitarevmonodsp::buildUserInterface
virtual void buildUserInterface(UI *ui_interface)
Definition: zitarevmonodsp.h:2030
Reverb
Applies freeverb or zitarev from the faustlibraries distribution: reverbs.lib.
Definition: Reverb.h:57
Reverb::init
void init(int samplingRate) override
Do proper Initialization of members and class instances. By default this initializes the Sampling Fre...
Definition: Reverb.h:113
zitarevmonodsp.h