-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: public:
AudioBuffer() AudioBuffer()
{ {
ID = privateID++; //ID = privateID++;
}
AudioBuffer(unsigned long size)
{
//ID = id;
buffer.resize(size);
} }
~AudioBuffer(); ~AudioBuffer();
/*
int getID() int getID()
{ {
return ID; return ID;
} }
*/
int getBeats() int getBeats()
{ {
return numBeats; return numBeats;
@ -42,8 +47,8 @@ class AudioBuffer
} }
protected: protected:
static int privateID; //static int privateID;
int ID; //int ID;
int numBeats; int numBeats;

View file

@ -44,6 +44,8 @@ namespace Event
TIME_TEMPO_TAP, TIME_TEMPO_TAP,
GUI_PRINT, GUI_PRINT,
LOOPER_REQUEST_BUFFER,
}; };
}; };
@ -235,6 +237,22 @@ class EventTimeBarBeat : public EventBase
EventTimeBarBeat(int ba, int be): bar(ba), beat(be) {} 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 // prints the string S in the GUI console
class EventGuiPrint : public EventBase class EventGuiPrint : public EventBase

View file

@ -11,6 +11,7 @@
// Internal // Internal
#include "gui.hxx" #include "gui.hxx"
#include "event.hxx" #include "event.hxx"
#include "audiobuffer.hxx"
#include "eventhandler.hxx" #include "eventhandler.hxx"
extern Gui* gui; extern Gui* gui;
@ -129,6 +130,20 @@ void handleGuiEvents()
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventTimeTempoTap) ); jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventTimeTempoTap) );
gui->getMasterTrack()->setTapTempo( ev.pressed ); gui->getMasterTrack()->setTapTempo( ev.pressed );
} break; } } 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: default:
{ {
cout << "GUI: Unkown message!! Will clog ringbuffer" << endl; cout << "GUI: Unkown message!! Will clog ringbuffer" << endl;

View file

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

View file

@ -198,6 +198,11 @@ void Looper::process(int nframes, Buffers* buffers)
{ {
// copy data from input buffer to recording buffer // 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() ) else if ( clips[clip].playing() )
{ {

View file

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