Skip to content

Commit

Permalink
Introduce first cut of live shifter
Browse files Browse the repository at this point in the history
  • Loading branch information
cannam committed Jun 29, 2023
1 parent 1eddafd commit 5935d17
Show file tree
Hide file tree
Showing 14 changed files with 4,284 additions and 2 deletions.
582 changes: 582 additions & 0 deletions ladspa-lv2/RubberBandLivePitchShifter.cpp

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions ladspa-lv2/RubberBandLivePitchShifter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */

/*
Rubber Band Library
An audio time-stretching and pitch-shifting library.
Copyright 2007-2023 Particular Programs Ltd.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
Alternatively, if you have a valid commercial licence for the
Rubber Band Library obtained by agreement with the copyright
holders, you may redistribute and/or modify it under the terms
described in that licence.
If you wish to distribute code using the Rubber Band Library
under terms other than those of the GNU General Public License,
you must obtain a valid commercial licence before doing so.
*/

#ifndef RUBBER_BAND_LIVE_SHIFTER_H
#define RUBBER_BAND_LIVE_SHIFTER_H

#ifdef RB_PLUGIN_LADSPA
#ifdef RB_PLUGIN_LV2
#error "Only one of RB_PLUGIN_LADSPA and RB_PLUGIN_LV2 may be defined at once"
#endif
#else
#ifndef RB_PLUGIN_LV2
#error "Including code must define either RB_PLUGIN_LADSPA or RB_PLUGIN_LV2"
#endif
#endif

#ifdef RB_PLUGIN_LADSPA
#include <ladspa.h>
#else
#include <lv2.h>
#endif

#include "common/RingBuffer.h"

namespace RubberBand {
class RubberBandLiveShifter;
}

class RubberBandLivePitchShifter
{
public:
#ifdef RB_PLUGIN_LADSPA
static const LADSPA_Descriptor *getDescriptor(unsigned long index);
#else
static const LV2_Descriptor *getDescriptor(uint32_t index);
#endif

protected:
RubberBandLivePitchShifter(int sampleRate, size_t channels);
~RubberBandLivePitchShifter();

enum {
LatencyPort = 0,
CentsPort = 1,
SemitonesPort = 2,
OctavesPort = 3,
FormantPort = 4,
WetDryPort = 5,
InputPort1 = 6,
OutputPort1 = 7,
PortCountMono = OutputPort1 + 1,
InputPort2 = 8,
OutputPort2 = 9,
PortCountStereo = OutputPort2 + 1
};

#ifdef RB_PLUGIN_LADSPA
static const char *const portNamesMono[PortCountMono];
static const LADSPA_PortDescriptor portsMono[PortCountMono];
static const LADSPA_PortRangeHint hintsMono[PortCountMono];

static const char *const portNamesStereo[PortCountStereo];
static const LADSPA_PortDescriptor portsStereo[PortCountStereo];
static const LADSPA_PortRangeHint hintsStereo[PortCountStereo];

static const LADSPA_Properties properties;

static const LADSPA_Descriptor ladspaDescriptorMono;
static const LADSPA_Descriptor ladspaDescriptorStereo;

static LADSPA_Handle instantiate(const LADSPA_Descriptor *, unsigned long);
static void connectPort(LADSPA_Handle, unsigned long, LADSPA_Data *);
static void activate(LADSPA_Handle);
static void run(LADSPA_Handle, unsigned long);
static void deactivate(LADSPA_Handle);
static void cleanup(LADSPA_Handle);

#else

static const LV2_Descriptor lv2DescriptorMono;
static const LV2_Descriptor lv2DescriptorStereo;

static LV2_Handle instantiate(const LV2_Descriptor *, double,
const char *, const LV2_Feature *const *);
static void connectPort(LV2_Handle, uint32_t, void *);
static void activate(LV2_Handle);
static void run(LV2_Handle, uint32_t);
static void deactivate(LV2_Handle);
static void cleanup(LV2_Handle);

#endif

void activateImpl();
void runImpl(uint32_t count);
void process();
void updateRatio();
void updateFormant();

float **m_input;
float **m_output;
float *m_latency;
float *m_cents;
float *m_semitones;
float *m_octaves;
float *m_formant;
float *m_wetDry;
double m_ratio;
double m_prevRatio;
bool m_currentFormant;

RubberBand::RubberBandLiveShifter *m_shifter;
RubberBand::RingBuffer<float> **m_irb;
RubberBand::RingBuffer<float> **m_orb;
float **m_ib;
float **m_ob;
RubberBand::RingBuffer<float> **m_delayMixBuffer;

int m_sampleRate;
int m_channels;
int m_blockSize;
int m_bufferSize;
int m_delay;

int getLatency() const;
};


