merged with 2.0-ongoing changes 2582-2605 (not thoroughly tested but it compiles...
[ardour.git] / libs / ardour / audio_diskstream.cc
index 14eef2961bc1829f8e529125685430a1419b744f..bc42cb0b5b5849c6c07c023ed6e8ac0a6fbf6541 100644 (file)
@@ -31,7 +31,6 @@
 #include <sys/mman.h>
 
 #include <pbd/error.h>
-#include <pbd/basename.h>
 #include <glibmm/thread.h>
 #include <pbd/xml++.h>
 #include <pbd/memento_command.h>
@@ -213,13 +212,14 @@ AudioDiskstream::get_input_sources ()
        uint32_t n;
        ChannelList::iterator chan;
        uint32_t ni = _io->n_inputs().n_audio();
+       vector<string> connections;
 
        for (n = 0, chan = c->begin(); chan != c->end() && n < ni; ++chan, ++n) {
                
-               const char **connections = _io->input(n)->get_connections ();
+               connections.clear ();
+
+               if (_io->input(n)->get_connections (connections) == 0) {
                
-               if (connections == 0 || connections[0] == 0) {
-                       
                        if ((*chan)->source) {
                                // _source->disable_metering ();
                        }
@@ -227,12 +227,7 @@ AudioDiskstream::get_input_sources ()
                        (*chan)->source = 0;
                        
                } else {
-                       (*chan)->source = dynamic_cast<AudioPort*>(
-                               _session.engine().get_port_by_name (connections[0]) );
-               }
-               
-               if (connections) {
-                       free (connections);
+                       (*chan)->source = dynamic_cast<AudioPort*>(_session.engine().get_port_by_name (connections[0]) );
                }
        }
 }              
@@ -767,11 +762,18 @@ AudioDiskstream::process (nframes_t transport_frame, nframes_t nframes, nframes_
                if (rec_nframes == 0 && _actual_speed != 1.0f && _actual_speed != -1.0f) {
                        
                        uint64_t phase = last_phase;
+                       int64_t phi_delta;
                        nframes_t i = 0;
 
                        // Linearly interpolate into the alt buffer
                        // using 40.24 fixp maths (swh)
 
+                       if (phi != target_phi) {
+                               phi_delta = ((int64_t)(target_phi - phi)) / nframes;
+                       } else {
+                               phi_delta = 0;
+                       }
+
                        for (chan = c->begin(); chan != c->end(); ++chan) {
 
                                float fr;
@@ -786,19 +788,21 @@ AudioDiskstream::process (nframes_t transport_frame, nframes_t nframes, nframes_
                                        chaninfo->speed_buffer[outsample] = 
                                                chaninfo->current_playback_buffer[i] * (1.0f - fr) +
                                                chaninfo->current_playback_buffer[i+1] * fr;
-                                       phase += phi;
+                                       phase += phi + phi_delta;
                                }
                                
                                chaninfo->current_playback_buffer = chaninfo->speed_buffer;
                        }
 
-                       playback_distance = i + 1;
+                       playback_distance = i; // + 1;
                        last_phase = (phase & 0xFFFFFF);
 
                } else {
                        playback_distance = nframes;
                }
 
+               phi = target_phi;
+
        }
 
        ret = 0;
@@ -1741,6 +1745,9 @@ AudioDiskstream::finish_capture (bool rec_monitors_input, boost::shared_ptr<Chan
 
        capture_info.push_back (ci);
        capture_captured = 0;
+
+       /* now we've finished a capture, reset first_recordable_frame for next time */
+       first_recordable_frame = max_frames;
 }
 
 void
@@ -1794,11 +1801,13 @@ AudioDiskstream::engage_record_enable ()
                                (*chan)->source->ensure_monitor_input (!(Config->get_auto_input() && rolling));
                        }
                        capturing_sources.push_back ((*chan)->write_source);
+                       (*chan)->write_source->mark_streaming_write_started ();
                }
                
        } else {
                for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
                        capturing_sources.push_back ((*chan)->write_source);
+                       (*chan)->write_source->mark_streaming_write_started ();
                }
        }