File_Ogg
[ class tree: File_Ogg ] [ index: File_Ogg ] [ all elements ]

Source for file Speex.php

Documentation is available at Speex.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------------+
  4. // | File_Ogg PEAR Package for Accessing Ogg Bitstreams                         |
  5. // | Copyright (c) 2005-2007                                                    |
  6. // | David Grant <david@grant.org.uk>                                           |
  7. // | Tim Starling <tstarling@wikimedia.org>                                     |
  8. // +----------------------------------------------------------------------------+
  9. // | This library is free software; you can redistribute it and/or              |
  10. // | modify it under the terms of the GNU Lesser General Public                 |
  11. // | License as published by the Free Software Foundation; either               |
  12. // | version 2.1 of the License, or (at your option) any later version.         |
  13. // |                                                                            |
  14. // | This library is distributed in the hope that it will be useful,            |
  15. // | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
  16. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          |
  17. // | Lesser General Public License for more details.                            |
  18. // |                                                                            |
  19. // | You should have received a copy of the GNU Lesser General Public           |
  20. // | License along with this library; if not, write to the Free Software        |
  21. // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA |
  22. // +----------------------------------------------------------------------------+
  23.  
  24. require_once('File/Ogg/Media.php');
  25.  
  26. /**
  27.  * @author      David Grant <david@grant.org.uk>, Tim Starling <tstarling@wikimedia.org>
  28.  * @category    File
  29.  * @copyright   David Grant <david@grant.org.uk>, Tim Starling <tstarling@wikimedia.org>
  30.  * @license     http://www.gnu.org/copyleft/lesser.html GNU LGPL
  31.  * @link        http://pear.php.net/package/File_Ogg
  32.  * @link        http://www.speex.org/docs.html
  33.  * @package     File_Ogg
  34.  * @version     CVS: $Id: Speex.php 302834 2010-08-27 02:16:20Z tstarling $
  35.  */
  36. {
  37.     /**
  38.      * @access  private
  39.      */
  40.     function __construct($streamSerial$streamData$filePointer)
  41.     {
  42.         parent::__construct($streamSerial$streamData$filePointer);
  43.         $this->_decodeHeader();
  44.         $this->_decodeCommentsHeader();
  45.         $endSec =
  46.             (( '0x' substr$this->_lastGranulePos0) ) pow(232
  47.             + '0x' substr$this->_lastGranulePos8) ))
  48.             / $this->_header['rate'];
  49.      
  50.          $startSec     =        
  51.             (( '0x' substr$this->_firstGranulePos0) ) pow(232
  52.             + '0x' substr$this->_firstGranulePos8) ))
  53.             / $this->_header['rate'];
  54.             
  55.          //make sure the offset is worth taking into account oggz_chop related hack
  56.         if$startSec > 1){
  57.             $this->_streamLength $endSec $startSec;
  58.             $this->_startOffset $startSec;
  59.         }else{
  60.             $this->_streamLength $endSec;
  61.         }
  62.       }
  63.  
  64.     /**
  65.      * Get a short string describing the type of the stream
  66.      * @return string 
  67.      */
  68.     function getType(
  69.     {
  70.         return 'Speex';
  71.     }
  72.  
  73.     /**
  74.      * Decode the stream header
  75.      * @access  private
  76.      */
  77.     function _decodeHeader()
  78.     {
  79.         fseek($this->_filePointer$this->_streamData['pages'][0]['body_offset']SEEK_SET);
  80.         // The first 8 characters should be "Speex   ".
  81.         if (fread($this->_filePointer8!= 'Speex   ')
  82.             throw new PEAR_Exception("Stream is undecodable due to a malformed header."OGG_ERROR_UNDECODABLE);
  83.  
  84.         $this->_version fread($this->_filePointer20);
  85.         $this->_header File_Ogg::_readLittleEndian($this->_filePointerarray(
  86.             'speex_version_id'      => 32,
  87.             'header_size'           => 32,
  88.             'rate'                  => 32,
  89.             'mode'                  => 32,
  90.             'mode_bitstream_version'=> 32,
  91.             'nb_channels'           => 32,
  92.             'bitrate'               => 32,
  93.             'frame_size'            => 32,
  94.             'vbr'                   => 32,
  95.             'frames_per_packet'     => 32,
  96.             'extra_headers'         => 32,
  97.             'reserved1'             => 32,
  98.             'reserved2'             => 32
  99.         ));
  100.         $this->_header['speex_version'$this->_version;
  101.     }
  102.  
  103.     /**
  104.      * Get an associative array containing header information about the stream
  105.      * @access  public
  106.      * @return  array 
  107.      */
  108.     function getHeader({
  109.         return $this->_header;
  110.     }
  111.  
  112.     /**
  113.      * Decode the comments header
  114.      * @access  private
  115.      */
  116.     function _decodeCommentsHeader()
  117.     {
  118.         fseek($this->_filePointer$this->_streamData['pages'][1]['body_offset']SEEK_SET);
  119.         $this->_decodeBareCommentsHeader();
  120.     }
  121. }
  122. ?>

Documentation generated on Mon, 11 Mar 2019 15:38:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.