mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-21 14:16:31 +01:00
merge 3578:4901 of thirdparty/rubberband/current
git-svn-id: svn://localhost/ardour2/branches/3.0@4982 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
c2b12f05f4
commit
1ff9e8afc0
20 changed files with 125 additions and 18 deletions
28
libs/rubberband/repopulate
Executable file
28
libs/rubberband/repopulate
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# this script copies the relevant files from $1 into this
|
||||
# working copy of the repository, adds new files and
|
||||
# prints a list of mods for SConscript
|
||||
#
|
||||
|
||||
from=$1
|
||||
#strip=`dirname $1`
|
||||
strip=$1
|
||||
|
||||
echo "Looking for copies in $from ... will strip $strip"
|
||||
|
||||
for file in `find $from \( -name \*.cpp -o -name \*.h -o -name \*.c \)`
|
||||
do
|
||||
src=$file
|
||||
copy=`echo $file | sed "s?$strip/??"`
|
||||
echo "Look for $copy"
|
||||
if [ -f $copy ] ; then
|
||||
cp $src $copy
|
||||
echo "copy $copy"
|
||||
else
|
||||
echo "ADD $copy"
|
||||
cp $src $copy
|
||||
svn add $copy
|
||||
fi
|
||||
done
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
#ifndef _RUBBERBANDSTRETCHER_H_
|
||||
#define _RUBBERBANDSTRETCHER_H_
|
||||
|
||||
#define RUBBERBAND_VERSION "1.2.0-gpl"
|
||||
#define RUBBERBAND_VERSION "1.3.0-gpl"
|
||||
#define RUBBERBAND_API_MAJOR_VERSION 2
|
||||
#define RUBBERBAND_API_MINOR_VERSION 0
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define RUBBERBAND_VERSION "1.2.0-gpl"
|
||||
#define RUBBERBAND_VERSION "1.3.0-gpl"
|
||||
#define RUBBERBAND_API_MAJOR_VERSION 2
|
||||
#define RUBBERBAND_API_MINOR_VERSION 0
|
||||
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ AudioCurve::~AudioCurve()
|
|||
}
|
||||
|
||||
float
|
||||
AudioCurve::process(const double *R__ mag, size_t increment)
|
||||
AudioCurve::processDouble(const double *R__ mag, size_t increment)
|
||||
{
|
||||
cerr << "WARNING: Using inefficient AudioCurve::process(double)" << endl;
|
||||
cerr << "AudioCurve::processDouble: WARNING: Using inefficient and lossy conversion for AudioCurve::process(float)" << endl;
|
||||
float *tmp = new float[m_windowSize];
|
||||
for (int i = 0; i < int(m_windowSize); ++i) tmp[i] = float(mag[i]);
|
||||
float df = process(tmp, increment);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public:
|
|||
virtual void setWindowSize(size_t newSize) = 0;
|
||||
|
||||
virtual float process(const float *R__ mag, size_t increment) = 0;
|
||||
virtual float process(const double *R__ mag, size_t increment);
|
||||
virtual float processDouble(const double *R__ mag, size_t increment);
|
||||
virtual void reset() = 0;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -43,5 +43,11 @@ ConstantAudioCurve::process(const float *R__, size_t)
|
|||
return 1.f;
|
||||
}
|
||||
|
||||
float
|
||||
ConstantAudioCurve::processDouble(const double *R__, size_t)
|
||||
{
|
||||
return 1.f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public:
|
|||
virtual void setWindowSize(size_t newSize);
|
||||
|
||||
virtual float process(const float *R__ mag, size_t increment);
|
||||
virtual float processDouble(const double *R__ mag, size_t increment);
|
||||
virtual void reset();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -51,5 +51,19 @@ HighFrequencyAudioCurve::process(const float *R__ mag, size_t increment)
|
|||
return result;
|
||||
}
|
||||
|
||||
float
|
||||
HighFrequencyAudioCurve::processDouble(const double *R__ mag, size_t increment)
|
||||
{
|
||||
float result = 0.0;
|
||||
|
||||
const int sz = m_windowSize / 2;
|
||||
|
||||
for (int n = 0; n <= sz; ++n) {
|
||||
result = result + (float)mag[n] * n;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ public:
|
|||
virtual void setWindowSize(size_t newSize);
|
||||
|
||||
virtual float process(const float *R__ mag, size_t increment);
|
||||
virtual float processDouble(const double *R__ mag, size_t increment);
|
||||
virtual void reset();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ PercussiveAudioCurve::process(const float *R__ mag, size_t increment)
|
|||
}
|
||||
|
||||
float
|
||||
PercussiveAudioCurve::process(const double *R__ mag, size_t increment)
|
||||
PercussiveAudioCurve::processDouble(const double *R__ mag, size_t increment)
|
||||
{
|
||||
Profiler profiler("PercussiveAudioCurve::process");
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public:
|
|||
virtual void setWindowSize(size_t newSize);
|
||||
|
||||
virtual float process(const float *R__ mag, size_t increment);
|
||||
virtual float process(const double *R__ mag, size_t increment);
|
||||
virtual float processDouble(const double *R__ mag, size_t increment);
|
||||
virtual void reset();
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -137,9 +137,11 @@ D_SRC::resample(const float *const R__ *const R__ in,
|
|||
data.data_out = *out;
|
||||
} else {
|
||||
if (incount * m_channels > m_iinsize) {
|
||||
m_iinsize = incount * m_channels;
|
||||
m_iin = allocFloat(m_iin, m_iinsize);
|
||||
}
|
||||
if (outcount * m_channels > m_ioutsize) {
|
||||
m_ioutsize = outcount * m_channels;
|
||||
m_iout = allocFloat(m_iout, m_ioutsize);
|
||||
}
|
||||
for (int i = 0; i < incount; ++i) {
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ SilentAudioCurve::process(const float *R__ mag, size_t)
|
|||
}
|
||||
|
||||
float
|
||||
SilentAudioCurve::process(const double *R__ mag, size_t)
|
||||
SilentAudioCurve::processDouble(const double *R__ mag, size_t)
|
||||
{
|
||||
const int hs = m_windowSize / 2;
|
||||
static double threshold = pow(10.0, -6);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public:
|
|||
virtual void setWindowSize(size_t newSize);
|
||||
|
||||
virtual float process(const float *R__ mag, size_t increment);
|
||||
virtual float process(const double *R__ mag, size_t increment);
|
||||
virtual float processDouble(const double *R__ mag, size_t increment);
|
||||
virtual void reset();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -65,5 +65,19 @@ SpectralDifferenceAudioCurve::process(const float *R__ mag, size_t increment)
|
|||
return result;
|
||||
}
|
||||
|
||||
float
|
||||
SpectralDifferenceAudioCurve::processDouble(const double *R__ mag, size_t increment)
|
||||
{
|
||||
float result = 0.0;
|
||||
|
||||
for (size_t n = 0; n <= m_windowSize / 2; ++n) {
|
||||
result += sqrtf(fabsf((mag[n] * mag[n]) -
|
||||
(m_prevMag[n] * m_prevMag[n])));
|
||||
m_prevMag[n] = (float)mag[n];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ public:
|
|||
virtual void setWindowSize(size_t newSize);
|
||||
|
||||
virtual float process(const float *R__ mag, size_t increment);
|
||||
virtual float processDouble(const double *R__ mag, size_t increment);
|
||||
virtual void reset();
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -104,6 +104,14 @@ RubberBandStretcher::Impl::ChannelData::construct(const std::set<size_t> &window
|
|||
for (size_t i = 0; i < initialWindowSize * oversample; ++i) {
|
||||
dblbuf[i] = 0.0;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < maxSize; ++i) {
|
||||
accumulator[i] = 0.f;
|
||||
windowAccumulator[i] = 0.f;
|
||||
}
|
||||
|
||||
// Avoid dividing opening sample (which will be discarded anyway) by zero
|
||||
windowAccumulator[0] = 1.f;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -273,6 +281,16 @@ RubberBandStretcher::Impl::ChannelData::reset()
|
|||
|
||||
if (resampler) resampler->reset();
|
||||
|
||||
size_t size = inbuf->getSize();
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
accumulator[i] = 0.f;
|
||||
windowAccumulator[i] = 0.f;
|
||||
}
|
||||
|
||||
// Avoid dividing opening sample (which will be discarded anyway) by zero
|
||||
windowAccumulator[0] = 1.f;
|
||||
|
||||
accumulatorFill = 0;
|
||||
prevIncrement = 0;
|
||||
chunkCount = 0;
|
||||
|
|
|
|||
|
|
@ -342,6 +342,19 @@ RubberBandStretcher::Impl::calculateSizes()
|
|||
size_t windowSize = m_baseWindowSize;
|
||||
size_t outputIncrement;
|
||||
|
||||
if (m_pitchScale <= 0.0) {
|
||||
// This special case is likelier than one might hope, because
|
||||
// of naive initialisations in programs that set it from a
|
||||
// variable
|
||||
std::cerr << "RubberBandStretcher: WARNING: Pitch scale must be greater than zero!\nResetting it from " << m_pitchScale << " to the default of 1.0: no pitch change will occur" << std::endl;
|
||||
m_pitchScale = 1.0;
|
||||
}
|
||||
if (m_timeRatio <= 0.0) {
|
||||
// Likewise
|
||||
std::cerr << "RubberBandStretcher: WARNING: Time ratio must be greater than zero!\nResetting it from " << m_timeRatio << " to the default of 1.0: no time stretch will occur" << std::endl;
|
||||
m_timeRatio = 1.0;
|
||||
}
|
||||
|
||||
double r = getEffectiveRatio();
|
||||
|
||||
if (m_realtime) {
|
||||
|
|
@ -921,9 +934,18 @@ RubberBandStretcher::Impl::calculateStretch()
|
|||
{
|
||||
Profiler profiler("RubberBandStretcher::Impl::calculateStretch");
|
||||
|
||||
size_t inputDuration = m_inputDuration;
|
||||
|
||||
if (!m_realtime && m_expectedInputDuration > 0) {
|
||||
if (m_expectedInputDuration != inputDuration) {
|
||||
std::cerr << "RubberBandStretcher: WARNING: Actual study() duration differs from duration set by setExpectedInputDuration (" << m_inputDuration << " vs " << m_expectedInputDuration << ", diff = " << (m_expectedInputDuration - m_inputDuration) << "), using the latter for calculation" << std::endl;
|
||||
inputDuration = m_expectedInputDuration;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<int> increments = m_stretchCalculator->calculate
|
||||
(getEffectiveRatio(),
|
||||
m_inputDuration,
|
||||
inputDuration,
|
||||
m_phaseResetDf,
|
||||
m_stretchDf);
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ RubberBandStretcher::Impl::ProcessThread::run()
|
|||
|
||||
m_dataAvailable.lock();
|
||||
if (!m_s->testInbufReadSpace(m_channel) && !m_abandoning) {
|
||||
m_dataAvailable.wait();
|
||||
m_dataAvailable.wait(50000); // bounded in case of abandonment
|
||||
} else {
|
||||
m_dataAvailable.unlock();
|
||||
}
|
||||
|
|
@ -448,8 +448,8 @@ RubberBandStretcher::Impl::calculateIncrements(size_t &phaseIncrementRtn,
|
|||
|
||||
if (m_channels == 1) {
|
||||
|
||||
df = m_phaseResetAudioCurve->process(cd.mag, m_increment);
|
||||
silent = (m_silentAudioCurve->process(cd.mag, m_increment) > 0.f);
|
||||
df = m_phaseResetAudioCurve->processDouble(cd.mag, m_increment);
|
||||
silent = (m_silentAudioCurve->processDouble(cd.mag, m_increment) > 0.f);
|
||||
|
||||
} else {
|
||||
|
||||
|
|
@ -464,8 +464,8 @@ RubberBandStretcher::Impl::calculateIncrements(size_t &phaseIncrementRtn,
|
|||
}
|
||||
}
|
||||
|
||||
df = m_phaseResetAudioCurve->process(tmp, m_increment);
|
||||
silent = (m_silentAudioCurve->process(tmp, m_increment) > 0.f);
|
||||
df = m_phaseResetAudioCurve->processDouble(tmp, m_increment);
|
||||
silent = (m_silentAudioCurve->processDouble(tmp, m_increment) > 0.f);
|
||||
}
|
||||
|
||||
int incr = m_stretchCalculator->calculateSingle
|
||||
|
|
@ -736,7 +736,7 @@ RubberBandStretcher::Impl::modifyChunk(size_t channel,
|
|||
bool inherit = false;
|
||||
|
||||
if (laminar) {
|
||||
if (distance >= mi) {
|
||||
if (distance >= mi || i == count) {
|
||||
inherit = false;
|
||||
} else if (bandlimited && (i == bandhigh || i == bandlow)) {
|
||||
inherit = false;
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ float *allocFloat(float *ptr, int count)
|
|||
void *allocated;
|
||||
#ifndef _WIN32
|
||||
#ifndef __APPLE__
|
||||
if (!posix_memalign(&allocated, 16, count * sizeof(float)))
|
||||
if (posix_memalign(&allocated, 16, count * sizeof(float)))
|
||||
#endif
|
||||
#endif
|
||||
allocated = malloc(count * sizeof(float));
|
||||
|
|
@ -133,7 +133,7 @@ double *allocDouble(double *ptr, int count)
|
|||
void *allocated;
|
||||
#ifndef _WIN32
|
||||
#ifndef __APPLE__
|
||||
if (!posix_memalign(&allocated, 16, count * sizeof(double)))
|
||||
if (posix_memalign(&allocated, 16, count * sizeof(double)))
|
||||
#endif
|
||||
#endif
|
||||
allocated = malloc(count * sizeof(double));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue