Пример #1
0
 /**
  * Decode the stream header
  * @access  private
  */
 function _decodeHeader()
 {
     fseek($this->_filePointer, $this->_streamList[0]['body_offset'], SEEK_SET);
     // The first 8 characters should be "Speex   ".
     if (fread($this->_filePointer, 8) != 'Speex   ') {
         throw new PEAR_Exception("Stream is undecodable due to a malformed header.", OGG_ERROR_UNDECODABLE);
     }
     $this->_version = fread($this->_filePointer, 20);
     $this->_header = File_Ogg::_readLittleEndian($this->_filePointer, array('speex_version_id' => 32, 'header_size' => 32, 'rate' => 32, 'mode' => 32, 'mode_bitstream_version' => 32, 'nb_channels' => 32, 'bitrate' => 32, 'frame_size' => 32, 'vbr' => 32, 'frames_per_packet' => 32, 'extra_headers' => 32, 'reserved1' => 32, 'reserved2' => 32));
     $this->_header['speex_version'] = $this->_version;
 }
Пример #2
0
 /**
  * Parse the identification header (the first of three headers) in a Vorbis stream.
  *
  * This function parses the identification header.  The identification header
  * contains simple audio characteristics, such as sample rate and number of
  * channels.  There are a number of error-checking provisions laid down in the Vorbis
  * specification to ensure the stream is pure.
  *
  * @access  private
  */
 function _decodeIdentificationHeader()
 {
     $this->_decodeCommonHeader(OGG_VORBIS_IDENTIFICATION_HEADER, OGG_VORBIS_IDENTIFICATION_PAGE_OFFSET);
     $h = File_Ogg::_readLittleEndian($this->_filePointer, array('vorbis_version' => 32, 'audio_channels' => 8, 'audio_sample_rate' => 32, 'bitrate_maximum' => 32, 'bitrate_nominal' => 32, 'bitrate_minimum' => 32, 'blocksize_0' => 4, 'blocksize_1' => 4, 'framing_flag' => 1));
     // The Vorbis stream version must be 0.
     if ($h['vorbis_version'] == 0) {
         $this->_version = $h['vorbis_version'];
     } else {
         throw new PEAR_Exception("Stream is undecodable due to an invalid vorbis stream version.", OGG_VORBIS_ERROR_UNDECODABLE);
     }
     // The number of channels MUST be greater than 0.
     if ($h['audio_channels'] == 0) {
         throw new PEAR_Exception("Stream is undecodable due to zero channels.", OGG_VORBIS_ERROR_UNDECODABLE);
     } else {
         $this->_channels = $h['audio_channels'];
     }
     // The sample rate MUST be greater than 0.
     if ($h['audio_sample_rate'] == 0) {
         throw new PEAR_Exception("Stream is undecodable due to a zero sample rate.", OGG_VORBIS_ERROR_UNDECODABLE);
     } else {
         $this->_sampleRate = $h['audio_sample_rate'];
     }
     // Extract the various bitrates
     $this->_maxBitrate = $h['bitrate_maximum'];
     $this->_nomBitrate = $h['bitrate_nominal'];
     $this->_minBitrate = $h['bitrate_minimum'];
     // Powers of two between 6 and 13 inclusive.
     $valid_block_sizes = array(64, 128, 256, 512, 1024, 2048, 4096, 8192);
     // blocksize_0 MUST be a valid blocksize.
     $blocksize_0 = pow(2, $h['blocksize_0']);
     if (FALSE == in_array($blocksize_0, $valid_block_sizes)) {
         throw new PEAR_Exception("Stream is undecodable because blocksize_0 is {$blocksize_0}, which is not a valid size.", OGG_VORBIS_ERROR_UNDECODABLE);
     }
     // Extract bits 5 to 8 from the character data.
     // blocksize_1 MUST be a valid blocksize.
     $blocksize_1 = pow(2, $h['blocksize_1']);
     if (FALSE == in_array($blocksize_1, $valid_block_sizes)) {
         throw new PEAR_Exception("Stream is undecodable because blocksize_1 is not a valid size.", OGG_VORBIS_ERROR_UNDECODABLE);
     }
     // blocksize 0 MUST be less than or equal to blocksize 1.
     if ($blocksize_0 > $blocksize_1) {
         throw new PEAR_Exception("Stream is undecodable because blocksize_0 is not less than or equal to blocksize_1.", OGG_VORBIS_ERROR_UNDECODABLE);
     }
     // The framing bit MUST be set to mark the end of the identification header.
     // Some encoders are broken though -- TS
     /*
             if ($h['framing_flag'] == 0)
        throw new PEAR_Exception("Stream in undecodable because the framing bit is not non-zero.", OGG_VORBIS_ERROR_UNDECODABLE);
     */
     $this->_idHeader = $h;
 }