projects
/
dcpomatic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add empty playlist list and configuration option.
[dcpomatic.git]
/
src
/
lib
/
resampler.cc
diff --git
a/src/lib/resampler.cc
b/src/lib/resampler.cc
index db5552d15ab3159b17510ca1295704d8806507a0..553180f0832c7a26852b2354bec045b1263faa01 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"
@@
-37,15
+38,14
@@
using boost::shared_ptr;
/** @param in Input sampling rate (Hz)
* @param out Output sampling rate (Hz)
* @param channels Number of channels.
/** @param in Input sampling rate (Hz)
* @param out Output sampling rate (Hz)
* @param channels Number of channels.
- * @param fast true to be fast rather than good.
*/
*/
-Resampler::Resampler (int in, int out, int channels
, bool fast
)
+Resampler::Resampler (int in, int out, int channels)
: _in_rate (in)
, _out_rate (out)
, _channels (channels)
{
int error;
: _in_rate (in)
, _out_rate (out)
, _channels (channels)
{
int error;
- _src = src_new (
fast ? SRC_LINEAR :
SRC_SINC_BEST_QUALITY, _channels, &error);
+ _src = src_new (SRC_SINC_BEST_QUALITY, _channels, &error);
if (!_src) {
throw runtime_error (String::compose (N_("could not create sample-rate converter (%1)"), error));
}
if (!_src) {
throw runtime_error (String::compose (N_("could not create sample-rate converter (%1)"), error));
}
@@
-56,6
+56,17
@@
Resampler::~Resampler ()
src_delete (_src);
}
src_delete (_src);
}
+void
+Resampler::set_fast ()
+{
+ src_delete (_src);
+ int error;
+ _src = src_new (SRC_LINEAR, _channels, &error);
+ if (!_src) {
+ throw runtime_error (String::compose (N_("could not create sample-rate converter (%1)"), error));
+ }
+}
+
shared_ptr<const AudioBuffers>
Resampler::run (shared_ptr<const AudioBuffers> in)
{
shared_ptr<const AudioBuffers>
Resampler::run (shared_ptr<const AudioBuffers> in)
{
@@
-70,11
+81,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];
@@
-82,6
+93,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];
@@
-106,6
+118,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;
}
@@
-173,3
+187,9
@@
Resampler::flush ()
delete[] buffer;
return out;
}
delete[] buffer;
return out;
}
+
+void
+Resampler::reset ()
+{
+ src_reset (_src);
+}