48 #include "limitertest.h"
63 Limiter(
int numchans,
int numclients,
bool verboseFlag =
false)
64 : mNumChannels(numchans), mNumClients(numclients)
65 , warningAmp(0.0), warnCount(0), peakMagnitude(0.0), nextWarning(1)
68 for (
int i = 0; i < mNumChannels; i++ ) {
70 limiterUIP.push_back(
new APIUI);
71 limiterP[i]->buildUserInterface(limiterUIP[i]);
73 limiterTestP.push_back(
new limitertest);
74 limiterTestUIP.push_back(
new APIUI);
75 limiterTestP[i]->buildUserInterface(limiterTestUIP[i]);
85 for (
int i = 0; i < mNumChannels; i++ ) {
93 void init(
int samplingRate)
override {
96 std::cerr <<
"Sampling rate not set by superclass!\n";
99 for (
int i = 0; i < mNumChannels; i++ ) {
100 limiterP[i]->init(fs);
101 int ndx = limiterUIP[i]->getParamIndex(
"NumClientsAssumed");
102 limiterUIP[i]->setParamValue(ndx, mNumClients);
104 limiterTestP[i]->init(fs);
105 ndx = limiterTestUIP[i]->getParamIndex(
"Amp");
106 limiterTestUIP[i]->setParamValue(ndx, 0.2);
107 ndx = limiterTestUIP[i]->getParamIndex(
"Freq");
108 float sineFreq = 110.0 * pow(1.5,
double(i)) * (mNumClients>1?1.25:1.0);
109 limiterTestUIP[i]->setParamValue(ndx, sineFreq);
116 void compute(
int nframes,
float** inputs,
float** outputs)
override;
119 warningAmp = std::max(0.0,std::min(1.0,wa));
124 void checkAmplitudes(
int nframes,
float* buf) {
125 const int maxWarningInterval { 10000 };
126 assert(warningAmp > 0.0);
127 assert(mNumClients > 0);
128 for (
int i=0; i<nframes; i++) {
129 double tmp_sample = double(buf[i]);
130 double limiterAmp = fabs(tmp_sample)/sqrt(
double(mNumClients));
131 if (limiterAmp >= warningAmp) {
133 peakMagnitude = std::max(peakMagnitude,limiterAmp);
134 if (warnCount==nextWarning) {
135 double peakMagnitudeDB = 20.0 * std::log10(peakMagnitude);
136 double warningAmpDB = 20.0 * std::log10(warningAmp);
138 if (warningAmp == 1.0) {
139 std::cerr <<
"*** Limiter.cpp: Audio HARD-CLIPPED!\n";
140 fprintf(stderr,
"\tReduce your audio input level(s) by %0.1f dB to avoid this.\n", peakMagnitudeDB);
143 "*** Limiter.cpp: Amplitude levels must stay below %0.1f dBFS to avoid compression.\n",
145 fprintf(stderr,
"\tReduce input level(s) by %0.1f dB to achieve this.\n",
146 peakMagnitudeDB-warningAmpDB);
149 fprintf(stderr,
"\tReduce audio input level(s) by %0.1f dB to avoid limiter compression distortion.\n",
150 peakMagnitudeDB-warningAmpDB);
153 if (nextWarning < maxWarningInterval) {
167 std::vector<limiterdsp*> limiterP;
168 std::vector<APIUI*> limiterUIP;
170 std::vector<limitertest*> limiterTestP;
171 std::vector<APIUI*> limiterTestUIP;
175 double peakMagnitude;