BigEndian2Bin example

            // Deviation in milliseconds %xxx....
            $frame_offset = 0;
            $parsedFrame['framesbetweenreferences'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 2));
            $parsedFrame['bytesbetweenreferences']  = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 2, 3));
            $parsedFrame['msbetweenreferences']     = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 5, 3));
            $parsedFrame['bitsforbytesdeviation']   = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 8, 1));
            $parsedFrame['bitsformsdeviation']      = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 9, 1));
            $parsedFrame['data'] = substr($parsedFrame['data'], 10);
            $deviationbitstream = '';
            while ($frame_offset < strlen($parsedFrame['data'])) {
                $deviationbitstream .= getid3_lib::BigEndian2Bin(substr($parsedFrame['data']$frame_offset++, 1));
            }
            $reference_counter = 0;
            while (strlen($deviationbitstream) > 0) {
                $parsedFrame[$reference_counter]['bytedeviation'] = bindec(substr($deviationbitstream, 0, $parsedFrame['bitsforbytesdeviation']));
                $parsedFrame[$reference_counter]['msdeviation']   = bindec(substr($deviationbitstream$parsedFrame['bitsforbytesdeviation']$parsedFrame['bitsformsdeviation']));
                $deviationbitstream = substr($deviationbitstream$parsedFrame['bitsforbytesdeviation'] + $parsedFrame['bitsformsdeviation']);
                $reference_counter++;
            }
            unset($parsedFrame['data']);


        }

        // syncinfo() {         // syncword 16         // crc1 16         // fscod 2         // frmsizecod 6         // } /* end of syncinfo */
        $this->fseek($info['avdataoffset']);
        $tempAC3header = $this->fread(100); // should be enough to cover all data, there are some variable-length fields...?         $this->AC3header['syncinfo']  =     getid3_lib::BigEndian2Int(substr($tempAC3header, 0, 2));
        $this->AC3header['bsi']       =     getid3_lib::BigEndian2Bin(substr($tempAC3header, 2));
        $thisfile_ac3_raw_bsi['bsid'] = (getid3_lib::LittleEndian2Int(substr($tempAC3header, 5, 1)) & 0xF8) >> 3; // AC3 and E-AC3 put the "bsid" version identifier in the same place, but unfortnately the 4 bytes between the syncword and the version identifier are interpreted differently, so grab it here so the following code structure can make sense         unset($tempAC3header);

        if ($this->AC3header['syncinfo'] !== self::syncword) {
            if (!$this->isDependencyFor('matroska')) {
                unset($info['fileformat']$info['ac3']);
                return $this->error('Expecting "'.dechex(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.dechex($this->AC3header['syncinfo']).'"');
            }
        }

        $info['audio']['dataformat']   = 'ac3';
        
unset($info['fileformat']);
            return $this->error('Expecting "'.implode('| ', array_map('getid3_lib::PrintHexBytes', self::$syncwords)).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($sync).'"');

        }

        // decode header         $fhBS = '';
        for ($word_offset = 0; $word_offset <= strlen($DTSheader)$word_offset += 2) {
            switch ($encoding) {
                case 0: // raw big-endian                     $fhBS .=        getid3_lib::BigEndian2Bin(       substr($DTSheader$word_offset, 2) );
                    break;
                case 1: // raw little-endian                     $fhBS .=        getid3_lib::BigEndian2Bin(strrev(substr($DTSheader$word_offset, 2)));
                    break;
                case 2: // 14-bit big-endian                     $fhBS .= substr(getid3_lib::BigEndian2Bin(       substr($DTSheader$word_offset, 2) ), 2, 14);
                    break;
                case 3: // 14-bit little-endian                     $fhBS .= substr(getid3_lib::BigEndian2Bin(strrev(substr($DTSheader$word_offset, 2))), 2, 14);
                    break;
            }
        }

    public static function parseSTREAMINFOdata($BlockData) {
        $streaminfo = array();
        $streaminfo['min_block_size']  = getid3_lib::BigEndian2Int(substr($BlockData, 0, 2));
        $streaminfo['max_block_size']  = getid3_lib::BigEndian2Int(substr($BlockData, 2, 2));
        $streaminfo['min_frame_size']  = getid3_lib::BigEndian2Int(substr($BlockData, 4, 3));
        $streaminfo['max_frame_size']  = getid3_lib::BigEndian2Int(substr($BlockData, 7, 3));

        $SRCSBSS                       = getid3_lib::BigEndian2Bin(substr($BlockData, 10, 8));
        $streaminfo['sample_rate']     = getid3_lib::Bin2Dec(substr($SRCSBSS,  0, 20));
        $streaminfo['channels']        = getid3_lib::Bin2Dec(substr($SRCSBSS, 20,  3)) + 1;
        $streaminfo['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 23,  5)) + 1;
        $streaminfo['samples_stream']  = getid3_lib::Bin2Dec(substr($SRCSBSS, 28, 36));

        $streaminfo['audio_signature'] =                           substr($BlockData, 18, 16);

        return $streaminfo;
    }

    /** * @param string $BlockData * * @return bool */
/** * ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic * * @link https://web.archive.org/web/20120325162206/http://www.psc.edu/general/software/packages/ieee/ieee.php * @link http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html * * @param string $byteword * * @return float|false */
    public static function BigEndian2Float($byteword) {
        $bitword = self::BigEndian2Bin($byteword);
        if (!$bitword) {
            return 0;
        }
        $signbit = $bitword[0];
        $floatvalue = 0;
        $exponentbits = 0;
        $fractionbits = 0;

        switch (strlen($byteword) * 8) {
            case 32:
                $exponentbits = 8;
                
Home | Imprint | This part of the site doesn't use cookies.