X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fresampler.cc;h=60eb7f5052a3e5ca4e47a14f850a83f762f75a05;hp=d08e7bc38e22f60eab6486d4c9626dc5562837f7;hb=2d4e8c5f69cc694625ad95dcee554499605f823b;hpb=89aa9d4ba69e471949f791cdafe4ae20cea554d2 diff --git a/src/lib/resampler.cc b/src/lib/resampler.cc index d08e7bc38..60eb7f505 100644 --- a/src/lib/resampler.cc +++ b/src/lib/resampler.cc @@ -33,7 +33,7 @@ using std::cout; using std::pair; using std::make_pair; using std::runtime_error; -using boost::shared_ptr; +using std::shared_ptr; /** @param in Input sampling rate (Hz) * @param out Output sampling rate (Hz) @@ -53,13 +53,17 @@ Resampler::Resampler (int in, int out, int channels) Resampler::~Resampler () { - src_delete (_src); + if (_src) { + src_delete (_src); + } } void Resampler::set_fast () { src_delete (_src); + _src = 0; + int error; _src = src_new (SRC_LINEAR, _channels, &error); if (!_src) { @@ -67,19 +71,9 @@ Resampler::set_fast () } } -pair, Frame> -Resampler::run (shared_ptr in, Frame frame) +shared_ptr +Resampler::run (shared_ptr in) { - if (!_next_in || !_next_out || _next_in.get() != frame) { - /* Either there was a discontinuity in the input or this is the first input; - reset _next_out. - */ - _next_out = lrintf (frame * _out_rate / _in_rate); - } - - /* Expected next input frame */ - _next_in = frame + in->frames (); - int in_frames = in->frames (); int in_offset = 0; int out_offset = 0; @@ -128,6 +122,8 @@ Resampler::run (shared_ptr in, Frame frame) } if (data.output_frames_gen == 0) { + delete[] data.data_in; + delete[] data.data_out; break; } @@ -152,12 +148,7 @@ Resampler::run (shared_ptr in, Frame frame) delete[] data.data_out; } - Frame out_frame = _next_out.get (); - - /* Expected next output frame */ - _next_out = _next_out.get() + resampled->frames(); - - return make_pair (resampled, out_frame); + return resampled; } shared_ptr @@ -200,3 +191,9 @@ Resampler::flush () delete[] buffer; return out; } + +void +Resampler::reset () +{ + src_reset (_src); +}