ZuluSCSI_audio.h 4.1 KB

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