Bläddra i källkod

Add MP3 Player example (thanks Frank B)

main
PaulStoffregen 8 år sedan
förälder
incheckning
d841f1f5cd
1 ändrade filer med 67 tillägg och 0 borttagningar
  1. +67
    -0
      examples/MP3Player/MP3Player.ino

+ 67
- 0
examples/MP3Player/MP3Player.ino Visa fil

@@ -0,0 +1,67 @@
// Simple MP3 file player example
//
// Requires the prop-shield and Teensy 3.2 or 3.1
// This example code is in the public domain.

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>
#include <play_sd_mp3.h> // https://github.com/FrankBoesing/Arduino-Teensy-Codec-lib
//#include <play_sd_aac.h>


// GUItool: begin automatically generated code
//AudioPlaySdWav playSdWav1; //xy=154,422
AudioPlaySdMp3 playMp31; //xy=154,422
AudioMixer4 mixer1; //xy=327,432
AudioOutputAnalog dac1; //xy=502,412
AudioConnection patchCord1(playMp31, 0, mixer1, 0);
AudioConnection patchCord2(playMp31, 1, mixer1, 1);
AudioConnection patchCord3(mixer1, dac1);
// GUItool: end automatically generated code


#define PROP_AMP_ENABLE 5
#define FLASH_CHIP_SELECT 6

void setup() {
AudioMemory(8); //4
delay(2000);

// Start SerialFlash
if (!SerialFlash.begin(FLASH_CHIP_SELECT)) {
while (1) {
Serial.println ("Cannot access SPI Flash chip");
delay (1000);
}
}

//Start Amplifier
pinMode(PROP_AMP_ENABLE, OUTPUT);
digitalWrite(PROP_AMP_ENABLE, HIGH); // Enable Amplifier
}

void playFile(const char *filename)
{

SerialFlashFile ff = SerialFlash.open(filename);
Serial.print("Playing file: ");
Serial.println(filename);

uint32_t sz = ff.size();
uint32_t pos = ff.getFlashAddress();

// Start playing the file. This sketch continues to
// run while the file plays.
playMp31.play(pos,sz);

// Simply wait for the file to finish playing.
while (playMp31.isPlaying()) {}
}


void loop() {
playFile("rain.mp3");
delay(1000);
}

Laddar…
Avbryt
Spara