Guest User

Untitled

a guest
Aug 27th, 2023
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.74 KB | None | 0 0
  1. /**
  2.  * @file player-sd-audiokit.ino
  3.  * @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-audiokit/player-sd-audiokit/README.md
  4.  * Make sure that the pins are set to off, on, on, off, off
  5.  * @author Phil Schatzmann
  6.  * @copyright GPLv3
  7.  */
  8.  
  9.  
  10. #include "AudioTools.h"
  11. #include "AudioLibs/AudioKit.h"
  12. #include "AudioLibs/AudioSourceSD.h" // or AudioSourceIdxSD.h
  13. #include "AudioCodecs/CodecWAV.h"
  14.  
  15. const char *startFilePath="/";
  16. const char* ext="wav";
  17. AudioSourceSD source(startFilePath, ext, PIN_AUDIO_KIT_SD_CARD_CS);
  18. AudioKitStream kit;
  19. WAVDecoder decoder;  // or change to MP3DecoderMAD
  20. AudioPlayer player(source, kit, decoder);
  21.  
  22. void next(bool, int, void*) {
  23.    player.next();
  24. }
  25.  
  26. void previous(bool, int, void*) {
  27.    player.previous();
  28. }
  29.  
  30. void startStop(bool, int, void*) {
  31.    player.setActive(!player.isActive());
  32. }
  33.  
  34. void setup() {
  35.   Serial.begin(115200);
  36.   AudioLogger::instance().begin(Serial, AudioLogger::Warning);
  37.  
  38.   // setup output
  39.   auto cfg = kit.defaultConfig(RXTX_MODE);
  40.   // sd_active is setting up SPI with the right SD pins by calling
  41.   // SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
  42.   cfg.sd_active = true;
  43.   //cfg.bits_per_sample = 8;
  44.   kit.begin(cfg);
  45.   kit.setVolume(0.9);
  46.   // setup additional buttons
  47.   kit.addAction(PIN_KEY1, startStop);
  48.   kit.addAction(PIN_KEY4, next);
  49.   kit.addAction(PIN_KEY3, previous);
  50.  
  51.  
  52.   // setup player
  53.   player.setVolume(0.9);
  54.   player.begin();
  55.  
  56.   // select file with setPath() or setIndex()
  57.   //player.setPath("/ZZ Top/Unknown Album/Lowrider.mp3");
  58.   //player.setIndex(1); // 2nd file
  59.  
  60. }
  61.  
  62. void loop() {
  63.   player.copy();
  64.   kit.processActions();
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment