[SCM] calf/master: Fixes for lookahead buffer resizing. Initialize variables.
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:40:46 UTC 2013
The following commit has been merged in the master branch:
commit 95214939212ed0a5833d5db188cd2583eb2a159a
Author: Markus Schmidt <schmidt at boomshop.net>
Date: Sat Dec 17 11:11:25 2011 +0000
Fixes for lookahead buffer resizing. Initialize variables.
diff --git a/src/audio_fx.cpp b/src/audio_fx.cpp
index c720327..d50776b 100644
--- a/src/audio_fx.cpp
+++ b/src/audio_fx.cpp
@@ -538,15 +538,8 @@ lookahead_limiter::lookahead_limiter() {
is_active = false;
channels = 2;
id = 0;
-}
-
-void lookahead_limiter::activate()
-{
- is_active = true;
- buffer_size = (int)srate * attack * channels; // buffer size attack rate multiplied by 2 channels
- buffer = (float*) calloc(buffer_size, sizeof(float));
- memset(buffer, 0, buffer_size * sizeof(float)); // reset buffer to zero
-
+ buffer_size = 0;
+ overall_buffer_size = 0;
att = 1.f;
att_max = 1.0;
pos = 0;
@@ -556,9 +549,18 @@ void lookahead_limiter::activate()
over_s = 0;
over_c = 1.f;
attack = 0.005;
+ __attack = -1;
pos_next = -1;
use_multi = false;
weight = 1.f;
+ _sanitize = false;
+}
+
+void lookahead_limiter::activate()
+{
+ is_active = true;
+ pos = 0;
+
}
void lookahead_limiter::set_multi(bool set) { use_multi = set; }
@@ -578,6 +580,11 @@ float lookahead_limiter::get_attenuation()
void lookahead_limiter::set_sample_rate(uint32_t sr)
{
srate = sr;
+ // rebuild buffer
+ overall_buffer_size = (int)(srate * (100.f / 1000.f) * channels) + channels; // buffer size attack rate multiplied by 2 channels
+ buffer = (float*) calloc(overall_buffer_size, sizeof(float));
+ memset(buffer, 0, overall_buffer_size * sizeof(float)); // reset buffer to zero
+ pos = 0;
}
void lookahead_limiter::set_params(float l, float a, float r, float w, bool ar, bool d)
@@ -589,12 +596,11 @@ void lookahead_limiter::set_params(float l, float a, float r, float w, bool ar,
debug = d;
weight = w;
//if(debug) printf("%.5f\n", release);
- if( attack != attack__) {
- // rebuild buffer
- buffer_size = (int)srate * attack * channels; // buffer size attack rate multiplied by 2 channels
- buffer = (float*) calloc(buffer_size, sizeof(float));
- memset(buffer, 0, buffer_size * sizeof(float)); // reset buffer to zero
- attack__ = attack;
+ if( attack != __attack) {
+ int bs = (int)(srate * attack * channels);
+ buffer_size = bs - bs % channels; // buffer size attack rate
+ __attack = attack;
+ _sanitize = true;
pos = 0;
}
}
@@ -604,8 +610,12 @@ void lookahead_limiter::process(float &left, float &right, float * multi_buffer)
int in0 = 0;
int out0 = 0;
// write left and right to buffer
- buffer[pos] = left;
- buffer[pos + 1] = right;
+ buffer[pos] = 0.f;
+ buffer[pos + 1] = 0.f;
+ if(!_sanitize) {
+ buffer[pos] = left;
+ buffer[pos + 1] = right;
+ }
// are we using multiband? get the multiband coefficient
float multi_coeff = (use_multi) ? multi_buffer[pos] : 1.f;
@@ -675,6 +685,11 @@ void lookahead_limiter::process(float &left, float &right, float * multi_buffer)
left *= att;
right *= att;
+ if(_sanitize) {
+ left = 0.f;
+ right = 0.f;
+ }
+
// release time seems over
if (att > 1.0f) {
att = 1.0f;
@@ -711,4 +726,5 @@ void lookahead_limiter::process(float &left, float &right, float * multi_buffer)
att_max = (att < att_max) ? att : att_max; // store max atten for meter output
pos = (pos + channels) % buffer_size;
+ if(pos == 0) _sanitize = false;
}
diff --git a/src/calf/audio_fx.h b/src/calf/audio_fx.h
index 657699d..5d23849 100644
--- a/src/calf/audio_fx.h
+++ b/src/calf/audio_fx.h
@@ -572,12 +572,13 @@ class lookahead_limiter {
private:
public:
float limit, attack, release, weight;
- float attack__;
+ float __attack;
uint32_t srate;
float att;
float att_max;
unsigned int pos;
unsigned int buffer_size;
+ unsigned int overall_buffer_size;
bool is_active;
bool debug;
bool auto_release;
@@ -591,6 +592,7 @@ public:
int pos_next;
bool use_multi;
unsigned int id;
+ bool _sanitize;
static inline void denormal(volatile float *f) {
*f += 1e-18;
*f -= 1e-18;
diff --git a/src/calf/modules_limit.h b/src/calf/modules_limit.h
index 927b988..3c6c3f6 100644
--- a/src/calf/modules_limit.h
+++ b/src/calf/modules_limit.h
@@ -67,11 +67,13 @@ private:
float freq_old[strips - 1], sep_old[strips - 1], q_old[strips - 1];
unsigned int pos;
unsigned int buffer_size;
- float attack_old;
+ unsigned int overall_buffer_size;
+ float __attack;
float *buffer;
int channels;
float striprel[strips];
float weight[strips];
+ bool _sanitize;
public:
uint32_t srate;
bool is_active;
diff --git a/src/modules_comp.cpp b/src/modules_comp.cpp
index 7d15b2b..4f86382 100644
--- a/src/modules_comp.cpp
+++ b/src/modules_comp.cpp
@@ -88,6 +88,7 @@ void multibandcompressor_audio_module::params_changed()
int j1;
switch(mode) {
case 0:
+ default:
j1 = 0;
break;
case 1:
@@ -222,6 +223,7 @@ uint32_t multibandcompressor_audio_module::process(uint32_t offset, uint32_t num
// send trough filters
switch(mode) {
case 0:
+ default:
j1 = 0;
break;
case 1:
diff --git a/src/modules_limit.cpp b/src/modules_limit.cpp
index dd743ce..f55cc07 100644
--- a/src/modules_limit.cpp
+++ b/src/modules_limit.cpp
@@ -205,8 +205,11 @@ multibandlimiter_audio_module::multibandlimiter_audio_module()
meter_inR = 0.f;
meter_outL = 0.f;
meter_outR = 0.f;
- attack_old = -1.f;
+ __attack = -1.f;
channels = 2;
+ buffer_size = 0;
+ overall_buffer_size = 0;
+ _sanitize = false;
}
void multibandlimiter_audio_module::activate()
@@ -252,6 +255,7 @@ void multibandlimiter_audio_module::params_changed()
int j1;
switch(mode) {
case 0:
+ default:
j1 = 0;
break;
case 1:
@@ -329,12 +333,11 @@ void multibandlimiter_audio_module::params_changed()
*params[param_effrelease3] = rel;
broadband.set_params(*params[param_limit], *params[param_attack], rel, 1.f);
// rebuild multiband buffer
- if( *params[param_attack] != attack_old) {
- // rebuild buffer
- buffer_size = (int)(srate * (*params[param_attack] / 1000.f) * channels); // buffer size attack rate
- buffer = (float*) calloc(buffer_size, sizeof(float));
- memset(buffer, 0, buffer_size * sizeof(float)); // reset buffer to zero
- attack_old = *params[param_attack];
+ if( *params[param_attack] != __attack) {
+ int bs = (int)(srate * (*params[param_attack] / 1000.f) * channels);
+ buffer_size = bs - bs % channels; // buffer size attack rate
+ __attack = *params[param_attack];
+ _sanitize = true;
pos = 0;
}
}
@@ -342,6 +345,11 @@ void multibandlimiter_audio_module::params_changed()
void multibandlimiter_audio_module::set_sample_rate(uint32_t sr)
{
srate = sr;
+ // rebuild buffer
+ overall_buffer_size = (int)(srate * (100.f / 1000.f) * channels) + channels; // buffer size max attack rate
+ buffer = (float*) calloc(overall_buffer_size, sizeof(float));
+ memset(buffer, 0, overall_buffer_size * sizeof(float)); // reset buffer to zero
+ pos = 0;
// set srate of all strips
for (int j = 0; j < strips; j ++) {
strip[j].set_sample_rate(srate);
@@ -393,9 +401,13 @@ uint32_t multibandlimiter_audio_module::process(uint32_t offset, uint32_t numsam
float _tmpL[channels];
float _tmpR[channels];
while(offset < numsamples) {
+ float inL = 0.f;
+ float inR = 0.f;
// cycle through samples
- float inL = ins[0][offset];
- float inR = ins[1][offset];
+ if(!_sanitize) {
+ inL = ins[0][offset];
+ inR = ins[1][offset];
+ }
// in level
inR *= *params[param_level_in];
inL *= *params[param_level_in];
@@ -426,6 +438,7 @@ uint32_t multibandlimiter_audio_module::process(uint32_t offset, uint32_t numsam
switch(mode) {
// how many filter passes? (12/36dB)
case 0:
+ default:
j1 = 0;
break;
case 1:
@@ -516,6 +529,7 @@ uint32_t multibandlimiter_audio_module::process(uint32_t offset, uint32_t numsam
// next sample
++offset;
pos = (pos + channels) % buffer_size;
+ if(pos == 0) _sanitize = false;
} // cycle trough samples
} // process all strips (no bypass)
@@ -559,6 +573,7 @@ bool multibandlimiter_audio_module::get_graph(int index, int subindex, float *da
freq = 20.0 * pow (20000.0 / 20.0, i * 1.0 / points);
switch(mode) {
case 0:
+ default:
j1 = 0;
break;
case 1:
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list