#include "dcpomatic_assert.h"
#include <samplerate.h>
#include <iostream>
+#include <cmath>
#include "i18n.h"
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)
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) {
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];
}
}
+ data.data_in = in_buffer;
data.input_frames = in_frames;
data.data_out = new float[max_resampled_frames * _channels];
}
if (data.output_frames_gen == 0) {
+ delete[] data.data_in;
+ delete[] data.data_out;
break;
}
delete[] buffer;
return out;
}
+
+void
+Resampler::reset ()
+{
+ src_reset (_src);
+}