diff options
author | David Robillard <d@drobilla.net> | 2006-08-13 03:40:04 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2006-08-13 03:40:04 +0000 |
commit | 0b572cdd84151335594965a3f0ed16f1665dfa56 (patch) | |
tree | 25818906a95bd0c47c190793d7924b75b5076fde /libs/ardour/amp.cc | |
parent | a98a67120eea8ebb817eebea048affc182ea054e (diff) |
More signal path cleanup, IO now has one deliver_output function that should do the reasonable thing in all cases.
Including deliver MIDI.
You can now create a MIDI Track, run some MIDI through it, and toggle the mute button on and off, hearing either
silence or a large amount of stuck notes depending on your luck. Woooo.
git-svn-id: svn://localhost/ardour2/branches/midi@818 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/amp.cc')
-rw-r--r-- | libs/ardour/amp.cc | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/libs/ardour/amp.cc b/libs/ardour/amp.cc new file mode 100644 index 0000000000..cfa20afe3b --- /dev/null +++ b/libs/ardour/amp.cc @@ -0,0 +1,98 @@ +/* + Copyright (C) 2006 Paul Davis + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include <ardour/amp.h> + +#include <algorithm> +#include <cmath> +#include <ardour/buffer_set.h> +#include <ardour/buffer.h> + +namespace ARDOUR { + + +/** Apply a declicked gain to the audio buffers of @a bufs */ +void +Amp::run (BufferSet& bufs, jack_nframes_t nframes, gain_t initial, gain_t target, bool invert_polarity) +{ + if (bufs.count().get(DataType::AUDIO) == 0) + return; + + assert(bufs.buffer_capacity(DataType::AUDIO) >= nframes); + + // if we don't need to declick, defer to apply_simple_gain + if (initial == target) { + apply_simple_gain(bufs, nframes, invert_polarity ? target : -target); + } + + const jack_nframes_t declick = std::min ((jack_nframes_t)128, nframes); + gain_t delta; + double fractional_shift = -1.0/declick; + double fractional_pos; + gain_t polscale = invert_polarity ? -1.0f : 1.0f; + + if (nframes == 0) + return; + + 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; + } + + for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) { + Sample* const buffer = i->data(nframes); + + fractional_pos = 1.0; + + for (jack_nframes_t nx = 0; nx < declick; ++nx) { + buffer[nx] *= polscale * (initial + (delta * (0.5 + 0.5 * cos (M_PI * fractional_pos)))); + fractional_pos += fractional_shift; + } + + /* now ensure the rest of the buffer has the target value applied, if necessary. */ + + if (declick != nframes) { + + if (invert_polarity) { + target = -target; + } + + if (target == 0.0) { + memset (&buffer[declick], 0, sizeof (Sample) * (nframes - declick)); + } else if (target != 1.0) { + for (jack_nframes_t nx = declick; nx < nframes; ++nx) { + buffer[nx] *= target; + } + } + } + } +} + +void +Amp::apply_simple_gain (BufferSet& bufs, jack_nframes_t nframes, gain_t target) +{ + for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) { + i->apply_gain(target, nframes); + } +} + + +} // namespace ARDOUR |