CastAsInt example

$framecounter = 0;
                        foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitratevalue => $bitratecount) {
                            $framecounter += $bitratecount;
                            if ($bitratevalue != 'free') {
                                $bittotal += ($bitratevalue * $bitratecount);
                            }
                        }
                        if ($framecounter == 0) {
                            $this->error('Corrupt MP3 file: framecounter == zero');
                            return false;
                        }
                        $info['mpeg']['audio']['frame_count'] = getid3_lib::CastAsInt($framecounter);
                        $info['mpeg']['audio']['bitrate']     = ($bittotal / $framecounter);

                        $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];


                        // Definitively set VBR vs CBR, even if the Xing/LAME/VBRI header says differently                         $distinct_bitrates = 0;
                        foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitrate_value => $bitrate_count) {
                            if ($bitrate_count > 0) {
                                $distinct_bitrates++;
                            }
                        }
unset($reader);

                        $copykeys = array('framerate'=>'frame_rate', 'width'=>'resolution_x', 'height'=>'resolution_y', 'audiodatarate'=>'bitrate', 'videodatarate'=>'bitrate');
                        foreach ($copykeys as $sourcekey => $destkey) {
                            if (isset($info['flv']['meta']['onMetaData'][$sourcekey])) {
                                switch ($sourcekey) {
                                    case 'width':
                                    case 'height':
                                        $info['video'][$destkey] = intval(round($info['flv']['meta']['onMetaData'][$sourcekey]));
                                        break;
                                    case 'audiodatarate':
                                        $info['audio'][$destkey] = getid3_lib::CastAsInt(round($info['flv']['meta']['onMetaData'][$sourcekey] * 1000));
                                        break;
                                    case 'videodatarate':
                                    case 'frame_rate':
                                    default:
                                        $info['video'][$destkey] = $info['flv']['meta']['onMetaData'][$sourcekey];
                                        break;
                                }
                            }
                        }
                        if (!empty($info['flv']['meta']['onMetaData']['duration'])) {
                            $found_valid_meta_playtime = true;
                        }
if ($signed && !$synchsafe) {
            // synchsafe ints are not allowed to be signed             if ($bytewordlen <= PHP_INT_SIZE) {
                $signMaskBit = 0x80 << (8 * ($bytewordlen - 1));
                if ($intvalue & $signMaskBit) {
                    $intvalue = 0 - ($intvalue & ($signMaskBit - 1));
                }
            } else {
                throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in self::BigEndian2Int()');
            }
        }
        return self::CastAsInt($intvalue);
    }

    /** * @param string $byteword * @param bool $signed * * @return int|float|false */
    public static function LittleEndian2Int($byteword$signed=false) {
        return self::BigEndian2Int(strrev($byteword), false, $signed);
    }

    
if ($iTunesBrokenFrameNameFixed = self::ID3v22iTunesBrokenFrameName($frame_name)) {
                    $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by iTunes (versions "X v2.0.3", "v3.0.1", "v7.0.0.70" are known-guilty, probably others too)]. Translated frame name from "'.str_replace("\x00", ' ', $frame_name).'" to "'.$iTunesBrokenFrameNameFixed.'" for parsing.');
                    $frame_name = $iTunesBrokenFrameNameFixed;
                }
                if (($frame_size <= strlen($framedata)) && ($this->IsValidID3v2FrameName($frame_name$id3v2_majorversion))) {

                    $parsedFrame                    = array();
                    $parsedFrame['frame_name']      = $frame_name;
                    $parsedFrame['frame_flags_raw'] = $frame_flags;
                    $parsedFrame['data']            = substr($framedata, 0, $frame_size);
                    $parsedFrame['datalength']      = getid3_lib::CastAsInt($frame_size);
                    $parsedFrame['dataoffset']      = $framedataoffset;

                    $this->ParseID3v2Frame($parsedFrame);
                    $thisfile_id3v2[$frame_name][] = $parsedFrame;

                    $framedata = substr($framedata$frame_size);

                } else { // invalid frame length or FrameID
                    if ($frame_size <= strlen($framedata)) {

                        
$thisfile_riff_raw['fact']['NumberOfSamples'] = $this->EitherEndian2Int(substr($thisfile_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($thisfile_riff_raw['fmt ']['nSamplesPerSec'])) {                     // $info['playtime_seconds'] = (float) $thisfile_riff_raw['fact']['NumberOfSamples'] / $thisfile_riff_raw['fmt ']['nSamplesPerSec'];                     // }                 }
                if (!empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) {
                    $thisfile_audio['bitrate'] = getid3_lib::CastAsInt($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'] * 8);
                }

                if (isset($thisfile_riff_WAVE['bext'][0]['data'])) {
                    // shortcut                     $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0];

                    $thisfile_riff_WAVE_bext_0['title']          =                              substr($thisfile_riff_WAVE_bext_0['data'],   0, 256);
                    $thisfile_riff_WAVE_bext_0['author']         =                              substr($thisfile_riff_WAVE_bext_0['data'], 256,  32);
                    $thisfile_riff_WAVE_bext_0['reference']      =                              substr($thisfile_riff_WAVE_bext_0['data'], 288,  32);
                    foreach (array('title','author','reference') as $bext_key) {
                        // Some software (notably Logic Pro) may not blank existing data before writing a null-terminated string to the offsets
Home | Imprint | This part of the site doesn't use cookies.