-Initial APC feedback working

main
Harry van Haaren 2013-05-18 20:33:13 +01:00
parent 370815e7aa
commit 39d6c6e60f
4 changed files with 30 additions and 28 deletions

View File

@ -13,7 +13,7 @@ class Buffers
memset( audio, 0, sizeof(float*)*2);
}
float* audio[32];
unsigned char* midi [32];
void* midi [32];
enum BUFFER {
MASTER_OUTPUT = 0,

View File

@ -85,23 +85,25 @@ void Jack::activate()
int Jack::process (jack_nframes_t nframes)
{
// do events from the ringbuffer
handleDspEvents();
// get buffers
buffers.audio[Buffers::MASTER_INPUT] = (float*)jack_port_get_buffer( masterInput , nframes);
buffers.audio[Buffers::MASTER_OUTPUT] = (float*)jack_port_get_buffer( masterOutput, nframes);
buffers.midi[Buffers::MASTER_MIDI_INPUT]= (unsigned char*) jack_port_get_buffer( masterMidiInput, nframes );
buffers.midi[Buffers::APC_INPUT] = (unsigned char*) jack_port_get_buffer( apcMidiInput , nframes );
buffers.midi[Buffers::APC_OUTPUT] = (unsigned char*) jack_port_get_buffer( apcMidiOutput , nframes );
buffers.midi[Buffers::MASTER_MIDI_INPUT]= (void*) jack_port_get_buffer( masterMidiInput, nframes );
buffers.midi[Buffers::APC_INPUT] = (void*) jack_port_get_buffer( apcMidiInput , nframes );
buffers.midi[Buffers::APC_OUTPUT] = (void*) jack_port_get_buffer( apcMidiOutput , nframes );
// pre-zero output buffers
memset( buffers.audio[Buffers::MASTER_OUTPUT], 0, sizeof(float) * nframes );
jack_midi_clear_buffer( buffers.midi[Buffers::APC_OUTPUT] );
// do events from the ringbuffer
handleDspEvents();
// process incoming MIDI
jack_midi_event_t in_event;
int masterMidiInputIndex = 0;
int event_count = (int) jack_midi_get_event_count( buffers.midi[Buffers::MASTER_MIDI_INPUT] );
@ -109,7 +111,7 @@ int Jack::process (jack_nframes_t nframes)
{
jack_midi_event_get(&in_event, buffers.midi[Buffers::MASTER_MIDI_INPUT], masterMidiInputIndex);
cout << int(in_event.buffer[0]) << int(in_event.buffer[1]) << int(in_event.buffer[2]) << endl;
cout << "Frame: " << in_event.time << " " << int(in_event.buffer[0]) << " " << int(in_event.buffer[1]) << " " << int(in_event.buffer[2]) << endl;
// check each looper for MIDI match
for(int i = 0; i < loopers.size(); i++)
@ -121,18 +123,7 @@ int Jack::process (jack_nframes_t nframes)
for(uint i = 0; i < loopers.size(); i++)
loopers.at(i)->process( nframes, &buffers );
if (true)
metronome.process( nframes, &buffers );
/*
float* input = buffers.audio[Buffers::MASTER_INPUT];
float* output = buffers.audio[Buffers::MASTER_OUTPUT];
for(uint i = 0; i < nframes; i++)
{
*output++ = *input++;
}
*/
metronome.process( nframes, &buffers );
return false;
}
@ -152,9 +143,10 @@ void Jack::writeApcOutput( unsigned char* data )
void* apcOutput = buffers.midi[Buffers::APC_OUTPUT];
unsigned char* buf = jack_midi_event_reserve( apcOutput, 0, 3);
if( buf )
if( buf != 0 )
{
memcpy( buf, data, sizeof( unsigned char ) * 3);
cout << "writeApcOutput " << int(buf[0]) << ", " << int(buf[1]) << ", " << int(buf[2]) << endl;
}
else
{

View File

@ -10,6 +10,8 @@ extern Jack* jack;
Looper::Looper(int t) :
track(t),
state(STATE_STOPPED),
fpb(120),
gain(1.f),
numBeats (4),
playedBeats(0),
stopRecordOnBar(false),
@ -55,6 +57,13 @@ void Looper::midi(unsigned char* data)
case 48: setState( STATE_STOP_QUEUED );
}
}
else if ( data[0] - 176 == track )
{
switch ( data[1] )
{
case 7: gain = int(data[2])/127.f; break;
}
}
}
@ -72,11 +81,10 @@ void Looper::setState(State s)
{
numBeats = 0;
unsigned char data[3];
data[0] == 144 + track;
data[1] == 48; // record LED
data[2] == 127;
data[0] = 144 + track;
data[1] = 48; // record LED
data[2] = 127;
jack->writeApcOutput( &data[0] );
cout << "wrote to APC" << endl;
}
}
@ -107,15 +115,14 @@ void Looper::process(int nframes, Buffers* buffers)
{
if ( playPoint < endPoint )
{
tmpBuffer[i] = sample[playPoint];
tmpBuffer[i] = sample[playPoint] * gain;
}
// always update playPoint, even when not playing sound.
// it updates the UI of progress
playPoint++;
}
// not pitch-shift the audio in the buffer
// now pitch-shift the audio in the buffer
pitchShift( nframes, &tmpBuffer[0], out);
float prog = (float(playPoint) / (fpb*numBeats));
@ -228,12 +235,14 @@ void Looper::pitchShift(int count, float* input, float* output)
float fTemp3 = min((fSlow2 * fRec0[0]), 1.f );
float fTemp4 = (fSlow0 + fRec0[0]);
int iTemp5 = int(fTemp4);
output0[i] += (float)(((1 - fTemp3) * (((fTemp4 - iTemp5) *
fVec0[(IOTA-int((int((1 + iTemp5)) & 65535)))&65535]) + ((0 - ((
fRec0[0] + fSlow3) - iTemp5)) * fVec0[(IOTA-int((iTemp5 & 65535)))
&65535]))) + (fTemp3 * (((fRec0[0] - iTemp1) * fVec0[(IOTA-int((int(
iTemp2) & 65535)))&65535]) + ((iTemp2 - fRec0[0]) * fVec0[(IOTA-int((
iTemp1 & 65535)))&65535]))));
fRec0[1] = fRec0[0];
IOTA = IOTA+1;
}

View File

@ -41,6 +41,7 @@ class Looper : public Observer // for notifications
State state;
int fpb;
float gain;
int numBeats;
int playedBeats;
bool stopRecordOnBar;