X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fresampler.cc;h=60eb7f5052a3e5ca4e47a14f850a83f762f75a05;hb=dd9be86db6cde0afa5da0d1d1ac43b42e05dca26;hp=ff93d1609ae5e68590c3dcb76f8e2a337be216bf;hpb=76f83b97c401c24b3c93baee0665e84be05f43ea;p=dcpomatic.git diff --git a/src/lib/resampler.cc b/src/lib/resampler.cc index ff93d1609..60eb7f505 100644 --- a/src/lib/resampler.cc +++ b/src/lib/resampler.cc @@ -25,6 +25,7 @@ #include "dcpomatic_assert.h" #include #include +#include #include "i18n.h" @@ -32,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) @@ -52,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) { @@ -80,11 +85,11 @@ Resampler::run (shared_ptr in) int const max_resampled_frames = ceil ((double) in_frames * _out_rate / _in_rate) + 32; SRC_DATA data; - data.data_in = new float[in_frames * _channels]; + float* in_buffer = new float[in_frames * _channels]; { float** p = in->data (); - float* q = data.data_in; + float* q = in_buffer; for (int i = 0; i < in_frames; ++i) { for (int j = 0; j < _channels; ++j) { *q++ = p[j][in_offset + i]; @@ -92,6 +97,7 @@ Resampler::run (shared_ptr in) } } + data.data_in = in_buffer; data.input_frames = in_frames; data.data_out = new float[max_resampled_frames * _channels]; @@ -116,6 +122,8 @@ Resampler::run (shared_ptr in) } if (data.output_frames_gen == 0) { + delete[] data.data_in; + delete[] data.data_out; break; } @@ -183,3 +191,9 @@ Resampler::flush () delete[] buffer; return out; } + +void +Resampler::reset () +{ + src_reset (_src); +}