DummyHardwareDeviceDriver.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Ryujinx.Audio.Common;
  2. using Ryujinx.Audio.Integration;
  3. using Ryujinx.Memory;
  4. using System.Threading;
  5. using static Ryujinx.Audio.Integration.IHardwareDeviceDriver;
  6. namespace Ryujinx.Audio.Backends.Dummy
  7. {
  8. public class DummyHardwareDeviceDriver : IHardwareDeviceDriver
  9. {
  10. private ManualResetEvent _updateRequiredEvent;
  11. private ManualResetEvent _pauseEvent;
  12. public static bool IsSupported => true;
  13. public DummyHardwareDeviceDriver()
  14. {
  15. _updateRequiredEvent = new ManualResetEvent(false);
  16. _pauseEvent = new ManualResetEvent(true);
  17. }
  18. public IHardwareDeviceSession OpenDeviceSession(Direction direction, IVirtualMemoryManager memoryManager, SampleFormat sampleFormat, uint sampleRate, uint channelCount, float volume)
  19. {
  20. if (sampleRate == 0)
  21. {
  22. sampleRate = Constants.TargetSampleRate;
  23. }
  24. if (channelCount == 0)
  25. {
  26. channelCount = 2;
  27. }
  28. if (direction == Direction.Output)
  29. {
  30. return new DummyHardwareDeviceSessionOutput(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
  31. }
  32. else
  33. {
  34. return new DummyHardwareDeviceSessionInput(this, memoryManager, sampleFormat, sampleRate, channelCount);
  35. }
  36. }
  37. public ManualResetEvent GetUpdateRequiredEvent()
  38. {
  39. return _updateRequiredEvent;
  40. }
  41. public ManualResetEvent GetPauseEvent()
  42. {
  43. return _pauseEvent;
  44. }
  45. public void Dispose()
  46. {
  47. Dispose(true);
  48. }
  49. protected virtual void Dispose(bool disposing)
  50. {
  51. if (disposing)
  52. {
  53. // NOTE: The _updateRequiredEvent will be disposed somewhere else.
  54. _pauseEvent.Dispose();
  55. }
  56. }
  57. public bool SupportsSampleRate(uint sampleRate)
  58. {
  59. return true;
  60. }
  61. public bool SupportsSampleFormat(SampleFormat sampleFormat)
  62. {
  63. return true;
  64. }
  65. public bool SupportsDirection(Direction direction)
  66. {
  67. return direction == Direction.Output || direction == Direction.Input;
  68. }
  69. public bool SupportsChannelCount(uint channelCount)
  70. {
  71. return channelCount == 1 || channelCount == 2 || channelCount == 6;
  72. }
  73. }
  74. }