audio.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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
  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. /**
  27. * Handler for DMA interrupts
  28. *
  29. * This is called from scsi_dma_irq() in scsi_accel_rp2040.cpp. That is
  30. * obviously a silly way to handle things. However, using
  31. * irq_add_shared_handler() causes a lockup, likely due to pico-sdk issue #724
  32. * fixed in 1.3.1. Current builds use pico-sdk 1.3.0 and are affected by
  33. * the bug. To work around the problem the above exclusive handler
  34. * delegates to this function if its normal mask is not matched.
  35. */
  36. void audio_dma_irq();
  37. /**
  38. * Indicates if the audio subsystem is actively streaming, including if it is
  39. * sending silent data during sample stall events.
  40. *
  41. * \return true if audio streaming is active, false otherwise.
  42. */
  43. bool audio_is_active();
  44. /**
  45. * Initializes the audio subsystem. Should be called only once, toward the end
  46. * of platform_late_init().
  47. */
  48. void audio_setup();
  49. /**
  50. * Called from platform_poll() to fill sample buffer(s) if needed.
  51. */
  52. void audio_poll();
  53. #endif // ENABLE_AUDIO_OUTPUT