-Looper speed variable, calculates using TimeManager

This commit is contained in:
Harry van Haaren 2013-08-13 17:57:14 +01:00
parent a19be701c9
commit 1be433f4c7
3 changed files with 53 additions and 10 deletions

View file

@ -27,6 +27,8 @@ Looper::Looper(int t) :
clips[i] = LooperClip();
}
fpb = 22050;
// init faust pitch shift variables
fSamplingFreq = 44100;
IOTA = 0;
@ -45,6 +47,14 @@ Looper::Looper(int t) :
void Looper::setRecord(int scene, bool r)
{
clips[scene].recording(r);
if ( !r )
{
// set beats based on recording duration
int beats = (clips[scene].getBufferLenght() / fpb) + 1;
clips[scene].setBeats( beats );
printf("stop record, has %i beats\n", beats );
}
}
void Looper::play(int scene, bool r)
@ -211,15 +221,26 @@ void Looper::process(int nframes, Buffers* buffers)
}
else if ( clips[clip].playing() )
{
//printf("Looper %i playing()\n", track );
// copy data into tmpBuffer, then pitch-stretch into track buffer
long targetFrames = clips[clip].getBeats() * fpb;
long actualFrames = clips[clip].getBufferLenght();
float playSpeed = 1.0;
if ( targetFrames != 0 && actualFrames != 0 )
{
playSpeed = float(actualFrames) / targetFrames;
}
for(int i = 0; i < nframes; i++ )
{
out[i] = clips[clip].getSample();
out[i] = clips[clip].getSample(playSpeed);
}
//printf("Looper %i playing(), speed = %f\n", track, playSpeed );
if ( uiUpdateCounter > uiUpdateConstant )
{
jack->getControllerUpdater()->setTrackSceneProgress(track, clip, clips[clip].getProgress() );
uiUpdateCounter = 0;
}

View file

@ -32,7 +32,7 @@ class Looper : public AudioProcessor, public TimeObserver
void midi(unsigned char* data);
void setFpb(int f) { /*fpb = f;*/ }
void setFpb(int f) { fpb = f; }
void queuePlayScene( int sc );
@ -52,6 +52,8 @@ class Looper : public AudioProcessor, public TimeObserver
int playingScene;
int queuedScene;
int fpb;
float* tmpRecordBuffer;
LooperClip clips[10];

View file

@ -53,6 +53,9 @@ class LooperClip
_buffer = ab;
_playhead = 0;
// set the endpoint to the buffer's size
_recordhead = _buffer->getData().size();
}
/// used to update the size of the buffer for this looperclip. The current
@ -117,20 +120,35 @@ class LooperClip
}
}
int getBeats()
{
if ( _buffer )
return _buffer->getBeats();
return 0;
}
long getBufferLenght()
{
return _recordhead;
}
bool loaded(){return _loaded;}
void playing(bool p){_playing = p; _playhead = 0; }
bool playing(){return _playing;}
bool recording(){return _recording;}
void recording(bool r){_recording = r;}
void recording(bool r) {_recording = r;}
void newBufferInTransit(bool n){_newBufferInTransit = n;}
bool newBufferInTransit(){return _newBufferInTransit;}
float getSample()
float getSample(float playSpeed)
{
if ( _buffer )
{
if ( _playhead >= _buffer->getData().size() || _playhead < 0 )
if ( _playhead >= _recordhead ||
_playhead >= _buffer->getData().size() ||
_playhead < 0 )
{
_playhead = 0;
printf("looper resetting playhead\n");
@ -138,7 +156,7 @@ class LooperClip
std::vector<float>& v = _buffer->getData();
float tmp = v.at(_playhead);
_playhead++;
_playhead += playSpeed;
return tmp;
}
@ -150,7 +168,9 @@ class LooperClip
{
if ( _buffer && _playing )
{
return float(_playhead) / _buffer->getData().size();
float p = float(_playhead) / _recordhead;
printf("LooperClip progress %f\n", p );
return p;
}
return 0.f;
}
@ -162,8 +182,8 @@ class LooperClip
bool _newBufferInTransit;
size_t _playhead;
size_t _recordhead;
float _playhead;
float _recordhead;
AudioBuffer* _buffer;
};