From f894f7c66f5e5a131dce8d81567877292f4f2075 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Fri, 4 Jul 2008 19:31:23 +0000 Subject: [PATCH] * update from personal repo --- Makefile.in | 8 ++-- src/StretcherImpl.cpp | 6 +-- src/StretcherProcess.cpp | 1 + src/ladspa/RubberBandPitchShifter.cpp | 58 ++++++++++++++++++++++++--- src/ladspa/RubberBandPitchShifter.h | 12 ++++-- 5 files changed, 67 insertions(+), 18 deletions(-) diff --git a/Makefile.in b/Makefile.in index 5aac345..bd28e0e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,7 +1,5 @@ CXX := @CXX@ -#CXXFLAGS := -DHAVE_FFTW3 -DFFTW_DOUBLE_ONLY -DNO_THREAD_CHECKS @CXXFLAGS@ @SRC_CFLAGS@ @SNDFILE_CFLAGS@ @FFTW_CFLAGS@ @Vamp_CFLAGS@ -Irubberband -Isrc $(OPTFLAGS) -OPTFLAGS := -O3 -ffast-math -ftree-vectorize -ftree-vect-loop-version -march=pentium4 -msse -msse2 CXXFLAGS := -DHAVE_FFTW3 -DFFTW_DOUBLE_ONLY -DNO_THREAD_CHECKS @CXXFLAGS@ @SRC_CFLAGS@ @SNDFILE_CFLAGS@ @FFTW_CFLAGS@ @Vamp_CFLAGS@ -Irubberband -Isrc $(OPTFLAGS) CFLAGS := @CFLAGS@ $(OPTFLAGS) LDFLAGS := @LDFLAGS@ -lpthread $(LDFLAGS) @@ -19,6 +17,8 @@ DYNAMIC_FULL_VERSION := .2.0.0 DYNAMIC_ABI_VERSION := .2 DYNAMIC_LIBNAME := librubberband$(DYNAMIC_EXTENSION) DYNAMIC_LDFLAGS := -shared -Wl,-Bsymbolic -Wl,-soname=$(DYNAMIC_LIBNAME)$(DYNAMIC_ABI_VERSION) +VAMP_LDFLAGS := -shared -Wl,-Bsymbolic -Wl,--version-script=src/vamp/vamp-plugin.map +LADSPA_LDFLAGS := -shared -Wl,-Bsymbolic -Wl,--version-script=src/ladspa/ladspa-plugin.map PROGRAM_TARGET := bin/rubberband STATIC_TARGET := lib/librubberband.a @@ -120,10 +120,10 @@ $(DYNAMIC_TARGET): $(LIBRARY_OBJECTS) $(CXX) $(DYNAMIC_LDFLAGS) $^ -o $@ $(LIBRARY_LIBS) $(LDFLAGS) $(VAMP_TARGET): $(LIBRARY_OBJECTS) $(VAMP_OBJECTS) - $(CXX) $(DYNAMIC_LDFLAGS) -o $@ $^ $(VAMP_PLUGIN_LIBS) $(LDFLAGS) + $(CXX) $(VAMP_LDFLAGS) -o $@ $^ $(VAMP_PLUGIN_LIBS) $(LDFLAGS) $(LADSPA_TARGET): $(LIBRARY_OBJECTS) $(LADSPA_OBJECTS) - $(CXX) $(DYNAMIC_LDFLAGS) -o $@ $^ $(LADSPA_PLUGIN_LIBS) $(LDFLAGS) + $(CXX) $(LADSPA_LDFLAGS) -o $@ $^ $(LADSPA_PLUGIN_LIBS) $(LDFLAGS) bin: $(MKDIR) $@ diff --git a/src/StretcherImpl.cpp b/src/StretcherImpl.cpp index 992f070..799f533 100644 --- a/src/StretcherImpl.cpp +++ b/src/StretcherImpl.cpp @@ -236,7 +236,7 @@ RubberBandStretcher::Impl::setPitchScale(double fs) } if (fs == m_pitchScale) return; - + bool was1 = (m_pitchScale == 1.f); bool rbs = resampleBeforeStretching(); @@ -247,9 +247,7 @@ RubberBandStretcher::Impl::setPitchScale(double fs) if (!(m_options & OptionPitchHighConsistency) && (was1 || resampleBeforeStretching() != rbs) && m_pitchScale != 1.f) { - - cerr << "reset resampler" << endl; - + // resampling mode has changed for (int c = 0; c < m_channels; ++c) { if (m_channelData[c]->resampler) { diff --git a/src/StretcherProcess.cpp b/src/StretcherProcess.cpp index 50ef553..9ff6bee 100644 --- a/src/StretcherProcess.cpp +++ b/src/StretcherProcess.cpp @@ -1042,6 +1042,7 @@ RubberBandStretcher::Impl::writeChunk(size_t channel, size_t shiftIncrement, boo 1.0 / m_pitchScale, last); + writeOutput(*cd.outbuf, cd.resamplebuf, outframes, cd.outCount, theoreticalOut); diff --git a/src/ladspa/RubberBandPitchShifter.cpp b/src/ladspa/RubberBandPitchShifter.cpp index 0788eb0..cb7c370 100644 --- a/src/ladspa/RubberBandPitchShifter.cpp +++ b/src/ladspa/RubberBandPitchShifter.cpp @@ -29,7 +29,8 @@ RubberBandPitchShifter::portNamesMono[PortCountMono] = "Semitones", "Octaves", "Crispness", - "Formant Preservation", + "Formant Preserving", + "Fast", "Input", "Output" }; @@ -42,7 +43,8 @@ RubberBandPitchShifter::portNamesStereo[PortCountStereo] = "Semitones", "Octaves", "Crispness", - "Formant Preservation", + "Formant Preserving", + "Fast", "Input L", "Output L", "Input R", @@ -58,6 +60,7 @@ RubberBandPitchShifter::portsMono[PortCountMono] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, + LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO, LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO }; @@ -71,6 +74,7 @@ RubberBandPitchShifter::portsStereo[PortCountStereo] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, + LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO, LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO, LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO, @@ -105,6 +109,11 @@ RubberBandPitchShifter::hintsMono[PortCountMono] = LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_TOGGLED, 0.0, 1.0 }, + { LADSPA_HINT_DEFAULT_0 | // fast + LADSPA_HINT_BOUNDED_BELOW | + LADSPA_HINT_BOUNDED_ABOVE | + LADSPA_HINT_TOGGLED, + 0.0, 1.0 }, { 0, 0, 0 }, { 0, 0, 0 } }; @@ -137,6 +146,11 @@ RubberBandPitchShifter::hintsStereo[PortCountStereo] = LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_TOGGLED, 0.0, 1.0 }, + { LADSPA_HINT_DEFAULT_0 | // fast + LADSPA_HINT_BOUNDED_BELOW | + LADSPA_HINT_BOUNDED_ABOVE | + LADSPA_HINT_TOGGLED, + 0.0, 1.0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, @@ -209,10 +223,12 @@ RubberBandPitchShifter::RubberBandPitchShifter(int sampleRate, size_t channels) m_octaves(0), m_crispness(0), m_formant(0), + m_fast(0), m_ratio(1.0), m_prevRatio(1.0), m_currentCrispness(-1), m_currentFormant(false), + m_currentFast(false), m_blockSize(1024), m_reserve(1024), m_stretcher(new RubberBandStretcher @@ -271,12 +287,19 @@ RubberBandPitchShifter::connectPort(LADSPA_Handle handle, &shifter->m_octaves, &shifter->m_crispness, &shifter->m_formant, + &shifter->m_fast, &shifter->m_input[0], &shifter->m_output[0], &shifter->m_input[1], &shifter->m_output[1] }; + if (shifter->m_channels == 1) { + if (port >= PortCountMono) return; + } else { + if (port >= PortCountStereo) return; + } + *ports[port] = (float *)location; if (shifter->m_latency) { @@ -300,7 +323,7 @@ RubberBandPitchShifter::activateImpl() m_stretcher->reset(); m_stretcher->setPitchScale(m_ratio); - for (int c = 0; c < m_channels; ++c) { + for (size_t c = 0; c < m_channels; ++c) { m_outputBuffer[c]->reset(); m_outputBuffer[c]->zero(m_reserve); } @@ -379,6 +402,23 @@ RubberBandPitchShifter::updateFormant() m_currentFormant = f; } +void +RubberBandPitchShifter::updateFast() +{ + if (!m_fast) return; + + bool f = (*m_fast > 0.5f); + if (f == m_currentFast) return; + + RubberBandStretcher *s = m_stretcher; + + s->setPitchOption(f ? + RubberBandStretcher::OptionPitchHighSpeed : + RubberBandStretcher::OptionPitchHighConsistency); + + m_currentFast = f; +} + void RubberBandPitchShifter::runImpl(unsigned long insamples) { @@ -391,7 +431,7 @@ RubberBandPitchShifter::runImpl(unsigned long insamples) while (offset < insamples) { unsigned long block = (unsigned long)m_blockSize; - if (block > insamples) block = insamples; + if (block + offset > insamples) block = insamples - offset; runImpl(block, offset); @@ -419,6 +459,7 @@ RubberBandPitchShifter::runImpl(unsigned long insamples, unsigned long offset) updateCrispness(); updateFormant(); + updateFast(); const int samples = insamples; int processed = 0; @@ -426,9 +467,14 @@ RubberBandPitchShifter::runImpl(unsigned long insamples, unsigned long offset) float *ptrs[2]; - if (m_outputBuffer[0]->getReadSpace() < m_reserve) { + int rs = m_outputBuffer[0]->getReadSpace(); + if (rs < int(m_reserve)) { +// std::cerr << "temporary expansion (have " << rs << ", want " +// << m_reserve << ")" << std::endl; m_stretcher->setTimeRatio(1.1); // fill up temporarily - } else if (m_outputBuffer[0]->getReadSpace() > 8192) { + } else if (rs > 8192) { +// std::cerr << "temporary reduction (have " << rs << ", want " +// << m_reserve << ")" << std::endl; m_stretcher->setTimeRatio(0.9); // reduce temporarily } else { m_stretcher->setTimeRatio(1.0); diff --git a/src/ladspa/RubberBandPitchShifter.h b/src/ladspa/RubberBandPitchShifter.h index 0b32370..fabdf48 100644 --- a/src/ladspa/RubberBandPitchShifter.h +++ b/src/ladspa/RubberBandPitchShifter.h @@ -39,11 +39,12 @@ protected: CentsPort = 3, CrispnessPort = 4, FormantPort = 5, - InputPort1 = 6, - OutputPort1 = 7, + FastPort = 6, + InputPort1 = 7, + OutputPort1 = 8, PortCountMono = OutputPort1 + 1, - InputPort2 = 8, - OutputPort2 = 9, + InputPort2 = 9, + OutputPort2 = 10, PortCountStereo = OutputPort2 + 1 }; @@ -73,6 +74,7 @@ protected: void updateRatio(); void updateCrispness(); void updateFormant(); + void updateFast(); float *m_input[2]; float *m_output[2]; @@ -82,10 +84,12 @@ protected: float *m_octaves; float *m_crispness; float *m_formant; + float *m_fast; double m_ratio; double m_prevRatio; int m_currentCrispness; bool m_currentFormant; + bool m_currentFast; size_t m_blockSize; size_t m_reserve;