#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Bounce.h>
// GUItool: begin automatically generated code
AudioPlaySdWav soundBoard; //xy=223,156
AudioPlaySdWav soundDAC; //xy=227,482
AudioMixer4 mixer1; //xy=529,307
AudioMixer4 mixer2; //xy=724,398
AudioOutputAnalog dac1; //xy=730,605
AudioOutputI2S i2s1; //xy=899,494
AudioConnection patchCord1(soundBoard, 0, mixer1, 0);
AudioConnection patchCord2(soundBoard, 1, mixer1, 1);
AudioConnection patchCord7(soundDAC, 0, mixer2, 0);
AudioConnection patchCord8(soundDAC, 1, mixer2, 1);
AudioConnection patchCord11(mixer1, 0, i2s1, 0);
AudioConnection patchCord12(mixer1, 0, i2s1, 1);
AudioConnection patchCord9(mixer2, 0, dac1, 0);
// GUItool: end automatically generated code
// Create an object to control the audio shield.
AudioControlSGTL5000 audioShield;
// Bounce objects to read pushbuttons
Bounce button1 = Bounce(0, 10); // 5 ms debounce time
Bounce button2 = Bounce(1, 10);
void setup() {
// Configure the pushbutton pins for pullups.
// Each button should connect from the pin to GND.
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(10);
// turn on the output
audioShield.enable();
audioShield.volume(1);
delay(1000);
// by default the Teensy 3.1 DAC uses 3.3Vp-p output
// if your 3.3V power has noise, switching to the
// internal 1.2V reference can give you a clean signal
//dac.analogReference(INTERNAL);
// reduce the gain on mixer channels, so more than 1
// sound can play simultaneously without clipping
float gainLevel = 0;
mixer1.gain(0, gainLevel);
mixer1.gain(1, gainLevel);
mixer2.gain(0, gainLevel);
mixer2.gain(1, gainLevel);
SPI.setMOSI(7);
SPI.setSCK(14);
if (!(SD.begin(10))) {
// stop here, but print a message repetitively
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
// Store the button states
button1.update();
button2.update();
}
void loop() {
// Update all the button objects
button1.update();
button2.update();
// When the buttons are pressed, just start a sound playing.
// The audio library will play each sound through the mixers
// so combinations of banks can play simultaneously.
// main buttons
if (button1.fallingEdge()) {
soundBoard.play("silence1.wav");
Serial.println("Playing silence1.wav");
}
if (button2.fallingEdge()) {
soundDAC.play("silence2.wav");
Serial.println("silence2.wav");
}
// volume control
// float vol = analogRead(15);
// vol = vol / 1024;
// audioShield.volume(vol);
}