|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
-
-
-
-
-
-
-
-
-
-
-
-
- #include <Audio.h>
- #include <Wire.h>
- #include <SPI.h>
- #include <SD.h>
- #include <SerialFlash.h>
- #include <Bounce.h>
-
- AudioPlaySdWav playSdWav1;
- AudioMixer4 mixer1;
- AudioEffectGranular granular1;
- AudioOutputI2S i2s1;
- AudioConnection patchCord1(playSdWav1, 0, mixer1, 0);
- AudioConnection patchCord2(playSdWav1, 1, mixer1, 1);
- AudioConnection patchCord3(mixer1, granular1);
- AudioConnection patchCord4(granular1, 0, i2s1, 0);
- AudioConnection patchCord5(granular1, 0, i2s1, 1);
- AudioControlSGTL5000 sgtl5000_1;
-
- Bounce button0 = Bounce(0, 15);
- Bounce button1 = Bounce(1, 15);
- Bounce button2 = Bounce(2, 15);
-
- #define GRANULAR_MEMORY_SIZE 12800
- int16_t granularMemory[GRANULAR_MEMORY_SIZE];
-
-
- #define SDCARD_CS_PIN 10
- #define SDCARD_MOSI_PIN 7
- #define SDCARD_SCK_PIN 14
-
-
-
-
-
-
-
-
-
-
-
- #define NUM_FILES 4
- const char *filenames[NUM_FILES]={"SDTEST1.WAV", "SDTEST2.WAV", "SDTEST3.WAV", "SDTEST4.WAV"};
- int nextfile=0;
-
- void setup() {
- Serial.begin(9600);
- AudioMemory(10);
-
- pinMode(0, INPUT_PULLUP);
- pinMode(1, INPUT_PULLUP);
- pinMode(2, INPUT_PULLUP);
-
- sgtl5000_1.enable();
- sgtl5000_1.volume(0.5);
-
- mixer1.gain(0, 0.5);
- mixer1.gain(1, 0.5);
-
-
- granular1.begin(granularMemory, GRANULAR_MEMORY_SIZE);
-
- SPI.setMOSI(SDCARD_MOSI_PIN);
- SPI.setSCK(SDCARD_SCK_PIN);
- if (!(SD.begin(SDCARD_CS_PIN))) {
-
- while (1) {
- Serial.println("Unable to access the SD card");
- delay(500);
- }
- }
- }
-
- void loop() {
- if (playSdWav1.isPlaying() == false) {
-
- playSdWav1.play(filenames[nextfile]);
- Serial.print("Playing: ");
- Serial.println(filenames[nextfile]);
- delay(5);
- nextfile = nextfile + 1;
- if (nextfile >= NUM_FILES) {
- nextfile = 0;
- }
- }
-
-
- button0.update();
- button1.update();
- button2.update();
-
- float knobA2 = (float)analogRead(A2) / 1023.0;
- float knobA3 = (float)analogRead(A3) / 1023.0;
-
-
- if (button0.fallingEdge()) {
- float msec = 100.0 + (knobA3 * 190.0);
- granular1.beginFreeze(msec);
- Serial.print("Begin granular freeze using ");
- Serial.print(msec);
- Serial.println(" grains");
- }
- if (button0.risingEdge()) {
- granular1.stop();
- }
-
-
- if (button1.fallingEdge()) {
- float msec = 25.0 + (knobA3 * 75.0);
- granular1.beginPitchShift(msec);
- Serial.print("Begin granular pitch phift using ");
- Serial.print(msec);
- Serial.println(" grains");
- }
- if (button1.risingEdge()) {
- granular1.stop();
- }
-
-
- float ratio;
- ratio = powf(2.0, knobA2 * 2.0 - 1.0);
-
- granular1.setSpeed(ratio);
- }
|