DummyHardwareDeviceDriver.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. public DummyHardwareDeviceDriver()
  28. {
  29. _updateRequiredEvent = new ManualResetEvent(false);
  30. }
  31. public IHardwareDeviceSession OpenDeviceSession(Direction direction, IVirtualMemoryManager memoryManager, SampleFormat sampleFormat, uint sampleRate, uint channelCount)
  32. {
  33. if (sampleRate == 0)
  34. {
  35. sampleRate = Constants.TargetSampleRate;
  36. }
  37. if (channelCount == 0)
  38. {
  39. channelCount = 2;
  40. }
  41. if (direction == Direction.Output)
  42. {
  43. return new DummyHardwareDeviceSessionOutput(this, memoryManager, sampleFormat, sampleRate, channelCount);
  44. }
  45. else
  46. {
  47. return new DummyHardwareDeviceSessionInput(this, memoryManager, sampleFormat, sampleRate, channelCount);
  48. }
  49. }
  50. public ManualResetEvent GetUpdateRequiredEvent()
  51. {
  52. return _updateRequiredEvent;
  53. }
  54. public void Dispose()
  55. {
  56. Dispose(true);
  57. }
  58. protected virtual void Dispose(bool disposing)
  59. {
  60. if (disposing)
  61. {
  62. // NOTE: The _updateRequiredEvent will be disposed somewhere else.
  63. }
  64. }
  65. public bool SupportsSampleRate(uint sampleRate)
  66. {
  67. return true;
  68. }
  69. public bool SupportsSampleFormat(SampleFormat sampleFormat)
  70. {
  71. return true;
  72. }
  73. public bool SupportsDirection(Direction direction)
  74. {
  75. return direction == Direction.Output || direction == Direction.Input;
  76. }
  77. public bool SupportsChannelCount(uint channelCount)
  78. {
  79. return channelCount == 1 || channelCount == 2 || channelCount == 6;
  80. }
  81. }
  82. }