bool32 trig
bool32 rst
bool32 load
charptr32 filename
bool32 o1
bool32 o2
bool32 o3
bool32 o4
bool32 trig
int32 cnt
int32 repeat1
bool32.tgl o1
bool32.tgl o2
bool32.tgl p1
bool32.tgl p2
bool32.tgl save
bool32.tgl load
frac32.u.map Gchance
frac32.u.map Pchance
frac32.u.map Pwidth
frac32.u.map Rchance
frac32.u.map Rwidth
frac32.u.map Dchance
frac32.u.map Dwidth
int32 mainlength
bool32 chance
bool32 gatelength
bool32 retrigger
bool32 delay
static const uint32_t LENGTHPOW = (10);
static const uint32_t LENGTH = (1024);
static const uint32_t LENGTHMASK = (1023);
int32_t *Array;
int8_t *array;
int count;
int ttrig;
int strig;
int ltrig;
int rtrig;
int ctrig;
int i;
int gate[4];
int32_t val[4];
int32_t CNT[4];
int32_t repeat[4];
int32_t Rep[4];
int32_t Wid[4];
int32_t Rat[4];
int Gate[4];
int32_t pulsewidth[4];
int32_t delay[4];
int rGate[4];
uint32_t cnt;
int32_t Time;
uint32_t write;
int Para;
int32_t select;
int Output;
uint32_t writepos;
int32_t prev;
int Rtrig;
int trig1;
static int8_t _array[1 << (LENGTHPOW << 2)] __attribute__((section(".sdram")));
static int32_t _Array[272] __attribute__((section(".sdram")));
array = &_array[0];
Array = &_Array[0];
int i;
writepos = 0;
for (i = 0; i < (LENGTH << 2); i++)
array[i] = 0;
strig = 0;
ltrig = 0;
rtrig = 0;
ctrig = 0;
write += 1;
write = write & 1023;
cnt += 1;
Output = param_o1 + (param_o2 << 1);
Para = param_p1 + (param_p2 << 1);
select = Para * 16 + Output * 64;
if ((param_save > 0) && !strig) {
strig = 1;
FIL FileObject;
FRESULT err;
UINT bytes_written;
err = f_open(&FileObject, inlet_filename, FA_WRITE | FA_CREATE_ALWAYS);
if (err != FR_OK) {
report_fatfs_error(err, "inlet_filename");
return;
}
int rem_sz = sizeof(*Array) * (272);
int offset = 0;
while (rem_sz > 0) {
if (rem_sz > sizeof(fbuff)) {
memcpy((char *)fbuff, (char *)(&Array[0]) + offset, sizeof(fbuff));
err = f_write(&FileObject, fbuff, sizeof(fbuff), &bytes_written);
rem_sz -= sizeof(fbuff);
offset += sizeof(fbuff);
} else {
memcpy((char *)fbuff, (char *)(&Array[0]) + offset, rem_sz);
err = f_write(&FileObject, fbuff, rem_sz, &bytes_written);
rem_sz = 0;
}
}
if (err != FR_OK)
report_fatfs_error(err, "inlet_filename");
err = f_close(&FileObject);
if (err != FR_OK)
report_fatfs_error(err, "inlet_filename");
} else if (!(param_save > 0)) {
strig = 0;
}
int load = param_load + inlet_load;
if ((load > 0) && !ltrig) {
ltrig = 1;
FIL FileObject;
FRESULT err;
UINT bytes_read;
err = f_open(&FileObject, inlet_filename, FA_READ | FA_OPEN_EXISTING);
if (err != FR_OK) {
report_fatfs_error(err, inlet_filename);
return;
}
int rem_sz = sizeof(*Array) * (272);
int offset = 0;
while (rem_sz > 0) {
if (rem_sz > sizeof(fbuff)) {
err = f_read(&FileObject, fbuff, sizeof(fbuff), &bytes_read);
if (bytes_read == 0)
break;
memcpy((char *)(&Array[0]) + offset, (char *)fbuff, bytes_read);
rem_sz -= bytes_read;
offset += bytes_read;
} else {
err = f_read(&FileObject, fbuff, rem_sz, &bytes_read);
memcpy((char *)(&Array[0]) + offset, (char *)fbuff, bytes_read);
rem_sz = 0;
}
}
if (err != FR_OK) {
report_fatfs_error(err, inlet_filename);
return;
};
err = f_close(&FileObject);
if (err != FR_OK) {
report_fatfs_error(err, inlet_filename);
return;
};
} else if (!(load > 0)) {
ltrig = 0;
}
if (!(prev == (select + param_load))) {
PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_Rchance],
Array[256 + Output], 0xFFFD);
PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_Gchance],
Array[260 + Output], 0xFFFD);
PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_Dwidth],
Array[264 + Output], 0xFFFD);
PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_Rwidth],
Array[268 + Output], 0xFFFD);
MidiSend3((midi_device_t)MIDI_DEVICE_USB_HOST, 1, MIDI_CONTROL_CHANGE, 11,
__USAT(Array[260 + Output] >> 20, 7));
MidiSend3((midi_device_t)MIDI_DEVICE_USB_HOST, 1, MIDI_CONTROL_CHANGE, 10,
__USAT(Array[256 + Output] >> 20, 7));
MidiSend3((midi_device_t)MIDI_DEVICE_USB_HOST, 1, MIDI_CONTROL_CHANGE, 9,
__USAT(Array[268 + Output] >> 20, 7));
MidiSend3((midi_device_t)MIDI_DEVICE_USB_HOST, 1, MIDI_CONTROL_CHANGE, 8,
__USAT(Array[264 + Output] >> 20, 7));
for (i = 0; i < 16; i++) {
if (Array[i + select] > 0) {
MidiSend3((midi_device_t)MIDI_DEVICE_USB_HOST, 1, MIDI_NOTE_ON + 1,
((i + 8) & 15) * 2 + 97, 64);
}
if (Array[i + select] == 0) {
MidiSend3((midi_device_t)MIDI_DEVICE_USB_HOST, 1, MIDI_NOTE_OFF + 1,
((i + 8) & 15) * 2 + 97, 64);
}
}
}
if ((inlet_rst) && !Rtrig) {
Rtrig = 1;
count = -1;
} else if (inlet_rst == 0) {
Rtrig = 0;
}
disp_chance = 0;
disp_gatelength = 0;
disp_retrigger = 0;
disp_delay = 0;
if (Para == 0) {
disp_chance = 1;
}
if (Para == 1) {
disp_gatelength = 1;
}
if (Para == 2) {
disp_retrigger = 1;
}
if (Para == 3) {
disp_delay = 1;
}
Array[256 + Output] = param_Rchance; // Rep[Output]
Array[260 + Output] = param_Gchance; // Gate[Output]
Array[264 + Output] = param_Dwidth; // Wid[Output]
Array[268 + Output] = param_Rwidth; // Rat[Output]
if ((inlet_trig > 0) && !ttrig) {
Time = cnt;
cnt = 0;
ttrig = 1;
count += 1;
count = count - (count / param_mainlength) * param_mainlength;
MidiSend3((midi_device_t)MIDI_DEVICE_USB_HOST, 1, MIDI_NOTE_ON + 1,
((count + 8) & 15) * 2 + 96, 64);
for (i = 0; i < 4; i++) {
val[i] = (int32_t)((GenerateRandomNumber() >> 5));
gate[i] = Array[count + i * 64] > val[i] ? 1 : 0;
repeat[i] = (((uint32_t)((GenerateRandomNumber()))) >> 5) < (Array[256 + i])
? 1
: 0;
if (repeat[i] > 0) {
repeat[i] = ___SMMUL(((uint32_t)((GenerateRandomNumber())) >> 24),
Array[268 + i]);
}
delay[i] =
(((uint32_t)((GenerateRandomNumber()))) >> 5) < (param_Dchance) ? 1 : 0;
if (delay[i] > 0) {
delay[i] = ___SMMUL(((uint32_t)((GenerateRandomNumber())) >> 5),
param_Dwidth << 4);
}
pulsewidth[i] =
(((uint32_t)((GenerateRandomNumber()))) >> 5) < (param_Pchance) ? 1 : 0;
if (pulsewidth[i] > 0) {
pulsewidth[i] = ___SMMUL(
___SMMUL(((uint32_t)((GenerateRandomNumber())) >> 5), Time << 5) << 3,
Array[264 + i] << 2);
}
rGate[i] = (((uint32_t)((GenerateRandomNumber()))) >> 5) < (Array[260 + i])
? 1
: 0;
}
} else if ((inlet_trig <= 0) && ttrig) {
ttrig = 0;
MidiSend3((midi_device_t)MIDI_DEVICE_USB_HOST, 1, MIDI_NOTE_OFF + 1,
((count + 8) & 15) * 2 + 96, 64);
}
array[(write + ___SMMUL(delay[0] << 3, Time << 2) +
___SMMUL(Array[count + 48] << 3, Time << 2)) &
1023] =
(gate[0] + rGate[0]) &&
((___SMMUL(Array[count + 16] << 3, Time << 2) + pulsewidth[0]) >= cnt - 5
? 1
: 0) &&
(CNT[0]);
array[((write + ___SMMUL(delay[1] << 3, Time << 2) +
___SMMUL(Array[count + 48 + 64] << 3, Time << 2)) &
1023) +
1024] = (gate[1] + rGate[1]) &&
((___SMMUL(Array[count + 16 + 64] << 3, Time << 2) +
pulsewidth[1]) >= cnt - 5
? 1
: 0) &&
(CNT[1]);
array[((write + ___SMMUL(delay[2] << 3, Time << 2) +
___SMMUL(Array[count + 48 + 128] << 3, Time << 2)) &
1023) +
2048] = (gate[2] + rGate[2]) &&
((___SMMUL(Array[count + 16 + 128] << 3, Time << 2) +
pulsewidth[2]) >= cnt - 5
? 1
: 0) &&
(CNT[2]);
array[((write + ___SMMUL(delay[3] << 3, Time << 2) +
___SMMUL(Array[count + 48 + 192] << 3, Time << 2)) &
1023) +
3072] = (gate[3] + rGate[3]) &&
((___SMMUL(Array[count + 16 + 192] << 3, Time << 2) +
pulsewidth[3]) >= cnt - 5
? 1
: 0) &&
(CNT[3]);
outlet_o1 = array[write];
outlet_o2 = array[write + 1024];
outlet_o3 = array[write + 2048];
outlet_o4 = array[write + 3072];
outlet_cnt = count & 15;
prev = select + param_load;
CNT[0] = (cnt - (cnt / (Time / (1 + repeat[0] / 2 +
___SMMUL(Array[count + 32], 7 << 5)))) *
(Time / (1 + repeat[0] / 2 +
___SMMUL(Array[count + 32], 7 << 5)))) < Time / 8
? 1
: 0;
CNT[1] =
(cnt - (cnt / (Time / (1 + repeat[1] / 2 +
___SMMUL(Array[count + 32 + 64], 7 << 5)))) *
(Time / (1 + repeat[1] / 2 +
___SMMUL(Array[count + 32 + 64], 7 << 5)))) < Time / 8
? 1
: 0;
CNT[2] =
(cnt - (cnt / (Time / (1 + repeat[2] / 2 +
___SMMUL(Array[count + 32 + 128], 7 << 5)))) *
(Time / (1 + repeat[2] / 2 +
___SMMUL(Array[count + 32 + 128], 7 << 5)))) < Time / 8
? 1
: 0;
CNT[3] =
(cnt - (cnt / (Time / (1 + repeat[3] / 2 +
___SMMUL(Array[count + 32 + 192], 7 << 5)))) *
(Time / (1 + repeat[3] / 2 +
___SMMUL(Array[count + 32 + 192], 7 << 5)))) < Time / 8
? 1
: 0;
outlet_repeat1 = 1 + repeat[0];
outlet_trig = (count & 15) == 0;
if ((status == 1 + MIDI_CONTROL_CHANGE) && (data1 > 0) && (data1 < 17)) {
Array[data1 - 1 + select] = data2 << 20;
}