TSCodecLPCM.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //============================================================================
  2. // BDInfo - Blu-ray Video and Audio Analysis Tool
  3. // Copyright © 2010 Cinema Squid
  4. //
  5. // This library is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU Lesser General Public
  7. // License as published by the Free Software Foundation; either
  8. // version 2.1 of the License, or (at your option) any later version.
  9. //
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. // Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public
  16. // License along with this library; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. //=============================================================================
  19. namespace BDInfo
  20. {
  21. public abstract class TSCodecLPCM
  22. {
  23. public static void Scan(
  24. TSAudioStream stream,
  25. TSStreamBuffer buffer,
  26. ref string tag)
  27. {
  28. if (stream.IsInitialized) return;
  29. byte[] header = buffer.ReadBytes(4);
  30. int flags = (header[2] << 8) + header[3];
  31. switch ((flags & 0xF000) >> 12)
  32. {
  33. case 1: // 1/0/0
  34. stream.ChannelCount = 1;
  35. stream.LFE = 0;
  36. break;
  37. case 3: // 2/0/0
  38. stream.ChannelCount = 2;
  39. stream.LFE = 0;
  40. break;
  41. case 4: // 3/0/0
  42. stream.ChannelCount = 3;
  43. stream.LFE = 0;
  44. break;
  45. case 5: // 2/1/0
  46. stream.ChannelCount = 3;
  47. stream.LFE = 0;
  48. break;
  49. case 6: // 3/1/0
  50. stream.ChannelCount = 4;
  51. stream.LFE = 0;
  52. break;
  53. case 7: // 2/2/0
  54. stream.ChannelCount = 4;
  55. stream.LFE = 0;
  56. break;
  57. case 8: // 3/2/0
  58. stream.ChannelCount = 5;
  59. stream.LFE = 0;
  60. break;
  61. case 9: // 3/2/1
  62. stream.ChannelCount = 5;
  63. stream.LFE = 1;
  64. break;
  65. case 10: // 3/4/0
  66. stream.ChannelCount = 7;
  67. stream.LFE = 0;
  68. break;
  69. case 11: // 3/4/1
  70. stream.ChannelCount = 7;
  71. stream.LFE = 1;
  72. break;
  73. default:
  74. stream.ChannelCount = 0;
  75. stream.LFE = 0;
  76. break;
  77. }
  78. switch ((flags & 0xC0) >> 6)
  79. {
  80. case 1:
  81. stream.BitDepth = 16;
  82. break;
  83. case 2:
  84. stream.BitDepth = 20;
  85. break;
  86. case 3:
  87. stream.BitDepth = 24;
  88. break;
  89. default:
  90. stream.BitDepth = 0;
  91. break;
  92. }
  93. switch ((flags & 0xF00) >> 8)
  94. {
  95. case 1:
  96. stream.SampleRate = 48000;
  97. break;
  98. case 4:
  99. stream.SampleRate = 96000;
  100. break;
  101. case 5:
  102. stream.SampleRate = 192000;
  103. break;
  104. default:
  105. stream.SampleRate = 0;
  106. break;
  107. }
  108. stream.BitRate = (uint)
  109. (stream.SampleRate * stream.BitDepth *
  110. (stream.ChannelCount + stream.LFE));
  111. stream.IsVBR = false;
  112. stream.IsInitialized = true;
  113. }
  114. }
  115. }