From 51462b3eba73a29d801bd6b79a6f2c9e262d1b42 Mon Sep 17 00:00:00 2001 From: Jesse Chappell Date: Mon, 13 Feb 2006 18:57:33 +0000 Subject: [PATCH] fixed various nasty send issues git-svn-id: svn://localhost/trunk/ardour2@324 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/session.h | 4 +++- libs/ardour/io.cc | 24 ++++++++++-------------- libs/ardour/send.cc | 14 ++++++++++++-- libs/ardour/session.cc | 29 +++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 7f0bc57e7b..b6009731f2 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -260,6 +260,7 @@ class Session : public sigc::trackable, public Stateful vector& get_passthru_buffers() { return _passthru_buffers; } vector& get_silent_buffers (uint32_t howmany); + vector& get_send_buffers () { return _send_buffers; } DiskStream *diskstream_by_id (id_t id); DiskStream *diskstream_by_name (string name); @@ -1008,7 +1009,8 @@ class Session : public sigc::trackable, public Stateful jack_nframes_t last_stop_frame; vector _passthru_buffers; vector _silent_buffers; - map _conversion_buffers; + vector _send_buffers; + map _conversion_buffers; jack_nframes_t current_block_size; jack_nframes_t _worst_output_latency; jack_nframes_t _worst_input_latency; diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index 6b6773c49d..dff0990f1a 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -162,7 +162,8 @@ IO::apply_declick (vector& bufs, uint32_t nbufs, jack_nframes_t nframe Sample *buffer; double fractional_shift; double fractional_pos; - + gain_t polscale = invert_polarity ? -1.0f : 1.0f; + fractional_shift = -1.0/declick; if (target < initial) { @@ -178,16 +179,9 @@ IO::apply_declick (vector& bufs, uint32_t nbufs, jack_nframes_t nframe buffer = bufs[n]; fractional_pos = 1.0; - if (invert_polarity) { - for (jack_nframes_t nx = 0; nx < declick; ++nx) { - buffer[nx] *= -(initial + (delta * (0.5 + 0.5 * cos (M_PI * fractional_pos)))); - fractional_pos += fractional_shift; - } - } else { - for (jack_nframes_t nx = 0; nx < declick; ++nx) { - buffer[nx] *= (initial + (delta * (0.5 + 0.5 * cos (M_PI * fractional_pos)))); - fractional_pos += fractional_shift; - } + 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 @@ -381,7 +375,8 @@ IO::deliver_output (vector& bufs, uint32_t nbufs, jack_nframes_t nfram gain_t dg; - + gain_t pangain = _gain; + { TentativeLockMonitor dm (declick_lock, __LINE__, __FILE__); @@ -395,14 +390,15 @@ IO::deliver_output (vector& bufs, uint32_t nbufs, jack_nframes_t nfram if (dg != _gain) { apply_declick (bufs, nbufs, nframes, _gain, dg, false); _gain = dg; + pangain = 1.0f; } /* simple, non-automation panning to outputs */ if (_session.transport_speed() > 1.5f || _session.transport_speed() < -1.5f) { - pan (bufs, nbufs, nframes, offset, _gain * speed_quietning); + pan (bufs, nbufs, nframes, offset, pangain * speed_quietning); } else { - pan (bufs, nbufs, nframes, offset, _gain); + pan (bufs, nbufs, nframes, offset, pangain); } } diff --git a/libs/ardour/send.cc b/libs/ardour/send.cc index f0afea5be5..50fdd4a96a 100644 --- a/libs/ardour/send.cc +++ b/libs/ardour/send.cc @@ -107,7 +107,17 @@ Send::run (vector& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_ { if (active()) { - IO::deliver_output (bufs, nbufs, nframes, offset); + // we have to copy the input, because IO::deliver_output may alter the buffers + // in-place, which a send must never do. + + vector& sendbufs = _session.get_send_buffers(); + + for (size_t i=0; i < nbufs; ++i) { + memcpy (sendbufs[i], bufs[i], sizeof (Sample) * nframes); + } + + + IO::deliver_output (sendbufs, nbufs, nframes, offset); if (_metering) { uint32_t n; @@ -122,7 +132,7 @@ Send::run (vector& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_ } else { for (n = 0; n < no; ++n) { - _peak_power[n] = Session::compute_peak (output(n)->get_buffer(nframes+offset) + offset, nframes, _peak_power[n]) * _gain; + _peak_power[n] = Session::compute_peak (output(n)->get_buffer(nframes) + offset, nframes, _peak_power[n]); } } } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 0b5cd8f3c1..4361bd244e 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -390,6 +390,10 @@ Session::~Session () free(*i); } + for (vector::iterator i = _send_buffers.begin(); i != _send_buffers.end(); ++i) { + free(*i); + } + for (map::iterator i = _conversion_buffers.begin(); i != _conversion_buffers.end(); ++i) { delete [] (i->second); } @@ -1451,6 +1455,21 @@ Session::set_block_size (jack_nframes_t nframes) ensure_passthru_buffers (np); + for (vector::iterator i = _send_buffers.begin(); i != _send_buffers.end(); ++i) { + free(*i); + + Sample *buf; +#ifdef NO_POSIX_MEMALIGN + buf = (Sample *) malloc(current_block_size * sizeof(Sample)); +#else + posix_memalign((void **)&buf,16,current_block_size * 4); +#endif + *i = buf; + + memset (*i, 0, sizeof (Sample) * current_block_size); + } + + if (_gain_automation_buffer) { delete [] _gain_automation_buffer; } @@ -3232,6 +3251,16 @@ Session::ensure_passthru_buffers (uint32_t howmany) memset (p, 0, sizeof (Sample) * current_block_size); _silent_buffers.push_back (p); + *p = 0; + +#ifdef NO_POSIX_MEMALIGN + p = (Sample *) malloc(current_block_size * sizeof(Sample)); +#else + posix_memalign((void **)&p,16,current_block_size * 4); +#endif + memset (p, 0, sizeof (Sample) * current_block_size); + _send_buffers.push_back (p); + } allocate_pan_automation_buffers (current_block_size, howmany, false); }