public function Analyze() { $getid3 = $this->getid3; $getid3->info['riff']['raw'] = array(); $info_riff =& $getid3->info['riff']; $info_riff_raw =& $info_riff['raw']; $info_audio =& $getid3->info['audio']; $info_video =& $getid3->info['video']; $info_avdataoffset =& $getid3->info['avdataoffset']; $info_avdataend =& $getid3->info['avdataend']; $info_audio_dataformat =& $info_audio['dataformat']; $info_riff_audio =& $info_riff['audio']; $info_riff_video =& $info_riff['video']; $original['avdataend'] = $info_avdataend; $this->fseek($info_avdataoffset, SEEK_SET); $riff_header = $this->fread(12); $riff_sub_type = substr($riff_header, 8, 4); switch (substr($riff_header, 0, 4)) { case 'FORM': $getid3->info['fileformat'] = 'aiff'; $this->endian_function = 'BigEndian2Int'; $riff_header_size = getid3_lib::BigEndian2Int(substr($riff_header, 4, 4)); $info_riff[$riff_sub_type] = $this->ParseRIFF($info_avdataoffset + 12, $info_avdataoffset + $riff_header_size); $info_riff['header_size'] = $riff_header_size; break; case 'RIFF': case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com) // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com) case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s if ($riff_sub_type == 'RMP3') { $riff_sub_type = 'WAVE'; } $getid3->info['fileformat'] = 'riff'; $this->endian_function = 'LittleEndian2Int'; $riff_header_size = getid3_lib::LittleEndian2Int(substr($riff_header, 4, 4)); $info_riff[$riff_sub_type] = $this->ParseRIFF($info_avdataoffset + 12, $info_avdataoffset + $riff_header_size); $info_riff['header_size'] = $riff_header_size; if ($riff_sub_type == 'WAVE') { $info_riff_wave =& $info_riff['WAVE']; } break; default: 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'); } $endian_function = $this->endian_function; $stream_index = 0; switch ($riff_sub_type) { case 'WAVE': if (empty($info_audio['bitrate_mode'])) { $info_audio['bitrate_mode'] = 'cbr'; } if (empty($info_audio_dataformat)) { $info_audio_dataformat = 'wav'; } if (isset($info_riff_wave['data'][0]['offset'])) { $info_avdataoffset = $info_riff_wave['data'][0]['offset'] + 8; $info_avdataend = $info_avdataoffset + $info_riff_wave['data'][0]['size']; } if (isset($info_riff_wave['fmt '][0]['data'])) { $info_riff_audio[$stream_index] = getid3_riff::RIFFparseWAVEFORMATex($info_riff_wave['fmt '][0]['data']); $info_audio['wformattag'] = $info_riff_audio[$stream_index]['raw']['wFormatTag']; $info_riff_raw['fmt '] = $info_riff_audio[$stream_index]['raw']; unset($info_riff_audio[$stream_index]['raw']); $info_audio['streams'][$stream_index] = $info_riff_audio[$stream_index]; $info_audio = getid3_riff::array_merge_noclobber($info_audio, $info_riff_audio[$stream_index]); if (substr($info_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') { $getid3->warning('Audio codec = ' . $info_audio['codec']); } $info_audio['bitrate'] = $info_riff_audio[$stream_index]['bitrate']; $getid3->info['playtime_seconds'] = (double) (($info_avdataend - $info_avdataoffset) * 8 / $info_audio['bitrate']); $info_audio['lossless'] = false; if (isset($info_riff_wave['data'][0]['offset']) && isset($info_riff_raw['fmt ']['wFormatTag'])) { switch ($info_riff_raw['fmt ']['wFormatTag']) { case 0x1: // PCM $info_audio['lossless'] = true; break; case 0x2000: // AC-3 $info_audio_dataformat = 'ac3'; break; default: // do nothing break; } } $info_audio['streams'][$stream_index]['wformattag'] = $info_audio['wformattag']; $info_audio['streams'][$stream_index]['bitrate_mode'] = $info_audio['bitrate_mode']; $info_audio['streams'][$stream_index]['lossless'] = $info_audio['lossless']; $info_audio['streams'][$stream_index]['dataformat'] = $info_audio_dataformat; } if (isset($info_riff_wave['rgad'][0]['data'])) { // shortcuts $rgadData =& $info_riff_wave['rgad'][0]['data']; $info_riff_raw['rgad'] = array('track' => array(), 'album' => array()); $info_riff_raw_rgad =& $info_riff_raw['rgad']; $info_riff_raw_rgad_track =& $info_riff_raw_rgad['track']; $info_riff_raw_rgad_album =& $info_riff_raw_rgad['album']; $info_riff_raw_rgad['fPeakAmplitude'] = getid3_riff::BigEndian2Float(strrev(substr($rgadData, 0, 4))); // LittleEndian2Float() $info_riff_raw_rgad['nRadioRgAdjust'] = getid3_lib::$endian_function(substr($rgadData, 4, 2)); $info_riff_raw_rgad['nAudiophileRgAdjust'] = getid3_lib::$endian_function(substr($rgadData, 6, 2)); $n_track_rg_adjust_bit_string = str_pad(decbin($info_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT); $n_album_rg_adjust_bit_string = str_pad(decbin($info_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT); $info_riff_raw_rgad_track['name'] = bindec(substr($n_track_rg_adjust_bit_string, 0, 3)); $info_riff_raw_rgad_track['originator'] = bindec(substr($n_track_rg_adjust_bit_string, 3, 3)); $info_riff_raw_rgad_track['signbit'] = bindec($n_track_rg_adjust_bit_string[6]); $info_riff_raw_rgad_track['adjustment'] = bindec(substr($n_track_rg_adjust_bit_string, 7, 9)); $info_riff_raw_rgad_album['name'] = bindec(substr($n_album_rg_adjust_bit_string, 0, 3)); $info_riff_raw_rgad_album['originator'] = bindec(substr($n_album_rg_adjust_bit_string, 3, 3)); $info_riff_raw_rgad_album['signbit'] = bindec($n_album_rg_adjust_bit_string[6]); $info_riff_raw_rgad_album['adjustment'] = bindec(substr($n_album_rg_adjust_bit_string, 7, 9)); $info_riff['rgad']['peakamplitude'] = $info_riff_raw_rgad['fPeakAmplitude']; if ($info_riff_raw_rgad_track['name'] != 0 && $info_riff_raw_rgad_track['originator'] != 0) { $info_riff['rgad']['track']['name'] = getid3_lib_replaygain::NameLookup($info_riff_raw_rgad_track['name']); $info_riff['rgad']['track']['originator'] = getid3_lib_replaygain::OriginatorLookup($info_riff_raw_rgad_track['originator']); $info_riff['rgad']['track']['adjustment'] = getid3_lib_replaygain::AdjustmentLookup($info_riff_raw_rgad_track['adjustment'], $info_riff_raw_rgad_track['signbit']); } if ($info_riff_raw_rgad_album['name'] != 0 && $info_riff_raw_rgad_album['originator'] != 0) { $info_riff['rgad']['album']['name'] = getid3_lib_replaygain::NameLookup($info_riff_raw_rgad_album['name']); $info_riff['rgad']['album']['originator'] = getid3_lib_replaygain::OriginatorLookup($info_riff_raw_rgad_album['originator']); $info_riff['rgad']['album']['adjustment'] = getid3_lib_replaygain::AdjustmentLookup($info_riff_raw_rgad_album['adjustment'], $info_riff_raw_rgad_album['signbit']); } } if (isset($info_riff_wave['fact'][0]['data'])) { $info_riff_raw['fact']['NumberOfSamples'] = getid3_lib::$endian_function(substr($info_riff_wave['fact'][0]['data'], 0, 4)); // 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 // if (!empty($info_riff_raw['fmt ']['nSamplesPerSec'])) { // $getid3->info['playtime_seconds'] = (float)$info_riff_raw['fact']['NumberOfSamples'] / $info_riff_raw['fmt ']['nSamplesPerSec']; // } } if (!empty($info_riff_raw['fmt ']['nAvgBytesPerSec'])) { $info_audio['bitrate'] = (int) $info_riff_raw['fmt ']['nAvgBytesPerSec'] * 8; } if (isset($info_riff_wave['bext'][0]['data'])) { $info_riff_wave_bext_0 =& $info_riff_wave['bext'][0]; getid3_lib::ReadSequence('LittleEndian2Int', $info_riff_wave_bext_0, $info_riff_wave_bext_0['data'], 0, array('title' => -256, 'author' => -32, 'reference' => -32, 'origin_date' => -10, 'origin_time' => -8, 'time_reference' => 8, 'bwf_version' => 1, 'reserved' => 254)); foreach (array('title', 'author', 'reference') as $key) { $info_riff_wave_bext_0[$key] = trim($info_riff_wave_bext_0[$key]); } $info_riff_wave_bext_0['coding_history'] = explode("\r\n", trim(substr($info_riff_wave_bext_0['data'], 601))); $info_riff_wave_bext_0['origin_date_unix'] = gmmktime(substr($info_riff_wave_bext_0['origin_time'], 0, 2), substr($info_riff_wave_bext_0['origin_time'], 3, 2), substr($info_riff_wave_bext_0['origin_time'], 6, 2), substr($info_riff_wave_bext_0['origin_date'], 5, 2), substr($info_riff_wave_bext_0['origin_date'], 8, 2), substr($info_riff_wave_bext_0['origin_date'], 0, 4)); $info_riff['comments']['author'][] = $info_riff_wave_bext_0['author']; $info_riff['comments']['title'][] = $info_riff_wave_bext_0['title']; } if (isset($info_riff_wave['MEXT'][0]['data'])) { $info_riff_wave_mext_0 =& $info_riff_wave['MEXT'][0]; $info_riff_wave_mext_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 0, 2)); $info_riff_wave_mext_0['flags']['homogenous'] = (bool) ($info_riff_wave_mext_0['raw']['sound_information'] & 0x1); if ($info_riff_wave_mext_0['flags']['homogenous']) { $info_riff_wave_mext_0['flags']['padding'] = $info_riff_wave_mext_0['raw']['sound_information'] & 0x2 ? false : true; $info_riff_wave_mext_0['flags']['22_or_44'] = (bool) ($info_riff_wave_mext_0['raw']['sound_information'] & 0x4); $info_riff_wave_mext_0['flags']['free_format'] = (bool) ($info_riff_wave_mext_0['raw']['sound_information'] & 0x8); $info_riff_wave_mext_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 2, 2)); } $info_riff_wave_mext_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 6, 2)); $info_riff_wave_mext_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_mext_0['data'], 8, 2)); $info_riff_wave_mext_0['flags']['anciliary_data_left'] = (bool) ($info_riff_wave_mext_0['raw']['anciliary_data_def'] & 0x1); $info_riff_wave_mext_0['flags']['anciliary_data_free'] = (bool) ($info_riff_wave_mext_0['raw']['anciliary_data_def'] & 0x2); $info_riff_wave_mext_0['flags']['anciliary_data_right'] = (bool) ($info_riff_wave_mext_0['raw']['anciliary_data_def'] & 0x4); } if (isset($info_riff_wave['cart'][0]['data'])) { $info_riff_wave_cart_0 =& $info_riff_wave['cart'][0]; getid3_lib::ReadSequence('LittleEndian2Int', $info_riff_wave_cart_0, $info_riff_wave_cart_0['data'], 0, array('version' => -4, 'title' => -64, 'artist' => -64, 'cut_id' => -64, 'client_id' => -64, 'category' => -64, 'classification' => -64, 'out_cue' => -64, 'start_date' => -10, 'start_time' => -8, 'end_date' => -10, 'end_time' => -8, 'producer_app_id' => -64, 'producer_app_version' => -64, 'user_defined_text' => -64)); 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) { $info_riff_wave_cart_0[$key] = trim($info_riff_wave_cart_0[$key]); } $info_riff_wave_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($info_riff_wave_cart_0['data'], 680, 4), true); for ($i = 0; $i < 8; $i++) { $info_riff_wave_cart_0['post_time'][$i]['usage_fourcc'] = substr($info_riff_wave_cart_0['data'], 684 + $i * 8, 4); $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)); } $info_riff_wave_cart_0['url'] = trim(substr($info_riff_wave_cart_0['data'], 748, 1024)); $info_riff_wave_cart_0['tag_text'] = explode("\r\n", trim(substr($info_riff_wave_cart_0['data'], 1772))); $info_riff['comments']['artist'][] = $info_riff_wave_cart_0['artist']; $info_riff['comments']['title'][] = $info_riff_wave_cart_0['title']; } if (!isset($info_audio['bitrate']) && isset($info_riff_audio[$stream_index]['bitrate'])) { $info_audio['bitrate'] = $info_riff_audio[$stream_index]['bitrate']; $getid3->info['playtime_seconds'] = (double) (($info_avdataend - $info_avdataoffset) * 8 / $info_audio['bitrate']); } if (@$getid3->info['wavpack']) { if (!$this->data_string_flag) { $info_audio_dataformat = 'wavpack'; $info_audio['bitrate_mode'] = 'vbr'; $info_audio['encoder'] = 'WavPack v' . $getid3->info['wavpack']['version']; // Reset to the way it was - RIFF parsing will have messed this up $info_avdataend = $original['avdataend']; $info_audio['bitrate'] = ($info_avdataend - $info_avdataoffset) * 8 / $getid3->info['playtime_seconds']; $this->fseek($info_avdataoffset - 44, SEEK_SET); $riff_data = $this->fread(44); $orignal_riff_header_size = getid3_lib::LittleEndian2Int(substr($riff_data, 4, 4)) + 8; $orignal_riff_data_size = getid3_lib::LittleEndian2Int(substr($riff_data, 40, 4)) + 44; if ($orignal_riff_header_size > $orignal_riff_data_size) { $info_avdataend -= $orignal_riff_header_size - $orignal_riff_data_size; $this->fseek($info_avdataend, SEEK_SET); $riff_data .= $this->fread($orignal_riff_header_size - $orignal_riff_data_size); } // move the data chunk after all other chunks (if any) // so that the RIFF parser doesn't see EOF when trying // to skip over the data chunk $riff_data = substr($riff_data, 0, 36) . substr($riff_data, 44) . substr($riff_data, 36, 8); // Save audio info key $saved_info_audio = $info_audio; // Analyze riff_data $this->AnalyzeString($riff_data); // Restore info key $info_audio = $saved_info_audio; } } if (isset($info_riff_raw['fmt ']['wFormatTag'])) { switch ($info_riff_raw['fmt ']['wFormatTag']) { case 0x8ae: // ClearJump LiteWave $info_audio['bitrate_mode'] = 'vbr'; $info_audio_dataformat = 'litewave'; //typedef struct tagSLwFormat { // WORD m_wCompFormat; // low byte defines compression method, high byte is compression flags // DWORD m_dwScale; // scale factor for lossy compression // DWORD m_dwBlockSize; // number of samples in encoded blocks // WORD m_wQuality; // alias for the scale factor // WORD m_wMarkDistance; // distance between marks in bytes // WORD m_wReserved; // // //following paramters are ignored if CF_FILESRC is not set // DWORD m_dwOrgSize; // original file size in bytes // WORD m_bFactExists; // indicates if 'fact' chunk exists in the original file // DWORD m_dwRiffChunkSize; // riff chunk size in the original file // // PCMWAVEFORMAT m_OrgWf; // original wave format // }SLwFormat, *PSLwFormat; $info_riff['litewave']['raw'] = array(); $info_riff_litewave =& $info_riff['litewave']; $info_riff_litewave_raw =& $info_riff_litewave['raw']; getid3_lib::ReadSequence('LittleEndian2Int', $info_riff_litewave_raw, $info_riff_wave['fmt '][0]['data'], 18, array('compression_method' => 1, 'compression_flags' => 1, 'm_dwScale' => 4, 'm_dwBlockSize' => 4, 'm_wQuality' => 2, 'm_wMarkDistance' => 2, 'm_wReserved' => 2, 'm_dwOrgSize' => 4, 'm_bFactExists' => 2, 'm_dwRiffChunkSize' => 4)); //$info_riff_litewave['quality_factor'] = intval(round((2000 - $info_riff_litewave_raw['m_dwScale']) / 20)); $info_riff_litewave['quality_factor'] = $info_riff_litewave_raw['m_wQuality']; $info_riff_litewave['flags']['raw_source'] = $info_riff_litewave_raw['compression_flags'] & 0x1 ? false : true; $info_riff_litewave['flags']['vbr_blocksize'] = $info_riff_litewave_raw['compression_flags'] & 0x2 ? false : true; $info_riff_litewave['flags']['seekpoints'] = (bool) ($info_riff_litewave_raw['compression_flags'] & 0x4); $info_audio['lossless'] = $info_riff_litewave_raw['m_wQuality'] == 100 ? true : false; $info_audio['encoder_options'] = '-q' . $info_riff_litewave['quality_factor']; break; } } if ($info_avdataend > $getid3->info['filesize']) { switch (@$info_audio_dataformat) { case 'wavpack': // WavPack // WavPack case 'lpac': // LPAC // LPAC case 'ofr': // OptimFROG // OptimFROG case 'ofs': // OptimFROG DualStream // lossless compressed audio formats that keep original RIFF headers - skip warning break; case 'litewave': if ($info_avdataend - $getid3->info['filesize'] == 1) { // LiteWave appears to incorrectly *not* pad actual output file // to nearest WORD boundary so may appear to be short by one // byte, in which case - skip warning } else { // Short by more than one byte, throw warning $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)'); } break; default: if ($info_avdataend - $getid3->info['filesize'] == 1 && $info_riff[$riff_sub_type]['data'][0]['size'] % 2 == 0 && ($getid3->info['filesize'] - $info_avdataoffset) % 2 == 1) { // output file appears to be incorrectly *not* padded to nearest WORD boundary // Output less severe warning $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)'); $info_avdataend = $getid3->info['filesize']; break; } // Short by more than one byte, throw warning $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)'); $info_avdataend = $getid3->info['filesize']; break; } } if (!empty($getid3->info['mpeg']['audio']['LAME']['audio_bytes'])) { if ($info_avdataend - $info_avdataoffset - $getid3->info['mpeg']['audio']['LAME']['audio_bytes'] == 1) { $info_avdataend--; $getid3->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored'); } } if (@$info_audio_dataformat == 'ac3') { unset($info_audio['bits_per_sample']); if (!empty($getid3->info['ac3']['bitrate']) && $getid3->info['ac3']['bitrate'] != $info_audio['bitrate']) { $info_audio['bitrate'] = $getid3->info['ac3']['bitrate']; } } break; case 'AVI ': $info_video['bitrate_mode'] = 'vbr'; // maybe not, but probably $info_video['dataformat'] = 'avi'; $getid3->info['mime_type'] = 'video/avi'; if (isset($info_riff[$riff_sub_type]['movi']['offset'])) { $info_avdataoffset = $info_riff[$riff_sub_type]['movi']['offset'] + 8; $info_avdataend = $info_avdataoffset + $info_riff[$riff_sub_type]['movi']['size']; if ($info_avdataend > $getid3->info['filesize']) { $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)'); $info_avdataend = $getid3->info['filesize']; } } if (isset($info_riff['AVI ']['hdrl']['avih'][$stream_index]['data'])) { $avihData = $info_riff['AVI ']['hdrl']['avih'][$stream_index]['data']; $info_riff_raw['avih'] = array(); $info_riff_raw_avih =& $info_riff_raw['avih']; getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_avih, $avihData, 0, array('dwMicroSecPerFrame' => 4, 'dwMaxBytesPerSec' => 4, 'dwPaddingGranularity' => 4, 'dwFlags' => 4, 'dwTotalFrames' => 4, 'dwInitialFrames' => 4, 'dwStreams' => 4, 'dwSuggestedBufferSize' => 4, 'dwWidth' => 4, 'dwHeight' => 4, 'dwScale' => 4, 'dwRate' => 4, 'dwStart' => 4, 'dwLength' => 4)); $info_riff_raw_avih['flags']['hasindex'] = (bool) ($info_riff_raw_avih['dwFlags'] & 0x10); $info_riff_raw_avih['flags']['mustuseindex'] = (bool) ($info_riff_raw_avih['dwFlags'] & 0x20); $info_riff_raw_avih['flags']['interleaved'] = (bool) ($info_riff_raw_avih['dwFlags'] & 0x100); $info_riff_raw_avih['flags']['trustcktype'] = (bool) ($info_riff_raw_avih['dwFlags'] & 0x800); $info_riff_raw_avih['flags']['capturedfile'] = (bool) ($info_riff_raw_avih['dwFlags'] & 0x10000); $info_riff_raw_avih['flags']['copyrighted'] = (bool) ($info_riff_raw_avih['dwFlags'] & 0x20010); $info_riff_video[$stream_index] = array(); $info_riff_video_current =& $info_riff_video[$stream_index]; if ($info_riff_raw_avih['dwWidth'] > 0) { $info_riff_video_current['frame_width'] = $info_riff_raw_avih['dwWidth']; $info_video['resolution_x'] = $info_riff_video_current['frame_width']; } if ($info_riff_raw_avih['dwHeight'] > 0) { $info_riff_video_current['frame_height'] = $info_riff_raw_avih['dwHeight']; $info_video['resolution_y'] = $info_riff_video_current['frame_height']; } if ($info_riff_raw_avih['dwTotalFrames'] > 0) { $info_riff_video_current['total_frames'] = $info_riff_raw_avih['dwTotalFrames']; $info_video['total_frames'] = $info_riff_video_current['total_frames']; } $info_riff_video_current['frame_rate'] = round(1000000 / $info_riff_raw_avih['dwMicroSecPerFrame'], 3); $info_video['frame_rate'] = $info_riff_video_current['frame_rate']; } if (isset($info_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) { if (is_array($info_riff['AVI ']['hdrl']['strl']['strh'])) { for ($i = 0; $i < count($info_riff['AVI ']['hdrl']['strl']['strh']); $i++) { if (isset($info_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) { $strh_data = $info_riff['AVI ']['hdrl']['strl']['strh'][$i]['data']; $strh_fcc_type = substr($strh_data, 0, 4); if (isset($info_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) { $strf_data = $info_riff['AVI ']['hdrl']['strl']['strf'][$i]['data']; // shortcut $info_riff_raw_strf_strh_fcc_type_stream_index =& $info_riff_raw['strf'][$strh_fcc_type][$stream_index]; switch ($strh_fcc_type) { case 'auds': $info_audio['bitrate_mode'] = 'cbr'; $info_audio_dataformat = 'wav'; if (isset($info_riff_audio) && is_array($info_riff_audio)) { $stream_index = count($info_riff_audio); } $info_riff_audio[$stream_index] = getid3_riff::RIFFparseWAVEFORMATex($strf_data); $info_audio['wformattag'] = $info_riff_audio[$stream_index]['raw']['wFormatTag']; // shortcut $info_audio['streams'][$stream_index] = $info_riff_audio[$stream_index]; $info_audio_streams_currentstream =& $info_audio['streams'][$stream_index]; if (@$info_audio_streams_currentstream['bits_per_sample'] === 0) { unset($info_audio_streams_currentstream['bits_per_sample']); } $info_audio_streams_currentstream['wformattag'] = $info_audio_streams_currentstream['raw']['wFormatTag']; unset($info_audio_streams_currentstream['raw']); // shortcut $info_riff_raw['strf'][$strh_fcc_type][$stream_index] = $info_riff_audio[$stream_index]['raw']; unset($info_riff_audio[$stream_index]['raw']); $info_audio = getid3_riff::array_merge_noclobber($info_audio, $info_riff_audio[$stream_index]); $info_audio['lossless'] = false; switch ($info_riff_raw_strf_strh_fcc_type_stream_index['wFormatTag']) { case 0x1: // PCM $info_audio_dataformat = 'wav'; $info_audio['lossless'] = true; break; case 0x50: // MPEG Layer 2 or Layer 1 $info_audio_dataformat = 'mp2'; // Assume Layer-2 break; case 0x55: // MPEG Layer 3 $info_audio_dataformat = 'mp3'; break; case 0xff: // AAC $info_audio_dataformat = 'aac'; break; case 0x161: // Windows Media v7 / v8 / v9 // Windows Media v7 / v8 / v9 case 0x162: // Windows Media Professional v9 // Windows Media Professional v9 case 0x163: // Windows Media Lossess v9 $info_audio_dataformat = 'wma'; break; case 0x2000: // AC-3 $info_audio_dataformat = 'ac3'; break; case 0x2001: // DTS $info_audio_dataformat = 'dts'; break; default: $info_audio_dataformat = 'wav'; break; } $info_audio_streams_currentstream['dataformat'] = $info_audio_dataformat; $info_audio_streams_currentstream['lossless'] = $info_audio['lossless']; $info_audio_streams_currentstream['bitrate_mode'] = $info_audio['bitrate_mode']; break; case 'iavs': case 'vids': // shortcut $info_riff_raw['strh'][$i] = array(); $info_riff_raw_strh_current =& $info_riff_raw['strh'][$i]; getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_strh_current, $strh_data, 0, array('fccType' => -4, 'fccHandler' => -4, 'dwFlags' => 4, 'wPriority' => 2, 'wLanguage' => 2, 'dwInitialFrames' => 4, 'dwScale' => 4, 'dwRate' => 4, 'dwStart' => 4, 'dwLength' => 4, 'dwSuggestedBufferSize' => 4, 'dwQuality' => 4, 'dwSampleSize' => 4, 'rcFrame' => 4)); $info_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($info_riff_raw_strh_current['fccHandler']); $info_video['fourcc'] = $info_riff_raw_strh_current['fccHandler']; 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'])) { $info_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']); $info_video['fourcc'] = $info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']; } $info_video['codec'] = $info_riff_video_current['codec']; $info_video['pixel_aspect_ratio'] = (double) 1; switch ($info_riff_raw_strh_current['fccHandler']) { case 'HFYU': // Huffman Lossless Codec // Huffman Lossless Codec case 'IRAW': // Intel YUV Uncompressed // Intel YUV Uncompressed case 'YUY2': // Uncompressed YUV 4:2:2 $info_video['lossless'] = true; break; default: $info_video['lossless'] = false; break; } switch ($strh_fcc_type) { case 'vids': getid3_lib::ReadSequence($this->endian_function, $info_riff_raw_strf_strh_fcc_type_stream_index, $strf_data, 0, array('biSize' => 4, 'biWidth' => 4, 'biHeight' => 4, 'biPlanes' => 2, 'biBitCount' => 2, 'fourcc' => -4, 'biSizeImage' => 4, 'biXPelsPerMeter' => 4, 'biYPelsPerMeter' => 4, 'biClrUsed' => 4, 'biClrImportant' => 4)); $info_video['bits_per_sample'] = $info_riff_raw_strf_strh_fcc_type_stream_index['biBitCount']; if ($info_riff_video_current['codec'] == 'DV') { $info_riff_video_current['dv_type'] = 2; } break; case 'iavs': $info_riff_video_current['dv_type'] = 1; break; } break; default: $getid3->warning('Unhandled fccType for stream (' . $i . '): "' . $strh_fcc_type . '"'); break; } } } 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'])) { $info_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']); $info_video['codec'] = $info_riff_video_current['codec']; $info_video['fourcc'] = $info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']; switch ($info_riff_raw_strf_strh_fcc_type_stream_index['fourcc']) { case 'HFYU': // Huffman Lossless Codec // Huffman Lossless Codec case 'IRAW': // Intel YUV Uncompressed // Intel YUV Uncompressed case 'YUY2': // Uncompressed YUV 4:2:2 $info_video['lossless'] = true; $info_video['bits_per_sample'] = 24; break; default: $info_video['lossless'] = false; $info_video['bits_per_sample'] = 24; break; } } } } } break; case 'CDDA': $info_audio['bitrate_mode'] = 'cbr'; $info_audio_dataformat = 'cda'; $info_audio['lossless'] = true; unset($getid3->info['mime_type']); $info_avdataoffset = 44; if (isset($info_riff['CDDA']['fmt '][0]['data'])) { $info_riff_cdda_fmt_0 =& $info_riff['CDDA']['fmt '][0]; getid3_lib::ReadSequence($this->endian_function, $info_riff_cdda_fmt_0, $info_riff_cdda_fmt_0['data'], 0, array('unknown1' => 2, 'track_num' => 2, 'disc_id' => 4, 'start_offset_frame' => 4, 'playtime_frames' => 4, 'unknown6' => 4, 'unknown7' => 4)); $info_riff_cdda_fmt_0['start_offset_seconds'] = (double) $info_riff_cdda_fmt_0['start_offset_frame'] / 75; $info_riff_cdda_fmt_0['playtime_seconds'] = (double) $info_riff_cdda_fmt_0['playtime_frames'] / 75; $getid3->info['comments']['track'] = $info_riff_cdda_fmt_0['track_num']; $getid3->info['playtime_seconds'] = $info_riff_cdda_fmt_0['playtime_seconds']; // hardcoded data for CD-audio $info_audio['sample_rate'] = 44100; $info_audio['channels'] = 2; $info_audio['bits_per_sample'] = 16; $info_audio['bitrate'] = $info_audio['sample_rate'] * $info_audio['channels'] * $info_audio['bits_per_sample']; $info_audio['bitrate_mode'] = 'cbr'; } break; case 'AIFF': case 'AIFC': $info_audio['bitrate_mode'] = 'cbr'; $info_audio_dataformat = 'aiff'; $info_audio['lossless'] = true; $getid3->info['mime_type'] = 'audio/x-aiff'; if (isset($info_riff[$riff_sub_type]['SSND'][0]['offset'])) { $info_avdataoffset = $info_riff[$riff_sub_type]['SSND'][0]['offset'] + 8; $info_avdataend = $info_avdataoffset + $info_riff[$riff_sub_type]['SSND'][0]['size']; if ($info_avdataend > $getid3->info['filesize']) { if ($info_avdataend == $getid3->info['filesize'] + 1 && $getid3->info['filesize'] % 2 == 1) { // structures rounded to 2-byte boundary, but dumb encoders // forget to pad end of file to make this actually work } else { $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'); } $info_avdataend = $getid3->info['filesize']; } } if (isset($info_riff[$riff_sub_type]['COMM'][0]['data'])) { // shortcut $info_riff_RIFFsubtype_COMM_0_data =& $info_riff[$riff_sub_type]['COMM'][0]['data']; $info_riff_audio['channels'] = getid3_lib::BigEndianSyncSafe2Int(substr($info_riff_RIFFsubtype_COMM_0_data, 0, 2)); $info_riff_audio['total_samples'] = getid3_lib::BigEndian2Int(substr($info_riff_RIFFsubtype_COMM_0_data, 2, 4)); $info_riff_audio['bits_per_sample'] = getid3_lib::BigEndianSyncSafe2Int(substr($info_riff_RIFFsubtype_COMM_0_data, 6, 2)); $info_riff_audio['sample_rate'] = (int) getid3_riff::BigEndian2Float(substr($info_riff_RIFFsubtype_COMM_0_data, 8, 10)); if ($info_riff[$riff_sub_type]['COMM'][0]['size'] > 18) { $info_riff_audio['codec_fourcc'] = substr($info_riff_RIFFsubtype_COMM_0_data, 18, 4); $codec_name_size = getid3_lib::BigEndian2Int(substr($info_riff_RIFFsubtype_COMM_0_data, 22, 1)); $info_riff_audio['codec_name'] = substr($info_riff_RIFFsubtype_COMM_0_data, 23, $codec_name_size); switch ($info_riff_audio['codec_name']) { case 'NONE': $info_audio['codec'] = 'Pulse Code Modulation (PCM)'; $info_audio['lossless'] = true; break; case '': switch ($info_riff_audio['codec_fourcc']) { // http://developer.apple.com/qa/snd/snd07.html case 'sowt': $info_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM'; $info_audio['lossless'] = true; break; case 'twos': $info_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM'; $info_audio['lossless'] = true; break; default: break; } break; default: $info_audio['codec'] = $info_riff_audio['codec_name']; $info_audio['lossless'] = false; break; } } $info_audio['channels'] = $info_riff_audio['channels']; if ($info_riff_audio['bits_per_sample'] > 0) { $info_audio['bits_per_sample'] = $info_riff_audio['bits_per_sample']; } $info_audio['sample_rate'] = $info_riff_audio['sample_rate']; $getid3->info['playtime_seconds'] = $info_riff_audio['total_samples'] / $info_audio['sample_rate']; } if (isset($info_riff[$riff_sub_type]['COMT'])) { $comment_count = getid3_lib::BigEndian2Int(substr($info_riff[$riff_sub_type]['COMT'][0]['data'], 0, 2)); $offset = 2; for ($i = 0; $i < $comment_count; $i++) { $getid3->info['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 4)); $offset += 4; $getid3->info['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndianSyncSafe2Int(substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 2)); $offset += 2; $comment_length = getid3_lib::BigEndian2Int(substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, 2)); $offset += 2; $getid3->info['comments_raw'][$i]['comment'] = substr($info_riff[$riff_sub_type]['COMT'][0]['data'], $offset, $comment_length); $offset += $comment_length; $getid3->info['comments_raw'][$i]['timestamp_unix'] = getid3_riff::DateMac2Unix($getid3->info['comments_raw'][$i]['timestamp']); $info_riff['comments']['comment'][] = $getid3->info['comments_raw'][$i]['comment']; } } foreach (array('NAME' => 'title', 'author' => 'artist', '(c) ' => 'copyright', 'ANNO' => 'comment') as $key => $value) { if (isset($info_riff[$riff_sub_type][$key][0]['data'])) { $info_riff['comments'][$value][] = $info_riff[$riff_sub_type][$key][0]['data']; } } break; case '8SVX': $info_audio['bitrate_mode'] = 'cbr'; $info_audio_dataformat = '8svx'; $info_audio['bits_per_sample'] = 8; $info_audio['channels'] = 1; // overridden below, if need be $getid3->info['mime_type'] = 'audio/x-aiff'; if (isset($info_riff[$riff_sub_type]['BODY'][0]['offset'])) { $info_avdataoffset = $info_riff[$riff_sub_type]['BODY'][0]['offset'] + 8; $info_avdataend = $info_avdataoffset + $info_riff[$riff_sub_type]['BODY'][0]['size']; if ($info_avdataend > $getid3->info['filesize']) { $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'); } } if (isset($info_riff[$riff_sub_type]['VHDR'][0]['offset'])) { // shortcut $info_riff_riff_sub_type_vhdr_0 =& $info_riff[$riff_sub_type]['VHDR'][0]; getid3_lib::ReadSequence('BigEndian2Int', $info_riff_riff_sub_type_vhdr_0, $info_riff_riff_sub_type_vhdr_0['data'], 0, array('oneShotHiSamples' => 4, 'repeatHiSamples' => 4, 'samplesPerHiCycle' => 4, 'samplesPerSec' => 2, 'ctOctave' => 1, 'sCompression' => 1, 'Volume' => -4)); $info_riff_riff_sub_type_vhdr_0['Volume'] = getid3_riff::FixedPoint16_16($info_riff_riff_sub_type_vhdr_0['Volume']); $info_audio['sample_rate'] = $info_riff_riff_sub_type_vhdr_0['samplesPerSec']; switch ($info_riff_riff_sub_type_vhdr_0['sCompression']) { case 0: $info_audio['codec'] = 'Pulse Code Modulation (PCM)'; $info_audio['lossless'] = true; $actual_bits_per_sample = 8; break; case 1: $info_audio['codec'] = 'Fibonacci-delta encoding'; $info_audio['lossless'] = false; $actual_bits_per_sample = 4; break; default: $getid3->warning('Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "' . sCompression . '"'); break; } } if (isset($info_riff[$riff_sub_type]['CHAN'][0]['data'])) { $ChannelsIndex = getid3_lib::BigEndian2Int(substr($info_riff[$riff_sub_type]['CHAN'][0]['data'], 0, 4)); switch ($ChannelsIndex) { case 6: // Stereo $info_audio['channels'] = 2; break; case 2: // Left channel only // Left channel only case 4: // Right channel only $info_audio['channels'] = 1; break; default: $getid3->warning('Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "' . $ChannelsIndex . '"'); break; } } foreach (array('NAME' => 'title', 'author' => 'artist', '(c) ' => 'copyright', 'ANNO' => 'comment') as $key => $value) { if (isset($info_riff[$riff_sub_type][$key][0]['data'])) { $info_riff['comments'][$value][] = $info_riff[$riff_sub_type][$key][0]['data']; } } $info_audio['bitrate'] = $info_audio['sample_rate'] * $actual_bits_per_sample * $info_audio['channels']; if (!empty($info_audio['bitrate'])) { $getid3->info['playtime_seconds'] = ($info_avdataend - $info_avdataoffset) / ($info_audio['bitrate'] / 8); } break; case 'CDXA': $getid3->info['mime_type'] = 'video/mpeg'; if (!empty($info_riff['CDXA']['data'][0]['size'])) { $GETID3_ERRORARRAY =& $getid3->info['warning']; if (!$getid3->include_module_optional('audio-video.mpeg')) { $getid3->warning('MPEG skipped because mpeg module is missing.'); } else { // Clone getid3 - messing with offsets - better safe than sorry $clone = clone $getid3; // Analyse $mpeg = new getid3_mpeg($clone); $mpeg->Analyze(); // Import from clone and destroy $getid3->info['audio'] = $clone->info['audio']; $getid3->info['video'] = $clone->info['video']; $getid3->info['mpeg'] = $clone->info['mpeg']; $getid3->info['warning'] = $clone->info['warning']; unset($clone); } } break; default: throw new getid3_exception('Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA), found "' . $riff_sub_type . '" instead'); } if (@$info_riff_raw['fmt ']['wFormatTag'] == 1) { // http://www.mega-nerd.com/erikd/Blog/Windiots/dts.html $this->fseek($getid3->info['avdataoffset'], SEEK_SET); $bytes4 = $this->fread(4); // DTSWAV if (preg_match('/^\\xFF\\x1F\\x00\\xE8/s', $bytes4)) { $info_audio_dataformat = 'dts'; } elseif (preg_match('/^\\x7F\\xFF\\x80\\x01/s', $bytes4)) { $info_audio_dataformat = 'dts'; } } if (@is_array($info_riff_wave['DISP'])) { $info_riff['comments']['title'][] = trim(substr($info_riff_wave['DISP'][count($info_riff_wave['DISP']) - 1]['data'], 4)); } if (@is_array($info_riff_wave['INFO'])) { getid3_riff::RIFFCommentsParse($info_riff_wave['INFO'], $info_riff['comments']); } if (isset($info_riff_wave['INFO']) && is_array($info_riff_wave['INFO'])) { 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) { if (isset($info_riff_wave['INFO'][$key])) { foreach ($info_riff_wave['INFO'][$key] as $comment_id => $comment_data) { if (trim($comment_data['data']) != '') { $info_riff['comments'][$value][] = trim($comment_data['data']); } } } } } if (empty($info_audio['encoder']) && !empty($getid3->info['mpeg']['audio']['LAME']['short_version'])) { $info_audio['encoder'] = $getid3->info['mpeg']['audio']['LAME']['short_version']; } if (!isset($getid3->info['playtime_seconds'])) { $getid3->info['playtime_seconds'] = 0; } if (isset($info_riff_raw['avih']['dwTotalFrames']) && isset($info_riff_raw['avih']['dwMicroSecPerFrame'])) { $getid3->info['playtime_seconds'] = $info_riff_raw['avih']['dwTotalFrames'] * ($info_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000); } if ($getid3->info['playtime_seconds'] > 0) { if (isset($info_riff_audio) && isset($info_riff_video)) { if (!isset($getid3->info['bitrate'])) { $getid3->info['bitrate'] = ($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds'] * 8; } } elseif (isset($info_riff_audio) && !isset($info_riff_video)) { if (!isset($info_audio['bitrate'])) { $info_audio['bitrate'] = ($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds'] * 8; } } elseif (!isset($info_riff_audio) && isset($info_riff_video)) { if (!isset($info_video['bitrate'])) { $info_video['bitrate'] = ($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds'] * 8; } } } if (isset($info_riff_video) && isset($info_audio['bitrate']) && $info_audio['bitrate'] > 0 && $getid3->info['playtime_seconds'] > 0) { $getid3->info['bitrate'] = ($info_avdataend - $info_avdataoffset) / $getid3->info['playtime_seconds'] * 8; $info_audio['bitrate'] = 0; $info_video['bitrate'] = $getid3->info['bitrate']; foreach ($info_riff_audio as $channelnumber => $audioinfoarray) { $info_video['bitrate'] -= $audioinfoarray['bitrate']; $info_audio['bitrate'] += $audioinfoarray['bitrate']; } if ($info_video['bitrate'] <= 0) { unset($info_video['bitrate']); } if ($info_audio['bitrate'] <= 0) { unset($info_audio['bitrate']); } } if (isset($getid3->info['mpeg']['audio'])) { $info_audio_dataformat = 'mp' . $getid3->info['mpeg']['audio']['layer']; $info_audio['sample_rate'] = $getid3->info['mpeg']['audio']['sample_rate']; $info_audio['channels'] = $getid3->info['mpeg']['audio']['channels']; $info_audio['bitrate'] = $getid3->info['mpeg']['audio']['bitrate']; $info_audio['bitrate_mode'] = strtolower($getid3->info['mpeg']['audio']['bitrate_mode']); if (!empty($getid3->info['mpeg']['audio']['codec'])) { $info_audio['codec'] = $getid3->info['mpeg']['audio']['codec'] . ' ' . $info_audio['codec']; } if (!empty($info_audio['streams'])) { foreach ($info_audio['streams'] as $streamnumber => $streamdata) { if ($streamdata['dataformat'] == $info_audio_dataformat) { $info_audio['streams'][$streamnumber]['sample_rate'] = $info_audio['sample_rate']; $info_audio['streams'][$streamnumber]['channels'] = $info_audio['channels']; $info_audio['streams'][$streamnumber]['bitrate'] = $info_audio['bitrate']; $info_audio['streams'][$streamnumber]['bitrate_mode'] = $info_audio['bitrate_mode']; $info_audio['streams'][$streamnumber]['codec'] = $info_audio['codec']; } } } $info_audio['encoder_options'] = getid3_mp3::GuessEncoderOptions($getid3->info); } if (!empty($info_riff_raw['fmt ']['wBitsPerSample']) && $info_riff_raw['fmt ']['wBitsPerSample'] > 0) { switch ($info_audio_dataformat) { case 'ac3': // ignore bits_per_sample break; default: $info_audio['bits_per_sample'] = $info_riff_raw['fmt ']['wBitsPerSample']; break; } } if (empty($info_riff_raw)) { unset($info_riff['raw']); } if (empty($info_riff_audio)) { unset($info_riff['audio']); } if (empty($info_riff_video)) { unset($info_riff['video']); } if (empty($info_audio_dataformat)) { unset($info_audio['dataformat']); } if (empty($getid3->info['audio'])) { unset($getid3->info['audio']); } if (empty($info_video)) { unset($getid3->info['video']); } return true; }
private function ParseID3v2Frame(&$parsed_frame) { $getid3 = $this->getid3; $id3v2_major_version = $getid3->info['id3v2']['majorversion']; $frame_name_long = getid3_id3v2::FrameNameLongLookup($parsed_frame['frame_name']); if ($frame_name_long) { $parsed_frame['framenamelong'] = $frame_name_long; } $frame_name_short = getid3_id3v2::FrameNameShortLookup($parsed_frame['frame_name']); if ($frame_name_short) { $parsed_frame['framenameshort'] = $frame_name_short; } if ($id3v2_major_version >= 3) { // frame flags are not part of the ID3v2.2 standard if ($id3v2_major_version == 3) { // Frame Header Flags // %abc00000 %ijk00000 $parsed_frame['flags']['TagAlterPreservation'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x8000); // a - Tag alter preservation $parsed_frame['flags']['FileAlterPreservation'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x4000); // b - File alter preservation $parsed_frame['flags']['ReadOnly'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x2000); // c - Read only $parsed_frame['flags']['compression'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x80); // i - Compression $parsed_frame['flags']['Encryption'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x40); // j - Encryption $parsed_frame['flags']['GroupingIdentity'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x20); // k - Grouping identity } elseif ($id3v2_major_version == 4) { // Frame Header Flags // %0abc0000 %0h00kmnp $parsed_frame['flags']['TagAlterPreservation'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x4000); // a - Tag alter preservation $parsed_frame['flags']['FileAlterPreservation'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x2000); // b - File alter preservation $parsed_frame['flags']['ReadOnly'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x1000); // c - Read only $parsed_frame['flags']['GroupingIdentity'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x40); // h - Grouping identity $parsed_frame['flags']['compression'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x8); // k - Compression $parsed_frame['flags']['Encryption'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x4); // m - Encryption $parsed_frame['flags']['Unsynchronisation'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x2); // n - Unsynchronisation $parsed_frame['flags']['DataLengthIndicator'] = (bool) ($parsed_frame['frame_flags_raw'] & 0x1); // p - Data length indicator // Frame-level de-unsynchronisation - ID3v2.4 if ($parsed_frame['flags']['Unsynchronisation']) { $parsed_frame['data'] = str_replace("ÿ", "ÿ", $parsed_frame['data']); } } // Frame-level de-compression if ($parsed_frame['flags']['compression']) { $parsed_frame['decompressed_size'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], 0, 4)); if (!function_exists('gzuncompress')) { $getid3->warning('gzuncompress() support required to decompress ID3v2 frame "' . $parsed_frame['frame_name'] . '"'); } elseif ($decompressed_data = @gzuncompress(substr($parsed_frame['data'], 4))) { $parsed_frame['data'] = $decompressed_data; } else { $getid3->warning('gzuncompress() failed on compressed contents of ID3v2 frame "' . $parsed_frame['frame_name'] . '"'); } } } if (isset($parsed_frame['datalength']) && $parsed_frame['datalength'] == 0) { $warning = 'Frame "' . $parsed_frame['frame_name'] . '" at offset ' . $parsed_frame['dataoffset'] . ' has no data portion'; switch ($parsed_frame['frame_name']) { case 'WCOM': $warning .= ' (this is known to happen with files tagged by RioPort)'; break; default: break; } $getid3->warning($warning); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'UFID' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'UFI') { // 4.1 UFI Unique file identifier // There may be more than one 'UFID' frame in a tag, // but only one with the same 'Owner identifier'. // <Header for 'Unique file identifier', ID: 'UFID'> // Owner identifier <text string> $00 // Identifier <up to 64 bytes binary data> $frame_terminator_pos = strpos($parsed_frame['data'], ""); $frame_id_string = substr($parsed_frame['data'], 0, $frame_terminator_pos); $parsed_frame['ownerid'] = $frame_id_string; $parsed_frame['data'] = substr($parsed_frame['data'], $frame_terminator_pos + strlen("")); unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'TXXX' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'TXX') { // 4.2.2 TXX User defined text information frame // There may be more than one 'TXXX' frame in each tag, // but only one with the same description. // <Header for 'User defined text information frame', ID: 'TXXX'> // Text encoding $xx // Description <text string according to encoding> $00 (00) // Value <text string according to encoding> $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } $frame_terminator_pos = @strpos($parsed_frame['data'], getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding), $frame_offset); if (ord(substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)), 1)) === 0) { $frame_terminator_pos++; // @strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $frame_description = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_description) === 0) { $frame_description = ''; } $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($frame_text_encoding); $parsed_frame['description'] = $frame_description; $parsed_frame['data'] = substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding))); if (!empty($parsed_frame['framenameshort']) && !empty($parsed_frame['data'])) { $getid3->info['id3v2']['comments'][$parsed_frame['framenameshort']][] = trim($getid3->iconv($parsed_frame['encoding'], 'UTF-8', $parsed_frame['data'])); } unset($parsed_frame['data']); return true; } if ($parsed_frame['frame_name'][0] == 'T') { // 4.2. T??[?] Text information frame // There may only be one text information frame of its kind in an tag. // <Header for 'Text information frame', ID: 'T000' - 'TZZZ', // excluding 'TXXX' described in 4.2.6.> // Text encoding $xx // Information <text string(s) according to encoding> $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } $parsed_frame['data'] = (string) substr($parsed_frame['data'], $frame_offset); $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($frame_text_encoding); if (!empty($parsed_frame['framenameshort']) && !empty($parsed_frame['data'])) { // remove possible terminating \x00 (put by encoding id or software bug) $string = $getid3->iconv($parsed_frame['encoding'], 'UTF-8', $parsed_frame['data']); if ($string[strlen($string) - 1] = "") { $string = substr($string, 0, strlen($string) - 1); } $getid3->info['id3v2']['comments'][$parsed_frame['framenameshort']][] = $string; unset($string); } return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'WXXX' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'WXX') { // 4.3.2 WXX User defined URL link frame // There may be more than one 'WXXX' frame in each tag, // but only one with the same description // <Header for 'User defined URL link frame', ID: 'WXXX'> // Text encoding $xx // Description <text string according to encoding> $00 (00) // URL <text string> $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } $frame_terminator_pos = @strpos($parsed_frame['data'], getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding), $frame_offset); if (ord(substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)), 1)) === 0) { $frame_terminator_pos++; // @strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $frame_description = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_description) === 0) { $frame_description = ''; } $parsed_frame['data'] = substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding))); $frame_terminator_pos = strpos($parsed_frame['data'], getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)); if (ord(substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)), 1)) === 0) { $frame_terminator_pos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 } if ($frame_terminator_pos) { // there are null bytes after the data - this is not according to spec // only use data up to first null byte $frame_urldata = (string) substr($parsed_frame['data'], 0, $frame_terminator_pos); } else { // no null bytes following data, just use all data $frame_urldata = (string) $parsed_frame['data']; } $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($frame_text_encoding); $parsed_frame['url'] = $frame_urldata; $parsed_frame['description'] = $frame_description; if (!empty($parsed_frame['framenameshort']) && $parsed_frame['url']) { $getid3->info['id3v2']['comments'][$parsed_frame['framenameshort']][] = $getid3->iconv($parsed_frame['encoding'], 'UTF-8', $parsed_frame['url']); } unset($parsed_frame['data']); return true; } if ($parsed_frame['frame_name'][0] == 'W') { // 4.3. W??? URL link frames // There may only be one URL link frame of its kind in a tag, // except when stated otherwise in the frame description // <Header for 'URL link frame', ID: 'W000' - 'WZZZ', excluding 'WXXX' // described in 4.3.2.> // URL <text string> $parsed_frame['url'] = trim($parsed_frame['data']); if (!empty($parsed_frame['framenameshort']) && $parsed_frame['url']) { $getid3->info['id3v2']['comments'][$parsed_frame['framenameshort']][] = $parsed_frame['url']; } unset($parsed_frame['data']); return true; } if ($id3v2_major_version == 3 && $parsed_frame['frame_name'] == 'IPLS' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'IPL') { // 4.4 IPL Involved people list (ID3v2.2 only) // There may only be one 'IPL' frame in each tag // <Header for 'User defined URL link frame', ID: 'IPL'> // Text encoding $xx // People list strings <textstrings> $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($parsed_frame['encodingid']); $parsed_frame['data'] = (string) substr($parsed_frame['data'], $frame_offset); if (!empty($parsed_frame['framenameshort']) && !empty($parsed_frame['data'])) { $getid3->info['id3v2']['comments'][$parsed_frame['framenameshort']][] = $getid3->iconv($parsed_frame['encoding'], 'UTF-8', $parsed_frame['data']); } return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'MCDI' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'MCI') { // 4.5 MCI Music CD identifier // There may only be one 'MCDI' frame in each tag // <Header for 'Music CD identifier', ID: 'MCDI'> // CD TOC <binary data> if (!empty($parsed_frame['framenameshort']) && !empty($parsed_frame['data'])) { $getid3->info['id3v2']['comments'][$parsed_frame['framenameshort']][] = $parsed_frame['data']; } return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'ETCO' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'ETC') { // 4.6 ETC Event timing codes // There may only be one 'ETCO' frame in each tag // <Header for 'Event timing codes', ID: 'ETCO'> // Time stamp format $xx // Where time stamp format is: // $01 (32-bit value) MPEG frames from beginning of file // $02 (32-bit value) milliseconds from beginning of file // Followed by a list of key events in the following format: // Type of event $xx // Time stamp $xx (xx ...) // The 'Time stamp' is set to zero if directly at the beginning of the sound // or after the previous event. All events MUST be sorted in chronological order. $frame_offset = 0; $parsed_frame['timestampformat'] = ord($parsed_frame['data'][$frame_offset++]); while ($frame_offset < strlen($parsed_frame['data'])) { $parsed_frame['typeid'] = $parsed_frame['data'][$frame_offset++]; $parsed_frame['type'] = getid3_id3v2::ETCOEventLookup($parsed_frame['typeid']); $parsed_frame['timestamp'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 4)); $frame_offset += 4; } unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'MLLT' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'MLL') { // 4.7 MLL MPEG location lookup table // There may only be one 'MLLT' frame in each tag // <Header for 'Location lookup table', ID: 'MLLT'> // MPEG frames between reference $xx xx // Bytes between reference $xx xx xx // Milliseconds between reference $xx xx xx // Bits for bytes deviation $xx // Bits for milliseconds dev. $xx // Then for every reference the following data is included; // Deviation in bytes %xxx.... // Deviation in milliseconds %xxx.... $frame_offset = 0; $parsed_frame['framesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], 0, 2)); $parsed_frame['bytesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], 2, 3)); $parsed_frame['msbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], 5, 3)); $parsed_frame['bitsforbytesdeviation'] = getid3_lib::BigEndian2Int($parsed_frame['data'][8]); $parsed_frame['bitsformsdeviation'] = getid3_lib::BigEndian2Int($parsed_frame['data'][9]); $parsed_frame['data'] = substr($parsed_frame['data'], 10); while ($frame_offset < strlen($parsed_frame['data'])) { $deviation_bitstream .= getid3_lib::BigEndian2Bin($parsed_frame['data'][$frame_offset++]); } $reference_counter = 0; while (strlen($deviation_bitstream) > 0) { $parsed_frame[$reference_counter]['bytedeviation'] = bindec(substr($deviation_bitstream, 0, $parsed_frame['bitsforbytesdeviation'])); $parsed_frame[$reference_counter]['msdeviation'] = bindec(substr($deviation_bitstream, $parsed_frame['bitsforbytesdeviation'], $parsed_frame['bitsformsdeviation'])); $deviation_bitstream = substr($deviation_bitstream, $parsed_frame['bitsforbytesdeviation'] + $parsed_frame['bitsformsdeviation']); $reference_counter++; } unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'SYTC' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'STC') { // 4.8 STC Synchronised tempo codes // There may only be one 'SYTC' frame in each tag // <Header for 'Synchronised tempo codes', ID: 'SYTC'> // Time stamp format $xx // Tempo data <binary data> // Where time stamp format is: // $01 (32-bit value) MPEG frames from beginning of file // $02 (32-bit value) milliseconds from beginning of file $frame_offset = 0; $parsed_frame['timestampformat'] = ord($parsed_frame['data'][$frame_offset++]); $timestamp_counter = 0; while ($frame_offset < strlen($parsed_frame['data'])) { $parsed_frame[$timestamp_counter]['tempo'] = ord($parsed_frame['data'][$frame_offset++]); if ($parsed_frame[$timestamp_counter]['tempo'] == 255) { $parsed_frame[$timestamp_counter]['tempo'] += ord($parsed_frame['data'][$frame_offset++]); } $parsed_frame[$timestamp_counter]['timestamp'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 4)); $frame_offset += 4; $timestamp_counter++; } unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'USLT' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'ULT') { // 4.9 ULT Unsynchronised lyric/text transcription // There may be more than one 'Unsynchronised lyrics/text transcription' frame // in each tag, but only one with the same language and content descriptor. // <Header for 'Unsynchronised lyrics/text transcription', ID: 'USLT'> // Text encoding $xx // Language $xx xx xx // Content descriptor <text string according to encoding> $00 (00) // Lyrics/text <full text string according to encoding> $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } $frame_language = substr($parsed_frame['data'], $frame_offset, 3); $frame_offset += 3; if ($frame_offset > strlen($parsed_frame['data'])) { $frame_offset = strlen($parsed_frame['data']) - 1; } $frame_terminator_pos = @strpos($parsed_frame['data'], getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding), $frame_offset); if (ord(substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)), 1)) === 0) { $frame_terminator_pos++; // @strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $frame_description = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_description) === 0) { $frame_description = ''; } $parsed_frame['data'] = substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding))); $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($frame_text_encoding); $parsed_frame['data'] = $parsed_frame['data']; $parsed_frame['language'] = $frame_language; $parsed_frame['languagename'] = getid3_id3v2::LanguageLookup($frame_language, false); $parsed_frame['description'] = $frame_description; if (!empty($parsed_frame['framenameshort']) && !empty($parsed_frame['data'])) { $getid3->info['id3v2']['comments'][$parsed_frame['framenameshort']][] = $getid3->iconv($parsed_frame['encoding'], 'UTF-8', $parsed_frame['data']); } unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'SYLT' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'SLT') { // 4.10 SLT Synchronised lyric/text // There may be more than one 'SYLT' frame in each tag, // but only one with the same language and content descriptor. // <Header for 'Synchronised lyrics/text', ID: 'SYLT'> // Text encoding $xx // Language $xx xx xx // Time stamp format $xx // $01 (32-bit value) MPEG frames from beginning of file // $02 (32-bit value) milliseconds from beginning of file // Content type $xx // Content descriptor <text string according to encoding> $00 (00) // Terminated text to be synced (typically a syllable) // Sync identifier (terminator to above string) $00 (00) // Time stamp $xx (xx ...) $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } $frame_language = substr($parsed_frame['data'], $frame_offset, 3); $frame_offset += 3; $parsed_frame['timestampformat'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['contenttypeid'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['contenttype'] = getid3_id3v2::SYTLContentTypeLookup($parsed_frame['contenttypeid']); $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($frame_text_encoding); $parsed_frame['language'] = $frame_language; $parsed_frame['languagename'] = getid3_id3v2::LanguageLookup($frame_language, false); $timestamp_index = 0; $frame_remaining_data = substr($parsed_frame['data'], $frame_offset); while (strlen($frame_remaining_data)) { $frame_offset = 0; $frame_terminator_pos = strpos($frame_remaining_data, getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)); if ($frame_terminator_pos === false) { $frame_remaining_data = ''; } else { if (ord(substr($frame_remaining_data, $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)), 1)) === 0) { $frame_terminator_pos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $parsed_frame['lyrics'][$timestamp_index]['data'] = substr($frame_remaining_data, $frame_offset, $frame_terminator_pos - $frame_offset); $frame_remaining_data = substr($frame_remaining_data, $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding))); if ($timestamp_index == 0 && ord($frame_remaining_data[0]) != 0) { // timestamp probably omitted for first data item } else { $parsed_frame['lyrics'][$timestamp_index]['timestamp'] = getid3_lib::BigEndian2Int(substr($frame_remaining_data, 0, 4)); $frame_remaining_data = substr($frame_remaining_data, 4); } $timestamp_index++; } } unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'COMM' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'COM') { // 4.11 COM Comments // There may be more than one comment frame in each tag, // but only one with the same language and content descriptor. // <Header for 'Comment', ID: 'COMM'> // Text encoding $xx // Language $xx xx xx // Short content descrip. <text string according to encoding> $00 (00) // The actual text <full text string according to encoding> if (strlen($parsed_frame['data']) < 5) { $getid3->warning('Invalid data (too short) for "' . $parsed_frame['frame_name'] . '" frame at offset ' . $parsed_frame['dataoffset']); return true; } $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } $frame_language = substr($parsed_frame['data'], $frame_offset, 3); $frame_offset += 3; $frame_terminator_pos = @strpos($parsed_frame['data'], getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding), $frame_offset); if (ord(substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)), 1)) === 0) { $frame_terminator_pos++; // @strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $frame_description = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_description) === 0) { $frame_description = ''; } $frame_text = (string) substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding))); $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($frame_text_encoding); $parsed_frame['language'] = $frame_language; $parsed_frame['languagename'] = getid3_id3v2::LanguageLookup($frame_language, false); $parsed_frame['description'] = $frame_description; $parsed_frame['data'] = $frame_text; if (!empty($parsed_frame['framenameshort']) && !empty($parsed_frame['data'])) { $getid3->info['id3v2']['comments'][$parsed_frame['framenameshort']][] = $getid3->iconv($parsed_frame['encoding'], 'UTF-8', $parsed_frame['data']); } return true; } if ($id3v2_major_version >= 4 && $parsed_frame['frame_name'] == 'RVA2') { // 4.11 RVA2 Relative volume adjustment (2) (ID3v2.4+ only) // There may be more than one 'RVA2' frame in each tag, // but only one with the same identification string // <Header for 'Relative volume adjustment (2)', ID: 'RVA2'> // Identification <text string> $00 // The 'identification' string is used to identify the situation and/or // device where this adjustment should apply. The following is then // repeated for every channel: // Type of channel $xx // Volume adjustment $xx xx // Bits representing peak $xx // Peak volume $xx (xx ...) $frame_terminator_pos = strpos($parsed_frame['data'], ""); $frame_id_string = substr($parsed_frame['data'], 0, $frame_terminator_pos); if (ord($frame_id_string) === 0) { $frame_id_string = ''; } $frame_remaining_data = substr($parsed_frame['data'], $frame_terminator_pos + strlen("")); $parsed_frame['description'] = $frame_id_string; while (strlen($frame_remaining_data)) { $frame_offset = 0; $frame_channeltypeid = ord(substr($frame_remaining_data, $frame_offset++, 1)); $parsed_frame[$frame_channeltypeid]['channeltypeid'] = $frame_channeltypeid; $parsed_frame[$frame_channeltypeid]['channeltype'] = getid3_id3v2::RVA2ChannelTypeLookup($frame_channeltypeid); $parsed_frame[$frame_channeltypeid]['volumeadjust'] = getid3_lib::BigEndian2Int(substr($frame_remaining_data, $frame_offset, 2), true); // 16-bit signed $frame_offset += 2; $parsed_frame[$frame_channeltypeid]['bitspeakvolume'] = ord(substr($frame_remaining_data, $frame_offset++, 1)); $frame_bytespeakvolume = ceil($parsed_frame[$frame_channeltypeid]['bitspeakvolume'] / 8); $parsed_frame[$frame_channeltypeid]['peakvolume'] = getid3_lib::BigEndian2Int(substr($frame_remaining_data, $frame_offset, $frame_bytespeakvolume)); $frame_remaining_data = substr($frame_remaining_data, $frame_offset + $frame_bytespeakvolume); } unset($parsed_frame['data']); return true; } if ($id3v2_major_version == 3 && $parsed_frame['frame_name'] == 'RVAD' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'RVA') { // 4.12 RVA Relative volume adjustment (ID3v2.2 only) // There may only be one 'RVA' frame in each tag // <Header for 'Relative volume adjustment', ID: 'RVA'> // ID3v2.2 => Increment/decrement %000000ba // ID3v2.3 => Increment/decrement %00fedcba // Bits used for volume descr. $xx // Relative volume change, right $xx xx (xx ...) // a // Relative volume change, left $xx xx (xx ...) // b // Peak volume right $xx xx (xx ...) // Peak volume left $xx xx (xx ...) // ID3v2.3 only, optional (not present in ID3v2.2): // Relative volume change, right back $xx xx (xx ...) // c // Relative volume change, left back $xx xx (xx ...) // d // Peak volume right back $xx xx (xx ...) // Peak volume left back $xx xx (xx ...) // ID3v2.3 only, optional (not present in ID3v2.2): // Relative volume change, center $xx xx (xx ...) // e // Peak volume center $xx xx (xx ...) // ID3v2.3 only, optional (not present in ID3v2.2): // Relative volume change, bass $xx xx (xx ...) // f // Peak volume bass $xx xx (xx ...) $frame_offset = 0; $frame_incrdecrflags = getid3_lib::BigEndian2Bin($parsed_frame['data'][$frame_offset++]); $parsed_frame['incdec']['right'] = (bool) substr($frame_incrdecrflags, 6, 1); $parsed_frame['incdec']['left'] = (bool) substr($frame_incrdecrflags, 7, 1); $parsed_frame['bitsvolume'] = ord($parsed_frame['data'][$frame_offset++]); $frame_bytesvolume = ceil($parsed_frame['bitsvolume'] / 8); $parsed_frame['volumechange']['right'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); if ($parsed_frame['incdec']['right'] === false) { $parsed_frame['volumechange']['right'] *= -1; } $frame_offset += $frame_bytesvolume; $parsed_frame['volumechange']['left'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); if ($parsed_frame['incdec']['left'] === false) { $parsed_frame['volumechange']['left'] *= -1; } $frame_offset += $frame_bytesvolume; $parsed_frame['peakvolume']['right'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); $frame_offset += $frame_bytesvolume; $parsed_frame['peakvolume']['left'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); $frame_offset += $frame_bytesvolume; if ($id3v2_major_version == 3) { $parsed_frame['data'] = substr($parsed_frame['data'], $frame_offset); if (strlen($parsed_frame['data']) > 0) { $parsed_frame['incdec']['rightrear'] = (bool) substr($frame_incrdecrflags, 4, 1); $parsed_frame['incdec']['leftrear'] = (bool) substr($frame_incrdecrflags, 5, 1); $parsed_frame['volumechange']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); if ($parsed_frame['incdec']['rightrear'] === false) { $parsed_frame['volumechange']['rightrear'] *= -1; } $frame_offset += $frame_bytesvolume; $parsed_frame['volumechange']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); if ($parsed_frame['incdec']['leftrear'] === false) { $parsed_frame['volumechange']['leftrear'] *= -1; } $frame_offset += $frame_bytesvolume; $parsed_frame['peakvolume']['rightrear'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); $frame_offset += $frame_bytesvolume; $parsed_frame['peakvolume']['leftrear'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); $frame_offset += $frame_bytesvolume; } $parsed_frame['data'] = substr($parsed_frame['data'], $frame_offset); if (strlen($parsed_frame['data']) > 0) { $parsed_frame['incdec']['center'] = (bool) substr($frame_incrdecrflags, 3, 1); $parsed_frame['volumechange']['center'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); if ($parsed_frame['incdec']['center'] === false) { $parsed_frame['volumechange']['center'] *= -1; } $frame_offset += $frame_bytesvolume; $parsed_frame['peakvolume']['center'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); $frame_offset += $frame_bytesvolume; } $parsed_frame['data'] = substr($parsed_frame['data'], $frame_offset); if (strlen($parsed_frame['data']) > 0) { $parsed_frame['incdec']['bass'] = (bool) substr($frame_incrdecrflags, 2, 1); $parsed_frame['volumechange']['bass'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); if ($parsed_frame['incdec']['bass'] === false) { $parsed_frame['volumechange']['bass'] *= -1; } $frame_offset += $frame_bytesvolume; $parsed_frame['peakvolume']['bass'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesvolume)); $frame_offset += $frame_bytesvolume; } } unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 4 && $parsed_frame['frame_name'] == 'EQU2') { // 4.12 EQU2 Equalisation (2) (ID3v2.4+ only) // There may be more than one 'EQU2' frame in each tag, // but only one with the same identification string // <Header of 'Equalisation (2)', ID: 'EQU2'> // Interpolation method $xx // $00 Band // $01 Linear // Identification <text string> $00 // The following is then repeated for every adjustment point // Frequency $xx xx // Volume adjustment $xx xx $frame_offset = 0; $frame_interpolationmethod = ord($parsed_frame['data'][$frame_offset++]); $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_id_string = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_id_string) === 0) { $frame_id_string = ''; } $parsed_frame['description'] = $frame_id_string; $frame_remaining_data = substr($parsed_frame['data'], $frame_terminator_pos + strlen("")); while (strlen($frame_remaining_data)) { $frame_frequency = getid3_lib::BigEndian2Int(substr($frame_remaining_data, 0, 2)) / 2; $parsed_frame['data'][$frame_frequency] = getid3_lib::BigEndian2Int(substr($frame_remaining_data, 2, 2), true); $frame_remaining_data = substr($frame_remaining_data, 4); } $parsed_frame['interpolationmethod'] = $frame_interpolationmethod; unset($parsed_frame['data']); return true; } if ($id3v2_major_version == 3 && $parsed_frame['frame_name'] == 'EQUA' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'EQU') { // 4.13 EQU Equalisation (ID3v2.2 only) // There may only be one 'EQUA' frame in each tag // <Header for 'Relative volume adjustment', ID: 'EQU'> // Adjustment bits $xx // This is followed by 2 bytes + ('adjustment bits' rounded up to the // nearest byte) for every equalisation band in the following format, // giving a frequency range of 0 - 32767Hz: // Increment/decrement %x (MSB of the Frequency) // Frequency (lower 15 bits) // Adjustment $xx (xx ...) $frame_offset = 0; $parsed_frame['adjustmentbits'] = $parsed_frame['data'][$frame_offset++]; $frame_adjustment_bytes = ceil($parsed_frame['adjustmentbits'] / 8); $frame_remaining_data = (string) substr($parsed_frame['data'], $frame_offset); while (strlen($frame_remaining_data) > 0) { $frame_frequencystr = getid3_lib::BigEndian2Bin(substr($frame_remaining_data, 0, 2)); $frame_incdec = (bool) substr($frame_frequencystr, 0, 1); $frame_frequency = bindec(substr($frame_frequencystr, 1, 15)); $parsed_frame[$frame_frequency]['incdec'] = $frame_incdec; $parsed_frame[$frame_frequency]['adjustment'] = getid3_lib::BigEndian2Int(substr($frame_remaining_data, 2, $frame_adjustment_bytes)); if ($parsed_frame[$frame_frequency]['incdec'] === false) { $parsed_frame[$frame_frequency]['adjustment'] *= -1; } $frame_remaining_data = substr($frame_remaining_data, 2 + $frame_adjustment_bytes); } unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'RVRB' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'REV') { // 4.14 REV Reverb // There may only be one 'RVRB' frame in each tag. // <Header for 'Reverb', ID: 'RVRB'> // Reverb left (ms) $xx xx // Reverb right (ms) $xx xx // Reverb bounces, left $xx // Reverb bounces, right $xx // Reverb feedback, left to left $xx // Reverb feedback, left to right $xx // Reverb feedback, right to right $xx // Reverb feedback, right to left $xx // Premix left to right $xx // Premix right to left $xx $frame_offset = 0; $parsed_frame['left'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 2)); $frame_offset += 2; $parsed_frame['right'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 2)); $frame_offset += 2; $parsed_frame['bouncesL'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['bouncesR'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['feedbackLL'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['feedbackLR'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['feedbackRR'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['feedbackRL'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['premixLR'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['premixRL'] = ord($parsed_frame['data'][$frame_offset++]); unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'APIC' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'PIC') { // 4.15 PIC Attached picture // There may be several pictures attached to one file, // each in their individual 'APIC' frame, but only one // with the same content descriptor // <Header for 'Attached picture', ID: 'APIC'> // Text encoding $xx // ID3v2.3+ => MIME type <text string> $00 // ID3v2.2 => Image format $xx xx xx // Picture type $xx // Description <text string according to encoding> $00 (00) // Picture data <binary data> $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } if ($id3v2_major_version == 2 && strlen($parsed_frame['data']) > $frame_offset) { $frame_imagetype = substr($parsed_frame['data'], $frame_offset, 3); if (strtolower($frame_imagetype) == 'ima') { // complete hack for mp3Rage (www.chaoticsoftware.com) that puts ID3v2.3-formatted // MIME type instead of 3-char ID3v2.2-format image type (thanks xbhoffØpacbell*net) $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_mimetype = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_mimetype) === 0) { $frame_mimetype = ''; } $frame_imagetype = strtoupper(str_replace('image/', '', strtolower($frame_mimetype))); if ($frame_imagetype == 'JPEG') { $frame_imagetype = 'JPG'; } $frame_offset = $frame_terminator_pos + strlen(""); } else { $frame_offset += 3; } } if ($id3v2_major_version > 2 && strlen($parsed_frame['data']) > $frame_offset) { $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_mimetype = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_mimetype) === 0) { $frame_mimetype = ''; } $frame_offset = $frame_terminator_pos + strlen(""); } $frame_picturetype = ord($parsed_frame['data'][$frame_offset++]); $frame_terminator_pos = @strpos($parsed_frame['data'], getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding), $frame_offset); if (ord(substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)), 1)) === 0) { $frame_terminator_pos++; // @strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $frame_description = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_description) === 0) { $frame_description = ''; } $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($frame_text_encoding); if ($id3v2_major_version == 2) { $parsed_frame['imagetype'] = $frame_imagetype; } else { $parsed_frame['mime'] = $frame_mimetype; } $parsed_frame['picturetypeid'] = $frame_picturetype; $parsed_frame['picturetype'] = getid3_id3v2::APICPictureTypeLookup($frame_picturetype); $parsed_frame['description'] = $frame_description; $parsed_frame['data'] = substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding))); if ($getid3->option_tags_images) { $image_chunk_check = getid3_lib_image_size::get($parsed_frame['data']); if ($image_chunk_check[2] >= 1 && $image_chunk_check[2] <= 3) { $parsed_frame['image_mime'] = image_type_to_mime_type($image_chunk_check[2]); if ($image_chunk_check[0]) { $parsed_frame['image_width'] = $image_chunk_check[0]; } if ($image_chunk_check[1]) { $parsed_frame['image_height'] = $image_chunk_check[1]; } $parsed_frame['image_bytes'] = strlen($parsed_frame['data']); } } return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'GEOB' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'GEO') { // 4.16 GEO General encapsulated object // There may be more than one 'GEOB' frame in each tag, // but only one with the same content descriptor // <Header for 'General encapsulated object', ID: 'GEOB'> // Text encoding $xx // MIME type <text string> $00 // Filename <text string according to encoding> $00 (00) // Content description <text string according to encoding> $00 (00) // Encapsulated object <binary data> $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_mimetype = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_mimetype) === 0) { $frame_mimetype = ''; } $frame_offset = $frame_terminator_pos + strlen(""); $frame_terminator_pos = @strpos($parsed_frame['data'], getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding), $frame_offset); if (ord(substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)), 1)) === 0) { $frame_terminator_pos++; // @strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $frame_filename = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_filename) === 0) { $frame_filename = ''; } $frame_offset = $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)); $frame_terminator_pos = @strpos($parsed_frame['data'], getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding), $frame_offset); if (ord(substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)), 1)) === 0) { $frame_terminator_pos++; // @strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $frame_description = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_description) === 0) { $frame_description = ''; } $frame_offset = $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)); $parsed_frame['objectdata'] = (string) substr($parsed_frame['data'], $frame_offset); $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($frame_text_encoding); $parsed_frame['mime'] = $frame_mimetype; $parsed_frame['filename'] = $frame_filename; $parsed_frame['description'] = $frame_description; unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'PCNT' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'CNT') { // 4.17 CNT Play counter // There may only be one 'PCNT' frame in each tag. // When the counter reaches all one's, one byte is inserted in // front of the counter thus making the counter eight bits bigger // <Header for 'Play counter', ID: 'PCNT'> // Counter $xx xx xx xx (xx ...) $parsed_frame['data'] = getid3_lib::BigEndian2Int($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'POPM' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'POP') { // 4.18 POP Popularimeter // There may be more than one 'POPM' frame in each tag, // but only one with the same email address // <Header for 'Popularimeter', ID: 'POPM'> // Email to user <text string> $00 // Rating $xx // Counter $xx xx xx xx (xx ...) $frame_offset = 0; $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_email_address = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_email_address) === 0) { $frame_email_address = ''; } $frame_offset = $frame_terminator_pos + strlen(""); $frame_rating = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['data'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset)); $parsed_frame['email'] = $frame_email_address; $parsed_frame['rating'] = $frame_rating; unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'RBUF' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'BUF') { // 4.19 BUF Recommended buffer size // There may only be one 'RBUF' frame in each tag // <Header for 'Recommended buffer size', ID: 'RBUF'> // Buffer size $xx xx xx // Embedded info flag %0000000x // Offset to next tag $xx xx xx xx $frame_offset = 0; $parsed_frame['buffersize'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 3)); $frame_offset += 3; $frame_embeddedinfoflags = getid3_lib::BigEndian2Bin($parsed_frame['data'][$frame_offset++]); $parsed_frame['flags']['embededinfo'] = (bool) substr($frame_embeddedinfoflags, 7, 1); $parsed_frame['nexttagoffset'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 4)); unset($parsed_frame['data']); return true; } if ($id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'CRM') { // 4.20 Encrypted meta frame (ID3v2.2 only) // There may be more than one 'CRM' frame in a tag, // but only one with the same 'owner identifier' // <Header for 'Encrypted meta frame', ID: 'CRM'> // Owner identifier <textstring> $00 (00) // Content/explanation <textstring> $00 (00) // Encrypted datablock <binary data> $frame_offset = 0; $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_owner_id = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); $frame_offset = $frame_terminator_pos + strlen(""); $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_description = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_description) === 0) { $frame_description = ''; } $frame_offset = $frame_terminator_pos + strlen(""); $parsed_frame['ownerid'] = $frame_owner_id; $parsed_frame['data'] = (string) substr($parsed_frame['data'], $frame_offset); $parsed_frame['description'] = $frame_description; unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'AENC' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'CRA') { // 4.21 CRA Audio encryption // There may be more than one 'AENC' frames in a tag, // but only one with the same 'Owner identifier' // <Header for 'Audio encryption', ID: 'AENC'> // Owner identifier <text string> $00 // Preview start $xx xx // Preview length $xx xx // Encryption info <binary data> $frame_offset = 0; $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_owner_id = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_owner_id) === 0) { $frame_owner_id == ''; } $frame_offset = $frame_terminator_pos + strlen(""); $parsed_frame['ownerid'] = $frame_owner_id; $parsed_frame['previewstart'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 2)); $frame_offset += 2; $parsed_frame['previewlength'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 2)); $frame_offset += 2; $parsed_frame['encryptioninfo'] = (string) substr($parsed_frame['data'], $frame_offset); unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'LINK' || $id3v2_major_version == 2 && $parsed_frame['frame_name'] == 'LNK') { // 4.22 LNK Linked information // There may be more than one 'LINK' frame in a tag, // but only one with the same contents // <Header for 'Linked information', ID: 'LINK'> // ID3v2.3+ => Frame identifier $xx xx xx xx // ID3v2.2 => Frame identifier $xx xx xx // URL <text string> $00 // ID and additional data <text string(s)> $frame_offset = 0; if ($id3v2_major_version == 2) { $parsed_frame['frameid'] = substr($parsed_frame['data'], $frame_offset, 3); $frame_offset += 3; } else { $parsed_frame['frameid'] = substr($parsed_frame['data'], $frame_offset, 4); $frame_offset += 4; } $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_url = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_url) === 0) { $frame_url = ''; } $frame_offset = $frame_terminator_pos + strlen(""); $parsed_frame['url'] = $frame_url; $parsed_frame['additionaldata'] = (string) substr($parsed_frame['data'], $frame_offset); if (!empty($parsed_frame['framenameshort']) && $parsed_frame['url']) { $getid3->info['id3v2']['comments'][$parsed_frame['framenameshort']][] = utf8_encode($parsed_frame['url']); } unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'POSS') { // 4.21 POSS Position synchronisation frame (ID3v2.3+ only) // There may only be one 'POSS' frame in each tag // <Head for 'Position synchronisation', ID: 'POSS'> // Time stamp format $xx // Position $xx (xx ...) $frame_offset = 0; $parsed_frame['timestampformat'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['position'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset)); unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'USER') { // 4.22 USER Terms of use (ID3v2.3+ only) // There may be more than one 'Terms of use' frame in a tag, // but only one with the same 'Language' // <Header for 'Terms of use frame', ID: 'USER'> // Text encoding $xx // Language $xx xx xx // The actual text <text string according to encoding> $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } $frame_language = substr($parsed_frame['data'], $frame_offset, 3); $frame_offset += 3; $parsed_frame['language'] = $frame_language; $parsed_frame['languagename'] = getid3_id3v2::LanguageLookup($frame_language, false); $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($frame_text_encoding); $parsed_frame['data'] = (string) substr($parsed_frame['data'], $frame_offset); if (!empty($parsed_frame['framenameshort']) && !empty($parsed_frame['data'])) { $getid3->info['id3v2']['comments'][$parsed_frame['framenameshort']][] = $getid3->iconv($parsed_frame['encoding'], 'UTF-8', $parsed_frame['data']); } unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'OWNE') { // 4.23 OWNE Ownership frame (ID3v2.3+ only) // There may only be one 'OWNE' frame in a tag // <Header for 'Ownership frame', ID: 'OWNE'> // Text encoding $xx // Price paid <text string> $00 // Date of purch. <text string> // Seller <text string according to encoding> $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($frame_text_encoding); $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_pricepaid = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); $frame_offset = $frame_terminator_pos + strlen(""); $parsed_frame['pricepaid']['currencyid'] = substr($frame_pricepaid, 0, 3); $parsed_frame['pricepaid']['currency'] = getid3_id3v2::LookupCurrencyUnits($parsed_frame['pricepaid']['currencyid']); $parsed_frame['pricepaid']['value'] = substr($frame_pricepaid, 3); $parsed_frame['purchasedate'] = substr($parsed_frame['data'], $frame_offset, 8); if (!getid3_id3v2::IsValidDateStampString($parsed_frame['purchasedate'])) { $parsed_frame['purchasedateunix'] = gmmktime(0, 0, 0, substr($parsed_frame['purchasedate'], 4, 2), substr($parsed_frame['purchasedate'], 6, 2), substr($parsed_frame['purchasedate'], 0, 4)); } $frame_offset += 8; $parsed_frame['seller'] = (string) substr($parsed_frame['data'], $frame_offset); unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'COMR') { // 4.24 COMR Commercial frame (ID3v2.3+ only) // There may be more than one 'commercial frame' in a tag, // but no two may be identical // <Header for 'Commercial frame', ID: 'COMR'> // Text encoding $xx // Price string <text string> $00 // Valid until <text string> // Contact URL <text string> $00 // Received as $xx // Name of seller <text string according to encoding> $00 (00) // Description <text string according to encoding> $00 (00) // Picture MIME type <string> $00 // Seller logo <binary data> $frame_offset = 0; $frame_text_encoding = ord($parsed_frame['data'][$frame_offset++]); if ($id3v2_major_version <= 3 && $frame_text_encoding > 1 || $id3v2_major_version == 4 && $frame_text_encoding > 3) { $getid3->warning('Invalid text encoding byte (' . $frame_text_encoding . ') in frame "' . $parsed_frame['frame_name'] . '" - defaulting to ISO-8859-1 encoding'); } $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_price_string = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); $frame_offset = $frame_terminator_pos + strlen(""); $frame_rawpricearray = explode('/', $frame_price_string); foreach ($frame_rawpricearray as $key => $val) { $frame_currencyid = substr($val, 0, 3); $parsed_frame['price'][$frame_currencyid]['currency'] = getid3_id3v2::LookupCurrencyUnits($frame_currencyid); $parsed_frame['price'][$frame_currencyid]['value'] = substr($val, 3); } $frame_date_string = substr($parsed_frame['data'], $frame_offset, 8); $frame_offset += 8; $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_contacturl = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); $frame_offset = $frame_terminator_pos + strlen(""); $frame_received_as_id = ord($parsed_frame['data'][$frame_offset++]); $frame_terminator_pos = @strpos($parsed_frame['data'], getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding), $frame_offset); if (ord(substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)), 1)) === 0) { $frame_terminator_pos++; // @strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $frame_sellername = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_sellername) === 0) { $frame_sellername = ''; } $frame_offset = $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)); $frame_terminator_pos = @strpos($parsed_frame['data'], getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding), $frame_offset); if (ord(substr($parsed_frame['data'], $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)), 1)) === 0) { $frame_terminator_pos++; // @strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $frame_description = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_description) === 0) { $frame_description = ''; } $frame_offset = $frame_terminator_pos + strlen(getid3_id3v2::TextEncodingTerminatorLookup($frame_text_encoding)); $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_mimetype = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); $frame_offset = $frame_terminator_pos + strlen(""); $frame_sellerlogo = substr($parsed_frame['data'], $frame_offset); $parsed_frame['encodingid'] = $frame_text_encoding; $parsed_frame['encoding'] = $this->TextEncodingNameLookup($frame_text_encoding); $parsed_frame['pricevaliduntil'] = $frame_date_string; $parsed_frame['contacturl'] = $frame_contacturl; $parsed_frame['receivedasid'] = $frame_received_as_id; $parsed_frame['receivedas'] = getid3_id3v2::COMRReceivedAsLookup($frame_received_as_id); $parsed_frame['sellername'] = $frame_sellername; $parsed_frame['description'] = $frame_description; $parsed_frame['mime'] = $frame_mimetype; $parsed_frame['logo'] = $frame_sellerlogo; unset($parsed_frame['data']); } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'ENCR') { // 4.25 ENCR Encryption method registration (ID3v2.3+ only) // There may be several 'ENCR' frames in a tag, // but only one containing the same symbol // and only one containing the same owner identifier // <Header for 'Encryption method registration', ID: 'ENCR'> // Owner identifier <text string> $00 // Method symbol $xx // Encryption data <binary data> $frame_offset = 0; $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_owner_id = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_owner_id) === 0) { $frame_owner_id = ''; } $frame_offset = $frame_terminator_pos + strlen(""); $parsed_frame['ownerid'] = $frame_owner_id; $parsed_frame['methodsymbol'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['data'] = (string) substr($parsed_frame['data'], $frame_offset); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'GRID') { // 4.26 GRID Group identification registration (ID3v2.3+ only) // There may be several 'GRID' frames in a tag, // but only one containing the same symbol // and only one containing the same owner identifier // <Header for 'Group ID registration', ID: 'GRID'> // Owner identifier <text string> $00 // Group symbol $xx // Group dependent data <binary data> $frame_offset = 0; $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_owner_id = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_owner_id) === 0) { $frame_owner_id = ''; } $frame_offset = $frame_terminator_pos + strlen(""); $parsed_frame['ownerid'] = $frame_owner_id; $parsed_frame['groupsymbol'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['data'] = (string) substr($parsed_frame['data'], $frame_offset); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'PRIV') { // 4.27 PRIV Private frame (ID3v2.3+ only) // The tag may contain more than one 'PRIV' frame // but only with different contents // <Header for 'Private frame', ID: 'PRIV'> // Owner identifier <text string> $00 // The private data <binary data> $frame_offset = 0; $frame_terminator_pos = @strpos($parsed_frame['data'], "", $frame_offset); $frame_owner_id = substr($parsed_frame['data'], $frame_offset, $frame_terminator_pos - $frame_offset); if (ord($frame_owner_id) === 0) { $frame_owner_id = ''; } $frame_offset = $frame_terminator_pos + strlen(""); $parsed_frame['ownerid'] = $frame_owner_id; $parsed_frame['data'] = (string) substr($parsed_frame['data'], $frame_offset); return true; } if ($id3v2_major_version >= 4 && $parsed_frame['frame_name'] == 'SIGN') { // 4.28 SIGN Signature frame (ID3v2.4+ only) // There may be more than one 'signature frame' in a tag, // but no two may be identical // <Header for 'Signature frame', ID: 'SIGN'> // Group symbol $xx // Signature <binary data> $frame_offset = 0; $parsed_frame['groupsymbol'] = ord($parsed_frame['data'][$frame_offset++]); $parsed_frame['data'] = (string) substr($parsed_frame['data'], $frame_offset); return true; } if ($id3v2_major_version >= 4 && $parsed_frame['frame_name'] == 'SEEK') { // 4.29 SEEK Seek frame (ID3v2.4+ only) // There may only be one 'seek frame' in a tag // <Header for 'Seek frame', ID: 'SEEK'> // Minimum offset to next tag $xx xx xx xx $frame_offset = 0; $parsed_frame['data'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 4)); return true; } if ($id3v2_major_version >= 4 && $parsed_frame['frame_name'] == 'ASPI') { // 4.30 ASPI Audio seek point index (ID3v2.4+ only) // There may only be one 'audio seek point index' frame in a tag // <Header for 'Seek Point Index', ID: 'ASPI'> // Indexed data start (S) $xx xx xx xx // Indexed data length (L) $xx xx xx xx // Number of index points (N) $xx xx // Bits per index point (b) $xx // Then for every index point the following data is included: // Fraction at index (Fi) $xx (xx) $frame_offset = 0; $parsed_frame['datastart'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 4)); $frame_offset += 4; $parsed_frame['indexeddatalength'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 4)); $frame_offset += 4; $parsed_frame['indexpoints'] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 2)); $frame_offset += 2; $parsed_frame['bitsperpoint'] = ord($parsed_frame['data'][$frame_offset++]); $frame_bytesperpoint = ceil($parsed_frame['bitsperpoint'] / 8); for ($i = 0; $i < $frame_indexpoints; $i++) { $parsed_frame['indexes'][$i] = getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, $frame_bytesperpoint)); $frame_offset += $frame_bytesperpoint; } unset($parsed_frame['data']); return true; } if ($id3v2_major_version >= 3 && $parsed_frame['frame_name'] == 'RGAD') { // Replay Gain Adjustment // http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html // There may only be one 'RGAD' frame in a tag // <Header for 'Replay Gain Adjustment', ID: 'RGAD'> // Peak Amplitude $xx $xx $xx $xx // Radio Replay Gain Adjustment %aaabbbcd %dddddddd // Audiophile Replay Gain Adjustment %aaabbbcd %dddddddd // a - name code // b - originator code // c - sign bit // d - replay gain adjustment $frame_offset = 0; $parsed_frame['peakamplitude'] = (double) getid3_lib::BigEndian2Int(substr($parsed_frame['data'], $frame_offset, 4)); $frame_offset += 4; $rg_track_adjustment = decbin(substr($parsed_frame['data'], $frame_offset, 2)); $frame_offset += 2; $rg_album_adjustment = decbin(substr($parsed_frame['data'], $frame_offset, 2)); $frame_offset += 2; $parsed_frame['raw']['track']['name'] = bindec(substr($rg_track_adjustment, 0, 3)); $parsed_frame['raw']['track']['originator'] = bindec(substr($rg_track_adjustment, 3, 3)); $parsed_frame['raw']['track']['signbit'] = bindec($rg_track_adjustment[6]); $parsed_frame['raw']['track']['adjustment'] = bindec(substr($rg_track_adjustment, 7, 9)); $parsed_frame['raw']['album']['name'] = bindec(substr($rg_album_adjustment, 0, 3)); $parsed_frame['raw']['album']['originator'] = bindec(substr($rg_album_adjustment, 3, 3)); $parsed_frame['raw']['album']['signbit'] = bindec($rg_album_adjustment[6]); $parsed_frame['raw']['album']['adjustment'] = bindec(substr($rg_album_adjustment, 7, 9)); $parsed_frame['track']['name'] = getid3_lib_replaygain::NameLookup($parsed_frame['raw']['track']['name']); $parsed_frame['track']['originator'] = getid3_lib_replaygain::OriginatorLookup($parsed_frame['raw']['track']['originator']); $parsed_frame['track']['adjustment'] = getid3_lib_replaygain::AdjustmentLookup($parsed_frame['raw']['track']['adjustment'], $parsed_frame['raw']['track']['signbit']); $parsed_frame['album']['name'] = getid3_lib_replaygain::NameLookup($parsed_frame['raw']['album']['name']); $parsed_frame['album']['originator'] = getid3_lib_replaygain::OriginatorLookup($parsed_frame['raw']['album']['originator']); $parsed_frame['album']['adjustment'] = getid3_lib_replaygain::AdjustmentLookup($parsed_frame['raw']['album']['adjustment'], $parsed_frame['raw']['album']['signbit']); $getid3->info['replay_gain']['track']['peak'] = $parsed_frame['peakamplitude']; $getid3->info['replay_gain']['track']['originator'] = $parsed_frame['track']['originator']; $getid3->info['replay_gain']['track']['adjustment'] = $parsed_frame['track']['adjustment']; $getid3->info['replay_gain']['album']['originator'] = $parsed_frame['album']['originator']; $getid3->info['replay_gain']['album']['adjustment'] = $parsed_frame['album']['adjustment']; unset($parsed_frame['data']); return true; } return true; }
public function decodeMPEGaudioHeader($fd, $offset, &$info, $recursive_search = true, $scan_as_cbr = false, $fast_mpeg_header_scan = false) { static $mpeg_audio_version_lookup; static $mpeg_audio_layer_lookup; static $mpeg_audio_bitrate_lookup; static $mpeg_audio_frequency_lookup; static $mpeg_audio_channel_mode_lookup; static $mpeg_audio_mode_extension_lookup; static $mpeg_audio_emphasis_lookup; if (empty($mpeg_audio_version_lookup)) { $mpeg_audio_version_lookup = getid3_mp3::MPEGaudioVersionarray(); $mpeg_audio_layer_lookup = getid3_mp3::MPEGaudioLayerarray(); $mpeg_audio_bitrate_lookup = getid3_mp3::MPEGaudioBitratearray(); $mpeg_audio_frequency_lookup = getid3_mp3::MPEGaudioFrequencyarray(); $mpeg_audio_channel_mode_lookup = getid3_mp3::MPEGaudioChannelModearray(); $mpeg_audio_mode_extension_lookup = getid3_mp3::MPEGaudioModeExtensionarray(); $mpeg_audio_emphasis_lookup = getid3_mp3::MPEGaudioEmphasisarray(); } if ($offset >= $info['avdataend']) { // non-fatal error: 'end of file encounter looking for MPEG synch' return; } fseek($fd, $offset, SEEK_SET); $header_string = fread($fd, 226); // LAME header at offset 36 + 190 bytes of Xing/LAME data // MP3 audio frame structure: // $aa $aa $aa $aa [$bb $bb] $cc... // where $aa..$aa is the four-byte mpeg-audio header (below) // $bb $bb is the optional 2-byte CRC // and $cc... is the audio data $head4 = substr($header_string, 0, 4); if (isset($mpeg_audio_header_decode_cache[$head4])) { $mpeg_header_raw_array = $mpeg_audio_header_decode_cache[$head4]; } else { $mpeg_header_raw_array = getid3_mp3::MPEGaudioHeaderDecode($head4); $mpeg_audio_header_decode_cache[$head4] = $mpeg_header_raw_array; } // Not in cache if (!isset($mpeg_audio_header_valid_cache[$head4])) { $mpeg_audio_header_valid_cache[$head4] = getid3_mp3::MPEGaudioHeaderValid($mpeg_header_raw_array, false, false); } // shortcut if (!isset($info['mpeg']['audio'])) { $info['mpeg']['audio'] = array(); } $thisfile_mpeg_audio =& $info['mpeg']['audio']; if ($mpeg_audio_header_valid_cache[$head4]) { $thisfile_mpeg_audio['raw'] = $mpeg_header_raw_array; } else { // non-fatal error: Invalid MPEG audio header at offset $offset return; } if (!$fast_mpeg_header_scan) { $thisfile_mpeg_audio['version'] = $mpeg_audio_version_lookup[$thisfile_mpeg_audio['raw']['version']]; $thisfile_mpeg_audio['layer'] = $mpeg_audio_layer_lookup[$thisfile_mpeg_audio['raw']['layer']]; $thisfile_mpeg_audio['channelmode'] = $mpeg_audio_channel_mode_lookup[$thisfile_mpeg_audio['raw']['channelmode']]; $thisfile_mpeg_audio['channels'] = $thisfile_mpeg_audio['channelmode'] == 'mono' ? 1 : 2; $thisfile_mpeg_audio['sample_rate'] = $mpeg_audio_frequency_lookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['raw']['sample_rate']]; $thisfile_mpeg_audio['protection'] = !$thisfile_mpeg_audio['raw']['protection']; $thisfile_mpeg_audio['private'] = (bool) $thisfile_mpeg_audio['raw']['private']; $thisfile_mpeg_audio['modeextension'] = $mpeg_audio_mode_extension_lookup[$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['modeextension']]; $thisfile_mpeg_audio['copyright'] = (bool) $thisfile_mpeg_audio['raw']['copyright']; $thisfile_mpeg_audio['original'] = (bool) $thisfile_mpeg_audio['raw']['original']; $thisfile_mpeg_audio['emphasis'] = $mpeg_audio_emphasis_lookup[$thisfile_mpeg_audio['raw']['emphasis']]; $info['audio']['channels'] = $thisfile_mpeg_audio['channels']; $info['audio']['sample_rate'] = $thisfile_mpeg_audio['sample_rate']; if ($thisfile_mpeg_audio['protection']) { $thisfile_mpeg_audio['crc'] = getid3_lib::BigEndian2Int(substr($header_string, 4, 2)); } } if ($thisfile_mpeg_audio['raw']['bitrate'] == 15) { // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0 $this->getid3->warning('Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1'); $thisfile_mpeg_audio['raw']['bitrate'] = 0; } $thisfile_mpeg_audio['padding'] = (bool) $thisfile_mpeg_audio['raw']['padding']; $thisfile_mpeg_audio['bitrate'] = $mpeg_audio_bitrate_lookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['bitrate']]; if ($thisfile_mpeg_audio['bitrate'] == 'free' && $offset == $info['avdataoffset']) { // only skip multiple frame check if free-format bitstream found at beginning of file // otherwise is quite possibly simply corrupted data $recursive_search = false; } // For Layer 2 there are some combinations of bitrate and mode which are not allowed. if (!$fast_mpeg_header_scan && $thisfile_mpeg_audio['layer'] == '2') { $info['audio']['dataformat'] = 'mp2'; switch ($thisfile_mpeg_audio['channelmode']) { case 'mono': if ($thisfile_mpeg_audio['bitrate'] == 'free' || $thisfile_mpeg_audio['bitrate'] <= 192000) { // these are ok } else { // non-fatal error: bitrate not allowed in Layer 2/mono return; } break; case 'stereo': case 'joint stereo': case 'dual channel': if ($thisfile_mpeg_audio['bitrate'] == 'free' || $thisfile_mpeg_audio['bitrate'] == 64000 || $thisfile_mpeg_audio['bitrate'] >= 96000) { // these are ok } else { // non-fatal error: bitrate not allowed in Layer 2/stereo/joint stereo/dual channel return; } break; } } if ($info['audio']['sample_rate'] > 0) { $thisfile_mpeg_audio['framelength'] = getid3_mp3::MPEGaudioFrameLength($thisfile_mpeg_audio['bitrate'], $thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['layer'], (int) $thisfile_mpeg_audio['padding'], $info['audio']['sample_rate']); } $next_frame_test_offset = $offset + 1; if ($thisfile_mpeg_audio['bitrate'] != 'free') { $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate']; if (isset($thisfile_mpeg_audio['framelength'])) { $next_frame_test_offset = $offset + $thisfile_mpeg_audio['framelength']; } else { // non-fatal error: Frame at offset('.$offset.') is has an invalid frame length. return; } } $expected_number_of_audio_bytes = 0; //////////////////////////////////////////////////////////////////////////////////// // Variable-bitrate headers if (substr($header_string, 4 + 32, 4) == 'VBRI') { // Fraunhofer VBR header is hardcoded 'VBRI' at offset 0x24 (36) // specs taken from http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html $thisfile_mpeg_audio['bitrate_mode'] = 'vbr'; $thisfile_mpeg_audio['VBR_method'] = 'Fraunhofer'; $info['audio']['codec'] = 'Fraunhofer'; $side_info_data = substr($header_string, 4 + 2, 32); $fraunhofer_vbr_offset = 36; $thisfile_mpeg_audio['VBR_encoder_version'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 4, 2)); // VbriVersion $thisfile_mpeg_audio['VBR_encoder_delay'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 6, 2)); // VbriDelay $thisfile_mpeg_audio['VBR_quality'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 8, 2)); // VbriQuality $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 10, 4)); // VbriStreamBytes $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 14, 4)); // VbriStreamFrames $thisfile_mpeg_audio['VBR_seek_offsets'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 18, 2)); // VbriTableSize $thisfile_mpeg_audio['VBR_seek_scale'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 20, 2)); // VbriTableScale $thisfile_mpeg_audio['VBR_entry_bytes'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 22, 2)); // VbriEntryBytes $thisfile_mpeg_audio['VBR_entry_frames'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 24, 2)); // VbriEntryFrames $expected_number_of_audio_bytes = $thisfile_mpeg_audio['VBR_bytes']; $previous_byte_offset = $offset; for ($i = 0; $i < $thisfile_mpeg_audio['VBR_seek_offsets']; $i++) { $fraunhofer_offset_n = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset, $thisfile_mpeg_audio['VBR_entry_bytes'])); $fraunhofer_vbr_offset += $thisfile_mpeg_audio['VBR_entry_bytes']; $thisfile_mpeg_audio['VBR_offsets_relative'][$i] = $fraunhofer_offset_n * $thisfile_mpeg_audio['VBR_seek_scale']; $thisfile_mpeg_audio['VBR_offsets_absolute'][$i] = $fraunhofer_offset_n * $thisfile_mpeg_audio['VBR_seek_scale'] + $previous_byte_offset; $previous_byte_offset += $fraunhofer_offset_n; } } else { // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36) // depending on MPEG layer and number of channels $vbr_id_offset = getid3_mp3::XingVBRidOffset($thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['channelmode']); $side_info_data = substr($header_string, 4 + 2, $vbr_id_offset - 4); if (substr($header_string, $vbr_id_offset, strlen('Xing')) == 'Xing' || substr($header_string, $vbr_id_offset, strlen('Info')) == 'Info') { // 'Xing' is traditional Xing VBR frame // 'Info' is LAME-encoded CBR (This was done to avoid CBR files to be recognized as traditional Xing VBR files by some decoders.) // 'Info' *can* legally be used to specify a VBR file as well, however. // http://www.multiweb.cz/twoinches/MP3inside.htm //00..03 = "Xing" or "Info" //04..07 = Flags: // 0x01 Frames Flag set if value for number of frames in file is stored // 0x02 Bytes Flag set if value for filesize in bytes is stored // 0x04 TOC Flag set if values for TOC are stored // 0x08 VBR Scale Flag set if values for VBR scale is stored //08..11 Frames: Number of frames in file (including the first Xing/Info one) //12..15 Bytes: File length in Bytes //16..115 TOC (Table of Contents): // Contains of 100 indexes (one Byte length) for easier lookup in file. Approximately solves problem with moving inside file. // Each Byte has a value according this formula: // (TOC[i] / 256) * fileLenInBytes // So if song lasts eg. 240 sec. and you want to jump to 60. sec. (and file is 5 000 000 Bytes length) you can use: // TOC[(60/240)*100] = TOC[25] // and corresponding Byte in file is then approximately at: // (TOC[25]/256) * 5000000 //116..119 VBR Scale // should be safe to leave this at 'vbr' and let it be overriden to 'cbr' if a CBR preset/mode is used by LAME $thisfile_mpeg_audio['bitrate_mode'] = 'vbr'; $thisfile_mpeg_audio['VBR_method'] = 'Xing'; $thisfile_mpeg_audio['xing_flags_raw'] = getid3_lib::BigEndian2Int(substr($header_string, $vbr_id_offset + 4, 4)); $thisfile_mpeg_audio['xing_flags']['frames'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x1); $thisfile_mpeg_audio['xing_flags']['bytes'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x2); $thisfile_mpeg_audio['xing_flags']['toc'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x4); $thisfile_mpeg_audio['xing_flags']['vbr_scale'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x8); if ($thisfile_mpeg_audio['xing_flags']['frames']) { $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($header_string, $vbr_id_offset + 8, 4)); } if ($thisfile_mpeg_audio['xing_flags']['bytes']) { $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($header_string, $vbr_id_offset + 12, 4)); } if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) { $frame_lengthfloat = $thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']; if ($thisfile_mpeg_audio['layer'] == '1') { // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 $info['audio']['bitrate'] = $frame_lengthfloat / 4 * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 12; } else { // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 $info['audio']['bitrate'] = $frame_lengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 144; } $thisfile_mpeg_audio['framelength'] = floor($frame_lengthfloat); } if ($thisfile_mpeg_audio['xing_flags']['toc']) { $lame_toc_data = substr($header_string, $vbr_id_offset + 16, 100); for ($i = 0; $i < 100; $i++) { $thisfile_mpeg_audio['toc'][$i] = ord($lame_toc_data[$i]); } } if ($thisfile_mpeg_audio['xing_flags']['vbr_scale']) { $thisfile_mpeg_audio['VBR_scale'] = getid3_lib::BigEndian2Int(substr($header_string, $vbr_id_offset + 116, 4)); } // http://gabriel.mp3-tech.org/mp3infotag.html if (substr($header_string, $vbr_id_offset + 120, 4) == 'LAME') { // shortcut $thisfile_mpeg_audio['LAME'] = array(); $thisfile_mpeg_audio_lame =& $thisfile_mpeg_audio['LAME']; $thisfile_mpeg_audio_lame['long_version'] = substr($header_string, $vbr_id_offset + 120, 20); $thisfile_mpeg_audio_lame['short_version'] = substr($thisfile_mpeg_audio_lame['long_version'], 0, 9); if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.90') { // extra 11 chars are not part of version string when LAMEtag present unset($thisfile_mpeg_audio_lame['long_version']); // It the LAME tag was only introduced in LAME v3.90 // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933 // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html // are assuming a 'Xing' identifier offset of 0x24, which is the case for // MPEG-1 non-mono, but not for other combinations $lame_tag_offset_contant = $vbr_id_offset - 0x24; // shortcuts $thisfile_mpeg_audio_lame['RGAD'] = array('track' => array(), 'album' => array()); $thisfile_mpeg_audio_lame_rgad =& $thisfile_mpeg_audio_lame['RGAD']; $thisfile_mpeg_audio_lame_rgad_track =& $thisfile_mpeg_audio_lame_rgad['track']; $thisfile_mpeg_audio_lame_rgad_album =& $thisfile_mpeg_audio_lame_rgad['album']; $thisfile_mpeg_audio_lame['raw'] = array(); $thisfile_mpeg_audio_lame_raw =& $thisfile_mpeg_audio_lame['raw']; // byte $9B VBR Quality // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications. // Actually overwrites original Xing bytes unset($thisfile_mpeg_audio['VBR_scale']); $thisfile_mpeg_audio_lame['vbr_quality'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0x9b, 1)); // bytes $9C-$A4 Encoder short VersionString $thisfile_mpeg_audio_lame['short_version'] = substr($header_string, $lame_tag_offset_contant + 0x9c, 9); // byte $A5 Info Tag revision + VBR method $lame_tagRevisionVBRmethod = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xa5, 1)); $thisfile_mpeg_audio_lame['tag_revision'] = ($lame_tagRevisionVBRmethod & 0xf0) >> 4; $thisfile_mpeg_audio_lame_raw['vbr_method'] = $lame_tagRevisionVBRmethod & 0xf; $thisfile_mpeg_audio_lame['vbr_method'] = getid3_mp3::LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw['vbr_method']); $thisfile_mpeg_audio['bitrate_mode'] = substr($thisfile_mpeg_audio_lame['vbr_method'], 0, 3); // usually either 'cbr' or 'vbr', but truncates 'vbr-old / vbr-rh' to 'vbr' // byte $A6 Lowpass filter value $thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xa6, 1)) * 100; // bytes $A7-$AE Replay Gain // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude" if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b') { // LAME 3.94a16 and later - 9.23 fixed point // ie 0x0059E2EE / (2^23) = 5890798 / 8388608 = 0.7022378444671630859375 $thisfile_mpeg_audio_lame_rgad['peak_amplitude'] = (double) (getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xa7, 4)) / 8388608); } else { // LAME 3.94a15 and earlier - 32-bit floating point // Actually 3.94a16 will fall in here too and be WRONG, but is hard to detect 3.94a16 vs 3.94a15 $thisfile_mpeg_audio_lame_rgad['peak_amplitude'] = getid3_lib::LittleEndian2Float(substr($header_string, $lame_tag_offset_contant + 0xa7, 4)); } if ($thisfile_mpeg_audio_lame_rgad['peak_amplitude'] == 0) { unset($thisfile_mpeg_audio_lame_rgad['peak_amplitude']); } else { $thisfile_mpeg_audio_lame_rgad['peak_db'] = 20 * log10($thisfile_mpeg_audio_lame_rgad['peak_amplitude']); } $thisfile_mpeg_audio_lame_raw['RGAD_track'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xab, 2)); $thisfile_mpeg_audio_lame_raw['RGAD_album'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xad, 2)); if ($thisfile_mpeg_audio_lame_raw['RGAD_track'] != 0) { $thisfile_mpeg_audio_lame_rgad_track['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0xe000) >> 13; $thisfile_mpeg_audio_lame_rgad_track['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x1c00) >> 10; $thisfile_mpeg_audio_lame_rgad_track['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x200) >> 9; $thisfile_mpeg_audio_lame_rgad_track['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x1ff; $thisfile_mpeg_audio_lame_rgad_track['name'] = getid3_lib_replaygain::NameLookup($thisfile_mpeg_audio_lame_rgad_track['raw']['name']); $thisfile_mpeg_audio_lame_rgad_track['originator'] = getid3_lib_replaygain::OriginatorLookup($thisfile_mpeg_audio_lame_rgad_track['raw']['originator']); $thisfile_mpeg_audio_lame_rgad_track['gain_db'] = getid3_lib_replaygain::AdjustmentLookup($thisfile_mpeg_audio_lame_rgad_track['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_rgad_track['raw']['sign_bit']); if (!empty($thisfile_mpeg_audio_lame_rgad['peak_amplitude'])) { $info['replay_gain']['track']['peak'] = $thisfile_mpeg_audio_lame_rgad['peak_amplitude']; } $info['replay_gain']['track']['originator'] = $thisfile_mpeg_audio_lame_rgad_track['originator']; $info['replay_gain']['track']['adjustment'] = $thisfile_mpeg_audio_lame_rgad_track['gain_db']; } else { unset($thisfile_mpeg_audio_lame_rgad['track']); } if ($thisfile_mpeg_audio_lame_raw['RGAD_album'] != 0) { $thisfile_mpeg_audio_lame_rgad_album['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0xe000) >> 13; $thisfile_mpeg_audio_lame_rgad_album['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x1c00) >> 10; $thisfile_mpeg_audio_lame_rgad_album['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x200) >> 9; $thisfile_mpeg_audio_lame_rgad_album['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x1ff; $thisfile_mpeg_audio_lame_rgad_album['name'] = getid3_lib_replaygain::NameLookup($thisfile_mpeg_audio_lame_rgad_album['raw']['name']); $thisfile_mpeg_audio_lame_rgad_album['originator'] = getid3_lib_replaygain::OriginatorLookup($thisfile_mpeg_audio_lame_rgad_album['raw']['originator']); $thisfile_mpeg_audio_lame_rgad_album['gain_db'] = getid3_lib_replaygain::AdjustmentLookup($thisfile_mpeg_audio_lame_rgad_album['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_rgad_album['raw']['sign_bit']); if (!empty($thisfile_mpeg_audio_lame_rgad['peak_amplitude'])) { $info['replay_gain']['album']['peak'] = $thisfile_mpeg_audio_lame_rgad['peak_amplitude']; } $info['replay_gain']['album']['originator'] = $thisfile_mpeg_audio_lame_rgad_album['originator']; $info['replay_gain']['album']['adjustment'] = $thisfile_mpeg_audio_lame_rgad_album['gain_db']; } else { unset($thisfile_mpeg_audio_lame_rgad['album']); } if (empty($thisfile_mpeg_audio_lame_rgad)) { unset($thisfile_mpeg_audio_lame['RGAD']); } // byte $AF Encoding flags + ATH Type $encoding_flags_ath_type = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xaf, 1)); $thisfile_mpeg_audio_lame['encoding_flags']['nspsytune'] = (bool) ($encoding_flags_ath_type & 0x10); $thisfile_mpeg_audio_lame['encoding_flags']['nssafejoint'] = (bool) ($encoding_flags_ath_type & 0x20); $thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'] = (bool) ($encoding_flags_ath_type & 0x40); $thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev'] = (bool) ($encoding_flags_ath_type & 0x80); $thisfile_mpeg_audio_lame['ath_type'] = $encoding_flags_ath_type & 0xf; // byte $B0 if ABR {specified bitrate} else {minimal bitrate} $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xb0, 1)); if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 2) { // Average BitRate (ABR) $thisfile_mpeg_audio_lame['bitrate_abr'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']; } elseif ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { // Constant BitRate (CBR) // ignore } elseif ($thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] > 0) { // Variable BitRate (VBR) - minimum bitrate $thisfile_mpeg_audio_lame['bitrate_min'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']; } // bytes $B1-$B3 Encoder delays $encoder_delays = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xb1, 3)); $thisfile_mpeg_audio_lame['encoder_delay'] = ($encoder_delays & 0xfff000) >> 12; $thisfile_mpeg_audio_lame['end_padding'] = $encoder_delays & 0xfff; // byte $B4 Misc $misc_byte = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xb4, 1)); $thisfile_mpeg_audio_lame_raw['noise_shaping'] = $misc_byte & 0x3; $thisfile_mpeg_audio_lame_raw['stereo_mode'] = ($misc_byte & 0x1c) >> 2; $thisfile_mpeg_audio_lame_raw['not_optimal_quality'] = ($misc_byte & 0x20) >> 5; $thisfile_mpeg_audio_lame_raw['source_sample_freq'] = ($misc_byte & 0xc0) >> 6; $thisfile_mpeg_audio_lame['noise_shaping'] = $thisfile_mpeg_audio_lame_raw['noise_shaping']; $thisfile_mpeg_audio_lame['stereo_mode'] = getid3_mp3::LAMEmiscStereoModeLookup($thisfile_mpeg_audio_lame_raw['stereo_mode']); $thisfile_mpeg_audio_lame['not_optimal_quality'] = (bool) $thisfile_mpeg_audio_lame_raw['not_optimal_quality']; $thisfile_mpeg_audio_lame['source_sample_freq'] = getid3_mp3::LAMEmiscSourceSampleFrequencyLookup($thisfile_mpeg_audio_lame_raw['source_sample_freq']); // byte $B5 MP3 Gain $thisfile_mpeg_audio_lame_raw['mp3_gain'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xb5, 1), false, true); $thisfile_mpeg_audio_lame['mp3_gain_db'] = 20 * log10(2) / 4 * $thisfile_mpeg_audio_lame_raw['mp3_gain']; $thisfile_mpeg_audio_lame['mp3_gain_factor'] = pow(2, $thisfile_mpeg_audio_lame['mp3_gain_db'] / 6); // bytes $B6-$B7 Preset and surround info $PresetSurroundBytes = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xb6, 2)); // Reserved = ($PresetSurroundBytes & 0xC000); $thisfile_mpeg_audio_lame_raw['surround_info'] = $PresetSurroundBytes & 0x3800; $thisfile_mpeg_audio_lame['surround_info'] = getid3_mp3::LAMEsurroundInfoLookup($thisfile_mpeg_audio_lame_raw['surround_info']); $thisfile_mpeg_audio_lame['preset_used_id'] = $PresetSurroundBytes & 0x7ff; $thisfile_mpeg_audio_lame['preset_used'] = getid3_mp3::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame); if (!empty($thisfile_mpeg_audio_lame['preset_used_id']) && empty($thisfile_mpeg_audio_lame['preset_used'])) { $this->getid3->warning('Unknown LAME preset used (' . $thisfile_mpeg_audio_lame['preset_used_id'] . ') - please report to info@getid3.org'); } if ($thisfile_mpeg_audio_lame['short_version'] == 'LAME3.90.' && !empty($thisfile_mpeg_audio_lame['preset_used_id'])) { // this may change if 3.90.4 ever comes out $thisfile_mpeg_audio_lame['short_version'] = 'LAME3.90.3'; } // bytes $B8-$BB MusicLength $thisfile_mpeg_audio_lame['audio_bytes'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xb8, 4)); $expected_number_of_audio_bytes = $thisfile_mpeg_audio_lame['audio_bytes'] > 0 ? $thisfile_mpeg_audio_lame['audio_bytes'] : $thisfile_mpeg_audio['VBR_bytes']; // bytes $BC-$BD MusicCRC $thisfile_mpeg_audio_lame['music_crc'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xbc, 2)); // bytes $BE-$BF CRC-16 of Info Tag $thisfile_mpeg_audio_lame['lame_tag_crc'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xbe, 2)); // LAME CBR if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; $thisfile_mpeg_audio['bitrate'] = getid3_mp3::ClosestStandardMP3Bitrate($thisfile_mpeg_audio['bitrate']); $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate']; } } } } else { // not Fraunhofer or Xing VBR methods, most likely CBR (but could be VBR with no header) $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; if ($recursive_search) { $thisfile_mpeg_audio['bitrate_mode'] = 'vbr'; if (getid3_mp3::RecursiveFrameScanning($fd, $info, $offset, $next_frame_test_offset, true)) { $recursive_search = false; $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; } if ($thisfile_mpeg_audio['bitrate_mode'] == 'vbr') { $this->getid3->warning('VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.'); } } } } if ($expected_number_of_audio_bytes > 0 && $expected_number_of_audio_bytes != $info['avdataend'] - $info['avdataoffset']) { if ($expected_number_of_audio_bytes > $info['avdataend'] - $info['avdataoffset']) { if ($expected_number_of_audio_bytes - ($info['avdataend'] - $info['avdataoffset']) == 1) { $this->getid3->warning('Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)'); } else { $this->getid3->warning('Probable truncated file: expecting ' . $expected_number_of_audio_bytes . ' bytes of audio data, only found ' . ($info['avdataend'] - $info['avdataoffset']) . ' (short by ' . ($expected_number_of_audio_bytes - ($info['avdataend'] - $info['avdataoffset'])) . ' bytes)'); } } else { if ($info['avdataend'] - $info['avdataoffset'] - $expected_number_of_audio_bytes == 1) { $info['avdataend']--; } else { $this->getid3->warning('Too much data in file: expecting ' . $expected_number_of_audio_bytes . ' bytes of audio data, found ' . ($info['avdataend'] - $info['avdataoffset']) . ' (' . ($info['avdataend'] - $info['avdataoffset'] - $expected_number_of_audio_bytes) . ' bytes too many)'); } } } if ($thisfile_mpeg_audio['bitrate'] == 'free' && empty($info['audio']['bitrate'])) { if ($offset == $info['avdataoffset'] && empty($thisfile_mpeg_audio['VBR_frames'])) { $frame_byte_length = getid3_mp3::FreeFormatFrameLength($fd, $offset, $info, true); if ($frame_byte_length > 0) { $thisfile_mpeg_audio['framelength'] = $frame_byte_length; if ($thisfile_mpeg_audio['layer'] == '1') { // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 $info['audio']['bitrate'] = ($frame_byte_length / 4 - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate'] / 12; } else { // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 $info['audio']['bitrate'] = ($frame_byte_length - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate'] / 144; } } else { // non-fatal error: Error calculating frame length of free-format MP3 without Xing/LAME header. return; } } } if (@$thisfile_mpeg_audio['VBR_frames']) { switch ($thisfile_mpeg_audio['bitrate_mode']) { case 'vbr': case 'abr': if ($thisfile_mpeg_audio['version'] == '1' && $thisfile_mpeg_audio['layer'] == 1) { $thisfile_mpeg_audio['VBR_bitrate'] = @$thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames'] * 8 * ($info['audio']['sample_rate'] / 384); } elseif (($thisfile_mpeg_audio['version'] == '2' || $thisfile_mpeg_audio['version'] == '2.5') && $thisfile_mpeg_audio['layer'] == 3) { $thisfile_mpeg_audio['VBR_bitrate'] = @$thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames'] * 8 * ($info['audio']['sample_rate'] / 576); } else { $thisfile_mpeg_audio['VBR_bitrate'] = @$thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames'] * 8 * ($info['audio']['sample_rate'] / 1152); } if ($thisfile_mpeg_audio['VBR_bitrate'] > 0) { $info['audio']['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; // to avoid confusion } break; } } // End variable-bitrate headers //////////////////////////////////////////////////////////////////////////////////// if ($recursive_search) { if (!getid3_mp3::RecursiveFrameScanning($fd, $info, $offset, $next_frame_test_offset, $scan_as_cbr)) { return false; } } return true; }