module.audio.ac3.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at http://getid3.sourceforge.net //
  5. // or http://www.getid3.org //
  6. // also https://github.com/JamesHeinrich/getID3 //
  7. /////////////////////////////////////////////////////////////////
  8. // See readme.txt for more details //
  9. /////////////////////////////////////////////////////////////////
  10. // //
  11. // module.audio.ac3.php //
  12. // module for analyzing AC-3 (aka Dolby Digital) audio files //
  13. // dependencies: NONE //
  14. // ///
  15. /////////////////////////////////////////////////////////////////
  16. class getid3_ac3 extends getid3_handler
  17. {
  18. private $AC3header = array();
  19. private $BSIoffset = 0;
  20. const syncword = "\x0B\x77";
  21. public function Analyze() {
  22. $info = &$this->getid3->info;
  23. ///AH
  24. $info['ac3']['raw']['bsi'] = array();
  25. $thisfile_ac3 = &$info['ac3'];
  26. $thisfile_ac3_raw = &$thisfile_ac3['raw'];
  27. $thisfile_ac3_raw_bsi = &$thisfile_ac3_raw['bsi'];
  28. // http://www.atsc.org/standards/a_52a.pdf
  29. $info['fileformat'] = 'ac3';
  30. // An AC-3 serial coded audio bit stream is made up of a sequence of synchronization frames
  31. // Each synchronization frame contains 6 coded audio blocks (AB), each of which represent 256
  32. // new audio samples per channel. A synchronization information (SI) header at the beginning
  33. // of each frame contains information needed to acquire and maintain synchronization. A
  34. // bit stream information (BSI) header follows SI, and contains parameters describing the coded
  35. // audio service. The coded audio blocks may be followed by an auxiliary data (Aux) field. At the
  36. // end of each frame is an error check field that includes a CRC word for error detection. An
  37. // additional CRC word is located in the SI header, the use of which, by a decoder, is optional.
  38. //
  39. // syncinfo() | bsi() | AB0 | AB1 | AB2 | AB3 | AB4 | AB5 | Aux | CRC
  40. // syncinfo() {
  41. // syncword 16
  42. // crc1 16
  43. // fscod 2
  44. // frmsizecod 6
  45. // } /* end of syncinfo */
  46. $this->fseek($info['avdataoffset']);
  47. $this->AC3header['syncinfo'] = $this->fread(5);
  48. if (strpos($this->AC3header['syncinfo'], self::syncword) === 0) {
  49. $thisfile_ac3_raw['synchinfo']['synchword'] = self::syncword;
  50. $offset = 2;
  51. } else {
  52. if (!$this->isDependencyFor('matroska')) {
  53. unset($info['fileformat'], $info['ac3']);
  54. return $this->error('Expecting "'.getid3_lib::PrintHexBytes(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($this->AC3header['syncinfo'], 0, 2)).'"');
  55. }
  56. $offset = 0;
  57. $this->fseek(-2, SEEK_CUR);
  58. }
  59. $info['audio']['dataformat'] = 'ac3';
  60. $info['audio']['bitrate_mode'] = 'cbr';
  61. $info['audio']['lossless'] = false;
  62. $thisfile_ac3_raw['synchinfo']['crc1'] = getid3_lib::LittleEndian2Int(substr($this->AC3header['syncinfo'], $offset, 2));
  63. $ac3_synchinfo_fscod_frmsizecod = getid3_lib::LittleEndian2Int(substr($this->AC3header['syncinfo'], ($offset + 2), 1));
  64. $thisfile_ac3_raw['synchinfo']['fscod'] = ($ac3_synchinfo_fscod_frmsizecod & 0xC0) >> 6;
  65. $thisfile_ac3_raw['synchinfo']['frmsizecod'] = ($ac3_synchinfo_fscod_frmsizecod & 0x3F);
  66. $thisfile_ac3['sample_rate'] = self::sampleRateCodeLookup($thisfile_ac3_raw['synchinfo']['fscod']);
  67. if ($thisfile_ac3_raw['synchinfo']['fscod'] <= 3) {
  68. $info['audio']['sample_rate'] = $thisfile_ac3['sample_rate'];
  69. }
  70. $thisfile_ac3['frame_length'] = self::frameSizeLookup($thisfile_ac3_raw['synchinfo']['frmsizecod'], $thisfile_ac3_raw['synchinfo']['fscod']);
  71. $thisfile_ac3['bitrate'] = self::bitrateLookup($thisfile_ac3_raw['synchinfo']['frmsizecod']);
  72. $info['audio']['bitrate'] = $thisfile_ac3['bitrate'];
  73. $this->AC3header['bsi'] = getid3_lib::BigEndian2Bin($this->fread(15));
  74. $ac3_bsi_offset = 0;
  75. $thisfile_ac3_raw_bsi['bsid'] = $this->readHeaderBSI(5);
  76. if ($thisfile_ac3_raw_bsi['bsid'] > 8) {
  77. // Decoders which can decode version 8 will thus be able to decode version numbers less than 8.
  78. // If this standard is extended by the addition of additional elements or features, a value of bsid greater than 8 will be used.
  79. // Decoders built to this version of the standard will not be able to decode versions with bsid greater than 8.
  80. $this->error('Bit stream identification is version '.$thisfile_ac3_raw_bsi['bsid'].', but getID3() only understands up to version 8');
  81. unset($info['ac3']);
  82. return false;
  83. }
  84. $thisfile_ac3_raw_bsi['bsmod'] = $this->readHeaderBSI(3);
  85. $thisfile_ac3_raw_bsi['acmod'] = $this->readHeaderBSI(3);
  86. $thisfile_ac3['service_type'] = self::serviceTypeLookup($thisfile_ac3_raw_bsi['bsmod'], $thisfile_ac3_raw_bsi['acmod']);
  87. $ac3_coding_mode = self::audioCodingModeLookup($thisfile_ac3_raw_bsi['acmod']);
  88. foreach($ac3_coding_mode as $key => $value) {
  89. $thisfile_ac3[$key] = $value;
  90. }
  91. switch ($thisfile_ac3_raw_bsi['acmod']) {
  92. case 0:
  93. case 1:
  94. $info['audio']['channelmode'] = 'mono';
  95. break;
  96. case 3:
  97. case 4:
  98. $info['audio']['channelmode'] = 'stereo';
  99. break;
  100. default:
  101. $info['audio']['channelmode'] = 'surround';
  102. break;
  103. }
  104. $info['audio']['channels'] = $thisfile_ac3['num_channels'];
  105. if ($thisfile_ac3_raw_bsi['acmod'] & 0x01) {
  106. // If the lsb of acmod is a 1, center channel is in use and cmixlev follows in the bit stream.
  107. $thisfile_ac3_raw_bsi['cmixlev'] = $this->readHeaderBSI(2);
  108. $thisfile_ac3['center_mix_level'] = self::centerMixLevelLookup($thisfile_ac3_raw_bsi['cmixlev']);
  109. }
  110. if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) {
  111. // If the msb of acmod is a 1, surround channels are in use and surmixlev follows in the bit stream.
  112. $thisfile_ac3_raw_bsi['surmixlev'] = $this->readHeaderBSI(2);
  113. $thisfile_ac3['surround_mix_level'] = self::surroundMixLevelLookup($thisfile_ac3_raw_bsi['surmixlev']);
  114. }
  115. if ($thisfile_ac3_raw_bsi['acmod'] == 0x02) {
  116. // When operating in the two channel mode, this 2-bit code indicates whether or not the program has been encoded in Dolby Surround.
  117. $thisfile_ac3_raw_bsi['dsurmod'] = $this->readHeaderBSI(2);
  118. $thisfile_ac3['dolby_surround_mode'] = self::dolbySurroundModeLookup($thisfile_ac3_raw_bsi['dsurmod']);
  119. }
  120. $thisfile_ac3_raw_bsi['lfeon'] = (bool) $this->readHeaderBSI(1);
  121. $thisfile_ac3['lfe_enabled'] = $thisfile_ac3_raw_bsi['lfeon'];
  122. if ($thisfile_ac3_raw_bsi['lfeon']) {
  123. //$info['audio']['channels']++;
  124. $info['audio']['channels'] .= '.1';
  125. }
  126. $thisfile_ac3['channels_enabled'] = self::channelsEnabledLookup($thisfile_ac3_raw_bsi['acmod'], $thisfile_ac3_raw_bsi['lfeon']);
  127. // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31.
  128. // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent.
  129. $thisfile_ac3_raw_bsi['dialnorm'] = $this->readHeaderBSI(5);
  130. $thisfile_ac3['dialogue_normalization'] = '-'.$thisfile_ac3_raw_bsi['dialnorm'].'dB';
  131. $thisfile_ac3_raw_bsi['compre_flag'] = (bool) $this->readHeaderBSI(1);
  132. if ($thisfile_ac3_raw_bsi['compre_flag']) {
  133. $thisfile_ac3_raw_bsi['compr'] = $this->readHeaderBSI(8);
  134. $thisfile_ac3['heavy_compression'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr']);
  135. }
  136. $thisfile_ac3_raw_bsi['langcode_flag'] = (bool) $this->readHeaderBSI(1);
  137. if ($thisfile_ac3_raw_bsi['langcode_flag']) {
  138. $thisfile_ac3_raw_bsi['langcod'] = $this->readHeaderBSI(8);
  139. }
  140. $thisfile_ac3_raw_bsi['audprodie'] = (bool) $this->readHeaderBSI(1);
  141. if ($thisfile_ac3_raw_bsi['audprodie']) {
  142. $thisfile_ac3_raw_bsi['mixlevel'] = $this->readHeaderBSI(5);
  143. $thisfile_ac3_raw_bsi['roomtyp'] = $this->readHeaderBSI(2);
  144. $thisfile_ac3['mixing_level'] = (80 + $thisfile_ac3_raw_bsi['mixlevel']).'dB';
  145. $thisfile_ac3['room_type'] = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp']);
  146. }
  147. if ($thisfile_ac3_raw_bsi['acmod'] == 0x00) {
  148. // If acmod is 0, then two completely independent program channels (dual mono)
  149. // are encoded into the bit stream, and are referenced as Ch1, Ch2. In this case,
  150. // a number of additional items are present in BSI or audblk to fully describe Ch2.
  151. // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31.
  152. // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent.
  153. $thisfile_ac3_raw_bsi['dialnorm2'] = $this->readHeaderBSI(5);
  154. $thisfile_ac3['dialogue_normalization2'] = '-'.$thisfile_ac3_raw_bsi['dialnorm2'].'dB';
  155. $thisfile_ac3_raw_bsi['compre_flag2'] = (bool) $this->readHeaderBSI(1);
  156. if ($thisfile_ac3_raw_bsi['compre_flag2']) {
  157. $thisfile_ac3_raw_bsi['compr2'] = $this->readHeaderBSI(8);
  158. $thisfile_ac3['heavy_compression2'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr2']);
  159. }
  160. $thisfile_ac3_raw_bsi['langcode_flag2'] = (bool) $this->readHeaderBSI(1);
  161. if ($thisfile_ac3_raw_bsi['langcode_flag2']) {
  162. $thisfile_ac3_raw_bsi['langcod2'] = $this->readHeaderBSI(8);
  163. }
  164. $thisfile_ac3_raw_bsi['audprodie2'] = (bool) $this->readHeaderBSI(1);
  165. if ($thisfile_ac3_raw_bsi['audprodie2']) {
  166. $thisfile_ac3_raw_bsi['mixlevel2'] = $this->readHeaderBSI(5);
  167. $thisfile_ac3_raw_bsi['roomtyp2'] = $this->readHeaderBSI(2);
  168. $thisfile_ac3['mixing_level2'] = (80 + $thisfile_ac3_raw_bsi['mixlevel2']).'dB';
  169. $thisfile_ac3['room_type2'] = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp2']);
  170. }
  171. }
  172. $thisfile_ac3_raw_bsi['copyright'] = (bool) $this->readHeaderBSI(1);
  173. $thisfile_ac3_raw_bsi['original'] = (bool) $this->readHeaderBSI(1);
  174. $thisfile_ac3_raw_bsi['timecode1_flag'] = (bool) $this->readHeaderBSI(1);
  175. if ($thisfile_ac3_raw_bsi['timecode1_flag']) {
  176. $thisfile_ac3_raw_bsi['timecode1'] = $this->readHeaderBSI(14);
  177. }
  178. $thisfile_ac3_raw_bsi['timecode2_flag'] = (bool) $this->readHeaderBSI(1);
  179. if ($thisfile_ac3_raw_bsi['timecode2_flag']) {
  180. $thisfile_ac3_raw_bsi['timecode2'] = $this->readHeaderBSI(14);
  181. }
  182. $thisfile_ac3_raw_bsi['addbsi_flag'] = (bool) $this->readHeaderBSI(1);
  183. if ($thisfile_ac3_raw_bsi['addbsi_flag']) {
  184. $thisfile_ac3_raw_bsi['addbsi_length'] = $this->readHeaderBSI(6);
  185. $this->AC3header['bsi'] .= getid3_lib::BigEndian2Bin($this->fread($thisfile_ac3_raw_bsi['addbsi_length']));
  186. $thisfile_ac3_raw_bsi['addbsi_data'] = substr($this->AC3header['bsi'], $this->BSIoffset, $thisfile_ac3_raw_bsi['addbsi_length'] * 8);
  187. $this->BSIoffset += $thisfile_ac3_raw_bsi['addbsi_length'] * 8;
  188. }
  189. return true;
  190. }
  191. private function readHeaderBSI($length) {
  192. $data = substr($this->AC3header['bsi'], $this->BSIoffset, $length);
  193. $this->BSIoffset += $length;
  194. return bindec($data);
  195. }
  196. public static function sampleRateCodeLookup($fscod) {
  197. static $sampleRateCodeLookup = array(
  198. 0 => 48000,
  199. 1 => 44100,
  200. 2 => 32000,
  201. 3 => 'reserved' // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute.
  202. );
  203. return (isset($sampleRateCodeLookup[$fscod]) ? $sampleRateCodeLookup[$fscod] : false);
  204. }
  205. public static function serviceTypeLookup($bsmod, $acmod) {
  206. static $serviceTypeLookup = array();
  207. if (empty($serviceTypeLookup)) {
  208. for ($i = 0; $i <= 7; $i++) {
  209. $serviceTypeLookup[0][$i] = 'main audio service: complete main (CM)';
  210. $serviceTypeLookup[1][$i] = 'main audio service: music and effects (ME)';
  211. $serviceTypeLookup[2][$i] = 'associated service: visually impaired (VI)';
  212. $serviceTypeLookup[3][$i] = 'associated service: hearing impaired (HI)';
  213. $serviceTypeLookup[4][$i] = 'associated service: dialogue (D)';
  214. $serviceTypeLookup[5][$i] = 'associated service: commentary (C)';
  215. $serviceTypeLookup[6][$i] = 'associated service: emergency (E)';
  216. }
  217. $serviceTypeLookup[7][1] = 'associated service: voice over (VO)';
  218. for ($i = 2; $i <= 7; $i++) {
  219. $serviceTypeLookup[7][$i] = 'main audio service: karaoke';
  220. }
  221. }
  222. return (isset($serviceTypeLookup[$bsmod][$acmod]) ? $serviceTypeLookup[$bsmod][$acmod] : false);
  223. }
  224. public static function audioCodingModeLookup($acmod) {
  225. // array(channel configuration, # channels (not incl LFE), channel order)
  226. static $audioCodingModeLookup = array (
  227. 0 => array('channel_config'=>'1+1', 'num_channels'=>2, 'channel_order'=>'Ch1,Ch2'),
  228. 1 => array('channel_config'=>'1/0', 'num_channels'=>1, 'channel_order'=>'C'),
  229. 2 => array('channel_config'=>'2/0', 'num_channels'=>2, 'channel_order'=>'L,R'),
  230. 3 => array('channel_config'=>'3/0', 'num_channels'=>3, 'channel_order'=>'L,C,R'),
  231. 4 => array('channel_config'=>'2/1', 'num_channels'=>3, 'channel_order'=>'L,R,S'),
  232. 5 => array('channel_config'=>'3/1', 'num_channels'=>4, 'channel_order'=>'L,C,R,S'),
  233. 6 => array('channel_config'=>'2/2', 'num_channels'=>4, 'channel_order'=>'L,R,SL,SR'),
  234. 7 => array('channel_config'=>'3/2', 'num_channels'=>5, 'channel_order'=>'L,C,R,SL,SR'),
  235. );
  236. return (isset($audioCodingModeLookup[$acmod]) ? $audioCodingModeLookup[$acmod] : false);
  237. }
  238. public static function centerMixLevelLookup($cmixlev) {
  239. static $centerMixLevelLookup;
  240. if (empty($centerMixLevelLookup)) {
  241. $centerMixLevelLookup = array(
  242. 0 => pow(2, -3.0 / 6), // 0.707 (-3.0 dB)
  243. 1 => pow(2, -4.5 / 6), // 0.595 (-4.5 dB)
  244. 2 => pow(2, -6.0 / 6), // 0.500 (-6.0 dB)
  245. 3 => 'reserved'
  246. );
  247. }
  248. return (isset($centerMixLevelLookup[$cmixlev]) ? $centerMixLevelLookup[$cmixlev] : false);
  249. }
  250. public static function surroundMixLevelLookup($surmixlev) {
  251. static $surroundMixLevelLookup;
  252. if (empty($surroundMixLevelLookup)) {
  253. $surroundMixLevelLookup = array(
  254. 0 => pow(2, -3.0 / 6),
  255. 1 => pow(2, -6.0 / 6),
  256. 2 => 0,
  257. 3 => 'reserved'
  258. );
  259. }
  260. return (isset($surroundMixLevelLookup[$surmixlev]) ? $surroundMixLevelLookup[$surmixlev] : false);
  261. }
  262. public static function dolbySurroundModeLookup($dsurmod) {
  263. static $dolbySurroundModeLookup = array(
  264. 0 => 'not indicated',
  265. 1 => 'Not Dolby Surround encoded',
  266. 2 => 'Dolby Surround encoded',
  267. 3 => 'reserved'
  268. );
  269. return (isset($dolbySurroundModeLookup[$dsurmod]) ? $dolbySurroundModeLookup[$dsurmod] : false);
  270. }
  271. public static function channelsEnabledLookup($acmod, $lfeon) {
  272. $lookup = array(
  273. 'ch1'=>(bool) ($acmod == 0),
  274. 'ch2'=>(bool) ($acmod == 0),
  275. 'left'=>(bool) ($acmod > 1),
  276. 'right'=>(bool) ($acmod > 1),
  277. 'center'=>(bool) ($acmod & 0x01),
  278. 'surround_mono'=>false,
  279. 'surround_left'=>false,
  280. 'surround_right'=>false,
  281. 'lfe'=>$lfeon);
  282. switch ($acmod) {
  283. case 4:
  284. case 5:
  285. $lookup['surround_mono'] = true;
  286. break;
  287. case 6:
  288. case 7:
  289. $lookup['surround_left'] = true;
  290. $lookup['surround_right'] = true;
  291. break;
  292. }
  293. return $lookup;
  294. }
  295. public static function heavyCompression($compre) {
  296. // The first four bits indicate gain changes in 6.02dB increments which can be
  297. // implemented with an arithmetic shift operation. The following four bits
  298. // indicate linear gain changes, and require a 5-bit multiply.
  299. // We will represent the two 4-bit fields of compr as follows:
  300. // X0 X1 X2 X3 . Y4 Y5 Y6 Y7
  301. // The meaning of the X values is most simply described by considering X to represent a 4-bit
  302. // signed integer with values from -8 to +7. The gain indicated by X is then (X + 1) * 6.02 dB. The
  303. // following table shows this in detail.
  304. // Meaning of 4 msb of compr
  305. // 7 +48.16 dB
  306. // 6 +42.14 dB
  307. // 5 +36.12 dB
  308. // 4 +30.10 dB
  309. // 3 +24.08 dB
  310. // 2 +18.06 dB
  311. // 1 +12.04 dB
  312. // 0 +6.02 dB
  313. // -1 0 dB
  314. // -2 -6.02 dB
  315. // -3 -12.04 dB
  316. // -4 -18.06 dB
  317. // -5 -24.08 dB
  318. // -6 -30.10 dB
  319. // -7 -36.12 dB
  320. // -8 -42.14 dB
  321. $fourbit = str_pad(decbin(($compre & 0xF0) >> 4), 4, '0', STR_PAD_LEFT);
  322. if ($fourbit{0} == '1') {
  323. $log_gain = -8 + bindec(substr($fourbit, 1));
  324. } else {
  325. $log_gain = bindec(substr($fourbit, 1));
  326. }
  327. $log_gain = ($log_gain + 1) * getid3_lib::RGADamplitude2dB(2);
  328. // The value of Y is a linear representation of a gain change of up to -6 dB. Y is considered to
  329. // be an unsigned fractional integer, with a leading value of 1, or: 0.1 Y4 Y5 Y6 Y7 (base 2). Y can
  330. // represent values between 0.111112 (or 31/32) and 0.100002 (or 1/2). Thus, Y can represent gain
  331. // changes from -0.28 dB to -6.02 dB.
  332. $lin_gain = (16 + ($compre & 0x0F)) / 32;
  333. // The combination of X and Y values allows compr to indicate gain changes from
  334. // 48.16 - 0.28 = +47.89 dB, to
  335. // -42.14 - 6.02 = -48.16 dB.
  336. return $log_gain - $lin_gain;
  337. }
  338. public static function roomTypeLookup($roomtyp) {
  339. static $roomTypeLookup = array(
  340. 0 => 'not indicated',
  341. 1 => 'large room, X curve monitor',
  342. 2 => 'small room, flat monitor',
  343. 3 => 'reserved'
  344. );
  345. return (isset($roomTypeLookup[$roomtyp]) ? $roomTypeLookup[$roomtyp] : false);
  346. }
  347. public static function frameSizeLookup($frmsizecod, $fscod) {
  348. $padding = (bool) ($frmsizecod % 2);
  349. $framesizeid = floor($frmsizecod / 2);
  350. static $frameSizeLookup = array();
  351. if (empty($frameSizeLookup)) {
  352. $frameSizeLookup = array (
  353. 0 => array(128, 138, 192),
  354. 1 => array(40, 160, 174, 240),
  355. 2 => array(48, 192, 208, 288),
  356. 3 => array(56, 224, 242, 336),
  357. 4 => array(64, 256, 278, 384),
  358. 5 => array(80, 320, 348, 480),
  359. 6 => array(96, 384, 416, 576),
  360. 7 => array(112, 448, 486, 672),
  361. 8 => array(128, 512, 556, 768),
  362. 9 => array(160, 640, 696, 960),
  363. 10 => array(192, 768, 834, 1152),
  364. 11 => array(224, 896, 974, 1344),
  365. 12 => array(256, 1024, 1114, 1536),
  366. 13 => array(320, 1280, 1392, 1920),
  367. 14 => array(384, 1536, 1670, 2304),
  368. 15 => array(448, 1792, 1950, 2688),
  369. 16 => array(512, 2048, 2228, 3072),
  370. 17 => array(576, 2304, 2506, 3456),
  371. 18 => array(640, 2560, 2786, 3840)
  372. );
  373. }
  374. if (($fscod == 1) && $padding) {
  375. // frame lengths are padded by 1 word (16 bits) at 44100
  376. $frameSizeLookup[$frmsizecod] += 2;
  377. }
  378. return (isset($frameSizeLookup[$framesizeid][$fscod]) ? $frameSizeLookup[$framesizeid][$fscod] : false);
  379. }
  380. public static function bitrateLookup($frmsizecod) {
  381. $framesizeid = floor($frmsizecod / 2);
  382. static $bitrateLookup = array(
  383. 0 => 32000,
  384. 1 => 40000,
  385. 2 => 48000,
  386. 3 => 56000,
  387. 4 => 64000,
  388. 5 => 80000,
  389. 6 => 96000,
  390. 7 => 112000,
  391. 8 => 128000,
  392. 9 => 160000,
  393. 10 => 192000,
  394. 11 => 224000,
  395. 12 => 256000,
  396. 13 => 320000,
  397. 14 => 384000,
  398. 15 => 448000,
  399. 16 => 512000,
  400. 17 => 576000,
  401. 18 => 640000
  402. );
  403. return (isset($bitrateLookup[$framesizeid]) ? $bitrateLookup[$framesizeid] : false);
  404. }
  405. }