summaryrefslogtreecommitdiff
path: root/libs/ardour/amp.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2007-05-03 23:28:57 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2007-05-03 23:28:57 +0000
commita8da89d745c6a7e7d4c20dfcfb16b2537d767428 (patch)
tree06fb6cc1795ef89a7ed847395c550b6215e253df /libs/ardour/amp.cc
parent5a1ca70f07aeb999ba3f0f09dbd49f1d50505f3c (diff)
optimize some performance bottlenecks; remove jack_nframes_t that crept back into the code
git-svn-id: svn://localhost/ardour2/branches/midi@1779 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/amp.cc')
-rw-r--r--libs/ardour/amp.cc31
1 files changed, 15 insertions, 16 deletions
diff --git a/libs/ardour/amp.cc b/libs/ardour/amp.cc
index 8a73e5708e..ca1aa74bb5 100644
--- a/libs/ardour/amp.cc
+++ b/libs/ardour/amp.cc
@@ -28,27 +28,31 @@ 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)
+Amp::run (BufferSet& bufs, nframes_t nframes, gain_t initial, gain_t target, bool invert_polarity)
{
+ if (nframes == 0)
+ return;
+
if (bufs.count().get(DataType::AUDIO) == 0)
return;
- assert(bufs.buffer_capacity(DataType::AUDIO) >= nframes);
+ // 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);
+ for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
+ apply_gain_to_buffer (i->data (), nframes, target);
+ }
+ return;
}
- const jack_nframes_t declick = std::min ((jack_nframes_t)128, nframes);
+ const nframes_t declick = std::min ((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);
@@ -58,11 +62,11 @@ Amp::run (BufferSet& bufs, jack_nframes_t nframes, gain_t initial, gain_t target
}
for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
- Sample* const buffer = i->data(nframes);
+ Sample* const buffer = i->data();
fractional_pos = 1.0;
- for (jack_nframes_t nx = 0; nx < declick; ++nx) {
+ for (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;
}
@@ -78,20 +82,15 @@ Amp::run (BufferSet& bufs, jack_nframes_t nframes, gain_t initial, gain_t 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;
- }
+ apply_gain_to_buffer (&buffer[declick], nframes - declick, target);
}
}
}
}
void
-Amp::apply_simple_gain (BufferSet& bufs, jack_nframes_t nframes, gain_t target)
+Amp::apply_simple_gain (BufferSet& bufs, nframes_t nframes, gain_t target)
{
- for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
- i->apply_gain(target, nframes);
- }
}