#endif
2 changes: 2 additions & 0 deletions ladspa-lv2/ladspa-rubberband.cat
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ ladspa:ladspa-rubberband:rubberband-pitchshifter-mono::Frequency > Pitch shifter
ladspa:ladspa-rubberband:rubberband-pitchshifter-stereo::Frequency > Pitch shifters
ladspa:ladspa-rubberband:rubberband-r3-pitchshifter-mono::Frequency > Pitch shifters
ladspa:ladspa-rubberband:rubberband-r3-pitchshifter-stereo::Frequency > Pitch shifters
ladspa:ladspa-rubberband:rubberband-live-pitchshifter-mono::Frequency > Pitch shifters
ladspa:ladspa-rubberband:rubberband-live-pitchshifter-stereo::Frequency > Pitch shifters
4 changes: 4 additions & 0 deletions ladspa-lv2/ladspa-rubberband.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

<ladspa:PitchPlugin rdf:about="&ladspa;2979"/>
<ladspa:PitchPlugin rdf:about="&ladspa;9792"/>
<ladspa:PitchPlugin rdf:about="&ladspa;29790"/>
<ladspa:PitchPlugin rdf:about="&ladspa;97920"/>
<ladspa:PitchPlugin rdf:about="&ladspa;29791"/>
<ladspa:PitchPlugin rdf:about="&ladspa;97921"/>

</rdf:RDF>

5 changes: 4 additions & 1 deletion ladspa-lv2/libmain-ladspa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#undef RB_PLUGIN_LV2
#include "RubberBandPitchShifter.cpp"
#include "RubberBandR3PitchShifter.cpp"
#include "RubberBandLivePitchShifter.cpp"

#include <stdio.h>

Expand All @@ -34,8 +35,10 @@ const LADSPA_Descriptor *ladspa_descriptor(unsigned long index)
{
if (index < 2) {
return RubberBandPitchShifter::getDescriptor(index);
} else {
} else if (index < 4) {
return RubberBandR3PitchShifter::getDescriptor(index - 2);
} else {
return RubberBandLivePitchShifter::getDescriptor(index - 4);
}
}

Expand Down
5 changes: 4 additions & 1 deletion ladspa-lv2/libmain-lv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#undef RB_PLUGIN_LADSPA
#include "RubberBandPitchShifter.cpp"
#include "RubberBandR3PitchShifter.cpp"
#include "RubberBandLivePitchShifter.cpp"

#include <stdio.h>

Expand All @@ -35,8 +36,10 @@ const LV2_Descriptor *lv2_descriptor(uint32_t index)
{
if (index < 2) {
return RubberBandPitchShifter::getDescriptor(index);
} else {
} else if (index < 4) {
return RubberBandR3PitchShifter::getDescriptor(index - 2);
} else {
return RubberBandLivePitchShifter::getDescriptor(index - 4);
}
}

Expand Down
89 changes: 89 additions & 0 deletions ladspa-lv2/rubberband.lv2/lv2-rubberband.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,43 @@ rubberband:r3mono
lv2:designation pg:center ;
] .

rubberband:livemono
a doap:Project, lv2:Plugin, lv2:PitchPlugin ;
doap:name "Rubber Band Live Mono Pitch Shifter" ;
doap:license <http://usefulinc.com/doap/licenses/gpl> ;
foaf:maker :maker ;
doap:developer :maker ;
doap:maintainer :maker ;
# Minor version will be 2x the Rubber Band API minor version
lv2:minorVersion 4 ;
lv2:microVersion 1 ;
lv2:optionalFeature lv2:hardRTCapable ;
pg:mainInput rubberband:mono_in_group ;
pg:mainOutput rubberband:mono_out_group ;
dc:replaces <urn:ladspa:29791> ;
lv2:port :latencyPort ,
:centsPort ,
:semitonesPort ,
:octavesPort ,
:formantPortR3 ,
:wetDryPortR3 ,
[ a lv2:AudioPort, lv2:InputPort ;
lv2:index 6 ;
lv2:symbol "input" ;
lv2:name "Input" ;
lv2:shortName "Input" ;
pg:group rubberband:mono_in_group ;
lv2:designation pg:center ;
], [
a lv2:AudioPort, lv2:OutputPort ;
lv2:index 7 ;
lv2:symbol "output" ;
lv2:name "Output" ;
lv2:shortName "Output" ;
pg:group rubberband:mono_out_group ;
lv2:designation pg:center ;
] .

