projects
/
dcpomatic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
std::shared_ptr
[dcpomatic.git]
/
src
/
lib
/
resampler.cc
diff --git
a/src/lib/resampler.cc
b/src/lib/resampler.cc
index ff93d1609ae5e68590c3dcb76f8e2a337be216bf..60eb7f5052a3e5ca4e47a14f850a83f762f75a05 100644
(file)
--- a/
src/lib/resampler.cc
+++ b/
src/lib/resampler.cc
@@
-25,6
+25,7
@@
#include "dcpomatic_assert.h"
#include <samplerate.h>
#include <iostream>
#include "dcpomatic_assert.h"
#include <samplerate.h>
#include <iostream>
+#include <cmath>
#include "i18n.h"
#include "i18n.h"
@@
-32,7
+33,7
@@
using std::cout;
using std::pair;
using std::make_pair;
using std::runtime_error;
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)
/** @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 ()
{
Resampler::~Resampler ()
{
- src_delete (_src);
+ if (_src) {
+ src_delete (_src);
+ }
}
void
Resampler::set_fast ()
{
src_delete (_src);
}
void
Resampler::set_fast ()
{
src_delete (_src);
+ _src = 0;
+
int error;
_src = src_new (SRC_LINEAR, _channels, &error);
if (!_src) {
int error;
_src = src_new (SRC_LINEAR, _channels, &error);
if (!_src) {
@@
-80,11
+85,11
@@
Resampler::run (shared_ptr<const AudioBuffers> in)
int const max_resampled_frames = ceil ((double) in_frames * _out_rate / _in_rate) + 32;
SRC_DATA data;
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** 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];
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<const AudioBuffers> in)
}
}
}
}
+ data.data_in = in_buffer;
data.input_frames = in_frames;
data.data_out = new float[max_resampled_frames * _channels];
data.input_frames = in_frames;
data.data_out = new float[max_resampled_frames * _channels];
@@
-116,6
+122,8
@@
Resampler::run (shared_ptr<const AudioBuffers> in)
}
if (data.output_frames_gen == 0) {
}
if (data.output_frames_gen == 0) {
+ delete[] data.data_in;
+ delete[] data.data_out;
break;
}
break;
}
@@
-183,3
+191,9
@@
Resampler::flush ()
delete[] buffer;
return out;
}
delete[] buffer;
return out;
}
+
+void
+Resampler::reset ()
+{
+ src_reset (_src);
+}