summaryrefslogtreecommitdiff
path: root/libs/ardour/amp.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-03-10 17:31:16 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-03-10 17:31:16 +0000
commit325671e20afa56f5c796d14ce9bb76146a232f0b (patch)
treed8eca3efc7d95d013459cee81fa55732a5b6d35d /libs/ardour/amp.cc
parentb2bc408cef1715de0009c65ff082c6e914de1991 (diff)
how about that ... a monitor/main section .. GUI is still unfinished .. several small fixes to processor loading/listen mgmt and a few debug output lines rmeoved. knob images are provisional, and can be found in icons/knob.png and related files
git-svn-id: svn://localhost/ardour2/branches/3.0@6744 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/amp.cc')
-rw-r--r--libs/ardour/amp.cc68
1 files changed, 64 insertions, 4 deletions
diff --git a/libs/ardour/amp.cc b/libs/ardour/amp.cc
index ddcb3f84db..35b567688c 100644
--- a/libs/ardour/amp.cc
+++ b/libs/ardour/amp.cc
@@ -179,10 +179,10 @@ Amp::run (BufferSet& bufs, sframes_t /*start_frame*/, sframes_t /*end_frame*/, n
void
Amp::apply_gain (BufferSet& bufs, nframes_t nframes, gain_t initial, gain_t target)
{
- /** Apply a (potentially) declicked gain to the audio buffers of @a bufs
+ /** Apply a (potentially) declicked gain to the buffers of @a bufs
*/
- if (nframes == 0 || bufs.count().n_audio() == 0) {
+ if (nframes == 0 || bufs.count().n_total() == 0) {
return;
}
@@ -196,7 +196,6 @@ Amp::apply_gain (BufferSet& bufs, nframes_t nframes, gain_t initial, gain_t targ
gain_t delta;
double fractional_shift = -1.0/declick;
double fractional_pos;
- gain_t polscale = 1.0f;
if (target < initial) {
/* fade out: remove more and more of delta from initial */
@@ -232,7 +231,7 @@ Amp::apply_gain (BufferSet& bufs, nframes_t nframes, gain_t initial, gain_t targ
fractional_pos = 1.0;
for (nframes_t nx = 0; nx < declick; ++nx) {
- buffer[nx] *= polscale * (initial + (delta * (0.5 + 0.5 * cos (M_PI * fractional_pos))));
+ buffer[nx] *= (initial + (delta * (0.5 + 0.5 * cos (M_PI * fractional_pos))));
fractional_pos += fractional_shift;
}
@@ -250,6 +249,57 @@ Amp::apply_gain (BufferSet& bufs, nframes_t nframes, gain_t initial, gain_t targ
}
void
+Amp::apply_gain (AudioBuffer& buf, nframes_t nframes, gain_t initial, gain_t target)
+{
+ /** Apply a (potentially) declicked gain to the contents of @a buf
+ */
+
+ if (nframes == 0) {
+ return;
+ }
+
+ // if we don't need to declick, defer to apply_simple_gain
+ if (initial == target) {
+ apply_simple_gain (buf, nframes, target);
+ return;
+ }
+
+ const nframes_t declick = std::min ((nframes_t)128, nframes);
+ gain_t delta;
+ double fractional_shift = -1.0/declick;
+ double fractional_pos;
+
+ 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;
+ }
+
+
+ Sample* const buffer = buf.data();
+
+ fractional_pos = 1.0;
+
+ for (nframes_t nx = 0; nx < declick; ++nx) {
+ buffer[nx] *= (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 (target == 0.0) {
+ memset (&buffer[declick], 0, sizeof (Sample) * (nframes - declick));
+ } else if (target != 1.0) {
+ apply_gain_to_buffer (&buffer[declick], nframes - declick, target);
+ }
+ }
+}
+
+void
Amp::apply_simple_gain (BufferSet& bufs, nframes_t nframes, gain_t target)
{
if (target == 0.0) {
@@ -289,6 +339,16 @@ Amp::apply_simple_gain (BufferSet& bufs, nframes_t nframes, gain_t target)
}
void
+Amp::apply_simple_gain (AudioBuffer& buf, nframes_t nframes, gain_t target)
+{
+ if (target == 0.0) {
+ memset (buf.data(), 0, sizeof (Sample) * nframes);
+ } else if (target != 1.0) {
+ apply_gain_to_buffer (buf.data(), nframes, target);
+ }
+}
+
+void
Amp::inc_gain (gain_t factor, void *src)
{
float desired_gain = _gain_control->user_float();