frac32buffer audio in
bool32.risingfalling record
bool32.risingfalling play (should be set to '1' normally)
bool32.risingfalling overdub
int32 playback position
int32 loop length
frac32buffer audio out
objref table
bool rec;
bool play;
bool play_logic;
bool dub;
int playpos;
int recpos;
int length;
playpos = 0;
recpos = 0;
rec = 0;
play = 0;
dub = 0;
length = 0;
// I guess this ((inlet_rec>0) && !rec)
// resets pos to 0 everytime rec goes from 0 to 1
// record
if ((inlet_rec > 0) && !rec) {
rec = 1;
recpos = 0;
length = 0;
} else if (!(inlet_rec > 0)) {
rec = 0;
length = recpos;
}
// play
play_logic = (!inlet_rec && inlet_play);
if ((play_logic > 0) && !play) {
play = 1;
playpos = 0;
} else if (!(play_logic > 0)) {
play = 0;
}
// dub
dub = (play_logic && inlet_dub);
outlet_pos = playpos;
outlet_length = length;
// record
if (rec) {
if (recpos < attr_table.LENGTH)
attr_table.array[recpos++] = __SSAT(inlet_wave, 28) >> attr_table.GAIN;
}
// play
if (play) {
if (!(playpos == length))
playpos == playpos++;
else
playpos = 0;
if (!(playpos == length))
outlet_wave = attr_table.array[playpos] << attr_table.GAIN;
else
outlet_wave = 0;
}
else
outlet_wave = 0;
// overdub
if (dub) {
attr_table.array[playpos] = (attr_table.array[playpos] << attr_table.GAIN) +
(__SSAT(inlet_wave, 28) >> attr_table.GAIN);
}