Browse Source

Update WavFilePlayer example

dds
PaulStoffregen 10 years ago
parent
commit
533e33d8e2
1 changed files with 59 additions and 24 deletions
  1. +59
    -24
      examples/WavFilePlayer/WavFilePlayer.ino

+ 59
- 24
examples/WavFilePlayer/WavFilePlayer.ino View File

@@ -1,43 +1,78 @@
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>

// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
// Simple WAV file player example
//
AudioPlaySdWav wav;
AudioOutputI2S dac;

// Create Audio connections between the components
// Requires the audio shield:
// http://www.pjrc.com/store/teensy3_audio.html
//
// Data files to put on your SD card can be downloaded here:
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
//
AudioConnection c1(wav, 0, dac, 0);
AudioConnection c2(wav, 1, dac, 1);
// This example code is in the public domain.

// Create an object to control the audio shield.
//
AudioControlSGTL5000 audioShield;
#include <Audio.h>
#include <Wire.h>
#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

void setup() {
Serial.begin(9600);

// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(5);

audioShield.enable();
audioShield.volume(0.5);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);

SPI.setMOSI(7);
SPI.setSCK(14);
if (SD.begin(10)) {
wav.play("01_16M.WAV");
if (!(SD.begin(10))) {
// stop here, but print a message repetitively
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
}

void playFile(const char *filename)
{
Serial.print("Playing file: ");
Serial.println(filename);

// Start playing the file. This sketch continues to
// run while the file plays.
playWav1.play(filename);

// A brief delay for the library read WAV info
delay(5);

// Simply wait for the file to finish playing.
while (playWav1.isPlaying()) {
// uncomment these lines if you audio shield
// has the optional volume pot soldered
//float vol = analogRead(15);
//vol = vol / 1024;
// sgtl5000_1.volume(vol);
}
}


void loop() {
float vol = analogRead(15);
vol = vol / 1024;
audioShield.volume(vol);
delay(20);
playFile("SDTEST1.WAV");
delay(500);
playFile("SDTEST2.WAV");
delay(500);
playFile("SDTEST3.WAV");
delay(500);
playFile("SDTEST4.WAV");
delay(1500);
}


Loading…
Cancel
Save