DummyAudioOut.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.Audio
  5. {
  6. /// <summary>
  7. /// A Dummy audio renderer that does not output any audio
  8. /// </summary>
  9. public class DummyAudioOut : IAalOutput
  10. {
  11. private int _lastTrackId = 1;
  12. private float _volume = 1.0f;
  13. private ConcurrentQueue<int> _trackIds;
  14. private ConcurrentQueue<long> _buffers;
  15. private ConcurrentDictionary<int, ReleaseCallback> _releaseCallbacks;
  16. public DummyAudioOut()
  17. {
  18. _buffers = new ConcurrentQueue<long>();
  19. _trackIds = new ConcurrentQueue<int>();
  20. _releaseCallbacks = new ConcurrentDictionary<int, ReleaseCallback>();
  21. }
  22. /// <summary>
  23. /// Dummy audio output is always available, Baka!
  24. /// </summary>
  25. public static bool IsSupported => true;
  26. public PlaybackState GetState(int trackId) => PlaybackState.Stopped;
  27. public int OpenTrack(int sampleRate, int channels, ReleaseCallback callback)
  28. {
  29. if (!_trackIds.TryDequeue(out int trackId))
  30. {
  31. trackId = ++_lastTrackId;
  32. }
  33. _releaseCallbacks[trackId] = callback;
  34. return trackId;
  35. }
  36. public void CloseTrack(int trackId)
  37. {
  38. _trackIds.Enqueue(trackId);
  39. _releaseCallbacks.Remove(trackId, out _);
  40. }
  41. public bool ContainsBuffer(int trackID, long bufferTag) => false;
  42. public long[] GetReleasedBuffers(int trackId, int maxCount)
  43. {
  44. List<long> bufferTags = new List<long>();
  45. for (int i = 0; i < maxCount; i++)
  46. {
  47. if (!_buffers.TryDequeue(out long tag))
  48. {
  49. break;
  50. }
  51. bufferTags.Add(tag);
  52. }
  53. return bufferTags.ToArray();
  54. }
  55. public void AppendBuffer<T>(int trackID, long bufferTag, T[] buffer) where T : struct
  56. {
  57. _buffers.Enqueue(bufferTag);
  58. if (_releaseCallbacks.TryGetValue(trackID, out var callback))
  59. {
  60. callback?.Invoke();
  61. }
  62. }
  63. public void Start(int trackId) { }
  64. public void Stop(int trackId) { }
  65. public float GetVolume() => _volume;
  66. public void SetVolume(float volume)
  67. {
  68. _volume = volume;
  69. }
  70. public void Dispose()
  71. {
  72. _buffers.Clear();
  73. }
  74. }
  75. }