DummyHardwareDeviceSessionOutput.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // Copyright (c) 2019-2021 Ryujinx
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. //
  17. using Ryujinx.Audio.Backends.Common;
  18. using Ryujinx.Audio.Common;
  19. using Ryujinx.Audio.Integration;
  20. using Ryujinx.Memory;
  21. using System.Threading;
  22. namespace Ryujinx.Audio.Backends.Dummy
  23. {
  24. internal class DummyHardwareDeviceSessionOutput : HardwareDeviceSessionOutputBase
  25. {
  26. private float _volume;
  27. private IHardwareDeviceDriver _manager;
  28. private ulong _playedSampleCount;
  29. public DummyHardwareDeviceSessionOutput(IHardwareDeviceDriver manager, IVirtualMemoryManager memoryManager, SampleFormat requestedSampleFormat, uint requestedSampleRate, uint requestedChannelCount, float requestedVolume) : base(memoryManager, requestedSampleFormat, requestedSampleRate, requestedChannelCount)
  30. {
  31. _volume = requestedVolume;
  32. _manager = manager;
  33. }
  34. public override void Dispose()
  35. {
  36. // Nothing to do.
  37. }
  38. public override ulong GetPlayedSampleCount()
  39. {
  40. return Interlocked.Read(ref _playedSampleCount);
  41. }
  42. public override float GetVolume()
  43. {
  44. return _volume;
  45. }
  46. public override void PrepareToClose() { }
  47. public override void QueueBuffer(AudioBuffer buffer)
  48. {
  49. Interlocked.Add(ref _playedSampleCount, GetSampleCount(buffer));
  50. _manager.GetUpdateRequiredEvent().Set();
  51. }
  52. public override void SetVolume(float volume)
  53. {
  54. _volume = volume;
  55. }
  56. public override void Start() { }
  57. public override void Stop() { }
  58. public override void UnregisterBuffer(AudioBuffer buffer) { }
  59. public override bool WasBufferFullyConsumed(AudioBuffer buffer)
  60. {
  61. return true;
  62. }
  63. }
  64. }