Constants.cs 6.6 KB

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