// VLSI 1053 codec Structure generator // /* Based recursive Cellular Automata Pot0 = chain note A Pot1 = chain note B Pot2 = chain instrument Pot3 = chain drum Pot4 = tempo/speed 45 - 350 BPM 16th note Channel 1-x random voices Channel 10 drums Created by JLS 2019 */ #include #include #define MAXTEMPO 14 // 350 BPM 16th note #define MINTEMPO 111 // 45 BPM 16th note MIDI_CREATE_DEFAULT_INSTANCE(); #define WIDTH 256 int xx; byte k; int state[WIDTH]; int delay_ms = 0; //SCI_MODE register defines #define SM_DIFF 0 #define SM_LAYER12 1 #define SM_RESET 2 #define SM_CANCEL 3 #define SM_EARSPEAKER_LO 4 #define SM_TESTS 5 #define SM_STREAM 6 #define SM_EARSPEAKER_HI 7 #define SM_DACT 8 #define SM_SDIORD 9 #define SM_SDISHARE 10 #define SM_SDINEW 11 #define SM_ADPCM 12 #define SM_ADPCM_HP 13 #define SM_LINE1 14 #define SM_CLK_RANGE 15 void cs_low() { digitalWrite(9, LOW); // CS low delayMicroseconds(250); } void cs_high() { digitalWrite(9, HIGH); // CS high delayMicroseconds(250); } void sci_write(char address, int data) { cs_low(); SPI.transfer(0x02); //send write command SPI.transfer(address); //send address we are going to write to SPI.transfer((data >> 8) & 0xFF); //send the first 8 MSBs of the data SPI.transfer(data & 0xFF); //send the LSBs cs_high(); } void sci_volume (char volleft, char volright) { cs_low(); SPI.transfer(0x02); SPI.transfer(0x0B); SPI.transfer(volleft); SPI.transfer(volright); cs_high(); } void sci_bass (char treble, char bass) { cs_low(); SPI.transfer(0x02); SPI.transfer(0x02); SPI.transfer(treble); SPI.transfer(bass); cs_high(); } void setup() { MIDI.begin (); pinMode (9,OUTPUT); // pin9 = CS SPI.begin(); SPI.setDataMode(SPI_MODE1); SPI.setClockDivider(SPI_CLOCK_DIV2); SPCR = (1<>2, k); int aa = k; int bb = (k+1)%16; int cc = aa ^ bb; MIDI.sendNoteOn (note_a, 24 + random(k*5), aa); MIDI.sendNoteOn (note_b, 24 + random(k*5), bb); MIDI.sendNoteOn (note_c, 24 + random(k*5), cc); MIDI.sendNoteOn (drum, 48 + random(k*3), 10); delay_ms = map(analogRead(4), 0, 1023, MINTEMPO, MAXTEMPO); delay (2 * delay_ms); MIDI.sendNoteOff (note_a, 0, aa); MIDI.sendNoteOff (note_b, 0, bb); MIDI.sendNoteOff (note_c, 0, cc); delay (delay_ms); if (xx == WIDTH) xx = 0; xx++; }