audio_out.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "audio_core/audio_out_manager.h"
  4. #include "audio_core/out/audio_out.h"
  5. #include "core/hle/kernel/k_event.h"
  6. namespace AudioCore::AudioOut {
  7. Out::Out(Core::System& system_, Manager& manager_, Kernel::KEvent* event_, size_t session_id_)
  8. : manager{manager_}, parent_mutex{manager.mutex}, event{event_},
  9. system{system_, event, session_id_} {}
  10. void Out::Free() {
  11. std::scoped_lock l{parent_mutex};
  12. manager.ReleaseSessionId(system.GetSessionId());
  13. }
  14. System& Out::GetSystem() {
  15. return system;
  16. }
  17. AudioOut::State Out::GetState() {
  18. std::scoped_lock l{parent_mutex};
  19. return system.GetState();
  20. }
  21. Result Out::StartSystem() {
  22. std::scoped_lock l{parent_mutex};
  23. return system.Start();
  24. }
  25. void Out::StartSession() {
  26. std::scoped_lock l{parent_mutex};
  27. system.StartSession();
  28. }
  29. Result Out::StopSystem() {
  30. std::scoped_lock l{parent_mutex};
  31. return system.Stop();
  32. }
  33. Result Out::AppendBuffer(const AudioOutBuffer& buffer, const u64 tag) {
  34. std::scoped_lock l{parent_mutex};
  35. if (system.AppendBuffer(buffer, tag)) {
  36. return ResultSuccess;
  37. }
  38. return Service::Audio::ResultBufferCountReached;
  39. }
  40. void Out::ReleaseAndRegisterBuffers() {
  41. std::scoped_lock l{parent_mutex};
  42. if (system.GetState() == State::Started) {
  43. system.ReleaseBuffers();
  44. system.RegisterBuffers();
  45. }
  46. }
  47. bool Out::FlushAudioOutBuffers() {
  48. std::scoped_lock l{parent_mutex};
  49. return system.FlushAudioOutBuffers();
  50. }
  51. u32 Out::GetReleasedBuffers(std::span<u64> tags) {
  52. std::scoped_lock l{parent_mutex};
  53. return system.GetReleasedBuffers(tags);
  54. }
  55. Kernel::KReadableEvent& Out::GetBufferEvent() {
  56. std::scoped_lock l{parent_mutex};
  57. return event->GetReadableEvent();
  58. }
  59. f32 Out::GetVolume() const {
  60. std::scoped_lock l{parent_mutex};
  61. return system.GetVolume();
  62. }
  63. void Out::SetVolume(const f32 volume) {
  64. std::scoped_lock l{parent_mutex};
  65. system.SetVolume(volume);
  66. }
  67. bool Out::ContainsAudioBuffer(const u64 tag) const {
  68. std::scoped_lock l{parent_mutex};
  69. return system.ContainsAudioBuffer(tag);
  70. }
  71. u32 Out::GetBufferCount() const {
  72. std::scoped_lock l{parent_mutex};
  73. return system.GetBufferCount();
  74. }
  75. u64 Out::GetPlayedSampleCount() const {
  76. std::scoped_lock l{parent_mutex};
  77. return system.GetPlayedSampleCount();
  78. }
  79. } // namespace AudioCore::AudioOut