public static function unpackSample($sampleBinary, $bitDepth = null)
    {
        if ($bitDepth === null) {
            $bitDepth = strlen($sampleBinary) * 8;
        }

        switch ($bitDepth) {
            case 8:
                // unsigned char
                return ord($sampleBinary);

            case 16:
                // signed short, little endian
                $data = unpack('v', $sampleBinary);
                $sample = $data[1];
                if ($sample >= 0x8000) {
                    $sample -= 0x10000;
                }
                return $sample;

            case 24:
                // 3 byte packed signed integer, little endian
                $data = unpack('C3', $sampleBinary);
                $sample = $data[1] | ($data[2] << 8) | ($data[3] << 16);
                if ($sample >= 0x800000) {
                    $sample -= 0x1000000;
                }
                return $sample;

            case 32:
                // 32-bit float
                $data = unpack('f', $sampleBinary);
                return $data[1];

            default:
                return null;
        }
    }
public static function unpackSample($sampleBinary, $bitDepth = null)
    {
        if ($bitDepth === null) {
            $bitDepth = strlen($sampleBinary) * 8;
        }

        switch ($bitDepth) {
            case 8:
                // unsigned char
                return ord($sampleBinary);

            case 16:
                // signed short, little endian
                $data = unpack('v', $sampleBinary);
                $sample = $data[1];
                if ($sample >= 0x8000) {
                    $sample -= 0x10000;
                }
                return $sample;

            case 24:
                // 3 byte packed signed integer, little endian
                $data = unpack('C3', $sampleBinary);
                $sample = $data[1] | ($data[2] << 8) | ($data[3] << 16);
                if ($sample >= 0x800000) {
                    $sample -= 0x1000000;
                }
                return $sample;

            case 32:
                // 32-bit float
                $data = unpack('f', $sampleBinary);
                return $data[1];

            default:
                return null;
        }
    }
public static function unpackSample ( $ sampleBinary , $ bitDepth = null ) { if ( $ bitDepth === null ) { $ bitDepth = strlen ( $ sampleBinary ) * 8 ; } switch ( $ bitDepth ) { case 8 : // unsigned char return ord ( $ sampleBinary ) ; case 16 : // signed short, little endian $ data = unpack ( 'v' , $ sampleBinary ) ; $ sample = $ data [ 1 ] ; if ( $ sample >= 0x8000 ) { $ sample -= 0x10000 ; } return $ sample ; case 24 : // 3 byte packed signed integer, little endian $ data = unpack ( 'C3' , $ sampleBinary ) ; $ sample = $ data [ 1 ] | ( $ data [ 2 ] << 8 ) | ( $ data [ 3 ] << 16 ) ; if ( $ sample >= 0x800000 ) { $ sample -= 0x1000000 ; } return $ sample ; case 32 : // 32-bit float $ data = unpack ( 'f' , $ sampleBinary ) ; return $ data [ 1 ] ; default : return null ; } }
Unpacks a single binary sample to numeric value.

@param string $sampleBinary  (Required) The sample to decode.
@param int $bitDepth  (Optional) The bits per sample to decode. If omitted, derives it from the length of $sampleBinary.
@return int|float|null  The numeric sample value. Float for 32-bit samples. Returns null for unsupported bit depths.
Unpacks a single binary sample to numeric value .