diff options
author | Hans Baier <hansfbaier@googlemail.com> | 2009-06-23 09:50:17 +0000 |
---|---|---|
committer | Hans Baier <hansfbaier@googlemail.com> | 2009-06-23 09:50:17 +0000 |
commit | 47e56905523cb9269a19300d2b468118dda3a161 (patch) | |
tree | 4bf586a28b11c98ba2bc55a09b416e1a3f87516f /libs/ardour/interpolation.cc | |
parent | 875568f01ff65f405f4246405dc48b166ed70138 (diff) |
Interpolation -> LibSamplerateInterpolation, keep state per channel
git-svn-id: svn://localhost/ardour2/branches/3.0@5257 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/interpolation.cc')
-rw-r--r-- | libs/ardour/interpolation.cc | 74 |
1 files changed, 46 insertions, 28 deletions
diff --git a/libs/ardour/interpolation.cc b/libs/ardour/interpolation.cc index 444183a2b1..3d2f754da9 100644 --- a/libs/ardour/interpolation.cc +++ b/libs/ardour/interpolation.cc @@ -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; } |