Browse Source

Plays samples from SPI flash. USB mass storage conflicts with USB MIDI so it's commented out for now

master
Oleksiy 1 year ago
parent
commit
d1671f7992
  1. 199
      NeoBreaks/NeoBreaks.ino

199
NeoBreaks/NeoBreaks.ino

@ -1,49 +1,21 @@
#include "Audio.h"
#include "Adafruit_NeoTrellisM4.h"
#include <Audio.h>
#include <play_fs_wav.h>
#include <Adafruit_NeoTrellisM4.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL343.h>
#include "AudioSampleG1_1.h"
#include "AudioSampleG1_2.h"
#include "AudioSampleG1_3.h"
#include "AudioSampleG1_4.h"
#include "AudioSampleG1_5.h"
#include "AudioSampleG1_6.h"
#include "AudioSampleG1_7.h"
//#include "AudioSampleG2_1.h"
//#include "AudioSampleG2_2.h"
//#include "AudioSampleG2_3.h"
//#include "AudioSampleG2_4.h"
//#include "AudioSampleG2_5.h"
//#include "AudioSampleG2_6.h"
//#include "AudioSampleG2_7.h"
#include "AudioSampleG3_1.h"
#include "AudioSampleG3_2.h"
#include "AudioSampleG3_3.h"
#include "AudioSampleG3_4.h"
#include "AudioSampleG3_5.h"
#include "AudioSampleG3_6.h"
#include "AudioSampleG3_7.h"
//#include "AudioSampleG4_1.h"
//#include "AudioSampleG4_2.h"
//#include "AudioSampleG4_3.h"
//#include "AudioSampleG4_4.h"
//#include "AudioSampleG4_5.h"
//#include "AudioSampleG4_6.h"
//#include "AudioSampleG4_7.h"
#include <Adafruit_SPIFlash.h>
// #include <Adafruit_TinyUSB.h> conflicts with Adafruit_NeoTrellisM4.h due to MIDI USB
#define BPM 160
// GUItool: begin automatically generated code
AudioPlayMemory playMem1; //xy=275,499
AudioPlayMemory playMem2; //xy=284,532.5
AudioPlayMemory playMem3; //xy=294,566.5
AudioPlayMemory playMem4; //xy=302,599.5
AudioPlayFSWav playMem1; //xy=275,499
AudioPlayFSWav playMem2; //xy=284,532.5
AudioPlayFSWav playMem3; //xy=294,566.5
AudioPlayFSWav playMem4; //xy=302,599.5
AudioMixer4 mixer1; //xy=491,517
AudioSynthWaveformDc dc1; //xy=507,581
AudioFilterStateVariable filter1; //xy=649,502
@ -57,7 +29,13 @@ AudioConnection patchCord6(dc1, 0, dacs1, 1);
AudioConnection patchCord7(filter1, 0, dacs1, 0);
// GUItool: end automatically generated code
int timeToClick;
//Flash memory stuff
Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
Adafruit_SPIFlash flash(&flashTransport);
FatFileSystem fatfs;
/*FatFile root; //related to USB Mass Storage
FatFile file;
Adafruit_USBD_MSC usb_msc;*/
Adafruit_NeoTrellisM4 trellis = Adafruit_NeoTrellisM4();
Adafruit_ADXL343 accel = Adafruit_ADXL343(50, &Wire1); //50 does not mean anything here, just a random id
@ -69,6 +47,8 @@ int colors[] = {
0x100800
};
int timeToClick;
int G1[] = {0,1,8,9,16,17,24,25};
int G2[] = {2,3,10,11,18,19,26,27};
int G3[] = {4,5,12,13,20,21,28,29};
@ -90,6 +70,37 @@ int EighthNote = 60000 / (BPM * 2);
int clickOn;
//bool USBFlash = false;
File sample1;
File sample2;
File sample3;
File sample4;
void setup() {
Serial.begin(115200);
trellis.begin();
trellis.setBrightness(127);
accel.begin();
AudioMemory(32);
redrawAndPlay();
filter1.resonance(2.2); //from 0.7 to 5
flash.begin();
/*if (USBFlash) { //related to USB Mass Storage
usb_msc.setID("Adafruit", "External Flash", "1.0");
usb_msc.setReadWriteCallback(msc_read_cb, msc_write_cb, msc_flush_cb);
usb_msc.setCapacity(flash.size()/512, 512);
usb_msc.setUnitReady(true);
usb_msc.begin();
}*/
fatfs.begin(&flash);
};
void clockTick(){
if(millis() >= timeToClick) {
timeToClick = millis() + EighthNote; //214 should be ~1/8 at 140 bpm
@ -107,6 +118,8 @@ void clickOff() {
}
void updatePlay() {
//if there's less than 30ms until the end of the sample, retriger it to prevent gap
if (playMem1.lengthMillis() - playMem1.positionMillis() < 30) {
G1Trigger = 1;
@ -115,25 +128,32 @@ void updatePlay() {
G1Trigger = 0;
switch (G1Select) {
case 6:
playMem1.play(AudioSampleG1_1);
sample1 = fatfs.open("G1_1.wav");
playMem1.play(sample1);
break;
case 4:
playMem1.play(AudioSampleG1_2);
sample1 = fatfs.open("G1_2.wav");
playMem1.play(sample1);
break;
case 2:
playMem1.play(AudioSampleG1_3);
sample1 = fatfs.open("G1_3.wav");
playMem1.play(sample1);
break;
case 0:
playMem1.play(AudioSampleG1_4);
sample1 = fatfs.open("G1_4.wav");
playMem1.play(sample1);
break;
case 1:
playMem1.play(AudioSampleG1_5);
sample1 = fatfs.open("G1_5.wav");
playMem1.play(sample1);
break;
case 3:
playMem1.play(AudioSampleG1_6);
sample1 = fatfs.open("G1_6.wav");
playMem1.play(sample1);
break;
case 5:
playMem1.play(AudioSampleG1_7);
sample1 = fatfs.open("G1_7.wav");
playMem1.play(sample1);
break;
}
}
@ -144,25 +164,32 @@ void updatePlay() {
G2Trigger = 0;
switch (G2Select) {
case 6:
//playMem2.play(AudioSampleG2_1);
sample2 = fatfs.open("G2_1.wav");
playMem2.play(sample2);
break;
case 4:
//playMem2.play(AudioSampleG2_2);
sample2 = fatfs.open("G2_2.wav");
playMem2.play(sample2);
break;
case 2:
//playMem2.play(AudioSampleG2_3);
sample2 = fatfs.open("G2_3.wav");
playMem2.play(sample2);
break;
case 0:
//playMem2.play(AudioSampleG2_4);
sample2 = fatfs.open("G2_4.wav");
playMem2.play(sample2);
break;
case 1:
//playMem2.play(AudioSampleG2_5);
sample2 = fatfs.open("G2_5.wav");
playMem2.play(sample2);
break;
case 3:
//playMem2.play(AudioSampleG2_6);
sample2 = fatfs.open("G2_6.wav");
playMem2.play(sample2);
break;
case 5:
//playMem2.play(AudioSampleG2_7);
sample2 = fatfs.open("G2_7.wav");
playMem2.play(sample2);
break;
}
}
@ -173,25 +200,32 @@ void updatePlay() {
G3Trigger = 0;
switch (G3Select) {
case 6:
playMem3.play(AudioSampleG3_1);
sample3= fatfs.open("G3_1.wav");
playMem3.play(sample3);
break;
case 4:
playMem3.play(AudioSampleG3_2);
sample3= fatfs.open("G3_2.wav");
playMem3.play(sample3);
break;
case 2:
playMem3.play(AudioSampleG3_3);
sample3= fatfs.open("G3_3.wav");
playMem3.play(sample3);
break;
case 0:
playMem3.play(AudioSampleG3_4);
sample3= fatfs.open("G3_4.wav");
playMem3.play(sample3);
break;
case 1:
playMem3.play(AudioSampleG3_5);
sample3= fatfs.open("G3_5.wav");
playMem3.play(sample3);
break;
case 3:
playMem3.play(AudioSampleG3_6);
sample3= fatfs.open("G3_6.wav");
playMem3.play(sample3);
break;
case 5:
playMem3.play(AudioSampleG3_7);
sample3= fatfs.open("G3_7.wav");
playMem3.play(sample3);
break;
}
}
@ -202,25 +236,32 @@ void updatePlay() {
G4Trigger = 0;
switch (G4Select) {
case 6:
//playMem4.play(AudioSampleG4_1);
sample4= fatfs.open("G4_1.wav");
playMem4.play(sample4);
break;
case 4:
//playMem4.play(AudioSampleG4_2);
sample4= fatfs.open("G4_2.wav");
playMem4.play(sample4);
break;
case 2:
//playMem4.play(AudioSampleG4_3);
sample4= fatfs.open("G4_3.wav");
playMem4.play(sample4);
break;
case 0:
//playMem4.play(AudioSampleG4_4);
sample4= fatfs.open("G4_4.wav");
playMem4.play(sample4);
break;
case 1:
//playMem4.play(AudioSampleG4_5);
sample4= fatfs.open("G4_5.wav");
playMem4.play(sample4);
break;
case 3:
//playMem4.play(AudioSampleG4_6);
sample4= fatfs.open("G4_6.wav");
playMem4.play(sample4);
break;
case 5:
//playMem4.play(AudioSampleG4_7);
sample4= fatfs.open("G4_7.wav");
playMem4.play(sample4);
break;
}
}
@ -268,20 +309,18 @@ void redrawAndPlay() {
}
}
void setup() {
Serial.begin(115200);
trellis.begin();
trellis.setBrightness(127);
accel.begin();
AudioMemory(32);
redrawAndPlay();
filter1.resonance(2.2); //from 0.7 to 5
};
/*Flash related functions
int32_t msc_read_cb (uint32_t lba, void* buffer, uint32_t bufsize) {
return flash.readBlocks(lba, (uint8_t*) buffer, bufsize/512) ? bufsize : -1;
}
int32_t msc_write_cb (uint32_t lba, uint8_t* buffer, uint32_t bufsize) {
digitalWrite(LED_BUILTIN, HIGH);
return flash.writeBlocks(lba, buffer, bufsize/512) ? bufsize : -1;
}
void msc_flush_cb (void) {
flash.syncBlocks();
fatfs.cacheClear();
}*/
void loop() {
trellis.tick();

Loading…
Cancel
Save