* Avoid using STL map in process()!
* Exceptions in resampler
This commit is contained in:
@@ -92,7 +92,11 @@ D_SRC::D_SRC(Resampler::Quality quality, int channels, int maxBufferSize,
|
|||||||
SRC_SINC_FASTEST,
|
SRC_SINC_FASTEST,
|
||||||
channels, &err);
|
channels, &err);
|
||||||
|
|
||||||
//!!! check err, throw
|
if (err) {
|
||||||
|
std::cerr << "Resampler::Resampler: failed to create libsamplerate resampler: "
|
||||||
|
<< src_strerror(err) << std::endl;
|
||||||
|
throw Resampler::ImplementationError; //!!! of course, need to catch this!
|
||||||
|
}
|
||||||
|
|
||||||
if (maxBufferSize > 0 && m_channels > 1) {
|
if (maxBufferSize > 0 && m_channels > 1) {
|
||||||
//!!! alignment?
|
//!!! alignment?
|
||||||
@@ -153,7 +157,11 @@ D_SRC::resample(const float *const R__ *const R__ in,
|
|||||||
|
|
||||||
int err = src_process(m_src, &data);
|
int err = src_process(m_src, &data);
|
||||||
|
|
||||||
//!!! check err, respond appropriately
|
if (err) {
|
||||||
|
std::cerr << "Resampler::process: libsamplerate error: "
|
||||||
|
<< src_strerror(err) << std::endl;
|
||||||
|
throw Resampler::ImplementationError; //!!! of course, need to catch this!
|
||||||
|
}
|
||||||
|
|
||||||
if (m_channels > 1) {
|
if (m_channels > 1) {
|
||||||
for (int i = 0; i < data.output_frames_gen; ++i) {
|
for (int i = 0; i < data.output_frames_gen; ++i) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class Resampler
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Quality { Best, FastestTolerable, Fastest };
|
enum Quality { Best, FastestTolerable, Fastest };
|
||||||
|
enum Exception { ImplementationError };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a resampler with the given quality level and channel
|
* Construct a resampler with the given quality level and channel
|
||||||
|
|||||||
@@ -982,7 +982,7 @@ RubberBandStretcher::Impl::process(const float *const *input, size_t samples, bo
|
|||||||
|
|
||||||
bool allConsumed = false;
|
bool allConsumed = false;
|
||||||
|
|
||||||
map<size_t, size_t> consumed;
|
size_t *consumed = (size_t *)alloca(m_channels * sizeof(size_t));
|
||||||
for (size_t c = 0; c < m_channels; ++c) {
|
for (size_t c = 0; c < m_channels; ++c) {
|
||||||
consumed[c] = 0;
|
consumed[c] = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -839,16 +839,21 @@ RubberBandStretcher::Impl::formantShiftChunk(size_t channel)
|
|||||||
|
|
||||||
const int sz = m_windowSize;
|
const int sz = m_windowSize;
|
||||||
const int hs = m_windowSize/2;
|
const int hs = m_windowSize/2;
|
||||||
|
const double denom = sz;
|
||||||
|
|
||||||
|
|
||||||
cd.fft->inverseCepstral(mag, dblbuf);
|
cd.fft->inverseCepstral(mag, dblbuf);
|
||||||
|
|
||||||
double denom = sz;
|
|
||||||
for (int i = 0; i < sz; ++i) {
|
for (int i = 0; i < sz; ++i) {
|
||||||
dblbuf[i] /= denom;
|
dblbuf[i] /= denom;
|
||||||
}
|
}
|
||||||
|
|
||||||
//!!! calculate this value -- the divisor should be the highest fundamental frequency we expect to find, plus a bit
|
//!!! calculate this value -- the divisor should be the highest fundamental frequency we expect to find, plus a bit
|
||||||
const int cutoff = m_sampleRate / 700;
|
const int cutoff = m_sampleRate / 700;
|
||||||
|
// const int cutoff = 1000;
|
||||||
|
// const int cutoff = 20;
|
||||||
|
|
||||||
|
// cerr <<"cutoff = "<< cutoff << ", m_sampleRate/cutoff = " << m_sampleRate/cutoff << ", m_sampleRate/700 = " << m_sampleRate/700 << endl;
|
||||||
|
|
||||||
dblbuf[0] /= 2;
|
dblbuf[0] /= 2;
|
||||||
dblbuf[cutoff-1] /= 2;
|
dblbuf[cutoff-1] /= 2;
|
||||||
@@ -859,6 +864,7 @@ RubberBandStretcher::Impl::formantShiftChunk(size_t channel)
|
|||||||
|
|
||||||
cd.fft->forward(dblbuf, envelope, 0);
|
cd.fft->forward(dblbuf, envelope, 0);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i <= hs; ++i) {
|
for (int i = 0; i <= hs; ++i) {
|
||||||
envelope[i] = exp(envelope[i]);
|
envelope[i] = exp(envelope[i]);
|
||||||
}
|
}
|
||||||
@@ -887,6 +893,7 @@ RubberBandStretcher::Impl::formantShiftChunk(size_t channel)
|
|||||||
|
|
||||||
for (int i = 0; i <= hs; ++i) {
|
for (int i = 0; i <= hs; ++i) {
|
||||||
mag[i] *= envelope[i];
|
mag[i] *= envelope[i];
|
||||||
|
// mag[i] = envelope[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
cd.unchanged = false;
|
cd.unchanged = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user