rubberband:stereo
a doap:Project, lv2:Plugin, lv2:PitchPlugin ;
doap:name "Rubber Band Stereo Pitch Shifter" ;
Expand Down Expand Up @@ -306,3 +343,55 @@ rubberband:r3stereo
lv2:designation pg:right ;
] .

rubberband:livestereo
a doap:Project, lv2:Plugin, lv2:PitchPlugin ;
doap:name "Rubber Band Live Stereo Pitch Shifter" ;
doap:license <http://usefulinc.com/doap/licenses/gpl> ;
foaf:maker :maker ;
doap:developer :maker ;
doap:maintainer :maker ;
# Minor version will be 2x the Rubber Band API minor version
lv2:minorVersion 4 ;
lv2:microVersion 1 ;
lv2:optionalFeature lv2:hardRTCapable ;
pg:mainInput rubberband:stereo_in_group ;
pg:mainOutput rubberband:stereo_out_group ;
dc:replaces <urn:ladspa:97921> ;
lv2:port :latencyPort ,
:centsPort ,
:semitonesPort ,
:octavesPort ,
:formantPortR3 ,
:wetDryPortR3 ,
[ a lv2:AudioPort, lv2:InputPort ;
lv2:index 6 ;
lv2:symbol "input_l" ;
lv2:name "Input L" ;
lv2:shortName "Input L" ;
pg:group rubberband:stereo_in_group ;
lv2:designation pg:left ;
], [
a lv2:AudioPort, lv2:OutputPort ;
lv2:index 7 ;
lv2:symbol "output_l" ;
lv2:name "Output L" ;
lv2:shortName "Output L" ;
pg:group rubberband:stereo_out_group ;
lv2:designation pg:left ;
], [ a lv2:AudioPort, lv2:InputPort ;
lv2:index 8 ;
lv2:symbol "input_r" ;
lv2:name "Input R" ;
lv2:shortName "Input R" ;
pg:group rubberband:stereo_in_group ;
lv2:designation pg:right ;
], [
a lv2:AudioPort, lv2:OutputPort ;
lv2:index 9 ;
lv2:symbol "output_r" ;
lv2:name "Output R" ;
lv2:shortName "Output R" ;
pg:group rubberband:stereo_out_group ;
lv2:designation pg:right ;
] .

10 changes: 10 additions & 0 deletions ladspa-lv2/rubberband.lv2/manifest.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ rubberband:r3mono
lv2:binary <lv2-rubberband.so> ;
rdfs:seeAlso <lv2-rubberband.ttl> .

rubberband:livemono
a lv2:Plugin ;
lv2:binary <lv2-rubberband.so> ;
rdfs:seeAlso <lv2-rubberband.ttl> .

rubberband:stereo
a lv2:Plugin ;
lv2:binary <lv2-rubberband.so> ;
Expand All @@ -22,3 +27,8 @@ rubberband:r3stereo
lv2:binary <lv2-rubberband.so> ;
rdfs:seeAlso <lv2-rubberband.ttl> .

rubberband:livestereo
a lv2:Plugin ;
lv2:binary <lv2-rubberband.so> ;
rdfs:seeAlso <lv2-rubberband.ttl> .

4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ pkg = import('pkgconfig')
public_headers = [
'rubberband/rubberband-c.h',
'rubberband/RubberBandStretcher.h',
'rubberband/RubberBandLiveShifter.h',
]

library_sources = [
'src/rubberband-c.cpp',
'src/RubberBandStretcher.cpp',
'src/RubberBandLiveShifter.cpp',
'src/faster/AudioCurveCalculator.cpp',
'src/faster/CompoundAudioCurve.cpp',
'src/faster/HighFrequencyAudioCurve.cpp',
Expand All @@ -52,6 +54,7 @@ library_sources = [
'src/common/mathmisc.cpp',
'src/common/Thread.cpp',
'src/finer/R3Stretcher.cpp',
'src/finer/R3LiveShifter.cpp',
]

jni_sources = [
Expand Down Expand Up @@ -89,6 +92,7 @@ lv2_sources = [
unit_test_sources = [
'src/test/TestAllocators.cpp',
'src/test/TestFFT.cpp',
'src/test/TestLiveShifter.cpp',
'src/test/TestResampler.cpp',
'src/test/TestVectorOpsComplex.cpp',
'src/test/TestVectorOps.cpp',
Expand Down
Loading

0 comments on commit 5935d17

Please sign in to comment.