fixed various nasty send issues
authorJesse Chappell <jesse@essej.net>
Mon, 13 Feb 2006 18:57:33 +0000 (18:57 +0000)
committerJesse Chappell <jesse@essej.net>
Mon, 13 Feb 2006 18:57:33 +0000 (18:57 +0000)
git-svn-id: svn://localhost/trunk/ardour2@324 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/session.h
libs/ardour/io.cc
libs/ardour/send.cc
libs/ardour/session.cc

index 7f0bc57e7b1e3be4fb22d3c3b1d36c81c5d42414..b6009731f21474631b6d963934e908e24adb2f49 100644 (file)
@@ -260,6 +260,7 @@ class Session : public sigc::trackable, public Stateful
 
        vector<Sample*>& get_passthru_buffers() { return _passthru_buffers; }
        vector<Sample*>& get_silent_buffers (uint32_t howmany);
+       vector<Sample*>& 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<Sample *>        _passthru_buffers;
        vector<Sample *>        _silent_buffers;
-       map<RunContext,char*> _conversion_buffers;
+       vector<Sample *>        _send_buffers;
+       map<RunContext,char*>   _conversion_buffers;
        jack_nframes_t           current_block_size;
        jack_nframes_t          _worst_output_latency;
        jack_nframes_t          _worst_input_latency;
index 6b6773c49d85139c49761e06486eba12c9624dab..dff0990f1a2313c2a061f0522fa463da0098c72d 100644 (file)
@@ -162,7 +162,8 @@ IO::apply_declick (vector<Sample *>& 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<Sample *>& 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<Sample *>& 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<Sample *>& 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);
        }
 }
 
index f0afea5be536da4a8a38a903453062076d13668b..50fdd4a96a0de82d6f2f02555552b5881e284206 100644 (file)
@@ -107,7 +107,17 @@ Send::run (vector<Sample *>& 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<Sample*>& 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<Sample *>& 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]);
                                }
                        }
                }
index 0b5cd8f3c1c4f0926cdb7f0f3fab5952f8937198..4361bd244e711ec2b3a1c66cf2f2c0c29c5341b2 100644 (file)
@@ -390,6 +390,10 @@ Session::~Session ()
                free(*i);
        }
 
+       for (vector<Sample*>::iterator i = _send_buffers.begin(); i != _send_buffers.end(); ++i) {
+               free(*i);
+       }
+
        for (map<RunContext,char*>::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<Sample*>::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);
 }