RendererConstants.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //
  2. // Copyright (c) 2019-2020 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. namespace Ryujinx.Audio.Renderer
  18. {
  19. /// <summary>
  20. /// Define constants used by the Audio Renderer.
  21. /// </summary>
  22. public static class RendererConstants
  23. {
  24. /// <summary>
  25. /// The maximum number of channels supported. (6 channels for 5.1 surround)
  26. /// </summary>
  27. public const int ChannelCountMax = 6;
  28. /// <summary>
  29. /// The maximum number of channels supported per voice.
  30. /// </summary>
  31. public const int VoiceChannelCountMax = ChannelCountMax;
  32. /// <summary>
  33. /// The max count of mix buffer supported per operations (volumes, mix effect, ...)
  34. /// </summary>
  35. public const int MixBufferCountMax = 24;
  36. /// <summary>
  37. /// The max count of wavebuffer per voice.
  38. /// </summary>
  39. public const int VoiceWaveBufferCount = 4;
  40. /// <summary>
  41. /// The max count of biquad filter per voice.
  42. /// </summary>
  43. public const int VoiceBiquadFilterCount = 2;
  44. /// <summary>
  45. /// The lowest priority that a voice can have.
  46. /// </summary>
  47. public const int VoiceLowestPriority = 0xFF;
  48. /// <summary>
  49. /// The highest priority that a voice can have.
  50. /// </summary>
  51. /// <remarks>Voices with the highest priority will not be dropped if a voice drop needs to occur.</remarks>
  52. public const int VoiceHighestPriority = 0;
  53. /// <summary>
  54. /// Max <see cref="Common.BehaviourParameter.ErrorInfo"/> that can be returned by <see cref="Parameter.BehaviourErrorInfoOutStatus"/>.
  55. /// </summary>
  56. public const int MaxErrorInfos = 10;
  57. /// <summary>
  58. /// Default alignment for buffers.
  59. /// </summary>
  60. public const int BufferAlignment = 0x40;
  61. /// <summary>
  62. /// Alignment required for the work buffer.
  63. /// </summary>
  64. public const int WorkBufferAlignment = 0x1000;
  65. /// <summary>
  66. /// Alignment required for every performance metrics frame.
  67. /// </summary>
  68. public const int PerformanceMetricsPerFramesSizeAlignment = 0x100;
  69. /// <summary>
  70. /// The id of the final mix.
  71. /// </summary>
  72. public const int FinalMixId = 0;
  73. /// <summary>
  74. /// The id defining an unused mix id.
  75. /// </summary>
  76. public const int UnusedMixId = int.MaxValue;
  77. /// <summary>
  78. /// The id defining an unused splitter id as a signed integer.
  79. /// </summary>
  80. public const int UnusedSplitterIdInt = -1;
  81. /// <summary>
  82. /// The id defining an unused splitter id.
  83. /// </summary>
  84. public const uint UnusedSplitterId = uint.MaxValue;
  85. /// <summary>
  86. /// The id of invalid/unused node id.
  87. /// </summary>
  88. public const int InvalidNodeId = -268435456;
  89. /// <summary>
  90. /// The indice considered invalid for processing order.
  91. /// </summary>
  92. public const int InvalidProcessingOrder = -1;
  93. /// <summary>
  94. /// The max number of audio renderer sessions allowed to be created system wide.
  95. /// </summary>
  96. public const int AudioRendererSessionCountMax = 2;
  97. /// <summary>
  98. /// The target sample rate of the audio renderer. (48kHz)
  99. /// </summary>
  100. public const uint TargetSampleRate = 48000;
  101. /// <summary>
  102. /// The target sample size of the audio renderer. (PCM16)
  103. /// </summary>
  104. public const int TargetSampleSize = sizeof(ushort);
  105. /// <summary>
  106. /// The target sample count per audio renderer update.
  107. /// </summary>
  108. public const int TargetSampleCount = 240;
  109. /// <summary>
  110. /// The size of an upsampler entry to process upsampling to <see cref="TargetSampleRate"/>.
  111. /// </summary>
  112. public const int UpSampleEntrySize = TargetSampleCount * VoiceChannelCountMax;
  113. /// <summary>
  114. /// The target audio latency computed from <see cref="TargetSampleRate"/> and <see cref="TargetSampleCount"/>.
  115. /// </summary>
  116. public const int AudioProcessorMaxUpdateTimeTarget = 1000000000 / ((int)TargetSampleRate / TargetSampleCount); // 5.00 ms
  117. /// <summary>
  118. /// The max update time of the DSP on original hardware.
  119. /// </summary>
  120. public const int AudioProcessorMaxUpdateTime = 5760000; // 5.76 ms
  121. /// <summary>
  122. /// The max update time per audio renderer session.
  123. /// </summary>
  124. public const int AudioProcessorMaxUpdateTimePerSessions = AudioProcessorMaxUpdateTime / AudioRendererSessionCountMax;
  125. /// <summary>
  126. /// Guest timer frequency used for system ticks.
  127. /// </summary>
  128. public const int TargetTimerFrequency = 19200000;
  129. /// <summary>
  130. /// The default coefficients used for standard 5.1 surround to stereo downmixing.
  131. /// </summary>
  132. public static float[] DefaultSurroundToStereoCoefficients = new float[4]
  133. {
  134. 1.0f,
  135. 0.707f,
  136. 0.251f,
  137. 0.707f,
  138. };
  139. }
  140. }