diff --git a/src/jack.cxx b/src/jack.cxx index 0bf7d70..b790745 100644 --- a/src/jack.cxx +++ b/src/jack.cxx @@ -50,6 +50,7 @@ int AudioBuffer::privateID = 0; // static pointers from main extern Gui* gui; extern Jack* jack; +bool Jack::noTimetstretching = false; void Jack::setup(std::string name) { @@ -201,6 +202,8 @@ Jack::Jack( std::string name ) : * In this case, the track's Looper instance. **/ loopers.push_back( new Looper(i) ); + loopers.back()->timestretch( !noTimetstretching ); + trackOutputs.push_back( new TrackOutput(i, loopers.back() ) ); buffers.audio[Buffers::TRACK_0 + i] = new float[ buffers.nframes ]; diff --git a/src/jack.hxx b/src/jack.hxx index 123101a..86bdd54 100644 --- a/src/jack.hxx +++ b/src/jack.hxx @@ -58,6 +58,10 @@ class Jack Jack(std::string name); ~Jack(); + + // hack to pass time stretch enable into JACK before setup + static bool noTimetstretching; + static void setup(std::string name); void activate(); diff --git a/src/looper.cxx b/src/looper.cxx index efb6f77..0262c8e 100644 --- a/src/looper.cxx +++ b/src/looper.cxx @@ -33,7 +33,8 @@ extern Jack* jack; Looper::Looper(int t) : AudioProcessor(), TimeObserver(), - track(t) + track(t), + timeStretchEnabled( true ) { uiUpdateConstant= jack->getSamplerate() / 30.f; uiUpdateCounter = jack->getSamplerate() / 30.f; @@ -66,6 +67,11 @@ Looper::Looper(int t) : crossfadeSize = 1000; } +void Looper::timestretch( bool ts ) +{ + timeStretchEnabled = ts; +} + LooperClip* Looper::getClip(int scene) { return clips[scene]; @@ -110,7 +116,8 @@ void Looper::process(unsigned int nframes, Buffers* buffers) long actualFrames = clips[clip]->getBufferLenght(); float playSpeed = 1.0; - if ( targetFrames != 0 && actualFrames != 0 ) + if ( timeStretchEnabled && + targetFrames != 0 && actualFrames != 0 ) { playSpeed = float(actualFrames) / targetFrames; } @@ -122,11 +129,14 @@ void Looper::process(unsigned int nframes, Buffers* buffers) // REFACTOR into system that is better than per sample function calls float tmp = clips[clip]->getSample(playSpeed); - float deltaPitch = 12 * log ( playSpeed ) / log (2); - semitoneShift = -deltaPitch; - - // write the pitch-shifted signal to the track buffer - pitchShift( 1, &tmp, &out[i] ); + //if ( timeStretchEnabled ) + { + float deltaPitch = 12 * log ( playSpeed ) / log (2); + semitoneShift = -deltaPitch; + + // write the pitch-shifted signal to the track buffer + pitchShift( 1, &tmp, &out[i] ); + } } //printf("Looper %i playing(), speed = %f\n", track, playSpeed ); @@ -138,10 +148,8 @@ void Looper::process(unsigned int nframes, Buffers* buffers) } uiUpdateCounter += nframes; } - } - } void Looper::pitchShift(int count, float* input, float* output) diff --git a/src/looper.hxx b/src/looper.hxx index 43f8fb1..5fb7cfe 100644 --- a/src/looper.hxx +++ b/src/looper.hxx @@ -47,6 +47,9 @@ class Looper : public AudioProcessor, public TimeObserver /// stores the framesPerBeat from TimeManager. Used to stretch audio void setFpb(int f); + /// sets if time stretching is used or not + void timestretch( bool ts ); + /// Retrieve a clip from the Looper LooperClip* getClip(int scene); @@ -62,6 +65,8 @@ class Looper : public AudioProcessor, public TimeObserver int fpb; + bool timeStretchEnabled; + //vector tmpRecordBuffer; LooperClip* clips[10]; diff --git a/src/main.cxx b/src/main.cxx index eb33f29..803c772 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -63,13 +63,19 @@ int main(int argc, char** argv) LUPPP_NOTE("Git: %s", GIT_VERSION ); bool runTests = false; - if ( runTests ){} // remove unused warning if not built with BUILD_TESTS + bool noTimetstretching = false; + // remove unused warning if not built with BUILD_TESTS + if ( runTests ); + if ( noTimetstretching ); for(int i = 0; i < argc; i++) { if ( strcmp(argv[i], "-test" ) == 0 ) { runTests = true; } + else if ( strcmp(argv[i], "-no-ts" ) == 0 ) { + noTimetstretching = true; + } else if ( i != 0 ) // don't try load with the program name! { // assume filename, try load it @@ -99,6 +105,8 @@ int main(int argc, char** argv) // setup the testing Gui / JACK: Jack first, then GUI gui = new Gui( argv[0] ); + + Jack::noTimetstretching = noTimetstretching; Jack::setup("LupppTEST"); // test offline functionality @@ -131,6 +139,7 @@ int main(int argc, char** argv) } else { + Jack::noTimetstretching = noTimetstretching; Jack::setup("Luppp"); jack->activate(); }