|
|
@@ -1,7 +1,24 @@ |
|
|
|
// Simple WAV file player example |
|
|
|
// |
|
|
|
// Requires the audio shield: |
|
|
|
// http://www.pjrc.com/store/teensy3_audio.html |
|
|
|
// Three types of output may be used, by configuring the code below. |
|
|
|
// |
|
|
|
// 1: Digital I2S - Normally used with the audio shield: |
|
|
|
// http://www.pjrc.com/store/teensy3_audio.html |
|
|
|
// |
|
|
|
// 2: Digital S/PDIF - Connect pin 22 to a S/PDIF transmitter |
|
|
|
// https://www.oshpark.com/shared_projects/KcDBKHta |
|
|
|
// |
|
|
|
// 3: Analog DAC - Connect the DAC pin to an amplified speaker |
|
|
|
// http://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog |
|
|
|
// |
|
|
|
// To configure the output type, first uncomment one of the three |
|
|
|
// output objects. If not using the audio shield, comment out |
|
|
|
// the sgtl5000_1 lines in setup(), so it does not wait forever |
|
|
|
// trying to configure the SGTL5000 codec chip. |
|
|
|
// |
|
|
|
// The SD card may connect to different pins, depending on the |
|
|
|
// hardware you are using. Uncomment or configure the SD card |
|
|
|
// pins to match your hardware. |
|
|
|
// |
|
|
|
// Data files to put on your SD card can be downloaded here: |
|
|
|
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html |
|
|
@@ -13,27 +30,41 @@ |
|
|
|
#include <SPI.h> |
|
|
|
#include <SD.h> |
|
|
|
|
|
|
|
// GUItool: begin automatically generated code |
|
|
|
AudioPlaySdWav playWav1; //xy=154,78 |
|
|
|
AudioOutputI2S i2s1; //xy=334,89 |
|
|
|
AudioConnection patchCord1(playWav1, 0, i2s1, 0); |
|
|
|
AudioConnection patchCord2(playWav1, 1, i2s1, 1); |
|
|
|
AudioControlSGTL5000 sgtl5000_1; //xy=240,153 |
|
|
|
// GUItool: end automatically generated code |
|
|
|
AudioPlaySdWav playWav1; |
|
|
|
// Use one of these 3 output types: Digital I2S, Digital S/PDIF, or Analog DAC |
|
|
|
AudioOutputI2S audioOutput; |
|
|
|
//AudioOutputSPDIF audioOutput; |
|
|
|
//AudioOutputAnalog audioOutput; |
|
|
|
AudioConnection patchCord1(playWav1, 0, audioOutput, 0); |
|
|
|
AudioConnection patchCord2(playWav1, 1, audioOutput, 1); |
|
|
|
AudioControlSGTL5000 sgtl5000_1; |
|
|
|
|
|
|
|
// Use these with the audio adaptor board |
|
|
|
#define SDCARD_CS_PIN 10 |
|
|
|
#define SDCARD_MOSI_PIN 7 |
|
|
|
#define SDCARD_SCK_PIN 14 |
|
|
|
|
|
|
|
// Use these for the SD+Wiz820 or other adaptors |
|
|
|
//#define SDCARD_CS_PIN 4 |
|
|
|
//#define SDCARD_MOSI_PIN 11 |
|
|
|
//#define SDCARD_SCK_PIN 13 |
|
|
|
|
|
|
|
void setup() { |
|
|
|
Serial.begin(9600); |
|
|
|
|
|
|
|
// Audio connections require memory to work. For more |
|
|
|
// detailed information, see the MemoryAndCpuUsage example |
|
|
|
AudioMemory(5); |
|
|
|
AudioMemory(8); |
|
|
|
|
|
|
|
// Comment these out if not using the audio adaptor board. |
|
|
|
// This may wait forever if the SDA & SCL pins lack |
|
|
|
// pullup resistors |
|
|
|
sgtl5000_1.enable(); |
|
|
|
sgtl5000_1.volume(0.5); |
|
|
|
|
|
|
|
SPI.setMOSI(7); |
|
|
|
SPI.setSCK(14); |
|
|
|
if (!(SD.begin(10))) { |
|
|
|
SPI.setMOSI(SDCARD_MOSI_PIN); |
|
|
|
SPI.setSCK(SDCARD_SCK_PIN); |
|
|
|
if (!(SD.begin(SDCARD_CS_PIN))) { |
|
|
|
// stop here, but print a message repetitively |
|
|
|
while (1) { |
|
|
|
Serial.println("Unable to access the SD card"); |