You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.0KB

  1. // Simple MP3 file player example
  2. //
  3. // https://forum.pjrc.com/threads/27059-MP3-Player-Lib-with-example?p=101537&viewfull=1#post101537
  4. //
  5. // Requires the prop-shield and Teensy 3.2 or 3.1
  6. // This example code is in the public domain.
  7. #include <Audio.h>
  8. #include <Wire.h>
  9. #include <SPI.h>
  10. #include <SD.h>
  11. #include <SerialFlash.h>
  12. #include <play_sd_mp3.h> // https://github.com/FrankBoesing/Arduino-Teensy-Codec-lib
  13. //#include <play_sd_aac.h>
  14. // GUItool: begin automatically generated code
  15. //AudioPlaySdWav playSdWav1; //xy=154,422
  16. AudioPlaySdMp3 playMp31; //xy=154,422
  17. AudioMixer4 mixer1; //xy=327,432
  18. AudioOutputAnalog dac1; //xy=502,412
  19. AudioConnection patchCord1(playMp31, 0, mixer1, 0);
  20. AudioConnection patchCord2(playMp31, 1, mixer1, 1);
  21. AudioConnection patchCord3(mixer1, dac1);
  22. // GUItool: end automatically generated code
  23. #define PROP_AMP_ENABLE 5
  24. #define FLASH_CHIP_SELECT 6
  25. // Uncomment this line if using the built-in SPI Flash device
  26. // on an Arduino 101 board
  27. //#define FLASH_CHIP_SELECT 21
  28. void setup() {
  29. Serial.begin(9600);
  30. AudioMemory(8); //4
  31. delay(2000);
  32. // Start SerialFlash
  33. if (!SerialFlash.begin(FLASH_CHIP_SELECT)) {
  34. while (1) {
  35. Serial.println ("Cannot access SPI Flash chip");
  36. delay (1000);
  37. }
  38. }
  39. //Set Volume
  40. mixer1.gain(0, 0.5);
  41. mixer1.gain(1, 0.5);
  42. //Start Amplifier
  43. pinMode(PROP_AMP_ENABLE, OUTPUT);
  44. digitalWrite(PROP_AMP_ENABLE, HIGH); // Enable Amplifier
  45. }
  46. void playFile(const char *filename)
  47. {
  48. SerialFlashFile ff = SerialFlash.open(filename);
  49. Serial.print("Playing file: ");
  50. Serial.println(filename);
  51. uint32_t sz = ff.size();
  52. uint32_t pos = ff.getFlashAddress();
  53. // Start playing the file. This sketch continues to
  54. // run while the file plays.
  55. playMp31.play(pos,sz);
  56. // Simply wait for the file to finish playing.
  57. while (playMp31.isPlaying()) {
  58. yield();
  59. }
  60. }
  61. void loop() {
  62. playFile("rain.mp3");
  63. delay(1000);
  64. }