Annotation of /trunk/lib/getid3/module.audio.lpac.php
Parent Directory
|
Revision Log
Revision 2 - (view) (download)
| 1 : | andphe | 2 | <?php |
| 2 : | ///////////////////////////////////////////////////////////////// | ||
| 3 : | /// getID3() by James Heinrich <info@getid3.org> // | ||
| 4 : | // available at http://getid3.sourceforge.net // | ||
| 5 : | // or http://www.getid3.org // | ||
| 6 : | ///////////////////////////////////////////////////////////////// | ||
| 7 : | // See readme.txt for more details // | ||
| 8 : | ///////////////////////////////////////////////////////////////// | ||
| 9 : | // // | ||
| 10 : | // module.audio.lpac.php // | ||
| 11 : | // module for analyzing LPAC Audio files // | ||
| 12 : | // dependencies: module.audio-video.riff.php // | ||
| 13 : | // /// | ||
| 14 : | ///////////////////////////////////////////////////////////////// | ||
| 15 : | // MOS Intruder Alerts | ||
| 16 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 17 : | |||
| 18 : | getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); | ||
| 19 : | |||
| 20 : | class getid3_lpac | ||
| 21 : | { | ||
| 22 : | |||
| 23 : | function getid3_lpac(&$fd, &$ThisFileInfo) { | ||
| 24 : | $StreamMarker = 0; | ||
| 25 : | fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); | ||
| 26 : | $LPACheader = fread($fd, 14); | ||
| 27 : | if (substr($LPACheader, 0, 4) != 'LPAC') { | ||
| 28 : | $ThisFileInfo['error'][] = 'Expected "LPAC" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$StreamMarker.'"'; | ||
| 29 : | return false; | ||
| 30 : | } | ||
| 31 : | $ThisFileInfo['avdataoffset'] += 14; | ||
| 32 : | |||
| 33 : | $ThisFileInfo['fileformat'] = 'lpac'; | ||
| 34 : | $ThisFileInfo['audio']['dataformat'] = 'lpac'; | ||
| 35 : | $ThisFileInfo['audio']['lossless'] = true; | ||
| 36 : | $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; | ||
| 37 : | |||
| 38 : | $ThisFileInfo['lpac']['file_version'] = getid3_lib::BigEndian2Int(substr($LPACheader, 4, 1)); | ||
| 39 : | $flags['audio_type'] = getid3_lib::BigEndian2Int(substr($LPACheader, 5, 1)); | ||
| 40 : | $ThisFileInfo['lpac']['total_samples']= getid3_lib::BigEndian2Int(substr($LPACheader, 6, 4)); | ||
| 41 : | $flags['parameters'] = getid3_lib::BigEndian2Int(substr($LPACheader, 10, 4)); | ||
| 42 : | |||
| 43 : | $ThisFileInfo['lpac']['flags']['is_wave'] = (bool) ($flags['audio_type'] & 0x40); | ||
| 44 : | $ThisFileInfo['lpac']['flags']['stereo'] = (bool) ($flags['audio_type'] & 0x04); | ||
| 45 : | $ThisFileInfo['lpac']['flags']['24_bit'] = (bool) ($flags['audio_type'] & 0x02); | ||
| 46 : | $ThisFileInfo['lpac']['flags']['16_bit'] = (bool) ($flags['audio_type'] & 0x01); | ||
| 47 : | |||
| 48 : | if ($ThisFileInfo['lpac']['flags']['24_bit'] && $ThisFileInfo['lpac']['flags']['16_bit']) { | ||
| 49 : | $ThisFileInfo['warning'][] = '24-bit and 16-bit flags cannot both be set'; | ||
| 50 : | } | ||
| 51 : | |||
| 52 : | $ThisFileInfo['lpac']['flags']['fast_compress'] = (bool) ($flags['parameters'] & 0x40000000); | ||
| 53 : | $ThisFileInfo['lpac']['flags']['random_access'] = (bool) ($flags['parameters'] & 0x08000000); | ||
| 54 : | $ThisFileInfo['lpac']['block_length'] = pow(2, (($flags['parameters'] & 0x07000000) >> 24)) * 256; | ||
| 55 : | $ThisFileInfo['lpac']['flags']['adaptive_prediction_order'] = (bool) ($flags['parameters'] & 0x00800000); | ||
| 56 : | $ThisFileInfo['lpac']['flags']['adaptive_quantization'] = (bool) ($flags['parameters'] & 0x00400000); | ||
| 57 : | $ThisFileInfo['lpac']['flags']['joint_stereo'] = (bool) ($flags['parameters'] & 0x00040000); | ||
| 58 : | $ThisFileInfo['lpac']['quantization'] = ($flags['parameters'] & 0x00001F00) >> 8; | ||
| 59 : | $ThisFileInfo['lpac']['max_prediction_order'] = ($flags['parameters'] & 0x0000003F); | ||
| 60 : | |||
| 61 : | if ($ThisFileInfo['lpac']['flags']['fast_compress'] && ($ThisFileInfo['lpac']['max_prediction_order'] != 3)) { | ||
| 62 : | $ThisFileInfo['warning'][] = 'max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$ThisFileInfo['lpac']['max_prediction_order'].'"'; | ||
| 63 : | } | ||
| 64 : | switch ($ThisFileInfo['lpac']['file_version']) { | ||
| 65 : | case 6: | ||
| 66 : | if ($ThisFileInfo['lpac']['flags']['adaptive_quantization']) { | ||
| 67 : | $ThisFileInfo['warning'][] = 'adaptive_quantization expected to be false in LPAC file stucture v6, actually true'; | ||
| 68 : | } | ||
| 69 : | if ($ThisFileInfo['lpac']['quantization'] != 20) { | ||
| 70 : | $ThisFileInfo['warning'][] = 'Quantization expected to be 20 in LPAC file stucture v6, actually '.$ThisFileInfo['lpac']['flags']['Q']; | ||
| 71 : | } | ||
| 72 : | break; | ||
| 73 : | |||
| 74 : | default: | ||
| 75 : | //$ThisFileInfo['warning'][] = 'This version of getID3() only supports LPAC file format version 6, this file is version '.$ThisFileInfo['lpac']['file_version'].' - please report to info@getid3.org'; | ||
| 76 : | break; | ||
| 77 : | } | ||
| 78 : | |||
| 79 : | $dummy = $ThisFileInfo; | ||
| 80 : | $riff = new getid3_riff($fd, $dummy); | ||
| 81 : | $ThisFileInfo['avdataoffset'] = $dummy['avdataoffset']; | ||
| 82 : | $ThisFileInfo['riff'] = $dummy['riff']; | ||
| 83 : | $ThisFileInfo['error'] = $dummy['error']; | ||
| 84 : | $ThisFileInfo['warning'] = $dummy['warning']; | ||
| 85 : | $ThisFileInfo['lpac']['comments']['comment'] = $dummy['comments']; | ||
| 86 : | $ThisFileInfo['audio']['sample_rate'] = $dummy['audio']['sample_rate']; | ||
| 87 : | |||
| 88 : | $ThisFileInfo['audio']['channels'] = ($ThisFileInfo['lpac']['flags']['stereo'] ? 2 : 1); | ||
| 89 : | |||
| 90 : | if ($ThisFileInfo['lpac']['flags']['24_bit']) { | ||
| 91 : | $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['riff']['audio'][0]['bits_per_sample']; | ||
| 92 : | } elseif ($ThisFileInfo['lpac']['flags']['16_bit']) { | ||
| 93 : | $ThisFileInfo['audio']['bits_per_sample'] = 16; | ||
| 94 : | } else { | ||
| 95 : | $ThisFileInfo['audio']['bits_per_sample'] = 8; | ||
| 96 : | } | ||
| 97 : | |||
| 98 : | if ($ThisFileInfo['lpac']['flags']['fast_compress']) { | ||
| 99 : | // fast | ||
| 100 : | $ThisFileInfo['audio']['encoder_options'] = '-1'; | ||
| 101 : | } else { | ||
| 102 : | switch ($ThisFileInfo['lpac']['max_prediction_order']) { | ||
| 103 : | case 20: // simple | ||
| 104 : | $ThisFileInfo['audio']['encoder_options'] = '-2'; | ||
| 105 : | break; | ||
| 106 : | case 30: // medium | ||
| 107 : | $ThisFileInfo['audio']['encoder_options'] = '-3'; | ||
| 108 : | break; | ||
| 109 : | case 40: // high | ||
| 110 : | $ThisFileInfo['audio']['encoder_options'] = '-4'; | ||
| 111 : | break; | ||
| 112 : | case 60: // extrahigh | ||
| 113 : | $ThisFileInfo['audio']['encoder_options'] = '-5'; | ||
| 114 : | break; | ||
| 115 : | } | ||
| 116 : | } | ||
| 117 : | |||
| 118 : | $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['lpac']['total_samples'] / $ThisFileInfo['audio']['sample_rate']; | ||
| 119 : | $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; | ||
| 120 : | |||
| 121 : | return true; | ||
| 122 : | } | ||
| 123 : | |||
| 124 : | } | ||
| 125 : | |||
| 126 : | |||
| 127 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

