-Buffer updating working, recording not yet being played back

This commit is contained in:
Harry van Haaren 2013-08-07 00:16:27 +01:00
parent a5071a3bbb
commit 18bd5144b2
9 changed files with 84 additions and 46 deletions

View file

@ -18,7 +18,7 @@ class AudioBuffer
//ID = id;
buffer.resize(size);
}
~AudioBuffer();
/*
int getID()
{

View file

@ -2,6 +2,7 @@
#ifndef LUPPP_EVENT_H
#define LUPPP_EVENT_H
#include <iostream>
#include <stdint.h>
/*
@ -14,6 +15,8 @@
#include "looper.hxx"
#include "gridlogic.hxx"
using namespace std;
namespace Event
{
enum SEND_TYPE
@ -50,6 +53,7 @@ namespace Event
GUI_PRINT,
LOOPER_REQUEST_BUFFER,
DEALLOCATE_BUFFER,
};
};
@ -285,10 +289,22 @@ class EventLooperClipRequestBuffer : public EventBase
AudioBuffer* ab;
EventLooperClipRequestBuffer(): track(0), scene(0), numElements(0), ab(0) {}
EventLooperClipRequestBuffer(int t, int s, int si): track(t), scene(s), numElements(si), ab(0) {}
EventLooperClipRequestBuffer(int t, int s, int siz): track(t), scene(s), numElements(siz), ab(0) {}
EventLooperClipRequestBuffer(int t, int s, AudioBuffer* a): track(t), scene(s), numElements(0), ab(a) {}
};
class EventDeallocateBuffer : public EventBase
{
public:
int type() { return int(DEALLOCATE_BUFFER); }
uint32_t size() { return sizeof(EventDeallocateBuffer); }
AudioBuffer* ab;
EventDeallocateBuffer(): ab(0) {}
EventDeallocateBuffer(AudioBuffer* a): ab(a) {}
};
// prints the string S in the GUI console
class EventGuiPrint : public EventBase

View file

@ -150,7 +150,13 @@ void handleGuiEvents()
AudioBuffer* ab = new AudioBuffer(ev.numElements);
EventLooperClipRequestBuffer returnEvent(ev.track, ev.scene, ab);
writeToDspRingbuffer( &returnEvent );
printf("new buffer going to track %i, scene %i");
printf("new buffer going to track %i, scene %i\n",ev.track, ev.scene);
} break; }
case Event::DEALLOCATE_BUFFER: {
if ( availableRead >= sizeof(EventDeallocateBuffer) ) {
EventDeallocateBuffer ev;
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventDeallocateBuffer) );
delete ev.ab;
} break; }

View file

@ -13,7 +13,7 @@ GridLogic::GridLogic()
void GridLogic::pressed( int track, int scene )
{
printf("before press state = %s\n", StateString[ int(state[track*NTRACKS + scene]) ] );
//printf("before press state = %s\n", StateString[ int(state[track*NTRACKS + scene]) ] );
if ( state[track*NSCENES + scene] == STATE_EMPTY )
state[track*NSCENES + scene] = STATE_RECORD_QUEUED;
@ -27,7 +27,7 @@ void GridLogic::pressed( int track, int scene )
if ( state[track*NSCENES + scene] == STATE_RECORDING )
state[track*NSCENES + scene] = STATE_STOP_QUEUED;
printf("after press state = %s\n", StateString[ int(state[track*NSCENES + scene]) ] );
//printf("after press state = %s\n", StateString[ int(state[track*NSCENES + scene]) ] );
jack->getControllerUpdater()->setSceneState(track, scene, state[track*NSCENES + scene]);
}
@ -52,30 +52,33 @@ void GridLogic::bar()
/// iterate over all clips, if they're set to QUEUED, set to the next state
for( int i = 0; i < NTRACKS*NSCENES; i++ )
{
int track = i / NSCENES;
int scene = i - track * NSCENES;
bool change = false;
if ( state[i] == STATE_PLAY_QUEUED )
{
state[i] = STATE_PLAYING;
jack->getLooper( track )->setRecord( scene, false);
change = true;
}
else if ( state[i] == STATE_STOP_QUEUED )
{
state[i] = STATE_LOADED;
jack->getLooper( track )->setRecord( scene, false);
change = true;
}
else if ( state[i] == STATE_RECORD_QUEUED )
{
state[i] = STATE_RECORDING;
jack->getLooper( track )->setRecord( scene, true);
change = true;
}
if ( change )
{
int track = i / NSCENES;
int scene = i - track * NSCENES;
jack->getControllerUpdater()->setSceneState(track, scene, state[track*NSCENES + scene] );
printf("GridLogic::bar(), i = %i, track %i, scene %i\n", i, track, scene );
//printf("GridLogic::bar(), i = %i, track %i, scene %i\n", i, track, scene );
}
}

View file

@ -180,15 +180,8 @@ int Jack::process (jack_nframes_t nframes)
{
midiObservers.at(i)->midi( (unsigned char*) &in_event.buffer[0] );
}
//std::for_each( midiObservers.begin(), midiObservers.end(), [](MidiObserver* mo) { mo->midi( ); } );
/*
for(unsigned int i = 0; i < loopers.size(); i++)
loopers.at(i)->midi( (unsigned char*)&in_event.buffer[0] );
*/
masterMidiInputIndex++;
}
@ -199,9 +192,8 @@ int Jack::process (jack_nframes_t nframes)
}
//metronome->process( nframes, &buffers );
metronome->process( nframes, &buffers );
/*
// process fx
float* buf[] = {
buffers.audio[Buffers::REVERB],
@ -215,10 +207,9 @@ int Jack::process (jack_nframes_t nframes)
reverbMeter->process(nframes, buffers.audio[Buffers::REVERB], buffers.audio[Buffers::REVERB] );
//reverb->process( nframes, &buf[0], &buf[2] );
}
*/
// db meter on master output, then memcpy to JACK
//masterMeter->process(nframes, buffers.audio[Buffers::MASTER_OUT_L], buffers.audio[Buffers::MASTER_OUT_R] );
masterMeter->process(nframes, buffers.audio[Buffers::MASTER_OUT_L], buffers.audio[Buffers::MASTER_OUT_R] );
if ( uiUpdateCounter > uiUpdateConstant )
{

View file

@ -42,6 +42,11 @@ Looper::Looper(int t) :
crossfadeSize = 1000;
}
void Looper::setRecord(int scene, bool r)
{
clips[scene].recording(r);
}
LooperClip* Looper::getClip(int scene)
{
return &clips[scene];
@ -148,7 +153,6 @@ void Looper::updateControllers()
void Looper::setRequestedBuffer(int s, AudioBuffer* ab)
{
clips[s].setRequestedBuffer( ab );
}
@ -203,13 +207,18 @@ void Looper::process(int nframes, Buffers* buffers)
// record into buffer, play from buffer, etc
if ( clips[clip].recording() )
{
// copy data from input buffer to recording buffer
if ( clips[clip].recordSpaceAvailable() < LOOPER_SAMPLES_BEFORE_REQUEST )
if ( clips[clip].recordSpaceAvailable() < LOOPER_SAMPLES_BEFORE_REQUEST &&
!clips[clip].newBufferInTransit() )
{
EventLooperClipRequestBuffer e( track, clip, clips[clip].audioBufferSize() + 44100 );
printf("requesting new buffer now\n");
EventLooperClipRequestBuffer e( track, clip, clips[clip].audioBufferSize() + 44100 * 4);
writeToGuiRingbuffer( &e );
clips[clip].newBufferInTransit(true);
}
// copy data from input buffer to recording buffer
float* input = buffers->audio[Buffers::MASTER_INPUT];
clips[clip].record( nframes, input, 0 );
}
else if ( clips[clip].playing() )
{

View file

@ -39,6 +39,8 @@ class Looper : public AudioProcessor, public TimeObserver
void queuePlayScene( int sc );
void setRecord(int scene, bool r);
LooperClip* getClip(int scene);

View file

@ -4,6 +4,7 @@
#include <stdio.h>
#include "config.hxx"
#include "eventhandler.hxx"
#include "audiobuffer.hxx"
/** LooperClip
@ -31,9 +32,11 @@ class LooperClip
_playing = false;
_recording = false;
_buffer = 0;
_buffer = new AudioBuffer(44100);
_newBufferInTransit = false;
_playhead = 0;
_playhead = 0;
_recordhead = 0;
}
/// loads a sample: eg from disk
@ -61,14 +64,23 @@ class LooperClip
{
if ( _buffer )
{
int size = _buffer->getData().size();
for(int i = 0; i < size; i++)
size_t size = _buffer->getData().size();
for(size_t i = 0; i < size; i++)
{
ab->getData().at(i) = _buffer->getData().at( i );
}
// Send Deallocate event for _buffer *here* *now*
_buffer = ab;
EventDeallocateBuffer e( _buffer );
writeToGuiRingbuffer( &e );
}
printf("New buffer size = %i\n", ab->getData().size() );
_buffer = ab;
_newBufferInTransit = false;
}
void record(int count, float* L, float* R)
@ -77,15 +89,19 @@ class LooperClip
if ( _buffer )
{
for(int i = 0; i < count; i++)
{
_buffer->getData().at( _recordhead ) = *L++;
_recordhead++;
}
}
}
bool recordSpaceAvailable()
unsigned long recordSpaceAvailable()
{
return _buffer->getData().size() - _recordhead;
}
size_t audioBufferSize()
{
if ( _buffer )
@ -98,6 +114,10 @@ class LooperClip
bool loaded(){return _loaded;}
bool playing(){return _playing;}
bool recording(){return _recording;}
void recording(bool r){_recording = r;}
void newBufferInTransit(bool n){_newBufferInTransit = n;}
bool newBufferInTransit(){return _newBufferInTransit;}
float getSample()
{
@ -127,17 +147,16 @@ class LooperClip
}
return 0.f;
}
// Set
//void clipLength(int l){_clipLenght = l;}
private:
bool _loaded;
bool _recording;
bool _playing;
unsigned int _playhead;
unsigned int _recordhead;
bool _newBufferInTransit;
size_t _playhead;
size_t _recordhead;
AudioBuffer* _buffer;
};

View file

@ -61,15 +61,7 @@ class TrackOutput : public AudioProcessor
/// copies the track output to master buffer, sidechain & post-side buffer
void process(int nframes, Buffers* buffers)
{
/*
// zero track buffer
float* buf = &_trackBuffer[0];
for(int i = 0; i < nframes; i++ )
{
*buf++ = 0.f;
}
*/
memset( &_trackBuffer[0], 0, nframes );
if ( previousInChain )
@ -78,9 +70,9 @@ class TrackOutput : public AudioProcessor
previousInChain->process( nframes, buffers );
}
/*
// run the meter
buf = _trackBuffer;
float* buf = &_trackBuffer[0];
dbMeter.process( nframes, buf, buf );
if (uiUpdateCounter > uiUpdateConstant )
@ -91,7 +83,7 @@ class TrackOutput : public AudioProcessor
uiUpdateCounter = 0;
}
uiUpdateCounter += nframes;
*/
/// copy audio data into reverb / sidechain / master buffers
float* trackBuf = buffers->audio[Buffers::TRACK_0 + track];