BlueSCSI_audio.h 5.0 KB

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