ZuluSCSI_audio.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * ZuluSCSI™ - Copyright (c) 2022 Rabbit Hole Computing™
  3. *
  4. * ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version. 
  5. *
  6. * https://www.gnu.org/licenses/gpl-3.0.html
  7. * ----
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version. 
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. * GNU General Public License for more details. 
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  20. **/
  21. #pragma once
  22. #include <stdint.h>
  23. /*
  24. * Status codes for audio playback, matching the SCSI 'audio status codes'.
  25. *
  26. * The first two are for a live condition and will be returned repeatedly. The
  27. * following two reflect a historical condition and are only returned once.
  28. */
  29. enum audio_status_code {
  30. ASC_PLAYING = 0x11,
  31. ASC_PAUSED = 0x12,
  32. ASC_COMPLETED = 0x13,
  33. ASC_ERRORED = 0x14,
  34. ASC_NO_STATUS = 0x15
  35. };
  36. /**
  37. * Indicates whether there is an active playback event for a given target.
  38. *
  39. * Note: this does not consider pause/resume events: even if audio is paused
  40. * this will indicate playback is in progress.
  41. *
  42. * \param owner The SCSI ID to check.
  43. * \return True if playback in progress, false if playback idle.
  44. */
  45. bool audio_is_playing(uint8_t id);
  46. /**
  47. * Begins audio playback for a file.
  48. *
  49. * \param owner The SCSI ID that initiated this playback operation.
  50. * \param file Path of a file containing PCM samples to play.
  51. * \param start Byte offset within file where playback will begin, inclusive.
  52. * \param end Byte offset within file where playback will end, exclusive.
  53. * \param swap If false, little-endian sample order, otherwise big-endian.
  54. * \return True if successful, false otherwise.
  55. */
  56. bool audio_play(uint8_t owner, const char* file, uint64_t start, uint64_t end, bool swap);
  57. /**
  58. * Pauses audio playback. This may be delayed slightly to allow sample buffers
  59. * to purge.
  60. *
  61. * \param id The SCSI ID to pause audio playback on.
  62. * \param pause If true, pause, otherwise resume.
  63. * \return True if operation changed audio output, false if no change.
  64. */
  65. bool audio_set_paused(uint8_t id, bool pause);
  66. /**
  67. * Stops audio playback.
  68. *
  69. * \param id The SCSI ID to stop audio playback on.
  70. */
  71. void audio_stop(uint8_t id);
  72. /**
  73. * Provides SCSI 'audio status code' for the given target. Depending on the
  74. * code this operation may produce side-effects, see the enum for details.
  75. *
  76. * \param id The SCSI ID to provide status codes for.
  77. * \return The matching audio status code.
  78. */
  79. audio_status_code audio_get_status_code(uint8_t id);
  80. /**
  81. * Provides the number of sample bytes read in during an individual audio
  82. * call. This can be combined with a separate starting offset to determine
  83. * virtual CD positioning information. This may only be an approximation due
  84. * to platform-specific behavior with sample reading.
  85. *
  86. * Data here should not be cleared when audio is stopped. Playback events
  87. * should reset this information.
  88. *
  89. * \param id The SCSI ID target to return data for.
  90. * \return The number of bytes read in during a playback.
  91. */
  92. uint32_t audio_get_bytes_read(uint8_t id);
  93. /**
  94. * Clears the byte counter in the above call. This should be supported even
  95. * during playback.
  96. *
  97. * \param id The SCSI ID target to clear data for.
  98. */
  99. void audio_clear_bytes_read(uint8_t id);