AC101AudioSink.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "AC101AudioSink.h"
  2. #include "driver/i2s.h"
  3. AC101AudioSink::AC101AudioSink() {
  4. // Disable software volume control, all handled by ::volumeChanged
  5. softwareVolumeControl = false;
  6. i2s_config_t i2s_config = {
  7. .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX), // Only TX
  8. .sample_rate = 44100,
  9. .bits_per_sample = (i2s_bits_per_sample_t)16,
  10. .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, //2-channels
  11. .communication_format = (i2s_comm_format_t)I2S_COMM_FORMAT_I2S,
  12. .intr_alloc_flags = 0, //Default interrupt priority
  13. .dma_buf_count = 8,
  14. .dma_buf_len = 512,
  15. .use_apll = true,
  16. .tx_desc_auto_clear = true //Auto clear tx descriptor on underflow
  17. };
  18. i2s_pin_config_t pin_config = {
  19. .bck_io_num = 27,
  20. .ws_io_num = 26,
  21. .data_out_num = 25,
  22. .data_in_num = -1 //Not used
  23. };
  24. dac = &dac_a1s;
  25. dac->init(0, 0, &i2s_config);
  26. dac->speaker(false);
  27. dac->power(ADAC_ON);
  28. startI2sFeed();
  29. }
  30. AC101AudioSink::~AC101AudioSink() {}
  31. void AC101AudioSink::volumeChanged(uint16_t volume) {
  32. dac->volume(volume, volume);
  33. }