TSCodecLPCM.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. using System;
  20. using System.Collections.Generic;
  21. using System.Text;
  22. namespace BDInfo
  23. {
  24. public abstract class TSCodecLPCM
  25. {
  26. public static void Scan(
  27. TSAudioStream stream,
  28. TSStreamBuffer buffer,
  29. ref string tag)
  30. {
  31. if (stream.IsInitialized) return;
  32. byte[] header = buffer.ReadBytes(4);
  33. int flags = (header[2] << 8) + header[3];
  34. switch ((flags & 0xF000) >> 12)
  35. {
  36. case 1: // 1/0/0
  37. stream.ChannelCount = 1;
  38. stream.LFE = 0;
  39. break;
  40. case 3: // 2/0/0
  41. stream.ChannelCount = 2;
  42. stream.LFE = 0;
  43. break;
  44. case 4: // 3/0/0
  45. stream.ChannelCount = 3;
  46. stream.LFE = 0;
  47. break;
  48. case 5: // 2/1/0
  49. stream.ChannelCount = 3;
  50. stream.LFE = 0;
  51. break;
  52. case 6: // 3/1/0
  53. stream.ChannelCount = 4;
  54. stream.LFE = 0;
  55. break;
  56. case 7: // 2/2/0
  57. stream.ChannelCount = 4;
  58. stream.LFE = 0;
  59. break;
  60. case 8: // 3/2/0
  61. stream.ChannelCount = 5;
  62. stream.LFE = 0;
  63. break;
  64. case 9: // 3/2/1
  65. stream.ChannelCount = 5;
  66. stream.LFE = 1;
  67. break;
  68. case 10: // 3/4/0
  69. stream.ChannelCount = 7;
  70. stream.LFE = 0;
  71. break;
  72. case 11: // 3/4/1
  73. stream.ChannelCount = 7;
  74. stream.LFE = 1;
  75. break;
  76. default:
  77. stream.ChannelCount = 0;
  78. stream.LFE = 0;
  79. break;
  80. }
  81. switch ((flags & 0xC0) >> 6)
  82. {
  83. case 1:
  84. stream.BitDepth = 16;
  85. break;
  86. case 2:
  87. stream.BitDepth = 20;
  88. break;
  89. case 3:
  90. stream.BitDepth = 24;
  91. break;
  92. default:
  93. stream.BitDepth = 0;
  94. break;
  95. }
  96. switch ((flags & 0xF00) >> 8)
  97. {
  98. case 1:
  99. stream.SampleRate = 48000;
  100. break;
  101. case 4:
  102. stream.SampleRate = 96000;
  103. break;
  104. case 5:
  105. stream.SampleRate = 192000;
  106. break;
  107. default:
  108. stream.SampleRate = 0;
  109. break;
  110. }
  111. stream.BitRate = (uint)
  112. (stream.SampleRate * stream.BitDepth *
  113. (stream.ChannelCount + stream.LFE));
  114. stream.IsVBR = false;
  115. stream.IsInitialized = true;
  116. }
  117. }
  118. }