示例#1
0
 public static function MPEGaudioHeaderValid($raw_array, $echo_errors = false, $allow_bitrate_15 = false)
 {
     if (($raw_array['synch'] & 0xffe) != 0xffe) {
         return 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 (isset($mpeg_audio_version_lookup[$raw_array['version']])) {
         $decodedVersion = $mpeg_audio_version_lookup[$raw_array['version']];
     } else {
         echo $echo_errors ? "\n" . 'invalid Version (' . $raw_array['version'] . ')' : '';
         return false;
     }
     if (isset($mpeg_audio_layer_lookup[$raw_array['layer']])) {
         $decodedLayer = $mpeg_audio_layer_lookup[$raw_array['layer']];
     } else {
         echo $echo_errors ? "\n" . 'invalid Layer (' . $raw_array['layer'] . ')' : '';
         return false;
     }
     if (!isset($mpeg_audio_bitrate_lookup[$decodedVersion][$decodedLayer][$raw_array['bitrate']])) {
         echo $echo_errors ? "\n" . 'invalid Bitrate (' . $raw_array['bitrate'] . ')' : '';
         if ($raw_array['bitrate'] == 15) {
             // known issue in LAME 3.90 - 3.93.1 where free-format has bitrate ID of 15 instead of 0
             // let it go through here otherwise file will not be identified
             if (!$allow_bitrate_15) {
                 return false;
             }
         } else {
             return false;
         }
     }
     if (!isset($mpeg_audio_frequency_lookup[$decodedVersion][$raw_array['sample_rate']])) {
         echo $echo_errors ? "\n" . 'invalid Frequency (' . $raw_array['sample_rate'] . ')' : '';
         return false;
     }
     if (!isset($mpeg_audio_channel_mode_lookup[$raw_array['channelmode']])) {
         echo $echo_errors ? "\n" . 'invalid ChannelMode (' . $raw_array['channelmode'] . ')' : '';
         return false;
     }
     if (!isset($mpeg_audio_mode_extension_lookup[$decodedLayer][$raw_array['modeextension']])) {
         echo $echo_errors ? "\n" . 'invalid Mode Extension (' . $raw_array['modeextension'] . ')' : '';
         return false;
     }
     if (!isset($mpeg_audio_emphasis_lookup[$raw_array['emphasis']])) {
         echo $echo_errors ? "\n" . 'invalid Emphasis (' . $raw_array['emphasis'] . ')' : '';
         return false;
     }
     // These are just either set or not set, you can't mess that up :)
     // $raw_array['protection'];
     // $raw_array['padding'];
     // $raw_array['private'];
     // $raw_array['copyright'];
     // $raw_array['original'];
     return true;
 }