+ return target;
+ }
+
+ /* MIDI Gain */
+ if (midi_amp) {
+ /* don't Trim midi velocity -- only relevant for Midi on Audio tracks */
+ for (BufferSet::midi_iterator i = bufs.midi_begin(); i != bufs.midi_end(); ++i) {
+
+ gain_t delta;
+ if (target < initial) {
+ /* fade out: remove more and more of delta from initial */
+ delta = -(initial - target);
+ } else {
+ /* fade in: add more and more of delta from initial */
+ delta = target - initial;
+ }
+
+ MidiBuffer& mb (*i);
+
+ for (MidiBuffer::iterator m = mb.begin(); m != mb.end(); ++m) {
+ Evoral::MIDIEvent<MidiBuffer::TimeType> ev = *m;
+
+ if (ev.is_note_on()) {
+ const gain_t scale = delta * (ev.time()/(double) nframes);
+ ev.scale_velocity (fabsf (initial+scale));
+ }
+ }
+ }
+ }
+
+ /* Audio Gain */
+
+ /* Low pass filter coefficient: 1.0 - e^(-2.0 * π * f / 48000) f in Hz.
+ * for f << SR, approx a ~= 6.2 * f / SR;
+ */
+ const double a = 156.825 / sample_rate; // 25 Hz LPF
+
+ for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
+ Sample* const buffer = i->data();
+ double lpf = initial;
+
+ for (pframes_t nx = 0; nx < nframes; ++nx) {
+ buffer[nx] *= lpf;
+ lpf += a * (target - lpf);
+ }
+ if (i == bufs.audio_begin()) {
+ rv = lpf;
+ }
+ }
+ if (fabsf (rv - target) < GAIN_COEFF_TINY) return target;
+ if (fabsf (rv) < GAIN_COEFF_TINY) return GAIN_COEFF_ZERO;
+ return rv;
+}
+
+void
+Amp::declick (BufferSet& bufs, framecnt_t nframes, int dir)
+{
+ if (nframes == 0 || bufs.count().n_total() == 0) {