$headerstring = ''; foreach ($headerbytearray as $textbyte) { $headerstring .= chr(hexdec($textbyte)); } $MP3fileInfo['error'] = ''; $MPEGheaderRawArray = MPEGaudioHeaderDecode(substr($headerstring, 0, 4)); if (MPEGaudioHeaderValid($MPEGheaderRawArray, true)) { $MP3fileInfo['raw'] = $MPEGheaderRawArray; $MP3fileInfo['version'] = MPEGaudioVersionLookup($MP3fileInfo['raw']['version']); $MP3fileInfo['layer'] = MPEGaudioLayerLookup($MP3fileInfo['raw']['layer']); $MP3fileInfo['protection'] = MPEGaudioCRCLookup($MP3fileInfo['raw']['protection']); $MP3fileInfo['bitrate'] = MPEGaudioBitrateLookup($MP3fileInfo['version'], $MP3fileInfo['layer'], $MP3fileInfo['raw']['bitrate']); $MP3fileInfo['frequency'] = MPEGaudioFrequencyLookup($MP3fileInfo['version'], $MP3fileInfo['raw']['sample_rate']); $MP3fileInfo['padding'] = (bool) $MP3fileInfo['raw']['padding']; $MP3fileInfo['private'] = (bool) $MP3fileInfo['raw']['private']; $MP3fileInfo['channelmode'] = MPEGaudioChannelModeLookup($MP3fileInfo['raw']['channelmode']); $MP3fileInfo['channels'] = $MP3fileInfo['channelmode'] == 'mono' ? 1 : 2; $MP3fileInfo['modeextension'] = MPEGaudioModeExtensionLookup($MP3fileInfo['layer'], $MP3fileInfo['raw']['modeextension']); $MP3fileInfo['copyright'] = (bool) $MP3fileInfo['raw']['copyright']; $MP3fileInfo['original'] = (bool) $MP3fileInfo['raw']['original']; $MP3fileInfo['emphasis'] = MPEGaudioEmphasisLookup($MP3fileInfo['raw']['emphasis']); if ($MP3fileInfo['protection']) { $MP3fileInfo['crc'] = BigEndian2Int(substr($headerstring, 4, 2)); } if ($MP3fileInfo['frequency'] > 0) { $MP3fileInfo['framelength'] = MPEGaudioFrameLength($MP3fileInfo['bitrate'], $MP3fileInfo['version'], $MP3fileInfo['layer'], (int) $MP3fileInfo['padding'], $MP3fileInfo['frequency']); } if ($MP3fileInfo['bitrate'] != 'free') { $MP3fileInfo['bitrate'] *= 1000; } } else {
function MPEGaudioHeaderValid($rawarray) { $decodedVersion = MPEGaudioVersionLookup($rawarray['version']); $decodedLayer = MPEGaudioLayerLookup($rawarray['layer']); if ($decodedVersion === FALSE) { return FALSE; } if ($decodedLayer === FALSE) { return FALSE; } if (MPEGaudioBitrateLookup($decodedVersion, $decodedLayer, $rawarray['bitrate']) === FALSE) { return FALSE; } if (MPEGaudioFrequencyLookup($decodedVersion, $rawarray['frequency']) === FALSE) { return FALSE; } if (MPEGaudioChannelModeLookup($rawarray['channelmode']) === FALSE) { return FALSE; } if (MPEGaudioModeExtensionLookup($decodedLayer, $rawarray['modeextension']) === FALSE) { return FALSE; } if (MPEGaudioEmphasisLookup($rawarray['emphasis']) === FALSE) { return FALSE; } // These are just either set or not set, you can't mess that up :) // $rawarray['protection']; // $rawarray['padding']; // $rawarray['private']; // $rawarray['copyright']; // $rawarray['original']; return TRUE; }