BlueSCSI_audio.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. #include "ImageBackingStore.h"
  24. /*
  25. * Starting volume level for audio output, with 0 being muted and 255 being
  26. * max volume. SCSI-2 says this should be 25% of maximum by default, MMC-1
  27. * says 100%. Testing shows this tends to be obnoxious at high volumes, so
  28. * go with SCSI-2.
  29. *
  30. * This implementation uses the high byte for output port 1 and the low byte
  31. * for port 0. The two values are averaged to determine final volume level.
  32. */
  33. #define DEFAULT_VOLUME_LEVEL 0x3F
  34. #define DEFAULT_VOLUME_LEVEL_2CH DEFAULT_VOLUME_LEVEL << 8 | DEFAULT_VOLUME_LEVEL
  35. /*
  36. * Defines the 'enable' masks for the two audio output ports of each device.
  37. * If this mask is matched with audio_get_channel() the relevant port will
  38. * have audio output to it, otherwise it will be muted, regardless of the
  39. * volume level.
  40. */
  41. #define AUDIO_CHANNEL_ENABLE_MASK 0x0201
  42. /*
  43. * Status codes for audio playback, matching the SCSI 'audio status codes'.
  44. *
  45. * The first two are for a live condition and will be returned repeatedly. The
  46. * following two reflect a historical condition and are only returned once.
  47. */
  48. enum audio_status_code {
  49. ASC_PLAYING = 0x11,
  50. ASC_PAUSED = 0x12,
  51. ASC_COMPLETED = 0x13,
  52. ASC_ERRORED = 0x14,
  53. ASC_NO_STATUS = 0x15
  54. };
  55. /**
  56. * Indicates whether there is an active playback event for a given target.
  57. *
  58. * Note: this does not consider pause/resume events: even if audio is paused
  59. * this will indicate playback is in progress.
  60. *
  61. * \param owner The SCSI ID to check.
  62. * \return True if playback in progress, false if playback idle.
  63. */
  64. bool audio_is_playing(uint8_t id);
  65. /**
  66. * Begins audio playback for a file.
  67. *
  68. * \param owner The SCSI ID that initiated this playback operation.
  69. * \param img Pointer to the image containing PCM samples to play.
  70. * \param start Byte offset within file where playback will begin, inclusive.
  71. * \param end Byte offset within file where playback will end, exclusive.
  72. * \param swap If false, little-endian sample order, otherwise big-endian.
  73. * \return True if successful, false otherwise.
  74. */
  75. bool audio_play(uint8_t owner, ImageBackingStore* img, uint64_t start, uint64_t end, bool swap);
  76. /**
  77. * Pauses audio playback. This may be delayed slightly to allow sample buffers
  78. * to purge.
  79. *
  80. * \param id The SCSI ID to pause audio playback on.
  81. * \param pause If true, pause, otherwise resume.
  82. * \return True if operation changed audio output, false if no change.
  83. */
  84. bool audio_set_paused(uint8_t id, bool pause);
  85. /**
  86. * Stops audio playback.
  87. *
  88. * \param id The SCSI ID to stop audio playback on.
  89. */
  90. void audio_stop(uint8_t id);
  91. /**
  92. * Provides SCSI 'audio status code' for the given target. Depending on the
  93. * code this operation may produce side-effects, see the enum for details.
  94. *
  95. * \param id The SCSI ID to provide status codes for.
  96. * \return The matching audio status code.
  97. */
  98. audio_status_code audio_get_status_code(uint8_t id);
  99. /**
  100. * Gets the current volume level for a target. This is a pair of 8-bit values
  101. * ranging from 0-255 that are averaged together to determine the final output
  102. * level, where 0 is muted and 255 is maximum volume. The high byte corresponds
  103. * to 0x0E channel 1 and the low byte to 0x0E channel 0. See the spec's mode
  104. * page documentation for more details.
  105. *
  106. * \param id SCSI ID to provide volume for.
  107. * \return The matching volume level.
  108. */
  109. uint16_t audio_get_volume(uint8_t id);
  110. /**
  111. * Sets the volume level for a target, as above. See 0x0E mode page for more.
  112. *
  113. * \param id SCSI ID to set volume for.
  114. * \param vol The new volume level.
  115. */
  116. void audio_set_volume(uint8_t id, uint16_t vol);
  117. /**
  118. * Gets the 0x0E channel information for both audio ports. The high byte
  119. * corresponds to port 1 and the low byte to port 0. If the bits defined in
  120. * AUDIO_CHANNEL_ENABLE_MASK are not set for the respective ports, that
  121. * output will be muted, regardless of volume set.
  122. *
  123. * \param id SCSI ID to provide channel information for.
  124. * \return The channel information.
  125. */
  126. uint16_t audio_get_channel(uint8_t id);
  127. /**
  128. * Sets the 0x0E channel information for a target, as above. See 0x0E mode
  129. * page for more.
  130. *
  131. * \param id SCSI ID to set channel information for.
  132. * \param chn The new channel information.
  133. */
  134. void audio_set_channel(uint8_t id, uint16_t chn);