PageRenderTime 73ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/public/library/xinha/plugins/MootoolsFileManager/mootools-filemanager/Backend/Assets/getid3/module.audio-video.riff.php

https://bitbucket.org/mayorbrain/precurio-v2
PHP | 2319 lines | 1796 code | 396 blank | 127 comment | 241 complexity | 85abc053d208d778413e3168f5885d64 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, MIT
  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP version 5 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 2 of the GPL license, |
  8. // | that is bundled with this package in the file license.txt and is |
  9. // | available through the world-wide-web at the following url: |
  10. // | http://www.gnu.org/copyleft/gpl.html |
  11. // +----------------------------------------------------------------------+
  12. // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
  13. // +----------------------------------------------------------------------+
  14. // | Authors: James Heinrich <infoŘgetid3*org> |
  15. // | Allan Hansen <ahŘartemis*dk> |
  16. // +----------------------------------------------------------------------+
  17. // | module.audio-video.riff.php |
  18. // | module for analyzing RIFF files: |
  19. // | Wave, AVI, AIFF/AIFC, (MP3,AC3)/RIFF, Wavpack3, 8SVX |
  20. // | dependencies: module.audio.mp3.php (optional) |
  21. // | module.audio.ac3.php (optional) |
  22. // | module.audio.dts.php (optional) |
  23. // | module.audio-video.mpeg.php (optional) |
  24. // +----------------------------------------------------------------------+
  25. //
  26. // $Id: module.audio-video.riff.php,v 1.10 2006/12/03 20:13:17 ah Exp $
  27. class getid3_riff extends getid3_handler
  28. {
  29. private $endian_function = 'LittleEndian2Int';
  30. public function Analyze() {
  31. $getid3 = $this->getid3;
  32. $getid3->info['riff']['raw'] = array ();
  33. $info_riff = &$getid3->info['riff'];
  34. $info_riff_raw = &$info_riff['raw'];
  35. $info_audio = &$getid3->info['audio'];
  36. $info_video = &$getid3->info['video'];
  37. $info_avdataoffset = &$getid3->info['avdataoffset'];
  38. $info_avdataend = &$getid3->info['avdataend'];
  39. $info_audio_dataformat = &$info_audio['dataformat'];
  40. $info_riff_audio = &$info_riff['audio'];
  41. $info_riff_video = &$info_riff['video'];
  42. $original['avdataend'] = $info_avdataend;
  43. $this->fseek($info_avdataoffset, SEEK_SET);
  44. $riff_header = $this->fread(12);
  45. $riff_sub_type = substr($riff_header, 8, 4);
  46. switch (substr($riff_header, 0, 4)) {
  47. case 'FORM':
  48. $getid3->info['fileformat'] = 'aiff';
  49. $this->endian_function = 'BigEndian2Int';
  50. $riff_header_size = getid3_lib::BigEndian2Int(substr($riff_header, 4, 4));
  51. $info_riff[$riff_sub_type] = $this->ParseRIFF($info_avdataoffset + 12, $info_avdataoffset + $riff_header_size);
  52. $info_riff['header_size'] = $riff_header_size;
  53. break;
  54. case 'RIFF':
  55. case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com)
  56. case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s
  57. if ($riff_sub_type == 'RMP3') {
  58. $riff_sub_type = 'WAVE';
  59. }
  60. $getid3->info['fileformat'] = 'riff';
  61. $this->endian_function = 'LittleEndian2Int';
  62. $riff_header_size = getid3_lib::LittleEndian2Int(substr($riff_header, 4, 4));
  63. $info_riff[$riff_sub_type] = $this->ParseRIFF($info_avdataoffset + 12, $info_avdataoffset + $riff_header_size);
  64. $info_riff['header_size'] = $riff_header_size;
  65. if ($riff_sub_type == 'WAVE') {
  66. $info_riff_wave = &$info_riff['WAVE'];
  67. }
  68. break;
  69. default:
  70. throw new getid3_exception('Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$riff_sub_type.'" instead');
  71. }
  72. $endian_function = $this->endian_function;
  73. $stream_index = 0;
  74. switch ($riff_sub_type) {
  75. case 'WAVE':
  76. if (empty($info_audio['bitrate_mode'])) {
  77. $info_audio['bitrate_mode'] = 'cbr';
  78. }
  79. if (empty($info_audio_dataformat)) {
  80. $info_audio_dataformat = 'wav';
  81. }
  82. if (isset($info_riff_wave['data'][0]['offset'])) {
  83. $info_avdataoffset = $info_riff_wave['data'][0]['offset'] + 8;
  84. $info_avdataend = $info_avdataoffset + $info_riff_wave['data'][0]['size'];
  85. }
  86. if (isset($info_riff_wave['fmt '][0]['data'])) {
  87. $info_riff_audio[$stream_index] = getid3_riff::RIFFparseWAVEFORMATex($info_riff_wave['fmt '][0]['data']);
  88. $info_audio['wformattag'] = $info_riff_audio[$stream_index]['raw']['wFormatTag'];
  89. $info_riff_raw['fmt '] = $info_riff_audio[$stream_index]['raw'];
  90. unset($info_riff_audio[$stream_index]['raw']);
  91. $info_audio['streams'][$stream_index] = $info_riff_audio[$stream_index];
  92. $info_audio = getid3_riff::array_merge_noclobber($info_audio, $info_riff_audio[$stream_index]);
  93. if (substr($info_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') {
  94. $getid3->warning('Audio codec = '.$info_audio['codec']);
  95. }
  96. $info_audio['bitrate'] = $info_riff_audio[$stream_index]['bitrate'];
  97. $getid3->info['playtime_seconds'] = (float)((($info_avdataend - $info_avdataoffset) * 8) / $info_audio['bitrate']);
  98. $info_audio['lossless'] = false;
  99. if (isset($info_riff_wave['data'][0]['offset']) && isset($info_riff_raw['fmt ']['wFormatTag'])) {
  100. switch ($info_riff_raw['fmt ']['wFormatTag']) {
  101. case 0x0001: // PCM
  102. $info_audio['lossless'] = true;
  103. break;
  104. case 0x2000: // AC-3
  105. $info_audio_dataformat = 'ac3';
  106. break;
  107. default:
  108. // do nothing
  109. break;
  110. }
  111. }
  112. $info_audio['streams'][$stream_index]['wformattag'] = $info_audio['wformattag'];
  113. $info_audio['streams'][$stream_index]['bitrate_mode'] = $info_audio['bitrate_mode'];
  114. $info_audio['streams'][$stream_index]['lossless'] = $info_audio['lossless'];
  115. $info_audio['streams'][$stream_index]['dataformat'] = $info_audio_dataformat;
  116. }
  117. if (isset($info_riff_wave['rgad'][0]['data'])) {
  118. // shortcuts
  119. $rgadData = &$info_riff_wave['rgad'][0]['data'];
  120. $info_riff_raw['rgad'] = array ('track'=>array(), 'album'=>array());
  121. $info_riff_raw_rgad = &$info_riff_raw['rgad'];
  122. $info_riff_raw_rgad_track = &$info_riff_raw_rgad['track'];
  123. $info_riff_raw_rgad_album = &$info_riff_raw_rgad['album'];
  124. $info_riff_raw_rgad['fPeakAmplitude'] = getid3_riff::BigEndian2Float(strrev(substr($rgadData, 0, 4))); // LittleEndian2Float()
  125. $info_riff_raw_rgad['nRadioRgAdjust'] = getid3_lib::$endian_function(substr($rgadData, 4, 2));
  126. $info_riff_raw_rgad['nAudiophileRgAdjust'] = getid3_lib::$endian_function(substr($rgadData, 6, 2));
  127. $n_track_rg_adjust_bit_string = str_pad(decbin($info_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT);
  128. $n_album_rg_adjust_bit_string = str_pad(decbin($info_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT);
  129. $info_riff_raw_rgad_track['name'] = bindec(substr($n_track_rg_adjust_bit_string, 0, 3));
  130. $info_riff_raw_rgad_track['originator'] = bindec(substr($n_track_rg_adjust_bit_string, 3, 3));
  131. $info_riff_raw_rgad_track['signbit'] = bindec($n_track_rg_adjust_bit_string[6]);
  132. $info_riff_raw_rgad_track['adjustment'] = bindec(substr($n_track_rg_adjust_bit_string, 7, 9));
  133. $info_riff_raw_rgad_album['name'] = bindec(substr($n_album_rg_adjust_bit_string, 0, 3));
  134. $info_riff_raw_rgad_album['originator'] = bindec(substr($n_album_rg_adjust_bit_string, 3, 3));
  135. $info_riff_raw_rgad_album['signbit'] = bindec($n_album_rg_adjust_bit_string[6]);
  136. $info_riff_raw_rgad_album['adjustment'] = bindec(substr($n_album_rg_adjust_bit_string, 7, 9));
  137. $info_riff['rgad']['peakamplitude'] = $info_riff_raw_rgad['fPeakAmplitude'];
  138. if (($info_riff_raw_rgad_track['name'] != 0) && ($info_riff_raw_rgad_track['originator'] != 0)) {
  139. $info_riff['rgad']['track']['name'] = getid3_lib_replaygain::NameLookup($info_riff_raw_rgad_track['name']);
  140. $info_riff['rgad']['track']['originator'] = getid3_lib_replaygain::OriginatorLookup($info_riff_raw_rgad_track['originator']);
  141. $info_riff['rgad']['track']['adjustment'] = getid3_lib_replaygain::AdjustmentLookup($info_riff_raw_rgad_track['adjustment'], $info_riff_raw_rgad_track['signbit']);
  142. }
  143. if (($info_riff_raw_rgad_album['name'] != 0) && ($info_riff_raw_rgad_album['originator'] != 0)) {
  144. $info_riff['rgad']['album']['name'] = getid3_lib_replaygain::NameLookup($info_riff_raw_rgad_album['name']);
  145. $info_riff['rgad']['album']['originator'] = getid3_lib_replaygain::OriginatorLookup($info_riff_raw_rgad_album['originator']);
  146. $info_riff['rgad']['album']['adjustment'] = getid3_lib_replaygain::AdjustmentLookup($info_riff_raw_rgad_album['adjustment'], $info_riff_raw_rgad_album['signbit']);
  147. }
  148. }
  149. if (isset($info_riff_wave['fact'][0]['data'])) {
  150. $info_riff_raw['fact']['NumberOfSamples'] = getid3_lib::$endian_function(substr($info_riff_wave['fact'][0]['data'], 0, 4));
  151. // This should be a good way of calculating exact playtime, but some sample files have had incorrect number of samples, so cannot use this method
  152. // if (!empty($info_riff_raw['fmt ']['nSamplesPerSec'])) {
  153. // $getid3->info['playtime_seconds'] = (float)$info_riff_raw['fact']['NumberOfSamples'] / $info_riff_raw['fmt ']['nSamplesPerSec'];
  154. // }
  155. }
  156. if (!empty($info_riff_raw['fmt ']['nAvgBytesPerSec'])) {
  157. $info_audio['bitrate'] = (int)$info_riff_raw['fmt ']['nAvgBytesPerSec'] * 8;
  158. }
  159. if (isset($info_riff_wave['bext'][0]['data'])) {
  160. $info_riff_wave_bext_0 = &$info_riff_wave['bext'][0];
  161. getid3_lib::ReadSequence('LittleEndian2Int', $info_riff_wave_bext_0, $info_riff_wave_bext_0['data'], 0,
  162. array (
  163. 'title' => -256,
  164. 'author' => -32,
  165. 'reference' => -32,
  166. 'origin_date' => -10,
  167. 'origin_time' => -8,
  168. 'time_reference' => 8,
  169. 'bwf_version' => 1,
  170. 'reserved' => 254
  171. )
  172. );
  173. foreach (array ('title', 'author', 'reference') as $key) {
  174. $info_riff_wave_bext_0[$key] = trim($info_riff_wave_bext_0[$key]);
  175. }
  176. $info_riff_wave_bext_0['coding_history'] = explode("\r\n", trim(substr($info_riff_wave_bext_0['data'], 601)));
  177. $info_riff_wave_bext_0['origin_date_unix'] = gmmktime(substr($info_riff_wave_bext_0['origin_time'], 0, 2),
  178. substr($info_riff_wave_bext_0['origin_time'], 3, 2),
  179. substr($info_riff_wave_bext_0['origin_time'], 6, 2),
  180. substr($info_riff_wave_bext_0['origin_date'], 5, 2),
  181. substr($info_riff_wave_bext_0['origin_date'], 8, 2),
  182. substr($info_riff_wave_bext_0['origin_date'], 0, 4));
  183. $info_riff['comments']['author'][] = $info_riff_wave_bext_0['author'];
  184. $info_riff['comments']['title'][] = $info_riff_wave_bext_0['title'];
  185. }
  186. if (isset($info_riff_wave['MEXT'][0]['data'])) {
  187. $info_riff_wave_mext_0 = &$info_riff_wave['MEXT'][0];
  188. $info_riff_wave_mext_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 0, 2));
  189. $info_riff_wave_mext_0['flags']['homogenous'] = (bool)($info_riff_wave_mext_0['raw']['sound_information'] & 0x0001);
  190. if ($info_riff_wave_mext_0['flags']['homogenous']) {
  191. $info_riff_wave_mext_0['flags']['padding'] = ($info_riff_wave_mext_0['raw']['sound_information'] & 0x0002) ? false : true;
  192. $info_riff_wave_mext_0['flags']['22_or_44'] = (bool)($info_riff_wave_mext_0['raw']['sound_information'] & 0x0004);
  193. $info_riff_wave_mext_0['flags']['free_format'] = (bool)($info_riff_wave_mext_0['raw']['sound_information'] & 0x0008);
  194. $info_riff_wave_mext_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 2, 2));
  195. }
  196. $info_riff_wave_mext_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 6, 2));
  197. $info_riff_wave_mext_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 8, 2));
  198. $info_riff_wave_mext_0['flags']['anciliary_data_left'] = (bool)($info_riff_wave_mext_0['raw']['anciliary_data_def'] & 0x0001);
  199. $info_riff_wave_mext_0['flags']['anciliary_data_free'] = (bool)($info_riff_wave_mext_0['raw']['anciliary_data_def'] & 0x0002);
  200. $info_riff_wave_mext_0['flags']['anciliary_data_right'] = (bool)($info_riff_wave_mext_0['raw']['anciliary_data_def'] & 0x0004);
  201. }
  202. if (isset($info_riff_wave['cart'][0]['data'])) {
  203. $info_riff_wave_cart_0 = &$info_riff_wave['cart'][0];
  204. getid3_lib::ReadSequence('LittleEndian2Int', $info_riff_wave_cart_0, $info_riff_wave_cart_0['data'], 0,
  205. array (
  206. 'version' => -4,
  207. 'title' => -64,
  208. 'artist' => -64,
  209. 'cut_id' => -64,
  210. 'client_id' => -64,
  211. 'category' => -64,
  212. 'classification' => -64,
  213. 'out_cue' => -64,
  214. 'start_date' => -10,
  215. 'start_time' => -8,
  216. 'end_date' => -10,
  217. 'end_time' => -8,
  218. 'producer_app_id' => -64,
  219. 'producer_app_version' => -64,
  220. 'user_defined_text' => -64,
  221. )
  222. );
  223. foreach (array ('artist', 'cut_id', 'client_id', 'category', 'classification', 'out_cue', 'start_date', 'start_time', 'end_date', 'end_time', 'producer_app_id', 'producer_app_version', 'user_defined_text') as $key) {
  224. $info_riff_wave_cart_0[$key] = trim($info_riff_wave_cart_0[$key]);
  225. }
  226. $info_riff_wave_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_cart_0['data'], 680, 4), true);
  227. for ($i = 0; $i < 8; $i++) {
  228. $info_riff_wave_cart_0['post_time'][$i]['usage_fourcc'] = substr($info_riff_wave_cart_0['data'], 684 + ($i * 8), 4);
  229. $info_riff_wave_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_cart_0['data'], 684 + ($i * 8) + 4, 4));
  230. }
  231. $info_riff_wave_cart_0['url'] = trim(substr($info_riff_wave_cart_0['data'], 748, 1024));
  232. $info_riff_wave_cart_0['tag_text'] = explode("\r\n", trim(substr($info_riff_wave_cart_0['data'], 1772)));
  233. $info_riff['comments']['artist'][] = $info_riff_wave_cart_0['artist'];
  234. $info_riff['comments']['title'][] = $info_riff_wave_cart_0['title'];
  235. }
  236. if (!isset($info_audio['bitrate']) && isset($info_riff_audio[$stream_index]['bitrate'])) {
  237. $info_audio['bitrate'] = $info_riff_audio[$stream_index]['bitrate'];
  238. $getid3->info['playtime_seconds'] = (float)((($info_avdataend - $info_avdataoffset) * 8) / $info_audio['bitrate']);
  239. }
  240. if (@$getid3->info['wavpack']) {
  241. if (!$this->data_string_flag) {
  242. $info_audio_dataformat = 'wavpack';
  243. $info_audio['bitrate_mode'] = 'vbr';
  244. $info_audio['encoder'] = 'WavPack v'.$getid3->info['wavpack']['version'];
  245. // Reset to the way it was - RIFF parsing will have messed this up
  246. $info_avdataend = $original['avdataend'];
  247. $info_audio['bitrate'] = (($info_avdataend - $info_avdataoffset) * 8) / $getid3->info['playtime_seconds'];
  248. $this->fseek($info_avdataoffset - 44, SEEK_SET);
  249. $riff_data = $this->fread(44);
  250. $orignal_riff_header_size = getid3_lib::LittleEndian2Int(substr($riff_data, 4, 4)) + 8;
  251. $orignal_riff_data_size = getid3_lib::LittleEndian2Int(substr($riff_data, 40, 4)) + 44;
  252. if ($orignal_riff_header_size > $orignal_riff_data_size) {
  253. $info_avdataend -= ($orignal_riff_header_size - $orignal_riff_data_size);
  254. $this->fseek($info_avdataend, SEEK_SET);
  255. $riff_data .= $this->fread($orignal_riff_header_size - $orignal_riff_data_size);
  256. }
  257. // move the data chunk after all other chunks (if any)
  258. // so that the RIFF parser doesn't see EOF when trying
  259. // to skip over the data chunk
  260. $riff_data = substr($riff_data, 0, 36).substr($riff_data, 44).substr($riff_data, 36, 8);
  261. // Save audio info key
  262. $saved_info_audio = $info_audio;
  263. // Analyze riff_data
  264. $this->AnalyzeString($riff_data);
  265. // Restore info key
  266. $info_audio = $saved_info_audio;
  267. }
  268. }
  269. if (isset($info_riff_raw['fmt ']['wFormatTag'])) {
  270. switch ($info_riff_raw['fmt ']['wFormatTag']) {
  271. case 0x08AE: // ClearJump LiteWave
  272. $info_audio['bitrate_mode'] = 'vbr';
  273. $info_audio_dataformat = 'litewave';
  274. //typedef struct tagSLwFormat {
  275. // WORD m_wCompFormat; // low byte defines compression method, high byte is compression flags
  276. // DWORD m_dwScale; // scale factor for lossy compression
  277. // DWORD m_dwBlockSize; // number of samples in encoded blocks
  278. // WORD m_wQuality; // alias for the scale factor
  279. // WORD m_wMarkDistance; // distance between marks in bytes
  280. // WORD m_wReserved;
  281. //
  282. // //following paramters are ignored if CF_FILESRC is not set
  283. // DWORD m_dwOrgSize; // original file size in bytes
  284. // WORD m_bFactExists; // indicates if 'fact' chunk exists in the original file
  285. // DWORD m_dwRiffChunkSize; // riff chunk size in the original file
  286. //
  287. // PCMWAVEFORMAT m_OrgWf; // original wave format
  288. // }SLwFormat, *PSLwFormat;
  289. $info_riff['litewave']['raw'] = array ();
  290. $info_riff_litewave = &$info_riff['litewave'];
  291. $info_riff_litewave_raw = &$info_riff_litewave['raw'];
  292. getid3_lib::ReadSequence('LittleEndian2Int', $info_riff_litewave_raw, $info_riff_wave['fmt '][0]['data'], 18,
  293. array (
  294. 'compression_method' => 1,
  295. 'compression_flags' => 1,
  296. 'm_dwScale' => 4,
  297. 'm_dwBlockSize' => 4,
  298. 'm_wQuality' => 2,
  299. 'm_wMarkDistance' => 2,
  300. 'm_wReserved' => 2,
  301. 'm_dwOrgSize' => 4,
  302. 'm_bFactExists' => 2,
  303. 'm_dwRiffChunkSize' => 4
  304. )
  305. );
  306. //$info_riff_litewave['quality_factor'] = intval(round((2000 - $info_riff_litewave_raw['m_dwScale']) / 20));
  307. $info_riff_litewave['quality_factor'] = $info_riff_litewave_raw['m_wQuality'];
  308. $info_riff_litewave['flags']['raw_source'] = ($info_riff_litewave_raw['compression_flags'] & 0x01) ? false : true;
  309. $info_riff_litewave['flags']['vbr_blocksize'] = ($info_riff_litewave_raw['compression_flags'] & 0x02) ? false : true;
  310. $info_riff_litewave['flags']['seekpoints'] = (bool)($info_riff_litewave_raw['compression_flags'] & 0x04);
  311. $info_audio['lossless'] = (($info_riff_litewave_raw['m_wQuality'] == 100) ? true : false);
  312. $info_audio['encoder_options'] = '-q'.$info_riff_litewave['quality_factor'];
  313. break;
  314. }
  315. }
  316. if ($info_avdataend > $getid3->info['filesize']) {
  317. switch (@$info_audio_dataformat) {
  318. case 'wavpack': // WavPack
  319. case 'lpac': // LPAC
  320. case 'ofr': // OptimFROG
  321. case 'ofs': // OptimFROG DualStream
  322. // lossless compressed audio formats that keep original RIFF headers - skip warning
  323. break;
  324. case 'litewave':
  325. if (($info_avdataend - $getid3->info['filesize']) == 1) {
  326. // LiteWave appears to incorrectly *not* pad actual output file
  327. // to nearest WORD boundary so may appear to be short by one
  328. // byte, in which case - skip warning
  329. } else {
  330. // Short by more than one byte, throw warning
  331. $getid3->warning('Probably truncated file - expecting '.$info_riff[$riff_sub_type]['data'][0]['size'].' bytes of data, only found '.($getid3->info['filesize'] - $info_avdataoffset).' (short by '.($info_riff[$riff_sub_type]['data'][0]['size'] - ($getid3->info['filesize'] - $info_avdataoffset)).' bytes)');
  332. }
  333. break;
  334. default:
  335. if ((($info_avdataend - $getid3->info['filesize']) == 1) && (($info_riff[$riff_sub_type]['data'][0]['size'] % 2) == 0) && ((($getid3->info['filesize'] - $info_avdataoffset) % 2) == 1)) {
  336. // output file appears to be incorrectly *not* padded to nearest WORD boundary
  337. // Output less severe warning
  338. $getid3->warning('File should probably be padded to nearest WORD boundary, but it is not (expecting '.$info_riff[$riff_sub_type]['data'][0]['size'].' bytes of data, only found '.($getid3->info['filesize'] - $info_avdataoffset).' therefore short by '.($info_riff[$riff_sub_type]['data'][0]['size'] - ($getid3->info['filesize'] - $info_avdataoffset)).' bytes)');
  339. $info_avdataend = $getid3->info['filesize'];
  340. break;
  341. }
  342. // Short by more than one byte, throw warning
  343. $getid3->warning('Probably truncated file - expecting '.$info_riff[$riff_sub_type]['data'][0]['size'].' bytes of data, only found '.($getid3->info['filesize'] - $info_avdataoffset).' (short by '.($info_riff[$riff_sub_type]['data'][0]['size'] - ($getid3->info['filesize'] - $info_avdataoffset)).' bytes)');
  344. $info_avdataend = $getid3->info['filesize'];
  345. break;
  346. }
  347. }
  348. if (!empty($getid3->info['mpeg']['audio']['LAME']['audio_bytes'])) {
  349. if ((($info_avdataend - $info_avdataoffset) - $getid3->info['mpeg']['audio']['LAME']['audio_bytes']) == 1) {
  350. $info_avdataend--;
  351. $getid3->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored');
  352. }
  353. }
  354. if (@$info_audio_dataformat == 'ac3') {
  355. unset($info_audio['bits_per_sample']);
  356. if (!empty($getid3->info['ac3']['bitrate']) && ($getid3->info['ac3']['bitrate'] != $info_audio['bitrate'])) {
  357. $info_audio['bitrate'] = $getid3->info['ac3']['bitrate'];
  358. }
  359. }
  360. break;
  361. case 'AVI ':
  362. $info_video['bitrate_mode'] = 'vbr'; // maybe not, but probably
  363. $info_video['dataformat'] = 'avi';
  364. $getid3->info['mime_type'] = 'video/avi';
  365. if (isset($info_riff[$riff_sub_type]['movi']['offset'])) {
  366. $info_avdataoffset = $info_riff[$riff_sub_type]['movi']['offset'] + 8;
  367. $info_avdataend = $info_avdataoffset + $info_riff[$riff_sub_type]['movi']['size'];
  368. if ($info_avdataend > $getid3->info['filesize']) {
  369. $getid3->warning('Probably truncated file - expecting '.$info_riff[$riff_sub_type]['movi']['size'].' bytes of data, only found '.($getid3->info['filesize'] - $info_avdataoffset).' (short by '.($info_riff[$riff_sub_type]['movi']['size'] - ($getid3->info['filesize'] - $info_avdataoffset)).' bytes)');
  370. $info_avdataend = $getid3->info['filesize'];
  371. }
  372. }
  373. if (isset($info_riff['AVI ']['hdrl']['avih'][$stream_index]['data'])) {
  374. $avihData = $info_riff['AVI ']['hdrl']['avih'][$stream_index]['data'];
  375. $info_riff_raw['avih'] = array ();
  376. $info_riff_raw_avih = &$info_riff_raw['avih'];
  377. getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_avih, $avihData, 0,
  378. array (
  379. 'dwMicroSecPerFrame' => 4, // frame display rate (or 0L)
  380. 'dwMaxBytesPerSec' => 4, // max. transfer rate
  381. 'dwPaddingGranularity' => 4, // pad to multiples of this size; normally 2K.
  382. 'dwFlags' => 4, // the ever-present flags
  383. 'dwTotalFrames' => 4, // # frames in file
  384. 'dwInitialFrames' => 4,
  385. 'dwStreams' => 4,
  386. 'dwSuggestedBufferSize' => 4,
  387. 'dwWidth' => 4,
  388. 'dwHeight' => 4,
  389. 'dwScale' => 4,
  390. 'dwRate' => 4,
  391. 'dwStart' => 4,
  392. 'dwLength' => 4
  393. )
  394. );
  395. $info_riff_raw_avih['flags']['hasindex'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00000010);
  396. $info_riff_raw_avih['flags']['mustuseindex'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00000020);
  397. $info_riff_raw_avih['flags']['interleaved'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00000100);
  398. $info_riff_raw_avih['flags']['trustcktype'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00000800);
  399. $info_riff_raw_avih['flags']['capturedfile'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00010000);
  400. $info_riff_raw_avih['flags']['copyrighted'] = (bool)($info_riff_raw_avih['dwFlags'] & 0x00020010);
  401. $info_riff_video[$stream_index] = array ();
  402. $info_riff_video_current = &$info_riff_video[$stream_index];
  403. if ($info_riff_raw_avih['dwWidth'] > 0) {
  404. $info_riff_video_current['frame_width'] = $info_riff_raw_avih['dwWidth'];
  405. $info_video['resolution_x'] = $info_riff_video_current['frame_width'];
  406. }
  407. if ($info_riff_raw_avih['dwHeight'] > 0) {
  408. $info_riff_video_current['frame_height'] = $info_riff_raw_avih['dwHeight'];
  409. $info_video['resolution_y'] = $info_riff_video_current['frame_height'];
  410. }
  411. if ($info_riff_raw_avih['dwTotalFrames'] > 0) {
  412. $info_riff_video_current['total_frames'] = $info_riff_raw_avih['dwTotalFrames'];
  413. $info_video['total_frames'] = $info_riff_video_current['total_frames'];
  414. }
  415. $info_riff_video_current['frame_rate'] = round(1000000 / $info_riff_raw_avih['dwMicroSecPerFrame'], 3);
  416. $info_video['frame_rate'] = $info_riff_video_current['frame_rate'];
  417. }
  418. if (isset($info_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) {
  419. if (is_array($info_riff['AVI ']['hdrl']['strl']['strh'])) {
  420. for ($i = 0; $i < count($info_riff['AVI ']['hdrl']['strl']['strh']); $i++) {
  421. if (isset($info_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) {
  422. $strh_data = $info_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'];
  423. $strh_fcc_type = substr($strh_data, 0, 4);
  424. if (isset($info_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) {
  425. $strf_data = $info_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'];
  426. // shortcut
  427. $info_riff_raw_strf_strh_fcc_type_stream_index = &$info_riff_raw['strf'][$strh_fcc_type][$stream_index];
  428. switch ($strh_fcc_type) {
  429. case 'auds':
  430. $info_audio['bitrate_mode'] = 'cbr';
  431. $info_audio_dataformat = 'wav';
  432. if (isset($info_riff_audio) && is_array($info_riff_audio)) {
  433. $stream_index = count($info_riff_audio);
  434. }
  435. $info_riff_audio[$stream_index] = getid3_riff::RIFFparseWAVEFORMATex($strf_data);
  436. $info_audio['wformattag'] = $info_riff_audio[$stream_index]['raw']['wFormatTag'];
  437. // shortcut
  438. $info_audio['streams'][$stream_index] = $info_riff_audio[$stream_index];
  439. $info_audio_streams_currentstream = &$info_audio['streams'][$stream_index];
  440. if (@$info_audio_streams_currentstream['bits_per_sample'] === 0) {
  441. unset($info_audio_streams_currentstream['bits_per_sample']);
  442. }
  443. $info_audio_streams_currentstream['wformattag'] = $info_audio_streams_currentstream['raw']['wFormatTag'];
  444. unset($info_audio_streams_currentstream['raw']);
  445. // shortcut
  446. $info_riff_raw['strf'][$strh_fcc_type][$stream_index] = $info_riff_audio[$stream_index]['raw'];
  447. unset($info_riff_audio[$stream_index]['raw']);
  448. $info_audio = getid3_riff::array_merge_noclobber($info_audio, $info_riff_audio[$stream_index]);
  449. $info_audio['lossless'] = false;
  450. switch ($info_riff_raw_strf_strh_fcc_type_stream_index['wFormatTag']) {
  451. case 0x0001: // PCM
  452. $info_audio_dataformat = 'wav';
  453. $info_audio['lossless'] = true;
  454. break;
  455. case 0x0050: // MPEG Layer 2 or Layer 1
  456. $info_audio_dataformat = 'mp2'; // Assume Layer-2
  457. break;
  458. case 0x0055: // MPEG Layer 3
  459. $info_audio_dataformat = 'mp3';
  460. break;
  461. case 0x00FF: // AAC
  462. $info_audio_dataformat = 'aac';
  463. break;
  464. case 0x0161: // Windows Media v7 / v8 / v9
  465. case 0x0162: // Windows Media Professional v9
  466. case 0x0163: // Windows Media Lossess v9
  467. $info_audio_dataformat = 'wma';
  468. break;
  469. case 0x2000: // AC-3
  470. $info_audio_dataformat = 'ac3';
  471. break;
  472. case 0x2001: // DTS
  473. $info_audio_dataformat = 'dts';
  474. break;
  475. default:
  476. $info_audio_dataformat = 'wav';
  477. break;
  478. }
  479. $info_audio_streams_currentstream['dataformat'] = $info_audio_dataformat;
  480. $info_audio_streams_currentstream['lossless'] = $info_audio['lossless'];
  481. $info_audio_streams_currentstream['bitrate_mode'] = $info_audio['bitrate_mode'];
  482. break;
  483. case 'iavs':
  484. case 'vids':
  485. // shortcut
  486. $info_riff_raw['strh'][$i] = array ();
  487. $info_riff_raw_strh_current = &$info_riff_raw['strh'][$i];
  488. getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_strh_current, $strh_data, 0,
  489. array (
  490. 'fccType' => -4, // same as $strh_fcc_type;
  491. 'fccHandler' => -4,
  492. 'dwFlags' => 4, // Contains AVITF_* flags
  493. 'wPriority' => 2,
  494. 'wLanguage' => 2,
  495. 'dwInitialFrames' => 4,
  496. 'dwScale' => 4,
  497. 'dwRate' => 4,
  498. 'dwStart' => 4,
  499. 'dwLength' => 4,
  500. 'dwSuggestedBufferSize' => 4,
  501. 'dwQuality' => 4,
  502. 'dwSampleSize' => 4,
  503. 'rcFrame' => 4
  504. )
  505. );
  506. $info_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($info_riff_raw_strh_current['fccHandler']);
  507. $info_video['fourcc'] = $info_riff_raw_strh_current['fccHandler'];
  508. if (!$info_riff_video_current['codec'] && isset($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']) && getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc'])) {
  509. $info_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']);
  510. $info_video['fourcc'] = $info_riff_raw_strf_strh_fcc_type_stream_index['fourcc'];
  511. }
  512. $info_video['codec'] = $info_riff_video_current['codec'];
  513. $info_video['pixel_aspect_ratio'] = (float)1;
  514. switch ($info_riff_raw_strh_current['fccHandler']) {
  515. case 'HFYU': // Huffman Lossless Codec
  516. case 'IRAW': // Intel YUV Uncompressed
  517. case 'YUY2': // Uncompressed YUV 4:2:2
  518. $info_video['lossless'] = true;
  519. break;
  520. default:
  521. $info_video['lossless'] = false;
  522. break;
  523. }
  524. switch ($strh_fcc_type) {
  525. case 'vids':
  526. getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_strf_strh_fcc_type_stream_index, $strf_data, 0,
  527. array (
  528. 'biSize' => 4, // number of bytes required by the BITMAPINFOHEADER structure
  529. 'biWidth' => 4, // width of the bitmap in pixels
  530. 'biHeight' => 4, // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner
  531. 'biPlanes' => 2, // number of color planes on the target device. In most cases this value must be set to 1
  532. 'biBitCount' => 2, // Specifies the number of bits per pixels
  533. 'fourcc' => -4, //
  534. 'biSizeImage' => 4, // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures)
  535. 'biXPelsPerMeter' => 4, // horizontal resolution, in pixels per metre, of the target device
  536. 'biYPelsPerMeter' => 4, // vertical resolution, in pixels per metre, of the target device
  537. 'biClrUsed' => 4, // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression
  538. 'biClrImportant' => 4 // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
  539. )
  540. );
  541. $info_video['bits_per_sample'] = $info_riff_raw_strf_strh_fcc_type_stream_index['biBitCount'];
  542. if ($info_riff_video_current['codec'] == 'DV') {
  543. $info_riff_video_current['dv_type'] = 2;
  544. }
  545. break;
  546. case 'iavs':
  547. $info_riff_video_current['dv_type'] = 1;
  548. break;
  549. }
  550. break;
  551. default:
  552. $getid3->warning('Unhandled fccType for stream ('.$i.'): "'.$strh_fcc_type.'"');
  553. break;
  554. }
  555. }
  556. }
  557. if (isset($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']) && getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc'])) {
  558. $info_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']);
  559. $info_video['codec'] = $info_riff_video_current['codec'];
  560. $info_video['fourcc'] = $info_riff_raw_strf_strh_fcc_type_stream_index['fourcc'];
  561. switch ($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']) {
  562. case 'HFYU': // Huffman Lossless Codec
  563. case 'IRAW': // Intel YUV Uncompressed
  564. case 'YUY2': // Uncompressed YUV 4:2:2
  565. $info_video['lossless'] = true;
  566. $info_video['bits_per_sample'] = 24;
  567. break;
  568. default:
  569. $info_video['lossless'] = false;
  570. $info_video['bits_per_sample'] = 24;
  571. break;
  572. }
  573. }
  574. }
  575. }
  576. }
  577. break;
  578. case 'CDDA':
  579. $info_audio['bitrate_mode'] = 'cbr';
  580. $info_audio_dataformat = 'cda';
  581. $info_audio['lossless'] = true;
  582. unset($getid3->info['mime_type']);
  583. $info_avdataoffset = 44;
  584. if (isset($info_riff['CDDA']['fmt '][0]['data'])) {
  585. $info_riff_cdda_fmt_0 = &$info_riff['CDDA']['fmt '][0];
  586. getid3_lib::ReadSequence($this->endian_function, $info_riff_cdda_fmt_0, $info_riff_cdda_fmt_0['data'], 0,
  587. array (
  588. 'unknown1' => 2,
  589. 'track_num' => 2,
  590. 'disc_id' => 4,
  591. 'start_offset_frame' => 4,
  592. 'playtime_frames' => 4,
  593. 'unknown6' => 4,
  594. 'unknown7' => 4
  595. )
  596. );
  597. $info_riff_cdda_fmt_0['start_offset_seconds'] = (float)$info_riff_cdda_fmt_0['start_offset_frame'] / 75;
  598. $info_riff_cdda_fmt_0['playtime_seconds'] = (float)$info_riff_cdda_fmt_0['playtime_frames'] / 75;
  599. $getid3->info['comments']['track'] = $info_riff_cdda_fmt_0['track_num'];
  600. $getid3->info['playtime_seconds'] = $info_riff_cdda_fmt_0['playtime_seconds'];
  601. // hardcoded data for CD-audio
  602. $info_audio['sample_rate'] = 44100;
  603. $info_audio['channels'] = 2;
  604. $info_audio['bits_per_sample'] = 16;
  605. $info_audio['bitrate'] = $info_audio['sample_rate'] * $info_audio['channels'] * $info_audio['bits_per_sample'];
  606. $info_audio['bitrate_mode'] = 'cbr';
  607. }
  608. break;
  609. case 'AIFF':
  610. case 'AIFC':
  611. $info_audio['bitrate_mode'] = 'cbr';
  612. $info_audio_dataformat = 'aiff';
  613. $info_audio['lossless'] = true;
  614. $getid3->info['mime_type'] = 'audio/x-aiff';
  615. if (isset($info_riff[$riff_sub_type]['SSND'][0]['offset'])) {
  616. $info_avdataoffset = $info_riff[$riff_sub_type]['SSND'][0]['offset'] + 8;
  617. $info_avdataend = $info_avdataoffset + $info_riff[$riff_sub_type]['SSND'][0]['size'];
  618. if ($info_avdataend > $getid3->info['filesize']) {
  619. if (($info_avdataend == ($getid3->info['filesize'] + 1)) && (($getid3->info['filesize'] % 2) == 1)) {
  620. // structures rounded to 2-byte boundary, but dumb encoders
  621. // forget to pad end of file to make this actually work
  622. } else {
  623. $getid3->warning('Probable truncated AIFF file: expecting '.$info_riff[$riff_sub_type]['SSND'][0]['size'].' bytes of audio data, only '.($getid3->info['filesize'] - $info_avdataoffset).' bytes found');
  624. }
  625. $info_avdataend = $getid3->info['filesize'];
  626. }
  627. }
  628. if (isset($info_riff[$riff_sub_type]['COMM'][0]['data'])) {
  629. // shortcut
  630. $info_riff_RIFFsubtype_COMM_0_data = &$info_riff[$riff_sub_type]['COMM'][0]['data'];
  631. $info_riff_audio['channels'] = getid3_lib::BigEndianSyncSafe2Int(substr($info_riff_RIFFsubtype_COMM_0_data, 0, 2));
  632. $info_riff_audio['total_samples'] = getid3_lib::BigEndian2Int( substr($info_riff_RIFFsubtype_COMM_0_data, 2, 4));
  633. $info_riff_audio['bits_per_sample'] = getid3_lib::BigEndianSyncSafe2Int(substr($info_riff_RIFFsubtype_COMM_0_data, 6, 2));
  634. $info_riff_audio['sample_rate'] = (int)getid3_riff::BigEndian2Float(substr($info_riff_RIFFsubtype_COMM_0_data, 8, 10));
  635. if ($info_riff[$riff_sub_type]['COMM'][0]['size'] > 18) {
  636. $info_riff_audio['codec_fourcc'] = substr($info_riff_RIFFsubtype_COMM_0_data, 18, 4);
  637. $codec_name_size = getid3_lib::BigEndian2Int(substr($info_riff_RIFFsubtype_COMM_0_data, 22, 1));
  638. $info_riff_audio['codec_name'] = substr($info_riff_RIFFsubtype_COMM_0_data, 23, $codec_name_size);
  639. switch ($info_riff_audio['codec_name']) {
  640. case 'NONE':
  641. $info_audio['codec'] = 'Pulse Code Modulation (PCM)';
  642. $info_audio['lossless'] = true;
  643. break;
  644. case '':
  645. switch ($info_riff_audio['codec_fourcc']) {
  646. // http://developer.apple.com/qa/snd/snd07.html
  647. case 'sowt':
  648. $info_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM';
  649. $info_audio['lossless'] = true;
  650. break;
  651. case 'twos':
  652. $info_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM';
  653. $info_audio['lossless'] = true;
  654. break;
  655. default:
  656. break;
  657. }
  658. break;
  659. default:
  660. $info_audio['codec'] = $info_riff_audio['codec_name'];
  661. $info_audio['lossless'] = false;
  662. break;
  663. }
  664. }
  665. $info_audio['channels'] = $info_riff_audio['channels'];
  666. if ($info_riff_audio['bits_per_sample'] > 0) {
  667. $info_audio['bits_per_sample'] = $info_riff_audio['bits_per_sample'];
  668. }
  669. $info_audio['sample_rate'] = $info_riff_audio['sample_rate'];
  670. $getid3->info['playtime_seconds'] = $info_riff_audio['total_samples'] / $info_audio['sample_rate'];
  671. }
  672. if (isset($info_riff[$riff_sub_type]['COMT'])) {
  673. $comment_count = getid3_lib::BigEndian2Int(substr($info_riff[$riff_sub_type]['COMT'][0]['data'], 0, 2));
  674. $offset = 2;
  675. for ($i = 0; $i < $comment_count; $i++) {
  676. $getid3->info['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int( substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 4));
  677. $offset += 4;
  678. $getid3->info['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndianSyncSafe2Int(substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 2));
  679. $offset += 2;
  680. $comment_length = getid3_lib::BigEndian2Int( substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 2));
  681. $offset += 2;
  682. $getid3->info['comments_raw'][$i]['comment'] = substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, $comment_length);
  683. $offset += $comment_length;
  684. $getid3->info['comments_raw'][$i]['timestamp_unix'] = getid3_riff::DateMac2Unix($getid3->info['comments_raw'][$i]['timestamp']);
  685. $info_riff['comments']['comment'][] = $getid3->info['comments_raw'][$i]['comment'];
  686. }
  687. }
  688. foreach (array ('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment') as $key => $value) {
  689. if (isset($info_riff[$riff_sub_type][$key][0]['data'])) {
  690. $info_riff['comments'][$value][] = $info_riff[$riff_sub_type][$key][0]['data'];
  691. }
  692. }
  693. break;
  694. case '8SVX':
  695. $info_audio['bitrate_mode'] = 'cbr';
  696. $info_audio_dataformat = '8svx';
  697. $info_audio['bits_per_sample'] = 8;
  698. $info_audio['channels'] = 1; // overridden below, if need be
  699. $getid3->info['mime_type'] = 'audio/x-aiff';
  700. if (isset($info_riff[$riff_sub_type]['BODY'][0]['offset'])) {
  701. $info_avdataoffset = $info_riff[$riff_sub_type]['BODY'][0]['offset'] + 8;
  702. $info_avdataend = $info_avdataoffset + $info_riff[$riff_sub_type]['BODY'][0]['size'];
  703. if ($info_avdataend > $getid3->info['filesize']) {
  704. $getid3->warning('Probable truncated AIFF file: expecting '.$info_riff[$riff_sub_type]['BODY'][0]['size'].' bytes of audio data, only '.($getid3->info['filesize'] - $info_avdataoffset).' bytes found');
  705. }
  706. }
  707. if (isset($info_riff[$riff_sub_type]['VHDR'][0]['offset'])) {
  708. // shortcut
  709. $info_riff_riff_sub_type_vhdr_0 = &$info_riff[$riff_sub_type]['VHDR'][0];
  710. getid3_lib::ReadSequence('BigEndian2Int', $info_riff_riff_sub_type_vhdr_0, $info_riff_riff_sub_type_vhdr_0['data'], 0,
  711. array (
  712. 'oneShotHiSamples' => 4,
  713. 'repeatHiSamples' => 4,
  714. 'samplesPerHiCycle' => 4,
  715. 'samplesPerSec' => 2,
  716. 'ctOctave' => 1,
  717. 'sCompression' => 1,
  718. 'Volume' => -4
  719. )
  720. );
  721. $info_riff_riff_sub_type_vhdr_0['Volume'] = getid3_riff::FixedPoint16_16($info_riff_riff_sub_type_vhdr_0['Volume']);
  722. $info_audio['sample_rate'] = $info_riff_riff_sub_type_vhdr_0['samplesPerSec'];
  723. switch ($info_riff_riff_sub_type_vhdr_0['sCompression']) {
  724. case 0:
  725. $info_audio['codec'] = 'Pulse Code Modulation (PCM)';
  726. $info_audio['lossless'] = true;
  727. $actual_bits_per_sample = 8;
  728. break;
  729. case 1:
  730. $info_audio['codec'] = 'Fibonacci-delta encoding';
  731. $info_audio['lossless'] = false;
  732. $actual_bits_per_sample = 4;
  733. break;
  734. default:
  735. $getid3->warning('Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"');
  736. break;
  737. }
  738. }
  739. if (isset($info_riff[$riff_sub_type]['CHAN'][0]['data'])) {
  740. $ChannelsIndex = getid3_lib::BigEndian2Int(substr($info_riff[$riff_sub_type]['CHAN'][0]['data'], 0, 4));
  741. switch ($ChannelsIndex) {
  742. case 6: // Stereo
  743. $info_audio['channels'] = 2;
  744. break;
  745. case 2: // Left channel only
  746. case 4: // Right channel only
  747. $info_audio['channels'] = 1;
  748. break;
  749. default:
  750. $getid3->warning('Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"');
  751. break;
  752. }
  753. }
  754. foreach (array ('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment') as $key => $value) {
  755. if (isset($info_riff[$riff_sub_type][$key][0]['data'])) {
  756. $info_riff['comments'][$value][] = $info_riff[$riff_sub_type][$key][0]['data'];
  757. }
  758. }
  759. $info_audio['bitrate'] = $info_audio['sample_rate'] * $actual_bits_per_sample * $info_audio['channels'];
  760. if (!empty($info_audio['bitrate'])) {
  761. $getid3->info['playtime_seconds'] = ($info_avdataend - $info_avdataoffset) / ($info_audio['bitrate'] / 8);
  762. }
  763. break;
  764. case 'CDXA':
  765. $getid3->info['mime_type'] = 'video/mpeg';
  766. if (!empty($info_riff['CDXA']['data'][0]['size'])) {
  767. $GETID3_ERRORARRAY = &$getid3->info['warning'];
  768. if (!$getid3->include_module_optional('audio-video.mpeg')) {
  769. $getid3->warning('MPEG skipped because mpeg module is missing.');
  770. }
  771. else {
  772. // Clone getid3 - messing with offsets - better safe than sorry
  773. $clone = clone $getid3;
  774. // Analyse
  775. $mpeg = new getid3_mpeg($clone);
  776. $mpeg->Analyze();
  777. // Import from clone and destroy
  778. $getid3->info['audio'] = $clone->info['audio'];
  779. $getid3->info['video'] = $clone->info['video'];
  780. $getid3->info['mpeg'] = $clone->info['mpeg'];
  781. $getid3->info['warning'] = $clone->info['warning'];
  782. unset($clone);
  783. }
  784. }
  785. break;
  786. default:
  787. throw new getid3_exception('Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA), found "'.$riff_sub_type.'" instead');
  788. }
  789. if (@$info_riff_raw['fmt ']['wFormatTag'] == 1) {
  790. // http://www.mega-nerd.com/erikd/Blog/Windiots/dts.html
  791. $this->fseek($getid3->info['avdataoffset'], SEEK_SET);
  792. $bytes4 = $this->fread(4);
  793. // DTSWAV
  794. if (preg_match('/^\xFF\x1F\x00\xE8/s', $bytes4)) {
  795. $info_audio_dataformat = 'dts';
  796. }
  797. // DTS, but this probably shouldn't happen
  798. elseif (preg_match('/^\x7F\xFF\x80\x01/s', $bytes4)) {
  799. $info_audio_dataformat = 'dts';
  800. }
  801. }
  802. if (@is_array($info_riff_wave['DISP'])) {
  803. $info_riff['comments']['title'][] = trim(substr($info_riff_wave['DISP'][count($info_riff_wave['DISP']) - 1]['data'], 4));
  804. }
  805. if (@is_array($info_riff_wave['INFO'])) {
  806. getid3_riff::RIFFCommentsParse($info_riff_wave['INFO'], $info_riff['comments']);
  807. }
  808. if (isset($info_riff_wave['INFO']) && is_array($info_riff_wave['INFO'])) {
  809. foreach (array ('IARL' => 'archivallocation', 'IART' => 'artist', 'ICDS' => 'costumedesigner', 'ICMS' => 'commissionedby', 'ICMT' => 'comment', 'ICNT' => 'country', 'ICOP' => 'copyright', 'ICRD' => 'creationdate', 'IDIM' => 'dimensions', 'IDIT' => 'digitizationdate', 'IDPI' => 'resolution', 'IDST' => 'distributor', 'IEDT' => 'editor', 'IENG' => 'engineers', 'IFRM' => 'accountofparts', 'IGNR' => 'genre', 'IKEY' => 'keywords', 'ILGT' => 'lightness', 'ILNG' => 'language', 'IMED' => 'orignalmedium', 'IMUS' => 'composer', 'INAM' => 'title', 'IPDS' => 'productiondesigner', 'IPLT' => 'palette', 'IPRD' => 'product', 'IPRO' => 'producer', 'IPRT' => 'part', 'IRTD' => 'rating', 'ISBJ' => 'subject', 'ISFT' => 'software', 'ISGN' => 'secondarygenre', 'ISHP' => 'sharpness', 'ISRC' => 'sourcesupplier', 'ISRF' => 'digitizationsource', 'ISTD' => 'productionstudio', 'ISTR' => 'starring', 'ITCH' => 'encoded_by', 'IWEB' => 'url', 'IWRI' => 'writer') as $key => $value) {
  810. if (isset($info_riff_wave['INFO'][$key])) {
  811. foreach ($info_riff_wave['INFO'][$key] as $comment_id => $comment_data) {
  812. if (trim($comment_data['data']) != '') {
  813. $info_riff['comments'][$value][] = trim($comment_data['data']);
  814. }
  815. }
  816. }
  817. }
  818. }
  819. if (empty($info_audio['encoder']) && !empty($getid3->info['mpeg']['audio']['LAME']['short_version'])) {
  820. $info_audio['encoder'] = $getid3->info['mpeg']['audio']['LAME']['short_version'];
  821. }
  822. if (!isset($getid3->info['playtime_seconds'])) {
  823. $getid3->info['playtime_seconds'] = 0;
  824. }
  825. if (isset($info_riff_raw['avih']['dwTotalFrames']) && isset($info_riff_raw['avih']['dwMicroSecPerFrame'])) {
  826. $getid3->info['playtime_seconds'] = $info_riff_raw['avih']['dwTotalFrames'] * ($info_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000);
  827. }
  828. if ($getid3->info['playtime_seconds'] > 0) {
  829. if (isset($info_riff_audio) && isset($info_riff_video)) {
  830. if (!isset($getid3->info['bitrate'])) {
  831. $getid3->info['bitrate'] = ((($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds']) * 8);
  832. }
  833. } elseif (isset($info_riff_audio) && !isset($info_riff_video)) {
  834. if (!isset($info_audio['bitrate'])) {
  835. $info_audio['bitrate'] = ((($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds']) * 8);
  836. }
  837. } elseif (!isset($info_riff_audio) && isset($info_riff_video)) {
  838. if (!isset($info_video['bitrate'])) {
  839. $info_video['bitrate'] = ((($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds']) * 8);
  840. }
  841. }
  842. }
  843. if (isset($info_riff_video) && isset($info_audio['bitrate']) && ($info_audio['bitrate'] > 0) && ($getid3->info['playtime_seconds'] > 0)) {
  844. $getid3->info['bitrate'] = ((($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds']) * 8);
  845. $info_audio['bitrate'] = 0;
  846. $info_video['bitrate'] = $getid3->info['bitrate'];
  847. foreach ($info_riff_audio as $channelnumber => $audioinfoarray) {
  848. $info_video['bitrate'] -= $audioinfoarray['bitrate'];
  849. $info_audio['bitrate'] += $audioinfoarray['bitrate'];
  850. }
  851. if ($info_video['bitrate'] <= 0) {
  852. unset($info_video['bitrate']);
  853. }
  854. if ($info_audio['bitrate'] <= 0) {
  855. unset($info_audio['bitrate']);
  856. }
  857. }
  858. if (isset($getid3->info['mpeg']['audio'])) {
  859. $info_audio_dataformat = 'mp'.$getid3->info['mpeg']['audio']['layer'];
  860. $info_audio['sample_rate'] = $getid3->info['mpeg']['audio']['sample_rate'];
  861. $info_audio['channels'] = $getid3->info['mpeg']['audio']['channels'];
  862. $info_audio['bitrate'] = $getid3->info['mpeg']['audio']['bitrate'];
  863. $info_audio['bitrate_mode'] = strtolower($getid3->info['mpeg']['audio']['bitrate_mode']);
  864. if (!empty($getid3->info['mpeg']['audio']['codec'])) {
  865. $info_audio['codec'] = $getid3->info['mpeg']['audio']['codec'].' '.$info_audio['codec'];
  866. }
  867. if (!empty($info_audio['streams'])) {
  868. foreach ($info_audio['streams'] as $streamnumber => $streamdata) {
  869. if ($streamdata['dataformat'] == $info_audio_dataformat) {
  870. $info_audio['streams'][$streamnumber]['sample_rate'] = $info_audio['sample_rate'];
  871. $info_audio['streams'][$streamnumber]['channels'] = $info_audio['channels'];
  872. $info_audio['streams'][$streamnumber]['bitrate'] = $info_audio['bitrate'];
  873. $info_audio['streams'][$streamnumber]['bitrate_mode'] = $info_audio['bitrate_mode'];
  874. $info_audio['streams'][$streamnumber]['codec'] = $info_audio['codec'];
  875. }
  876. }
  877. }
  878. $info_audio['encoder_options'] = getid3_mp3::GuessEncoderOptions($getid3->info);
  879. }
  880. if (!empty($info_riff_raw['fmt ']['wBitsPerSample']) && ($info_riff_raw['fmt ']['wBitsPerSample'] > 0)) {
  881. switch ($info_audio_dataformat) {
  882. case 'ac3':
  883. // ignore bits_per_sample
  884. break;
  885. default:
  886. $info_audio['bits_per_sample'] = $info_riff_raw['fmt ']['wBitsPerSample'];
  887. break;
  888. }
  889. }
  890. if (empty($info_riff_raw)) {
  891. unset($info_riff['raw']);
  892. }
  893. if (empty($info_riff_audio)) {
  894. unset($info_riff['audio']);
  895. }
  896. if (empty($info_riff_video)) {
  897. unset($info_riff['video']);
  898. }
  899. if (empty($info_audio_dataformat)) {
  900. unset($info_audio['dataformat']);
  901. }
  902. if (empty($getid3->info['audio'])) {
  903. unset($getid3->info['audio']);
  904. }
  905. if (empty($info_video)) {
  906. unset($getid3->info['video']);
  907. }
  908. return true;
  909. }
  910. public function ParseRIFF($start_offset, $max_offset) {
  911. $getid3 = $this->getid3;
  912. $info = &$getid3->info;
  913. $endian_function = $this->endian_function;
  914. $max_offset = min($max_offset, $info['avdataend']);
  915. $riff_chunk = false;
  916. $this->fseek($start_offset, SEEK_SET);
  917. while ($this->ftell() < $max_offset) {
  918. $chunk_name = $this->fread(4);
  919. if (strlen($chunk_name) < 4) {
  920. throw new getid3_exception('Expecting chunk name at offset '.($this->ftell() - 4).' but found nothing. Aborting RIFF parsing.');
  921. }
  922. $chunk_size = getid3_lib::$endian_function($this->fread(4));
  923. if ($chunk_size == 0) {
  924. continue;
  925. throw new getid3_exception('Chunk size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.');
  926. }
  927. if (($chunk_size % 2) != 0) {
  928. // all structures are packed on word boundaries
  929. $chunk_size++;
  930. }
  931. switch ($chunk_name) {
  932. case 'LIST':
  933. $list_name = $this->fread(4);
  934. switch ($list_name) {
  935. case 'movi':
  936. case 'rec ':
  937. $riff_chunk[$list_name]['offset'] = $this->ftell() - 4;
  938. $riff_chunk[$list_name]['size'] = $chunk_size;
  939. static $parsed_audio_stream = false;
  940. if (!$parsed_audio_stream) {
  941. $where_we_were = $this->ftell();
  942. $audio_chunk_header = $this->fread(12);
  943. $audio_chunk_stream_num = substr($audio_chunk_header, 0, 2);
  944. $audio_chunk_stream_type = substr($audio_chunk_header, 2, 2);
  945. $audio_chunk_size = getid3_lib::LittleEndian2Int(substr($audio_chunk_header, 4, 4));
  946. if ($audio_chunk_stream_type == 'wb') {
  947. $first_four_bytes = substr($audio_chunk_header, 8, 4);
  948. //// MPEG
  949. if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $first_four_bytes)) {
  950. if (!$getid3->include_module_optional('audio.mp3')) {
  951. $getid3->warning('MP3 skipped because mp3 module is missing.');
  952. }
  953. elseif (getid3_mp3::MPEGaudioHeaderBytesValid($first_four_bytes)) {
  954. // Clone getid3 - messing with offsets - better safe than sorry
  955. $clone = clone $getid3;
  956. $clone->info['avdataoffset'] = $this->ftell() - 4;
  957. $clone->info['avdataend'] = $this->ftell() + $audio_chunk_size;
  958. $mp3 = new getid3_mp3($clone);
  959. $mp3->AnalyzeMPEGaudioInfo();
  960. // Import from clone and destroy
  961. if (isset($clone->info['mpeg']['audio'])) {
  962. $info['mpeg']['audio'] = $clone->info['mpeg']['audio'];
  963. $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer'];
  964. $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
  965. $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
  966. $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
  967. $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
  968. $info['bitrate'] = $info['audio']['bitrate'];
  969. $getid3->warning($clone->warnings());
  970. unset($clone);
  971. }
  972. }
  973. }
  974. //// AC3-WAVE
  975. elseif (preg_match('/^\x0B\x77/s', $first_four_bytes)) {
  976. if (!$getid3->include_module_optional('audio.ac3')) {
  977. $getid3->warning('AC3 skipped because ac3 module is missing.');
  978. }
  979. else {
  980. // Clone getid3 - messing with offsets - better safe than sorry
  981. $clone = clone $getid3;
  982. $clone->info['avdataoffset'] = $this->ftell() - 4;
  983. $clone->info['avdataend'] = $this->ftell() + $audio_chunk_size;
  984. // Analyze clone by fp
  985. $ac3 = new getid3_ac3($clone);
  986. $ac3->Analyze();
  987. // Import from clone and destroy
  988. $info['audio'] = $clone->info['audio'];
  989. $info['ac3'] = $clone->info['ac3'];
  990. $getid3->warning($clone->warnings());
  991. unset($clone);
  992. }
  993. }
  994. }
  995. $parsed_audio_stream = true;
  996. $this->fseek($where_we_were, SEEK_SET);
  997. }
  998. $this->fseek($chunk_size - 4, SEEK_CUR);
  999. break;
  1000. default:
  1001. if (!isset($riff_chunk[$list_name])) {
  1002. $riff_chunk[$list_name] = array ();
  1003. }
  1004. $list_chunk_parent = $list_name;
  1005. $list_chunk_max_offset = $this->ftell() - 4 + $chunk_size;
  1006. if ($parsed_chunk = $this->ParseRIFF($this->ftell(), $this->ftell() + $chunk_size - 4)) {
  1007. $riff_chunk[$list_name] = array_merge_recursive($riff_chunk[$list_name], $parsed_chunk);
  1008. }
  1009. break;
  1010. }
  1011. break;
  1012. default:
  1013. $this_index = 0;
  1014. if (isset($riff_chunk[$chunk_name]) && is_array($riff_chunk[$chunk_name])) {
  1015. $this_index = count($riff_chunk[$chunk_name]);
  1016. }
  1017. $riff_chunk[$chunk_name][$this_index]['offset'] = $this->ftell() - 8;
  1018. $riff_chunk[$chunk_name][$this_index]['size'] = $chunk_size;
  1019. switch ($chunk_name) {
  1020. case 'data':
  1021. $info['avdataoffset'] = $this->ftell();
  1022. $info['avdataend'] = $info['avdataoffset'] + $chunk_size;
  1023. $riff_data_chunk_contents_test = $this->fread(36);
  1024. //// This is probably MP3 data
  1025. if ((strlen($riff_data_chunk_contents_test) > 0) && preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($riff_data_chunk_contents_test, 0, 4))) {
  1026. try {
  1027. if (!$getid3->include_module_optional('audio.mp3')) {
  1028. $getid3->warning('MP3 skipped because mp3 module is missing.');
  1029. }
  1030. // Clone getid3 - messing with offsets - better safe than sorry
  1031. $clone = clone $getid3;
  1032. if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($riff_data_chunk_contents_test, 0, 4))) {
  1033. $mp3 = new getid3_mp3($clone);
  1034. $mp3->AnalyzeMPEGaudioInfo();
  1035. // Import from clone and destroy
  1036. if (isset($clone->info['mpeg']['audio'])) {
  1037. $info['mpeg']['audio'] = $clone->info['mpeg']['audio'];
  1038. $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
  1039. $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
  1040. $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
  1041. $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
  1042. $info['bitrate'] = $info['audio']['bitrate'];
  1043. $getid3->warning($clone->warnings());
  1044. unset($clone);
  1045. }
  1046. }
  1047. }
  1048. catch (Exception $e) {
  1049. // do nothing - not MP3 data
  1050. }
  1051. }
  1052. //// This is probably AC-3 data
  1053. elseif ((strlen($riff_data_chunk_contents_test) > 0) && (substr($riff_data_chunk_contents_test, 0, 2) == "\x0B\x77")) {
  1054. if (!$getid3->include_module_optional('audio.ac3')) {
  1055. $getid3->warning('AC3 skipped because ac3 module is missing.');
  1056. }
  1057. else {
  1058. // Clone getid3 - messing with offsets - better safe than sorry
  1059. $clone = clone $getid3;
  1060. $clone->info['avdataoffset'] = $riff_chunk[$chunk_name][$this_index]['offset'];
  1061. $clone->info['avdataend'] = $clone->info['avdataoffset'] + $riff_chunk[$chunk_name][$this_index]['size'];
  1062. // Analyze clone by fp
  1063. $ac3 = new getid3_ac3($clone);
  1064. $ac3->Analyze();
  1065. // Import from clone and destroy
  1066. $info['audio'] = $clone->info['audio'];
  1067. $info['ac3'] = $clone->info['ac3'];
  1068. $getid3->warning($clone->warnings());
  1069. unset($clone);
  1070. }
  1071. }
  1072. // Dolby Digital WAV
  1073. // AC-3 content, but not encoded in same format as normal AC-3 file
  1074. // For one thing, byte order is swapped
  1075. elseif ((strlen($riff_data_chunk_contents_test) > 0) && (substr($riff_data_chunk_contents_test, 8, 2) == "\x77\x0B")) {
  1076. if (!$getid3->include_module_optional('audio.ac3')) {
  1077. $getid3->warning('AC3 skipped because ac3 module is missing.');
  1078. }
  1079. else {
  1080. // Extract ac3 data to string
  1081. $ac3_data = '';
  1082. for ($i = 0; $i < 28; $i += 2) {
  1083. // swap byte order
  1084. $ac3_data .= substr($riff_data_chunk_contents_test, 8 + $i + 1, 1);
  1085. $ac3_data .= substr($riff_data_chunk_contents_test, 8 + $i + 0, 1);
  1086. }
  1087. // Clone getid3 - messing with offsets - better safe than sorry
  1088. $clone = clone $getid3;
  1089. $clone->info['avdataoffset'] = 0;
  1090. $clone->info['avdataend'] = 20;
  1091. // Analyse clone by string
  1092. $ac3 = new getid3_ac3($clone);
  1093. $ac3->AnalyzeString($ac3_data);
  1094. // Import from clone and destroy
  1095. $info['audio'] = $clone->info['audio'];
  1096. $info['ac3'] = $clone->info['ac3'];
  1097. $getid3->warning($clone->warnings());
  1098. unset($clone);
  1099. }
  1100. }
  1101. if ((strlen($riff_data_chunk_contents_test) > 0) && (substr($riff_data_chunk_contents_test, 0, 4) == 'wvpk')) {
  1102. // This is WavPack data
  1103. $info['wavpack']['offset'] = $riff_chunk[$chunk_name][$this_index]['offset'];
  1104. $info['wavpack']['size'] = getid3_lib::LittleEndian2Int(substr($riff_data_chunk_contents_test, 4, 4));
  1105. $this->RIFFparseWavPackHeader(substr($riff_data_chunk_contents_test, 8, 28));
  1106. } else {
  1107. // This is some other kind of data (quite possibly just PCM)
  1108. // do nothing special, just skip it
  1109. }
  1110. $this->fseek($riff_chunk[$chunk_name][$this_index]['offset'] + 8 + $chunk_size, SEEK_SET);
  1111. break;
  1112. case 'bext':
  1113. case 'cart':
  1114. case 'fmt ':
  1115. case 'MEXT':
  1116. case 'DISP':
  1117. // always read data in
  1118. $riff_chunk[$chunk_name][$this_index]['data'] = $this->fread($chunk_size);
  1119. break;
  1120. default:
  1121. if (!empty($list_chunk_parent) && (($riff_chunk[$chunk_name][$this_index]['offset'] + $riff_chunk[$chunk_name][$this_index]['size']) <= $list_chunk_max_offset)) {
  1122. $riff_chunk[$list_chunk_parent][$chunk_name][$this_index]['offset'] = $riff_chunk[$chunk_name][$this_index]['offset'];
  1123. $riff_chunk[$list_chunk_parent][$chunk_name][$this_index]['size'] = $riff_chunk[$chunk_name][$this_index]['size'];
  1124. unset($riff_chunk[$chunk_name][$this_index]['offset']);
  1125. unset($riff_chunk[$chunk_name][$this_index]['size']);
  1126. if (isset($riff_chunk[$chunk_name][$this_index]) && empty($riff_chunk[$chunk_name][$this_index])) {
  1127. unset($riff_chunk[$chunk_name][$this_index]);
  1128. }
  1129. if (isset($riff_chunk[$chunk_name]) && empty($riff_chunk[$chunk_name])) {
  1130. unset($riff_chunk[$chunk_name]);
  1131. }
  1132. $riff_chunk[$list_chunk_parent][$chunk_name][$this_index]['data'] = $this->fread($chunk_size);
  1133. } elseif ($chunk_size < 2048) {
  1134. // only read data in if smaller than 2kB
  1135. $riff_chunk[$chunk_name][$this_index]['data'] = $this->fread($chunk_size);
  1136. } else {
  1137. $this->fseek($chunk_size, SEEK_CUR);
  1138. }
  1139. break;
  1140. }
  1141. break;
  1142. }
  1143. }
  1144. return $riff_chunk;
  1145. }
  1146. private function RIFFparseWavPackHeader($wavpack3_chunk_data) {
  1147. // typedef struct {
  1148. // char ckID [4];
  1149. // long ckSize;
  1150. // short version;
  1151. // short bits; // added for version 2.00
  1152. // short flags, shift; // added for version 3.00
  1153. // long total_samples, crc, crc2;
  1154. // char extension [4], extra_bc, extras [3];
  1155. // } WavpackHeader;
  1156. $this->getid3->info['wavpack'] = array ();
  1157. $info_wavpack = &$this->getid3->info['wavpack'];
  1158. $info_wavpack['version'] = getid3_lib::LittleEndian2Int(substr($wavpack3_chunk_data, 0, 2));
  1159. if ($info_wavpack['version'] >= 2) {
  1160. $info_wavpack['bits'] = getid3_lib::LittleEndian2Int(substr($wavpack3_chunk_data, 2, 2));
  1161. }
  1162. if ($info_wavpack['version'] >= 3) {
  1163. getid3_lib::ReadSequence('LittleEndian2Int', $info_wavpack, $wavpack3_chunk_data, 4,
  1164. array (
  1165. 'flags_raw' => 2,
  1166. 'shift' => 2,
  1167. 'total_samples' => 4,
  1168. 'crc1' => 4,
  1169. 'crc2' => 4,
  1170. 'extension' => -4,
  1171. 'extra_bc' => 1
  1172. )
  1173. );
  1174. for ($i = 0; $i < 3; $i++) {
  1175. $info_wavpack['extras'][] = getid3_lib::LittleEndian2Int($wavpack3_chunk_data{25 + $i});
  1176. }
  1177. $info_wavpack['flags'] = array ();
  1178. $info_wavpack_flags = &$info_wavpack['flags'];
  1179. $info_wavpack_flags['mono'] = (bool)($info_wavpack['flags_raw'] & 0x000001);
  1180. $info_wavpack_flags['fast_mode'] = (bool)($info_wavpack['flags_raw'] & 0x000002);
  1181. $info_wavpack_flags['raw_mode'] = (bool)($info_wavpack['flags_raw'] & 0x000004);
  1182. $info_wavpack_flags['calc_noise'] = (bool)($info_wavpack['flags_raw'] & 0x000008);
  1183. $info_wavpack_flags['high_quality'] = (bool)($info_wavpack['flags_raw'] & 0x000010);
  1184. $info_wavpack_flags['3_byte_samples'] = (bool)($info_wavpack['flags_raw'] & 0x000020);
  1185. $info_wavpack_flags['over_20_bits'] = (bool)($info_wavpack['flags_raw'] & 0x000040);
  1186. $info_wavpack_flags['use_wvc'] = (bool)($info_wavpack['flags_raw'] & 0x000080);
  1187. $info_wavpack_flags['noiseshaping'] = (bool)($info_wavpack['flags_raw'] & 0x000100);
  1188. $info_wavpack_flags['very_fast_mode'] = (bool)($info_wavpack['flags_raw'] & 0x000200);
  1189. $info_wavpack_flags['new_high_quality'] = (bool)($info_wavpack['flags_raw'] & 0x000400);
  1190. $info_wavpack_flags['cancel_extreme'] = (bool)($info_wavpack['flags_raw'] & 0x000800);
  1191. $info_wavpack_flags['cross_decorrelation'] = (bool)($info_wavpack['flags_raw'] & 0x001000);
  1192. $info_wavpack_flags['new_decorrelation'] = (bool)($info_wavpack['flags_raw'] & 0x002000);
  1193. $info_wavpack_flags['joint_stereo'] = (bool)($info_wavpack['flags_raw'] & 0x004000);
  1194. $info_wavpack_flags['extra_decorrelation'] = (bool)($info_wavpack['flags_raw'] & 0x008000);
  1195. $info_wavpack_flags['override_noiseshape'] = (bool)($info_wavpack['flags_raw'] & 0x010000);
  1196. $info_wavpack_flags['override_jointstereo'] = (bool)($info_wavpack['flags_raw'] & 0x020000);
  1197. $info_wavpack_flags['copy_source_filetime'] = (bool)($info_wavpack['flags_raw'] & 0x040000);
  1198. $info_wavpack_flags['create_exe'] = (bool)($info_wavpack['flags_raw'] & 0x080000);
  1199. }
  1200. return true;
  1201. }
  1202. public function AnalyzeString(&$string) {
  1203. // Rewrite header_size in header
  1204. $new_header_size = getid3_lib::LittleEndian2String(strlen($string), 4);
  1205. for ($i = 0; $i < 4; $i++) {
  1206. $string{$i + 4} = $new_header_size{$i};
  1207. }
  1208. return parent::AnalyzeString($string);
  1209. }
  1210. public static function RIFFparseWAVEFORMATex($wave_format_ex_data) {
  1211. $wave_format_ex['raw'] = array ();
  1212. $wave_format_ex_raw = &$wave_format_ex['raw'];
  1213. getid3_lib::ReadSequence('LittleEndian2Int', $wave_format_ex_raw, $wave_format_ex_data, 0,
  1214. array (
  1215. 'wFormatTag' => 2,
  1216. 'nChannels' => 2,
  1217. 'nSamplesPerSec' => 4,
  1218. 'nAvgBytesPerSec' => 4,
  1219. 'nBlockAlign' => 2,
  1220. 'wBitsPerSample' => 2
  1221. )
  1222. );
  1223. if (strlen($wave_format_ex_data) > 16) {
  1224. $wave_format_ex_raw['cbSize'] = getid3_lib::LittleEndian2Int(substr($wave_format_ex_data, 16, 2));
  1225. }
  1226. $wave_format_ex['codec'] = getid3_riff::RIFFwFormatTagLookup($wave_format_ex_raw['wFormatTag']);
  1227. $wave_format_ex['channels'] = $wave_format_ex_raw['nChannels'];
  1228. $wave_format_ex['sample_rate'] = $wave_format_ex_raw['nSamplesPerSec'];
  1229. $wave_format_ex['bitrate'] = $wave_format_ex_raw['nAvgBytesPerSec'] * 8;
  1230. if (@$wave_format_ex_raw['wBitsPerSample']) {
  1231. $wave_format_ex['bits_per_sample'] = $wave_format_ex_raw['wBitsPerSample'];
  1232. }
  1233. return $wave_format_ex;
  1234. }
  1235. public static function RIFFwFormatTagLookup($w_format_tag) {
  1236. static $lookup = array (
  1237. 0x0000 => 'Microsoft Unknown Wave Format',
  1238. 0x0001 => 'Pulse Code Modulation (PCM)',
  1239. 0x0002 => 'Microsoft ADPCM',
  1240. 0x0003 => 'IEEE Float',
  1241. 0x0004 => 'Compaq Computer VSELP',
  1242. 0x0005 => 'IBM CVSD',
  1243. 0x0006 => 'Microsoft A-Law',
  1244. 0x0007 => 'Microsoft mu-Law',
  1245. 0x0008 => 'Microsoft DTS',
  1246. 0x0010 => 'OKI ADPCM',
  1247. 0x0011 => 'Intel DVI/IMA ADPCM',
  1248. 0x0012 => 'Videologic MediaSpace ADPCM',
  1249. 0x0013 => 'Sierra Semiconductor ADPCM',
  1250. 0x0014 => 'Antex Electronics G.723 ADPCM',
  1251. 0x0015 => 'DSP Solutions DigiSTD',
  1252. 0x0016 => 'DSP Solutions DigiFIX',
  1253. 0x0017 => 'Dialogic OKI ADPCM',
  1254. 0x0018 => 'MediaVision ADPCM',
  1255. 0x0019 => 'Hewlett-Packard CU',
  1256. 0x0020 => 'Yamaha ADPCM',
  1257. 0x0021 => 'Speech Compression Sonarc',
  1258. 0x0022 => 'DSP Group TrueSpeech',
  1259. 0x0023 => 'Echo Speech EchoSC1',
  1260. 0x0024 => 'Audiofile AF36',
  1261. 0x0025 => 'Audio Processing Technology APTX',
  1262. 0x0026 => 'AudioFile AF10',
  1263. 0x0027 => 'Prosody 1612',
  1264. 0x0028 => 'LRC',
  1265. 0x0030 => 'Dolby AC2',
  1266. 0x0031 => 'Microsoft GSM 6.10',
  1267. 0x0032 => 'MSNAudio',
  1268. 0x0033 => 'Antex Electronics ADPCME',
  1269. 0x0034 => 'Control Resources VQLPC',
  1270. 0x0035 => 'DSP Solutions DigiREAL',
  1271. 0x0036 => 'DSP Solutions DigiADPCM',
  1272. 0x0037 => 'Control Resources CR10',
  1273. 0x0038 => 'Natural MicroSystems VBXADPCM',
  1274. 0x0039 => 'Crystal Semiconductor IMA ADPCM',
  1275. 0x003A => 'EchoSC3',
  1276. 0x003B => 'Rockwell ADPCM',
  1277. 0x003C => 'Rockwell Digit LK',
  1278. 0x003D => 'Xebec',
  1279. 0x0040 => 'Antex Electronics G.721 ADPCM',
  1280. 0x0041 => 'G.728 CELP',
  1281. 0x0042 => 'MSG723',
  1282. 0x0050 => 'MPEG Layer-2 or Layer-1',
  1283. 0x0052 => 'RT24',
  1284. 0x0053 => 'PAC',
  1285. 0x0055 => 'MPEG Layer-3',
  1286. 0x0059 => 'Lucent G.723',
  1287. 0x0060 => 'Cirrus',
  1288. 0x0061 => 'ESPCM',
  1289. 0x0062 => 'Voxware',
  1290. 0x0063 => 'Canopus Atrac',
  1291. 0x0064 => 'G.726 ADPCM',
  1292. 0x0065 => 'G.722 ADPCM',
  1293. 0x0066 => 'DSAT',
  1294. 0x0067 => 'DSAT Display',
  1295. 0x0069 => 'Voxware Byte Aligned',
  1296. 0x0070 => 'Voxware AC8',
  1297. 0x0071 => 'Voxware AC10',
  1298. 0x0072 => 'Voxware AC16',
  1299. 0x0073 => 'Voxware AC20',
  1300. 0x0074 => 'Voxware MetaVoice',
  1301. 0x0075 => 'Voxware MetaSound',
  1302. 0x0076 => 'Voxware RT29HW',
  1303. 0x0077 => 'Voxware VR12',
  1304. 0x0078 => 'Voxware VR18',
  1305. 0x0079 => 'Voxware TQ40',
  1306. 0x0080 => 'Softsound',
  1307. 0x0081 => 'Voxware TQ60',
  1308. 0x0082 => 'MSRT24',
  1309. 0x0083 => 'G.729A',
  1310. 0x0084 => 'MVI MV12',
  1311. 0x0085 => 'DF G.726',
  1312. 0x0086 => 'DF GSM610',
  1313. 0x0088 => 'ISIAudio',
  1314. 0x0089 => 'Onlive',
  1315. 0x0091 => 'SBC24',
  1316. 0x0092 => 'Dolby AC3 SPDIF',
  1317. 0x0093 => 'MediaSonic G.723',
  1318. 0x0094 => 'Aculab PLC Prosody 8kbps',
  1319. 0x0097 => 'ZyXEL ADPCM',
  1320. 0x0098 => 'Philips LPCBB',
  1321. 0x0099 => 'Packed',
  1322. 0x00FF => 'AAC',
  1323. 0x0100 => 'Rhetorex ADPCM',
  1324. 0x0101 => 'IBM mu-law',
  1325. 0x0102 => 'IBM A-law',
  1326. 0x0103 => 'IBM AVC Adaptive Differential Pulse Code Modulation (ADPCM)',
  1327. 0x0111 => 'Vivo G.723',
  1328. 0x0112 => 'Vivo Siren',
  1329. 0x0123 => 'Digital G.723',
  1330. 0x0125 => 'Sanyo LD ADPCM',
  1331. 0x0130 => 'Sipro Lab Telecom ACELP NET',
  1332. 0x0131 => 'Sipro Lab Telecom ACELP 4800',
  1333. 0x0132 => 'Sipro Lab Telecom ACELP 8V3',
  1334. 0x0133 => 'Sipro Lab Telecom G.729',
  1335. 0x0134 => 'Sipro Lab Telecom G.729A',
  1336. 0x0135 => 'Sipro Lab Telecom Kelvin',
  1337. 0x0140 => 'Windows Media Video V8',
  1338. 0x0150 => 'Qualcomm PureVoice',
  1339. 0x0151 => 'Qualcomm HalfRate',
  1340. 0x0155 => 'Ring Zero Systems TUB GSM',
  1341. 0x0160 => 'Microsoft Audio 1',
  1342. 0x0161 => 'Windows Media Audio V7 / V8 / V9',
  1343. 0x0162 => 'Windows Media Audio Professional V9',
  1344. 0x0163 => 'Windows Media Audio Lossless V9',
  1345. 0x0200 => 'Creative Labs ADPCM',
  1346. 0x0202 => 'Creative Labs Fastspeech8',
  1347. 0x0203 => 'Creative Labs Fastspeech10',
  1348. 0x0210 => 'UHER Informatic GmbH ADPCM',
  1349. 0x0220 => 'Quarterdeck',
  1350. 0x0230 => 'I-link Worldwide VC',
  1351. 0x0240 => 'Aureal RAW Sport',
  1352. 0x0250 => 'Interactive Products HSX',
  1353. 0x0251 => 'Interactive Products RPELP',
  1354. 0x0260 => 'Consistent Software CS2',
  1355. 0x0270 => 'Sony SCX',
  1356. 0x0300 => 'Fujitsu FM Towns Snd',
  1357. 0x0400 => 'BTV Digital',
  1358. 0x0401 => 'Intel Music Coder',
  1359. 0x0450 => 'QDesign Music',
  1360. 0x0680 => 'VME VMPCM',
  1361. 0x0681 => 'AT&T Labs TPC',
  1362. 0x08AE => 'ClearJump LiteWave',
  1363. 0x1000 => 'Olivetti GSM',
  1364. 0x1001 => 'Olivetti ADPCM',
  1365. 0x1002 => 'Olivetti CELP',
  1366. 0x1003 => 'Olivetti SBC',
  1367. 0x1004 => 'Olivetti OPR',
  1368. 0x1100 => 'Lernout & Hauspie Codec (0x1100)',
  1369. 0x1101 => 'Lernout & Hauspie CELP Codec (0x1101)',
  1370. 0x1102 => 'Lernout & Hauspie SBC Codec (0x1102)',
  1371. 0x1103 => 'Lernout & Hauspie SBC Codec (0x1103)',
  1372. 0x1104 => 'Lernout & Hauspie SBC Codec (0x1104)',
  1373. 0x1400 => 'Norris',
  1374. 0x1401 => 'AT&T ISIAudio',
  1375. 0x1500 => 'Soundspace Music Compression',
  1376. 0x181C => 'VoxWare RT24 Speech',
  1377. 0x1FC4 => 'NCT Soft ALF2CD (www.nctsoft.com)',
  1378. 0x2000 => 'Dolby AC3',
  1379. 0x2001 => 'Dolby DTS',
  1380. 0x2002 => 'WAVE_FORMAT_14_4',
  1381. 0x2003 => 'WAVE_FORMAT_28_8',
  1382. 0x2004 => 'WAVE_FORMAT_COOK',
  1383. 0x2005 => 'WAVE_FORMAT_DNET',
  1384. 0x674F => 'Ogg Vorbis 1',
  1385. 0x6750 => 'Ogg Vorbis 2',
  1386. 0x6751 => 'Ogg Vorbis 3',
  1387. 0x676F => 'Ogg Vorbis 1+',
  1388. 0x6770 => 'Ogg Vorbis 2+',
  1389. 0x6771 => 'Ogg Vorbis 3+',
  1390. 0x7A21 => 'GSM-AMR (CBR, no SID)',
  1391. 0x7A22 => 'GSM-AMR (VBR, including SID)',
  1392. 0xFFFE => 'WAVE_FORMAT_EXTENSIBLE',
  1393. 0xFFFF => 'WAVE_FORMAT_DEVELOPMENT'
  1394. );
  1395. return @$lookup[$w_format_tag];
  1396. }
  1397. public static function RIFFfourccLookup($four_cc) {
  1398. static $lookup = array (
  1399. 'swot' => 'http://developer.apple.com/qa/snd/snd07.html',
  1400. '____' => 'No Codec (____)',
  1401. '_BIT' => 'BI_BITFIELDS (Raw RGB)',
  1402. '_JPG' => 'JPEG compressed',
  1403. '_PNG' => 'PNG compressed W3C/ISO/IEC (RFC-2083)',
  1404. '_RAW' => 'Full Frames (Uncompressed)',
  1405. '_RGB' => 'Raw RGB Bitmap',
  1406. '_RL4' => 'RLE 4bpp RGB',
  1407. '_RL8' => 'RLE 8bpp RGB',
  1408. '3IV1' => '3ivx MPEG-4 v1',
  1409. '3IV2' => '3ivx MPEG-4 v2',
  1410. '3IVX' => '3ivx MPEG-4',
  1411. 'AASC' => 'Autodesk Animator',
  1412. 'ABYR' => 'Kensington ?ABYR?',
  1413. 'AEMI' => 'Array Microsystems VideoONE MPEG1-I Capture',
  1414. 'AFLC' => 'Autodesk Animator FLC',
  1415. 'AFLI' => 'Autodesk Animator FLI',
  1416. 'AMPG' => 'Array Microsystems VideoONE MPEG',
  1417. 'ANIM' => 'Intel RDX (ANIM)',
  1418. 'AP41' => 'AngelPotion Definitive',
  1419. 'ASV1' => 'Asus Video v1',
  1420. 'ASV2' => 'Asus Video v2',
  1421. 'ASVX' => 'Asus Video 2.0 (audio)',
  1422. 'AUR2' => 'AuraVision Aura 2 Codec - YUV 4:2:2',
  1423. 'AURA' => 'AuraVision Aura 1 Codec - YUV 4:1:1',
  1424. 'AVDJ' => 'Independent JPEG Group\'s codec (AVDJ)',
  1425. 'AVRN' => 'Independent JPEG Group\'s codec (AVRN)',
  1426. 'AYUV' => '4:4:4 YUV (AYUV)',
  1427. 'AZPR' => 'Quicktime Apple Video (AZPR)',
  1428. 'BGR ' => 'Raw RGB32',
  1429. 'BLZ0' => 'FFmpeg MPEG-4',
  1430. 'BTVC' => 'Conexant Composite Video',
  1431. 'BINK' => 'RAD Game Tools Bink Video',
  1432. 'BT20' => 'Conexant Prosumer Video',
  1433. 'BTCV' => 'Conexant Composite Video Codec',
  1434. 'BW10' => 'Data Translation Broadway MPEG Capture',
  1435. 'CC12' => 'Intel YUV12',
  1436. 'CDVC' => 'Canopus DV',
  1437. 'CFCC' => 'Digital Processing Systems DPS Perception',
  1438. 'CGDI' => 'Microsoft Office 97 Camcorder Video',
  1439. 'CHAM' => 'Winnov Caviara Champagne',
  1440. 'CJPG' => 'Creative WebCam JPEG',
  1441. 'CLJR' => 'Cirrus Logic YUV 4:1:1',
  1442. 'CMYK' => 'Common Data Format in Printing (Colorgraph)',
  1443. 'CPLA' => 'Weitek 4:2:0 YUV Planar',
  1444. 'CRAM' => 'Microsoft Video 1 (CRAM)',
  1445. 'cvid' => 'Radius Cinepak',
  1446. 'CVID' => 'Radius Cinepak',
  1447. 'CWLT' => 'Microsoft Color WLT DIB',
  1448. 'CYUV' => 'Creative Labs YUV',
  1449. 'CYUY' => 'ATI YUV',
  1450. 'D261' => 'H.261',
  1451. 'D263' => 'H.263',
  1452. 'DIB ' => 'Device Independent Bitmap',
  1453. 'DIV1' => 'FFmpeg OpenDivX',
  1454. 'DIV2' => 'Microsoft MPEG-4 v1/v2',
  1455. 'DIV3' => 'DivX ;-) MPEG-4 v3.x Low-Motion',
  1456. 'DIV4' => 'DivX ;-) MPEG-4 v3.x Fast-Motion',
  1457. 'DIV5' => 'DivX MPEG-4 v5.x',
  1458. 'DIV6' => 'DivX ;-) (MS MPEG-4 v3.x)',
  1459. 'DIVX' => 'DivX MPEG-4 v4 (OpenDivX / Project Mayo)',
  1460. 'divx' => 'DivX MPEG-4',
  1461. 'DMB1' => 'Matrox Rainbow Runner hardware MJPEG',
  1462. 'DMB2' => 'Paradigm MJPEG',
  1463. 'DSVD' => '?DSVD?',
  1464. 'DUCK' => 'Duck TrueMotion 1.0',
  1465. 'DPS0' => 'DPS/Leitch Reality Motion JPEG',
  1466. 'DPSC' => 'DPS/Leitch PAR Motion JPEG',
  1467. 'DV25' => 'Matrox DVCPRO codec',
  1468. 'DV50' => 'Matrox DVCPRO50 codec',
  1469. 'DVC ' => 'IEC 61834 and SMPTE 314M (DVC/DV Video)',
  1470. 'DVCP' => 'IEC 61834 and SMPTE 314M (DVC/DV Video)',
  1471. 'DVHD' => 'IEC Standard DV 1125 lines @ 30fps / 1250 lines @ 25fps',
  1472. 'DVMA' => 'Darim Vision DVMPEG (dummy for MPEG compressor) (www.darvision.com)',
  1473. 'DVSL' => 'IEC Standard DV compressed in SD (SDL)',
  1474. 'DVAN' => '?DVAN?',
  1475. 'DVE2' => 'InSoft DVE-2 Videoconferencing',
  1476. 'dvsd' => 'IEC 61834 and SMPTE 314M DVC/DV Video',
  1477. 'DVSD' => 'IEC 61834 and SMPTE 314M DVC/DV Video',
  1478. 'DVX1' => 'Lucent DVX1000SP Video Decoder',
  1479. 'DVX2' => 'Lucent DVX2000S Video Decoder',
  1480. 'DVX3' => 'Lucent DVX3000S Video Decoder',
  1481. 'DX50' => 'DivX v5',
  1482. 'DXT1' => 'Microsoft DirectX Compressed Texture (DXT1)',
  1483. 'DXT2' => 'Microsoft DirectX Compressed Texture (DXT2)',
  1484. 'DXT3' => 'Microsoft DirectX Compressed Texture (DXT3)',
  1485. 'DXT4' => 'Microsoft DirectX Compressed Texture (DXT4)',
  1486. 'DXT5' => 'Microsoft DirectX Compressed Texture (DXT5)',
  1487. 'DXTC' => 'Microsoft DirectX Compressed Texture (DXTC)',
  1488. 'DXTn' => 'Microsoft DirectX Compressed Texture (DXTn)',
  1489. 'EM2V' => 'Etymonix MPEG-2 I-frame (www.etymonix.com)',
  1490. 'EKQ0' => 'Elsa ?EKQ0?',
  1491. 'ELK0' => 'Elsa ?ELK0?',
  1492. 'ESCP' => 'Eidos Escape',
  1493. 'ETV1' => 'eTreppid Video ETV1',
  1494. 'ETV2' => 'eTreppid Video ETV2',
  1495. 'ETVC' => 'eTreppid Video ETVC',
  1496. 'FLIC' => 'Autodesk FLI/FLC Animation',
  1497. 'FRWT' => 'Darim Vision Forward Motion JPEG (www.darvision.com)',
  1498. 'FRWU' => 'Darim Vision Forward Uncompressed (www.darvision.com)',
  1499. 'FLJP' => 'D-Vision Field Encoded Motion JPEG',
  1500. 'FRWA' => 'SoftLab-Nsk Forward Motion JPEG w/ alpha channel',
  1501. 'FRWD' => 'SoftLab-Nsk Forward Motion JPEG',
  1502. 'FVF1' => 'Iterated Systems Fractal Video Frame',
  1503. 'GLZW' => 'Motion LZW (gabest@freemail.hu)',
  1504. 'GPEG' => 'Motion JPEG (gabest@freemail.hu)',
  1505. 'GWLT' => 'Microsoft Greyscale WLT DIB',
  1506. 'H260' => 'Intel ITU H.260 Videoconferencing',
  1507. 'H261' => 'Intel ITU H.261 Videoconferencing',
  1508. 'H262' => 'Intel ITU H.262 Videoconferencing',
  1509. 'H263' => 'Intel ITU H.263 Videoconferencing',
  1510. 'H264' => 'Intel ITU H.264 Videoconferencing',
  1511. 'H265' => 'Intel ITU H.265 Videoconferencing',
  1512. 'H266' => 'Intel ITU H.266 Videoconferencing',
  1513. 'H267' => 'Intel ITU H.267 Videoconferencing',
  1514. 'H268' => 'Intel ITU H.268 Videoconferencing',
  1515. 'H269' => 'Intel ITU H.269 Videoconferencing',
  1516. 'HFYU' => 'Huffman Lossless Codec',
  1517. 'HMCR' => 'Rendition Motion Compensation Format (HMCR)',
  1518. 'HMRR' => 'Rendition Motion Compensation Format (HMRR)',
  1519. 'I263' => 'FFmpeg I263 decoder',
  1520. 'IF09' => 'Indeo YVU9 ("YVU9 with additional delta-frame info after the U plane")',
  1521. 'IUYV' => 'Interlaced version of UYVY (www.leadtools.com)',
  1522. 'IY41' => 'Interlaced version of Y41P (www.leadtools.com)',
  1523. 'IYU1' => '12 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard',
  1524. 'IYU2' => '24 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard',
  1525. 'IYUV' => 'Planar YUV format (8-bpp Y plane, followed by 8-bpp 2×2 U and V planes)',
  1526. 'i263' => 'Intel ITU H.263 Videoconferencing (i263)',
  1527. 'I420' => 'Intel Indeo 4',
  1528. 'IAN ' => 'Intel Indeo 4 (RDX)',
  1529. 'ICLB' => 'InSoft CellB Videoconferencing',
  1530. 'IGOR' => 'Power DVD',
  1531. 'IJPG' => 'Intergraph JPEG',
  1532. 'ILVC' => 'Intel Layered Video',
  1533. 'ILVR' => 'ITU-T H.263+',
  1534. 'IPDV' => 'I-O Data Device Giga AVI DV Codec',
  1535. 'IR21' => 'Intel Indeo 2.1',
  1536. 'IRAW' => 'Intel YUV Uncompressed',
  1537. 'IV30' => 'Intel Indeo 3.0',
  1538. 'IV31' => 'Intel Indeo 3.1',
  1539. 'IV32' => 'Ligos Indeo 3.2',
  1540. 'IV33' => 'Ligos Indeo 3.3',
  1541. 'IV34' => 'Ligos Indeo 3.4',
  1542. 'IV35' => 'Ligos Indeo 3.5',
  1543. 'IV36' => 'Ligos Indeo 3.6',
  1544. 'IV37' => 'Ligos Indeo 3.7',
  1545. 'IV38' => 'Ligos Indeo 3.8',
  1546. 'IV39' => 'Ligos Indeo 3.9',
  1547. 'IV40' => 'Ligos Indeo Interactive 4.0',
  1548. 'IV41' => 'Ligos Indeo Interactive 4.1',
  1549. 'IV42' => 'Ligos Indeo Interactive 4.2',
  1550. 'IV43' => 'Ligos Indeo Interactive 4.3',
  1551. 'IV44' => 'Ligos Indeo Interactive 4.4',
  1552. 'IV45' => 'Ligos Indeo Interactive 4.5',
  1553. 'IV46' => 'Ligos Indeo Interactive 4.6',
  1554. 'IV47' => 'Ligos Indeo Interactive 4.7',
  1555. 'IV48' => 'Ligos Indeo Interactive 4.8',
  1556. 'IV49' => 'Ligos Indeo Interactive 4.9',
  1557. 'IV50' => 'Ligos Indeo Interactive 5.0',
  1558. 'JBYR' => 'Kensington ?JBYR?',
  1559. 'JPEG' => 'Still Image JPEG DIB',
  1560. 'JPGL' => 'Pegasus Lossless Motion JPEG',
  1561. 'KMVC' => 'Team17 Software Karl Morton\'s Video Codec',
  1562. 'LSVM' => 'Vianet Lighting Strike Vmail (Streaming) (www.vianet.com)',
  1563. 'LEAD' => 'LEAD Video Codec',
  1564. 'Ljpg' => 'LEAD MJPEG Codec',
  1565. 'MDVD' => 'Alex MicroDVD Video (hacked MS MPEG-4) (www.tiasoft.de)',
  1566. 'MJPA' => 'Morgan Motion JPEG (MJPA) (www.morgan-multimedia.com)',
  1567. 'MJPB' => 'Morgan Motion JPEG (MJPB) (www.morgan-multimedia.com)',
  1568. 'MMES' => 'Matrox MPEG-2 I-frame',
  1569. 'MP2v' => 'Microsoft S-Mpeg 4 version 1 (MP2v)',
  1570. 'MP42' => 'Microsoft S-Mpeg 4 version 2 (MP42)',
  1571. 'MP43' => 'Microsoft S-Mpeg 4 version 3 (MP43)',
  1572. 'MP4S' => 'Microsoft S-Mpeg 4 version 3 (MP4S)',
  1573. 'MP4V' => 'FFmpeg MPEG-4',
  1574. 'MPG1' => 'FFmpeg MPEG 1/2',
  1575. 'MPG2' => 'FFmpeg MPEG 1/2',
  1576. 'MPG3' => 'FFmpeg DivX ;-) (MS MPEG-4 v3)',
  1577. 'MPG4' => 'Microsoft MPEG-4',
  1578. 'MPGI' => 'Sigma Designs MPEG',
  1579. 'MPNG' => 'PNG images decoder',
  1580. 'MSS1' => 'Microsoft Windows Screen Video',
  1581. 'MSZH' => 'LCL (Lossless Codec Library) (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)',
  1582. 'M261' => 'Microsoft H.261',
  1583. 'M263' => 'Microsoft H.263',
  1584. 'M4S2' => 'Microsoft Fully Compliant MPEG-4 v2 simple profile (M4S2)',
  1585. 'm4s2' => 'Microsoft Fully Compliant MPEG-4 v2 simple profile (m4s2)',
  1586. 'MC12' => 'ATI Motion Compensation Format (MC12)',
  1587. 'MCAM' => 'ATI Motion Compensation Format (MCAM)',
  1588. 'MJ2C' => 'Morgan Multimedia Motion JPEG2000',
  1589. 'mJPG' => 'IBM Motion JPEG w/ Huffman Tables',
  1590. 'MJPG' => 'Microsoft Motion JPEG DIB',
  1591. 'MP42' => 'Microsoft MPEG-4 (low-motion)',
  1592. 'MP43' => 'Microsoft MPEG-4 (fast-motion)',
  1593. 'MP4S' => 'Microsoft MPEG-4 (MP4S)',
  1594. 'mp4s' => 'Microsoft MPEG-4 (mp4s)',
  1595. 'MPEG' => 'Chromatic Research MPEG-1 Video I-Frame',
  1596. 'MPG4' => 'Microsoft MPEG-4 Video High Speed Compressor',
  1597. 'MPGI' => 'Sigma Designs MPEG',
  1598. 'MRCA' => 'FAST Multimedia Martin Regen Codec',
  1599. 'MRLE' => 'Microsoft Run Length Encoding',
  1600. 'MSVC' => 'Microsoft Video 1',
  1601. 'MTX1' => 'Matrox ?MTX1?',
  1602. 'MTX2' => 'Matrox ?MTX2?',
  1603. 'MTX3' => 'Matrox ?MTX3?',
  1604. 'MTX4' => 'Matrox ?MTX4?',
  1605. 'MTX5' => 'Matrox ?MTX5?',
  1606. 'MTX6' => 'Matrox ?MTX6?',
  1607. 'MTX7' => 'Matrox ?MTX7?',
  1608. 'MTX8' => 'Matrox ?MTX8?',
  1609. 'MTX9' => 'Matrox ?MTX9?',
  1610. 'MV12' => 'Motion Pixels Codec (old)',
  1611. 'MWV1' => 'Aware Motion Wavelets',
  1612. 'nAVI' => 'SMR Codec (hack of Microsoft MPEG-4) (IRC #shadowrealm)',
  1613. 'NT00' => 'NewTek LightWave HDTV YUV w/ Alpha (www.newtek.com)',
  1614. 'NUV1' => 'NuppelVideo',
  1615. 'NTN1' => 'Nogatech Video Compression 1',
  1616. 'NVS0' => 'nVidia GeForce Texture (NVS0)',
  1617. 'NVS1' => 'nVidia GeForce Texture (NVS1)',
  1618. 'NVS2' => 'nVidia GeForce Texture (NVS2)',
  1619. 'NVS3' => 'nVidia GeForce Texture (NVS3)',
  1620. 'NVS4' => 'nVidia GeForce Texture (NVS4)',
  1621. 'NVS5' => 'nVidia GeForce Texture (NVS5)',
  1622. 'NVT0' => 'nVidia GeForce Texture (NVT0)',
  1623. 'NVT1' => 'nVidia GeForce Texture (NVT1)',
  1624. 'NVT2' => 'nVidia GeForce Texture (NVT2)',
  1625. 'NVT3' => 'nVidia GeForce Texture (NVT3)',
  1626. 'NVT4' => 'nVidia GeForce Texture (NVT4)',
  1627. 'NVT5' => 'nVidia GeForce Texture (NVT5)',
  1628. 'PIXL' => 'MiroXL, Pinnacle PCTV',
  1629. 'PDVC' => 'I-O Data Device Digital Video Capture DV codec',
  1630. 'PGVV' => 'Radius Video Vision',
  1631. 'PHMO' => 'IBM Photomotion',
  1632. 'PIM1' => 'MPEG Realtime (Pinnacle Cards)',
  1633. 'PIM2' => 'Pegasus Imaging ?PIM2?',
  1634. 'PIMJ' => 'Pegasus Imaging Lossless JPEG',
  1635. 'PVEZ' => 'Horizons Technology PowerEZ',
  1636. 'PVMM' => 'PacketVideo Corporation MPEG-4',
  1637. 'PVW2' => 'Pegasus Imaging Wavelet Compression',
  1638. 'Q1.0' => 'Q-Team\'s QPEG 1.0 (www.q-team.de)',
  1639. 'Q1.1' => 'Q-Team\'s QPEG 1.1 (www.q-team.de)',
  1640. 'QPEG' => 'Q-Team QPEG 1.0',
  1641. 'qpeq' => 'Q-Team QPEG 1.1',
  1642. 'RGB ' => 'Raw BGR32',
  1643. 'RGBA' => 'Raw RGB w/ Alpha',
  1644. 'RMP4' => 'REALmagic MPEG-4 (unauthorized XVID copy) (www.sigmadesigns.com)',
  1645. 'ROQV' => 'Id RoQ File Video Decoder',
  1646. 'RPZA' => 'Quicktime Apple Video (RPZA)',
  1647. 'RUD0' => 'Rududu video codec (http://rududu.ifrance.com/rududu/)',
  1648. 'RV10' => 'RealVideo 1.0 (aka RealVideo 5.0)',
  1649. 'RV13' => 'RealVideo 1.0 (RV13)',
  1650. 'RV20' => 'RealVideo G2',
  1651. 'RV30' => 'RealVideo 8',
  1652. 'RV40' => 'RealVideo 9',
  1653. 'RGBT' => 'Raw RGB w/ Transparency',
  1654. 'RLE ' => 'Microsoft Run Length Encoder',
  1655. 'RLE4' => 'Run Length Encoded (4bpp, 16-color)',
  1656. 'RLE8' => 'Run Length Encoded (8bpp, 256-color)',
  1657. 'RT21' => 'Intel Indeo RealTime Video 2.1',
  1658. 'rv20' => 'RealVideo G2',
  1659. 'rv30' => 'RealVideo 8',
  1660. 'RVX ' => 'Intel RDX (RVX )',
  1661. 'SMC ' => 'Apple Graphics (SMC )',
  1662. 'SP54' => 'Logitech Sunplus Sp54 Codec for Mustek GSmart Mini 2',
  1663. 'SPIG' => 'Radius Spigot',
  1664. 'SVQ3' => 'Sorenson Video 3 (Apple Quicktime 5)',
  1665. 's422' => 'Tekram VideoCap C210 YUV 4:2:2',
  1666. 'SDCC' => 'Sun Communication Digital Camera Codec',
  1667. 'SFMC' => 'CrystalNet Surface Fitting Method',
  1668. 'SMSC' => 'Radius SMSC',
  1669. 'SMSD' => 'Radius SMSD',
  1670. 'smsv' => 'WorldConnect Wavelet Video',
  1671. 'SPIG' => 'Radius Spigot',
  1672. 'SPLC' => 'Splash Studios ACM Audio Codec (www.splashstudios.net)',
  1673. 'SQZ2' => 'Microsoft VXTreme Video Codec V2',
  1674. 'STVA' => 'ST Microelectronics CMOS Imager Data (Bayer)',
  1675. 'STVB' => 'ST Microelectronics CMOS Imager Data (Nudged Bayer)',
  1676. 'STVC' => 'ST Microelectronics CMOS Imager Data (Bunched)',
  1677. 'STVX' => 'ST Microelectronics CMOS Imager Data (Extended CODEC Data Format)',
  1678. 'STVY' => 'ST Microelectronics CMOS Imager Data (Extended CODEC Data Format with Correction Data)',
  1679. 'SV10' => 'Sorenson Video R1',
  1680. 'SVQ1' => 'Sorenson Video',
  1681. 'T420' => 'Toshiba YUV 4:2:0',
  1682. 'TM2A' => 'Duck TrueMotion Archiver 2.0 (www.duck.com)',
  1683. 'TVJP' => 'Pinnacle/Truevision Targa 2000 board (TVJP)',
  1684. 'TVMJ' => 'Pinnacle/Truevision Targa 2000 board (TVMJ)',
  1685. 'TY0N' => 'Tecomac Low-Bit Rate Codec (www.tecomac.com)',
  1686. 'TY2C' => 'Trident Decompression Driver',
  1687. 'TLMS' => 'TeraLogic Motion Intraframe Codec (TLMS)',
  1688. 'TLST' => 'TeraLogic Motion Intraframe Codec (TLST)',
  1689. 'TM20' => 'Duck TrueMotion 2.0',
  1690. 'TM2X' => 'Duck TrueMotion 2X',
  1691. 'TMIC' => 'TeraLogic Motion Intraframe Codec (TMIC)',
  1692. 'TMOT' => 'Horizons Technology TrueMotion S',
  1693. 'tmot' => 'Horizons TrueMotion Video Compression',
  1694. 'TR20' => 'Duck TrueMotion RealTime 2.0',
  1695. 'TSCC' => 'TechSmith Screen Capture Codec',
  1696. 'TV10' => 'Tecomac Low-Bit Rate Codec',
  1697. 'TY2N' => 'Trident ?TY2N?',
  1698. 'U263' => 'UB Video H.263/H.263+/H.263++ Decoder',
  1699. 'UMP4' => 'UB Video MPEG 4 (www.ubvideo.com)',
  1700. 'UYNV' => 'Nvidia UYVY packed 4:2:2',
  1701. 'UYVP' => 'Evans & Sutherland YCbCr 4:2:2 extended precision',
  1702. 'UCOD' => 'eMajix.com ClearVideo',
  1703. 'ULTI' => 'IBM Ultimotion',
  1704. 'UYVY' => 'UYVY packed 4:2:2',
  1705. 'V261' => 'Lucent VX2000S',
  1706. 'VIFP' => 'VFAPI Reader Codec (www.yks.ne.jp/~hori/)',
  1707. 'VIV1' => 'FFmpeg H263+ decoder',
  1708. 'VIV2' => 'Vivo H.263',
  1709. 'VQC2' => 'Vector-quantised codec 2 (research) http://eprints.ecs.soton.ac.uk/archive/00001310/01/VTC97-js.pdf)',
  1710. 'VTLP' => 'Alaris VideoGramPiX',
  1711. 'VYU9' => 'ATI YUV (VYU9)',
  1712. 'VYUY' => 'ATI YUV (VYUY)',
  1713. 'V261' => 'Lucent VX2000S',
  1714. 'V422' => 'Vitec Multimedia 24-bit YUV 4:2:2 Format',
  1715. 'V655' => 'Vitec Multimedia 16-bit YUV 4:2:2 Format',
  1716. 'VCR1' => 'ATI Video Codec 1',
  1717. 'VCR2' => 'ATI Video Codec 2',
  1718. 'VCR3' => 'ATI VCR 3.0',
  1719. 'VCR4' => 'ATI VCR 4.0',
  1720. 'VCR5' => 'ATI VCR 5.0',
  1721. 'VCR6' => 'ATI VCR 6.0',
  1722. 'VCR7' => 'ATI VCR 7.0',
  1723. 'VCR8' => 'ATI VCR 8.0',
  1724. 'VCR9' => 'ATI VCR 9.0',
  1725. 'VDCT' => 'Vitec Multimedia Video Maker Pro DIB',
  1726. 'VDOM' => 'VDOnet VDOWave',
  1727. 'VDOW' => 'VDOnet VDOLive (H.263)',
  1728. 'VDTZ' => 'Darim Vison VideoTizer YUV',
  1729. 'VGPX' => 'Alaris VideoGramPiX',
  1730. 'VIDS' => 'Vitec Multimedia YUV 4:2:2 CCIR 601 for V422',
  1731. 'VIVO' => 'Vivo H.263 v2.00',
  1732. 'vivo' => 'Vivo H.263',
  1733. 'VIXL' => 'Miro/Pinnacle Video XL',
  1734. 'VLV1' => 'VideoLogic/PURE Digital Videologic Capture',
  1735. 'VP30' => 'On2 VP3.0',
  1736. 'VP31' => 'On2 VP3.1',
  1737. 'VX1K' => 'Lucent VX1000S Video Codec',
  1738. 'VX2K' => 'Lucent VX2000S Video Codec',
  1739. 'VXSP' => 'Lucent VX1000SP Video Codec',
  1740. 'WBVC' => 'Winbond W9960',
  1741. 'WHAM' => 'Microsoft Video 1 (WHAM)',
  1742. 'WINX' => 'Winnov Software Compression',
  1743. 'WJPG' => 'AverMedia Winbond JPEG',
  1744. 'WMV1' => 'Windows Media Video V7',
  1745. 'WMV2' => 'Windows Media Video V8',
  1746. 'WMV3' => 'Windows Media Video V9',
  1747. 'WNV1' => 'Winnov Hardware Compression',
  1748. 'XYZP' => 'Extended PAL format XYZ palette (www.riff.org)',
  1749. 'x263' => 'Xirlink H.263',
  1750. 'XLV0' => 'NetXL Video Decoder',
  1751. 'XMPG' => 'Xing MPEG (I-Frame only)',
  1752. 'XVID' => 'XviD MPEG-4 (www.xvid.org)',
  1753. 'XXAN' => '?XXAN?',
  1754. 'YU92' => 'Intel YUV (YU92)',
  1755. 'YUNV' => 'Nvidia Uncompressed YUV 4:2:2',
  1756. 'YUVP' => 'Extended PAL format YUV palette (www.riff.org)',
  1757. 'Y211' => 'YUV 2:1:1 Packed',
  1758. 'Y411' => 'YUV 4:1:1 Packed',
  1759. 'Y41B' => 'Weitek YUV 4:1:1 Planar',
  1760. 'Y41P' => 'Brooktree PC1 YUV 4:1:1 Packed',
  1761. 'Y41T' => 'Brooktree PC1 YUV 4:1:1 with transparency',
  1762. 'Y42B' => 'Weitek YUV 4:2:2 Planar',
  1763. 'Y42T' => 'Brooktree UYUV 4:2:2 with transparency',
  1764. 'Y422' => 'ADS Technologies Copy of UYVY used in Pyro WebCam firewire camera',
  1765. 'Y800' => 'Simple, single Y plane for monochrome images',
  1766. 'Y8 ' => 'Grayscale video',
  1767. 'YC12' => 'Intel YUV 12 codec',
  1768. 'YUV8' => 'Winnov Caviar YUV8',
  1769. 'YUV9' => 'Intel YUV9',
  1770. 'YUY2' => 'Uncompressed YUV 4:2:2',
  1771. 'YUYV' => 'Canopus YUV',
  1772. 'YV12' => 'YVU12 Planar',
  1773. 'YVU9' => 'Intel YVU9 Planar (8-bpp Y plane, followed by 8-bpp 4x4 U and V planes)',
  1774. 'YVYU' => 'YVYU 4:2:2 Packed',
  1775. 'ZLIB' => 'Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm)',
  1776. 'ZPEG' => 'Metheus Video Zipper'
  1777. );
  1778. return @$lookup[$four_cc];
  1779. }
  1780. public static function RIFFcommentsParse(&$riff_info_aray, &$comments_target_array) {
  1781. static $lookup = array(
  1782. 'IARL' => 'archivallocation',
  1783. 'IART' => 'artist',
  1784. 'ICDS' => 'costumedesigner',
  1785. 'ICMS' => 'commissionedby',
  1786. 'ICMT' => 'comment',
  1787. 'ICNT' => 'country',
  1788. 'ICOP' => 'copyright',
  1789. 'ICRD' => 'creationdate',
  1790. 'IDIM' => 'dimensions',
  1791. 'IDIT' => 'digitizationdate',
  1792. 'IDPI' => 'resolution',
  1793. 'IDST' => 'distributor',
  1794. 'IEDT' => 'editor',
  1795. 'IENG' => 'engineers',
  1796. 'IFRM' => 'accountofparts',
  1797. 'IGNR' => 'genre',
  1798. 'IKEY' => 'keywords',
  1799. 'ILGT' => 'lightness',
  1800. 'ILNG' => 'language',
  1801. 'IMED' => 'orignalmedium',
  1802. 'IMUS' => 'composer',
  1803. 'INAM' => 'title',
  1804. 'IPDS' => 'productiondesigner',
  1805. 'IPLT' => 'palette',
  1806. 'IPRD' => 'product',
  1807. 'IPRO' => 'producer',
  1808. 'IPRT' => 'part',
  1809. 'IRTD' => 'rating',
  1810. 'ISBJ' => 'subject',
  1811. 'ISFT' => 'software',
  1812. 'ISGN' => 'secondarygenre',
  1813. 'ISHP' => 'sharpness',
  1814. 'ISRC' => 'sourcesupplier',
  1815. 'ISRF' => 'digitizationsource',
  1816. 'ISTD' => 'productionstudio',
  1817. 'ISTR' => 'starring',
  1818. 'ITCH' => 'encoded_by',
  1819. 'IWEB' => 'url',
  1820. 'IWRI' => 'writer'
  1821. );
  1822. foreach ($lookup as $key => $value) {
  1823. if (isset($riff_info_aray[$key])) {
  1824. foreach ($riff_info_aray[$key] as $comment_id => $comment_data) {
  1825. if (trim($comment_data['data']) != '') {
  1826. @$comments_target_array[$value][] = trim($comment_data['data']);
  1827. }
  1828. }
  1829. }
  1830. }
  1831. return true;
  1832. }
  1833. public static function array_merge_noclobber($array1, $array2) {
  1834. if (!is_array($array1) || !is_array($array2)) {
  1835. return false;
  1836. }
  1837. $new_array = $array1;
  1838. foreach ($array2 as $key => $val) {
  1839. if (is_array($val) && isset($new_array[$key]) && is_array($new_array[$key])) {
  1840. $new_array[$key] = getid3_riff::array_merge_noclobber($new_array[$key], $val);
  1841. } elseif (!isset($new_array[$key])) {
  1842. $new_array[$key] = $val;
  1843. }
  1844. }
  1845. return $new_array;
  1846. }
  1847. public static function DateMac2Unix($mac_date) {
  1848. // Macintosh timestamp: seconds since 00:00h January 1, 1904
  1849. // UNIX timestamp: seconds since 00:00h January 1, 1970
  1850. return (int)($mac_date - 2082844800);
  1851. }
  1852. public static function FixedPoint16_16($raw_data) {
  1853. return getid3_lib::BigEndian2Int(substr($raw_data, 0, 2)) + (float)(getid3_lib::BigEndian2Int(substr($raw_data, 2, 2)) / 65536); // pow(2, 16) = 65536
  1854. }
  1855. function BigEndian2Float($byte_word) {
  1856. // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
  1857. // http://www.psc.edu/general/software/packages/ieee/ieee.html
  1858. // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
  1859. $bit_word = getid3_lib::BigEndian2Bin($byte_word);
  1860. $sign_bit = $bit_word{0};
  1861. switch (strlen($byte_word) * 8) {
  1862. case 32:
  1863. $exponent_bits = 8;
  1864. $fraction_bits = 23;
  1865. break;
  1866. case 64:
  1867. $exponent_bits = 11;
  1868. $fraction_bits = 52;
  1869. break;
  1870. case 80:
  1871. // 80-bit Apple SANE format
  1872. // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
  1873. $exponent_string = substr($bit_word, 1, 15);
  1874. $is_normalized = intval($bit_word{16});
  1875. $fraction_string = substr($bit_word, 17, 63);
  1876. $exponent = pow(2, bindec($exponent_string) - 16383);
  1877. $fraction = $is_normalized + bindec($fraction_string) / bindec('1'.str_repeat('0', strlen($fraction_string)));
  1878. $float_value = $exponent * $fraction;
  1879. if ($sign_bit == '1') {
  1880. $float_value *= -1;
  1881. }
  1882. return $float_value;
  1883. break;
  1884. default:
  1885. return false;
  1886. break;
  1887. }
  1888. $exponent_string = substr($bit_word, 1, $exponent_bits);
  1889. $fraction_string = substr($bit_word, $exponent_bits + 1, $fraction_bits);
  1890. $exponent = bindec($exponent_string);
  1891. $fraction = bindec($fraction_string);
  1892. if (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction != 0)) {
  1893. // Not a Number
  1894. $float_value = false;
  1895. } elseif (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction == 0)) {
  1896. if ($sign_bit == '1') {
  1897. $float_value = '-infinity';
  1898. } else {
  1899. $float_value = '+infinity';
  1900. }
  1901. } elseif (($exponent == 0) && ($fraction == 0)) {
  1902. if ($sign_bit == '1') {
  1903. $float_value = -0;
  1904. } else {
  1905. $float_value = 0;
  1906. }
  1907. $float_value = ($sign_bit ? 0 : -0);
  1908. } elseif (($exponent == 0) && ($fraction != 0)) {
  1909. // These are 'unnormalized' values
  1910. $float_value = pow(2, (-1 * (pow(2, $exponent_bits - 1) - 2))) * bindec($fraction_string) / bindec('1'.str_repeat('0', strlen($fraction_string)));
  1911. if ($sign_bit == '1') {
  1912. $float_value *= -1;
  1913. }
  1914. } elseif ($exponent != 0) {
  1915. $float_value = pow(2, ($exponent - (pow(2, $exponent_bits - 1) - 1))) * (1 + bindec($fraction_string) / bindec('1'.str_repeat('0', strlen($fraction_string))));
  1916. if ($sign_bit == '1') {
  1917. $float_value *= -1;
  1918. }
  1919. }
  1920. return (float) $float_value;
  1921. }
  1922. }
  1923. ?>