Skip to content

Commit

Permalink
Merge from default branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cannam committed Jun 26, 2024
2 parents b4b11d4 + 832f577 commit ad1811b
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 18 deletions.
8 changes: 4 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,11 @@ ladspa_symbol_args = []
lv2_symbol_args = []
vamp_symbol_args = []

if get_option('buildtype').startswith('release')
config_summary += { 'Build type': 'Release' }
feature_defines += ['-DNO_THREAD_CHECKS', '-DNO_TIMING', '-DNDEBUG']
if get_option('debug')
config_summary += { 'Debug': 'Enabled' }
else
config_summary += { 'Build type': 'Debug' }
config_summary += { 'Debug': 'Disabled' }
feature_defines += ['-DNO_THREAD_CHECKS', '-DNO_TIMING', '-DNDEBUG']
endif

if system == 'darwin'
Expand Down
4 changes: 2 additions & 2 deletions otherbuilds/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ else
make -f otherbuilds/Makefile.macos

echo " *** Linking against static library"
c++ -std=c++11 main/main.cpp lib/librubberband.a -I. -Isrc -o test_static -lsndfile -framework Accelerate
c++ -std=c++11 main/main.cpp lib/librubberband.a -I. -Isrc -o test_static -I/opt/homebrew/include -L/opt/homebrew/lib -lsndfile -framework Accelerate

echo " *** Running build from macOS-specific Makefile"
./test_static -V

echo " *** Building with single-file source"
c++ -O3 -std=c++11 main/main.cpp single/RubberBandSingle.cpp -o test_single -lsndfile -framework Accelerate
c++ -O3 -std=c++11 main/main.cpp single/RubberBandSingle.cpp -o test_single -I/opt/homebrew/include -L/opt/homebrew/lib -lsndfile -framework Accelerate

echo " *** Running build from single-file source"
./test_single -V
Expand Down
3 changes: 2 additions & 1 deletion src/common/Allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#include "VectorOps.h"

#include <new> // for std::bad_alloc
#include <stdlib.h>
#include <cstdlib>
#include <cstddef> // ptrdiff_t

#include <stdexcept>

Expand Down
2 changes: 1 addition & 1 deletion src/common/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class MutexLocker
class Condition
{
public:
Condition(std::string name) { }
Condition(std::string) { }
~Condition() { }

void lock() { }
Expand Down
19 changes: 10 additions & 9 deletions src/faster/R2Stretcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,8 @@ R2Stretcher::study(const float *const *input, size_t samples, bool final)
mixdown = input[0];
}

std::vector<float> optionalFoldBuffer;

while (consumed < samples) {

size_t writable = inbuf.getWriteSpace();
Expand Down Expand Up @@ -1042,33 +1044,32 @@ R2Stretcher::study(const float *const *input, size_t samples, bool final)

// Note that we can't do this in-place. Pity

float *tmp = (float *)alloca
(std::max(m_fftSize, m_aWindowSize) * sizeof(float));
// This doesn't have to be allocation-free, as we're
// in offline-mode study

optionalFoldBuffer.resize(std::max(m_fftSize, m_aWindowSize));

if (m_aWindowSize > m_fftSize) {
m_afilter->cut(cd.accumulator);
}

cutShiftAndFold(tmp, m_fftSize, cd.accumulator, m_awindow);
v_copy(cd.accumulator, tmp, m_fftSize);
cutShiftAndFold(optionalFoldBuffer.data(), m_fftSize,
cd.accumulator, m_awindow);
v_copy(cd.accumulator, optionalFoldBuffer.data(), m_fftSize);
}

m_studyFFT->forwardMagnitude(cd.accumulator, cd.fltbuf);

float df = m_phaseResetAudioCurve->processFloat(cd.fltbuf, m_increment);
m_phaseResetDf.push_back(df);

// cout << m_phaseResetDf.size() << " [" << final << "] -> " << df << " \t: ";

df = m_silentAudioCurve->processFloat(cd.fltbuf, m_increment);
bool silent = (df > 0.f);
if (silent) {
m_log.log(2, "silence at", m_inputDuration);
}
m_silence.push_back(silent);

// cout << df << endl;

// We have augmented the input by m_aWindowSize/2 so that
// the first chunk is centred on the first audio sample.
// We want to ensure that m_inputDuration contains the
Expand All @@ -1080,7 +1081,7 @@ R2Stretcher::study(const float *const *input, size_t samples, bool final)
inbuf.skip(m_increment);
}
}

if (final) {
int rs = inbuf.getReadSpace();
m_inputDuration += rs;
Expand Down
8 changes: 7 additions & 1 deletion src/faster/StretcherProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ R2Stretcher::consumeChannel(size_t c,

inbuf.write(cd.resamplebuf, toWrite);
cd.inCount += samples;

m_log.log(2, "consumeChannel: wrote to inbuf from resamplebuf, inCount now", toWrite, cd.inCount);

return samples;

} else {
Expand All @@ -249,6 +252,9 @@ R2Stretcher::consumeChannel(size_t c,

inbuf.write(input, toWrite);
cd.inCount += toWrite;

m_log.log(2, "consumeChannel: wrote to inbuf from input, inCount now", toWrite, cd.inCount);

return toWrite;
}
}
Expand Down Expand Up @@ -340,7 +346,7 @@ R2Stretcher::processOneChunk()
return false;
}
ChannelData &cd = *m_channelData[c];
m_log.log(3, "read space and draining", cd.inbuf->getReadSpace(), cd.draining);
m_log.log(2, "read space and draining", cd.inbuf->getReadSpace(), cd.draining);
if (!cd.draining) {
size_t ready = cd.inbuf->getReadSpace();
assert(ready >= m_aWindowSize || cd.inputSize >= 0);
Expand Down
28 changes: 28 additions & 0 deletions src/test/TestStretcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,4 +1516,32 @@ BOOST_AUTO_TEST_CASE(with_resets_2x_5up_realtime_faster)
with_resets(RubberBandStretcher::OptionProcessRealTime | RubberBandStretcher::OptionEngineFaster, 2.0, 1.5);
}

BOOST_AUTO_TEST_CASE(long_blocksize_with_smoothing)
{
// Test added because the smoothing option was calling alloca in a
// loop, which could run us out of stack. This test is best used
// with a small stack artificially enforced via e.g. ulimit -s 32

int n = 10000;
float freq = 440.f;
int rate = 44100;
RubberBandStretcher stretcher
(rate, 1,
RubberBandStretcher::OptionEngineFaster |
RubberBandStretcher::OptionProcessOffline |
RubberBandStretcher::OptionSmoothingOn);

vector<float> in(n);
for (int i = 0; i < n; ++i) {
in[i] = sinf(float(i) * freq * M_PI * 2.f / float(rate));
}
float *inp = in.data();

stretcher.setMaxProcessSize(n);
stretcher.setExpectedInputDuration(n);

stretcher.study(&inp, n, true);
stretcher.process(&inp, n, true);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit ad1811b

Please sign in to comment.