SinkContext.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 System.Diagnostics;
  18. namespace Ryujinx.Audio.Renderer.Server.Sink
  19. {
  20. /// <summary>
  21. /// Sink context.
  22. /// </summary>
  23. public class SinkContext
  24. {
  25. /// <summary>
  26. /// Storage for <see cref="BaseSink"/>.
  27. /// </summary>
  28. private BaseSink[] _sinks;
  29. /// <summary>
  30. /// The total sink count.
  31. /// </summary>
  32. private uint _sinkCount;
  33. /// <summary>
  34. /// Initialize the <see cref="SinkContext"/>.
  35. /// </summary>
  36. /// <param name="sinksCount">The total sink count.</param>
  37. public void Initialize(uint sinksCount)
  38. {
  39. _sinkCount = sinksCount;
  40. _sinks = new BaseSink[_sinkCount];
  41. for (int i = 0; i < _sinkCount; i++)
  42. {
  43. _sinks[i] = new BaseSink();
  44. }
  45. }
  46. /// <summary>
  47. /// Get the total sink count.
  48. /// </summary>
  49. /// <returns>The total sink count.</returns>
  50. public uint GetCount()
  51. {
  52. return _sinkCount;
  53. }
  54. /// <summary>
  55. /// Get a reference to a <see cref="BaseSink"/> at the given <paramref name="id"/>.
  56. /// </summary>
  57. /// <param name="id">The index to use.</param>
  58. /// <returns>A reference to a <see cref="BaseSink"/> at the given <paramref name="id"/>.</returns>
  59. public ref BaseSink GetSink(int id)
  60. {
  61. Debug.Assert(id >= 0 && id < _sinkCount);
  62. return ref _sinks[id];
  63. }
  64. }
  65. }