DummyHardwareDeviceDriver.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 DummyHardwareDeviceDriver()
  13. {
  14. _updateRequiredEvent = new ManualResetEvent(false);
  15. _pauseEvent = new ManualResetEvent(true);
  16. }
  17. public IHardwareDeviceSession OpenDeviceSession(Direction direction, IVirtualMemoryManager memoryManager, SampleFormat sampleFormat, uint sampleRate, uint channelCount, float volume)
  18. {
  19. if (sampleRate == 0)
  20. {
  21. sampleRate = Constants.TargetSampleRate;
  22. }
  23. if (channelCount == 0)
  24. {
  25. channelCount = 2;
  26. }
  27. if (direction == Direction.Output)
  28. {
  29. return new DummyHardwareDeviceSessionOutput(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
  30. }
  31. else
  32. {
  33. return new DummyHardwareDeviceSessionInput(this, memoryManager, sampleFormat, sampleRate, channelCount);
  34. }
  35. }
  36. public ManualResetEvent GetUpdateRequiredEvent()
  37. {
  38. return _updateRequiredEvent;
  39. }
  40. public ManualResetEvent GetPauseEvent()
  41. {
  42. return _pauseEvent;
  43. }
  44. public void Dispose()
  45. {
  46. Dispose(true);
  47. }
  48. protected virtual void Dispose(bool disposing)
  49. {
  50. if (disposing)
  51. {
  52. // NOTE: The _updateRequiredEvent will be disposed somewhere else.
  53. _pauseEvent.Dispose();
  54. }
  55. }
  56. public bool SupportsSampleRate(uint sampleRate)
  57. {
  58. return true;
  59. }
  60. public bool SupportsSampleFormat(SampleFormat sampleFormat)
  61. {
  62. return true;
  63. }
  64. public bool SupportsDirection(Direction direction)
  65. {
  66. return direction == Direction.Output || direction == Direction.Input;
  67. }
  68. public bool SupportsChannelCount(uint channelCount)
  69. {
  70. return channelCount == 1 || channelCount == 2 || channelCount == 6;
  71. }
  72. }
  73. }