audio_spdif.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright (C) 2023 saybur
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version. 
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. * GNU General Public License for more details. 
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  16. **/
  17. #pragma once
  18. #ifdef ENABLE_AUDIO_OUTPUT_SPDIF
  19. #include <stdint.h>
  20. // audio subsystem DMA channels
  21. #define SOUND_DMA_CHA 6
  22. #define SOUND_DMA_CHB 7
  23. // size of the two audio sample buffers, in bytes
  24. // these must be divisible by 1024
  25. // #define AUDIO_BUFFER_SIZE 8192 // ~46.44ms
  26. #define AUDIO_BUFFER_SIZE 4096 // reduce memory usage
  27. /**
  28. * Handler for DMA interrupts
  29. *
  30. * This is called from scsi_dma_irq() in scsi_accel_rp2040.cpp. That is
  31. * obviously a silly way to handle things. However, using
  32. * irq_add_shared_handler() causes a lockup, likely due to pico-sdk issue #724
  33. * fixed in 1.3.1. Current builds use pico-sdk 1.3.0 and are affected by
  34. * the bug. To work around the problem the above exclusive handler
  35. * delegates to this function if its normal mask is not matched.
  36. */
  37. void audio_dma_irq();
  38. /**
  39. * Indicates if the audio subsystem is actively streaming, including if it is
  40. * sending silent data during sample stall events.
  41. *
  42. * \return true if audio streaming is active, false otherwise.
  43. */
  44. bool audio_is_active();
  45. /**
  46. * Initializes the audio subsystem. Should be called only once, toward the end
  47. * of platform_late_init().
  48. */
  49. void audio_setup();
  50. /**
  51. * Called from platform_poll() to fill sample buffer(s) if needed.
  52. */
  53. void audio_poll();
  54. #endif // ENABLE_AUDIO_OUTPUT_SPDIF