-Working on resizeable recording buffers

This commit is contained in:
Harry van Haaren 2013-08-06 22:10:27 +01:00
parent 6d20ae6cb1
commit 9e01e639d4
6 changed files with 61 additions and 12 deletions

View file

@ -12,15 +12,20 @@ class AudioBuffer
public:
AudioBuffer()
{
ID = privateID++;
//ID = privateID++;
}
AudioBuffer(unsigned long size)
{
//ID = id;
buffer.resize(size);
}
~AudioBuffer();
/*
int getID()
{
return ID;
}
*/
int getBeats()
{
return numBeats;
@ -42,8 +47,8 @@ class AudioBuffer
}
protected:
static int privateID;
int ID;
//static int privateID;
//int ID;
int numBeats;

View file

@ -44,6 +44,8 @@ namespace Event
TIME_TEMPO_TAP,
GUI_PRINT,
LOOPER_REQUEST_BUFFER,
};
};
@ -235,6 +237,22 @@ class EventTimeBarBeat : public EventBase
EventTimeBarBeat(int ba, int be): bar(ba), beat(be) {}
};
class EventLooperClipRequestBuffer : public EventBase
{
public:
int type() { return int(LOOPER_REQUEST_BUFFER); }
uint32_t size() { return sizeof(EventLooperClipRequestBuffer); }
int track;
int scene;
// number of floats to contain
unsigned long numElements;
EventLooperClipRequestBuffer(): track(0), scene(0){}
EventLooperClipRequestBuffer(int t, int s, int si): track(t), scene(s), numElements(si) {}
};
// prints the string S in the GUI console
class EventGuiPrint : public EventBase

View file

@ -11,6 +11,7 @@
// Internal
#include "gui.hxx"
#include "event.hxx"
#include "audiobuffer.hxx"
#include "eventhandler.hxx"
extern Gui* gui;
@ -129,6 +130,20 @@ void handleGuiEvents()
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventTimeTempoTap) );
gui->getMasterTrack()->setTapTempo( ev.pressed );
} break; }
case Event::LOOPER_REQUEST_BUFFER: {
if ( availableRead >= sizeof(EventLooperClipRequestBuffer) ) {
EventLooperClipRequestBuffer ev;
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventLooperClipRequestBuffer) );
/// allocate a new AudioBuffer with ev.numElements, pass back to DSP
AudioBuffer* ab = new AudioBuffer(ev.numElements);
//gui->getMasterTrack()->setTapTempo( ev.pressed );
} break; }
default:
{
cout << "GUI: Unkown message!! Will clog ringbuffer" << endl;

View file

@ -14,7 +14,7 @@
// Hack, move to gtrack.cpp
int GTrack::privateID = 0;
int GMasterTrack::privateID = 0;
int AudioBuffer::privateID = 0;
//int AudioBuffer::privateID = 0;
using namespace std;

View file

@ -198,6 +198,11 @@ void Looper::process(int nframes, Buffers* buffers)
{
// copy data from input buffer to recording buffer
if ( clips[clip].recordSpaceAvailable() < LOOPER_SAMPLES_BEFORE_REQUEST )
{
EventLooperClipRequestBuffer e( track, clip, clips[clip].audioBufferSize() + 44100 );
writeToGuiRingbuffer( &e );
}
}
else if ( clips[clip].playing() )
{

View file

@ -71,14 +71,20 @@ class LooperClip
_buffer->getData().at( _recordhead ) = *L++;
}
if(_buffer->getData().size() - _recordhead < LOOPER_SAMPLES_BEFORE_REQUEST)
{
// request bigger buffer for this LooperClip
}
}
bool recordSpaceAvailable()
{
return _buffer->getData().size() - _recordhead;
}
size_t audioBufferSize()
{
if ( _buffer )
{
return _buffer->getData().size();
}
return 0;
}
bool loaded(){return _loaded;}
bool playing(){return _playing;}