audio_in.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <mutex>
  5. #include "audio_core/in/audio_in_system.h"
  6. namespace Core {
  7. class System;
  8. }
  9. namespace Kernel {
  10. class KEvent;
  11. class KReadableEvent;
  12. } // namespace Kernel
  13. namespace AudioCore::AudioIn {
  14. class Manager;
  15. /**
  16. * Interface between the service and audio in system. Mainly responsible for forwarding service
  17. * calls to the system.
  18. */
  19. class In {
  20. public:
  21. explicit In(Core::System& system, Manager& manager, Kernel::KEvent* event, size_t session_id);
  22. /**
  23. * Free this audio in from the audio in manager.
  24. */
  25. void Free();
  26. /**
  27. * Get this audio in's system.
  28. */
  29. System& GetSystem();
  30. /**
  31. * Get the current state.
  32. *
  33. * @return Started or Stopped.
  34. */
  35. AudioIn::State GetState();
  36. /**
  37. * Start the system
  38. *
  39. * @return Result code
  40. */
  41. Result StartSystem();
  42. /**
  43. * Start the system's device session.
  44. */
  45. void StartSession();
  46. /**
  47. * Stop the system.
  48. *
  49. * @return Result code
  50. */
  51. Result StopSystem();
  52. /**
  53. * Append a new buffer to the system, the buffer event will be signalled when it is filled.
  54. *
  55. * @param buffer - The new buffer to append.
  56. * @param tag - Unique tag for this buffer.
  57. * @return Result code.
  58. */
  59. Result AppendBuffer(const AudioInBuffer& buffer, u64 tag);
  60. /**
  61. * Release all completed buffers, and register any appended.
  62. */
  63. void ReleaseAndRegisterBuffers();
  64. /**
  65. * Flush all buffers.
  66. */
  67. bool FlushAudioInBuffers();
  68. /**
  69. * Get all of the currently released buffers.
  70. *
  71. * @param tags - Output container for the buffer tags which were released.
  72. * @return The number of buffers released.
  73. */
  74. u32 GetReleasedBuffers(std::span<u64> tags);
  75. /**
  76. * Get the buffer event for this audio in, this event will be signalled when a buffer is filled.
  77. *
  78. * @return The buffer event.
  79. */
  80. Kernel::KReadableEvent& GetBufferEvent();
  81. /**
  82. * Get the current system volume.
  83. *
  84. * @return The current volume.
  85. */
  86. f32 GetVolume() const;
  87. /**
  88. * Set the system volume.
  89. *
  90. * @param volume - The volume to set.
  91. */
  92. void SetVolume(f32 volume);
  93. /**
  94. * Check if a buffer is in the system.
  95. *
  96. * @param tag - The tag to search for.
  97. * @return True if the buffer is in the system, otherwise false.
  98. */
  99. bool ContainsAudioBuffer(u64 tag) const;
  100. /**
  101. * Get the maximum number of buffers.
  102. *
  103. * @return The maximum number of buffers.
  104. */
  105. u32 GetBufferCount() const;
  106. /**
  107. * Get the total played sample count for this audio in.
  108. *
  109. * @return The played sample count.
  110. */
  111. u64 GetPlayedSampleCount() const;
  112. private:
  113. /// The AudioIn::Manager this audio in is registered with
  114. Manager& manager;
  115. /// Manager's mutex
  116. std::recursive_mutex& parent_mutex;
  117. /// Buffer event, signalled when buffers are ready to be released
  118. Kernel::KEvent* event;
  119. /// Main audio in system
  120. System system;
  121. };
  122. } // namespace AudioCore::AudioIn