DummyHardwareDeviceDriver.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.Common;
  18. using Ryujinx.Audio.Integration;
  19. using Ryujinx.Memory;
  20. using System.Threading;
  21. using static Ryujinx.Audio.Integration.IHardwareDeviceDriver;
  22. namespace Ryujinx.Audio.Backends.Dummy
  23. {
  24. public class DummyHardwareDeviceDriver : IHardwareDeviceDriver
  25. {
  26. private ManualResetEvent _updateRequiredEvent;
  27. private ManualResetEvent _pauseEvent;
  28. public DummyHardwareDeviceDriver()
  29. {
  30. _updateRequiredEvent = new ManualResetEvent(false);
  31. _pauseEvent = new ManualResetEvent(true);
  32. }
  33. public IHardwareDeviceSession OpenDeviceSession(Direction direction, IVirtualMemoryManager memoryManager, SampleFormat sampleFormat, uint sampleRate, uint channelCount, float volume)
  34. {
  35. if (sampleRate == 0)
  36. {
  37. sampleRate = Constants.TargetSampleRate;
  38. }
  39. if (channelCount == 0)
  40. {
  41. channelCount = 2;
  42. }
  43. if (direction == Direction.Output)
  44. {
  45. return new DummyHardwareDeviceSessionOutput(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
  46. }
  47. else
  48. {
  49. return new DummyHardwareDeviceSessionInput(this, memoryManager, sampleFormat, sampleRate, channelCount);
  50. }
  51. }
  52. public ManualResetEvent GetUpdateRequiredEvent()
  53. {
  54. return _updateRequiredEvent;
  55. }
  56. public ManualResetEvent GetPauseEvent()
  57. {
  58. return _pauseEvent;
  59. }
  60. public void Dispose()
  61. {
  62. Dispose(true);
  63. }
  64. protected virtual void Dispose(bool disposing)
  65. {
  66. if (disposing)
  67. {
  68. // NOTE: The _updateRequiredEvent will be disposed somewhere else.
  69. _pauseEvent.Dispose();
  70. }
  71. }
  72. public bool SupportsSampleRate(uint sampleRate)
  73. {
  74. return true;
  75. }
  76. public bool SupportsSampleFormat(SampleFormat sampleFormat)
  77. {
  78. return true;
  79. }
  80. public bool SupportsDirection(Direction direction)
  81. {
  82. return direction == Direction.Output || direction == Direction.Input;
  83. }
  84. public bool SupportsChannelCount(uint channelCount)
  85. {
  86. return channelCount == 1 || channelCount == 2 || channelCount == 6;
  87. }
  88. }
  89. }