diff options
author | Robin Gareus <robin@gareus.org> | 2015-04-07 03:54:31 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2015-04-07 05:25:12 +0200 |
commit | a30696828302cd98fae4e7a2065c76b863c89286 (patch) | |
tree | 41b604bc6912b3f9af8c9a4984d7374a3d048a50 /libs/ardour/amp.cc | |
parent | 83519faffbfc3d38d4258cbca1107c06109f0573 (diff) |
linear declick
Diffstat (limited to 'libs/ardour/amp.cc')
-rw-r--r-- | libs/ardour/amp.cc | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/libs/ardour/amp.cc b/libs/ardour/amp.cc index cca465a0b4..523b538359 100644 --- a/libs/ardour/amp.cc +++ b/libs/ardour/amp.cc @@ -210,51 +210,39 @@ Amp::apply_gain (BufferSet& bufs, framecnt_t sample_rate, framecnt_t nframes, ga void Amp::declick (BufferSet& bufs, framecnt_t nframes, int dir) { - /* Similar to ::apply_gain() but skips MIDI buffers - * and use cos() Sigmoid decay with fixed initial+target values. - */ - if (nframes == 0 || bufs.count().n_total() == 0) { return; } - const framecnt_t declick = std::min ((framecnt_t) 128, nframes); - gain_t delta, initial, target; - double fractional_shift = -1.0/(declick-1); - double fractional_pos; + const framecnt_t declick = std::min ((framecnt_t) 512, nframes); + const double fractional_shift = 1.0 / declick ; + gain_t delta, initial; if (dir < 0) { /* fade out: remove more and more of delta from initial */ delta = -1.0; initial = 1.0; - target = 0.0; } else { /* fade in: add more and more of delta from initial */ delta = 1.0; initial = 0.0; - target = 1.0; } /* Audio Gain */ - for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) { Sample* const buffer = i->data(); - fractional_pos = 1.0; + double fractional_pos = 0.0; for (pframes_t nx = 0; nx < declick; ++nx) { - buffer[nx] *= (initial + (delta * (0.5 + 0.5 * cos (M_PI * fractional_pos)))); + buffer[nx] *= initial + (delta * fractional_pos); fractional_pos += fractional_shift; } /* now ensure the rest of the buffer has the target value applied, if necessary. */ - if (declick != nframes) { - - if (target == 0.0) { + if (dir < 0) { memset (&buffer[declick], 0, sizeof (Sample) * (nframes - declick)); - } else if (target != 1.0) { - apply_gain_to_buffer (&buffer[declick], nframes - declick, target); } } } |