Interpolation -> LibSamplerateInterpolation, keep state per channel
authorHans Baier <hansfbaier@googlemail.com>
Tue, 23 Jun 2009 09:50:17 +0000 (09:50 +0000)
committerHans Baier <hansfbaier@googlemail.com>
Tue, 23 Jun 2009 09:50:17 +0000 (09:50 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@5257 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/audio_diskstream.h
libs/ardour/ardour/interpolation.h
libs/ardour/ardour/session.h
libs/ardour/interpolation.cc

index ad3b1adde242fdcbe72cdb3b56a633f3d1407b6d..55cb747a4cf75a8f4491be4993e901c8fe4cfc5c 100644 (file)
@@ -146,7 +146,7 @@ class AudioDiskstream : public Diskstream
                }
        }
        
-       Interpolation interpolation;
+       LibSamplerateInterpolation interpolation;
 
        XMLNode* deprecated_io_node;
        
index d0ba3c48bc87973bcd7f9fe7a0b1f27ac1189e4c..cec951c841bb0b8c3a24de0af2e8352dae3c973e 100644 (file)
@@ -8,20 +8,20 @@
 
 namespace ARDOUR {
 
-class Interpolation {
+class LibSamplerateInterpolation {
 protected:
        double   _speed;
        
-       SRC_STATE*            state;
-       std::vector<SRC_DATA> data;
+       std::vector<SRC_STATE*>  state;
+       std::vector<SRC_DATA*>   data;
        
        int        error;
        
        void reset_state ();
        
 public:
-        Interpolation ();
-        ~Interpolation ();
+        LibSamplerateInterpolation ();
+        ~LibSamplerateInterpolation ();
     
         void   set_speed (double new_speed);
         void   set_target_speed (double new_speed)   {}
index 5c2c32655fba089c630af54cb0da8f3cc27d10d5..8b291dd75bbbac753c2b54c26d4879c27b7572ae 100644 (file)
@@ -1008,10 +1008,10 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable
        bool                    _silent;
        
     // varispeed playback
-       volatile double         _transport_speed;
-       double                  _last_transport_speed;
-       double                  _target_transport_speed;
-       Interpolation            interpolation;
+       volatile double             _transport_speed;
+       double                      _last_transport_speed;
+       double                      _target_transport_speed;
+       LibSamplerateInterpolation  interpolation;
        
        bool                     auto_play_legal;
        nframes_t               _last_slave_transport_frame;
index 444183a2b1d3493fa5f3fffcf117f56afb389728..3d2f754da9c59a7785788874061ea02e4f09ebe0 100644 (file)
@@ -4,74 +4,92 @@
 
 using namespace ARDOUR;
 
-Interpolation::Interpolation()  : _speed (1.0L), state (0)
+LibSamplerateInterpolation::LibSamplerateInterpolation()  : _speed (1.0L), state (0)
 {
 }
 
-Interpolation::~Interpolation() 
+LibSamplerateInterpolation::~LibSamplerateInterpolation() 
 {
-       state = src_delete (state);
+       for (int i = 0; i < state.size(); i++) {
+               state[i] = src_delete (state[i]);
+       }
 }
 
 void
-Interpolation::set_speed (double new_speed)
+LibSamplerateInterpolation::set_speed (double new_speed)
 { 
        _speed = new_speed; 
-       src_set_ratio (state, 1.0/_speed); 
+       for (int i = 0; i < state.size(); i++) {
+               src_set_ratio (state[i], 1.0/_speed);
+       }
 }
 
 void
-Interpolation::reset_state ()
+LibSamplerateInterpolation::reset_state ()
 {
-       if (state) {
-               src_reset (state);
-       } else {
-               state = src_new (SRC_LINEAR, 1, &error);
+       printf("INTERPOLATION: reset_state()\n");
+       for (int i = 0; i < state.size(); i++) {
+               if (state[i]) {
+                       src_reset (state[i]);
+               } else {
+                       state[i] = src_new (SRC_SINC_FASTEST, 1, &error);
+               }
        }
 }
 
 void
-Interpolation::add_channel_to (int input_buffer_size, int output_buffer_size) 
+LibSamplerateInterpolation::add_channel_to (int input_buffer_size, int output_buffer_size) 
 {
-       SRC_DATA newdata;
+       SRC_DATA* newdata = new SRC_DATA;
        
        /* Set up sample rate converter info. */
-       newdata.end_of_input = 0 ; 
+       newdata->end_of_input = 0 ; 
 
-       newdata.input_frames  = input_buffer_size;
-       newdata.output_frames = output_buffer_size;
+       newdata->input_frames  = input_buffer_size;
+       newdata->output_frames = output_buffer_size;
 
-       newdata.input_frames_used = 0 ;
-       newdata.output_frames_gen = 0 ;
+       newdata->input_frames_used = 0 ;
+       newdata->output_frames_gen = 0 ;
 
-       newdata.src_ratio = 1.0/_speed;
+       newdata->src_ratio = 1.0/_speed;
        
        data.push_back (newdata);
+       state.push_back (0);
        
        reset_state ();
 }
 
 void
-Interpolation::remove_channel_from () 
+LibSamplerateInterpolation::remove_channel_from () 
 {
+       delete data.back ();
        data.pop_back ();
+       delete state.back ();
+       state.pop_back ();
        reset_state ();
 }
 
 nframes_t
-Interpolation::interpolate (int channel, nframes_t nframes, Sample *input, Sample *output)
+LibSamplerateInterpolation::interpolate (int channel, nframes_t nframes, Sample *input, Sample *output)
 {      
-       data[channel].data_in       = input;
-       data[channel].data_out      = output;
+       if (!data.size ()) {
+               printf ("ERROR: trying to interpolate with no channels\n");
+               return 0;
+       }
+       
+       data[channel]->data_in       = input;
+       data[channel]->data_out      = output;
        
-       data[channel].input_frames = nframes * _speed;
-       data[channel].output_frames = nframes;
-       data[channel].src_ratio     = 1.0/_speed; 
+       data[channel]->input_frames  = nframes * _speed;
+       data[channel]->output_frames = nframes;
+       data[channel]->src_ratio     = 1.0/_speed; 
 
-       if ((error = src_process (state, &data[channel]))) {    
+       if ((error = src_process (state[channel], data[channel]))) {    
                printf ("\nError : %s\n\n", src_strerror (error));
                exit (1);
        }
-
-       return data[channel].input_frames_used;
+       
+       //printf("INTERPOLATION: channel %d input_frames_used: %d\n", channel, data[channel]->input_frames_used);
+       
+       return data[channel]->input_frames_used;
 }