PageRenderTime 52ms CodeModel.GetById 43ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Zend/Media/Vorbis/Header/Identification.php

http://php-reader.googlecode.com/
PHP | 170 lines | 62 code | 19 blank | 89 comment | 3 complexity | b761fc2609daa8df298302cee0e6c7c9 MD5 | raw file
  1<?php
  2/**
  3 * Zend Framework
  4 *
  5 * LICENSE
  6 *
  7 * This source file is subject to the new BSD license that is bundled
  8 * with this package in the file LICENSE.txt.
  9 * It is also available through the world-wide-web at this URL:
 10 * http://framework.zend.com/license/new-bsd
 11 * If you did not receive a copy of the license and are unable to
 12 * obtain it through the world-wide-web, please send an email
 13 * to license@zend.com so we can send you a copy immediately.
 14 *
 15 * @category   Zend
 16 * @package    Zend_Media
 17 * @subpackage Vorbis
 18 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 20 * @version    $Id: Identification.php 233 2011-05-14 16:00:55Z svollbehr $
 21 */
 22
 23/**#@+ @ignore */
 24require_once 'Zend/Media/Vorbis/Header.php';
 25/**#@-*/
 26
 27/**
 28 * The identication header is a short header of only a few fields used to declare the stream definitively as Vorbis,
 29 * and provide a few externally relevant pieces of information about the audio stream.
 30 *
 31 * @category   Zend
 32 * @package    Zend_Media
 33 * @subpackage Vorbis
 34 * @author     Sven Vollbehr <sven@vollbehr.eu>
 35 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 36 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 37 * @version    $Id: Identification.php 233 2011-05-14 16:00:55Z svollbehr $
 38 */
 39final class Zend_Media_Vorbis_Header_Identification extends Zend_Media_Vorbis_Header
 40{
 41    /** @var integer */
 42    private $_vorbisVersion;
 43
 44    /** @var integer */
 45    private $_audioChannels;
 46
 47    /** @var integer */
 48    private $_audioSampleRate;
 49
 50    /** @var integer */
 51    private $_bitrateMaximum;
 52
 53    /** @var integer */
 54    private $_bitrateNominal;
 55
 56    /** @var integer */
 57    private $_bitrateMinimum;
 58
 59    /** @var integer */
 60    private $_blocksize0;
 61
 62    /** @var integer */
 63    private $_blocksize1;
 64
 65    /**
 66     * Constructs the class with given parameters.
 67     *
 68     * @param Zend_Io_Reader $reader The reader object.
 69     */
 70    public function __construct($reader)
 71    {
 72        parent::__construct($reader);
 73
 74        $this->_vorbisVersion = $this->_reader->readUInt32LE();
 75        $this->_audioChannels = $this->_reader->readUInt8();
 76        $this->_audioSampleRate = $this->_reader->readUInt32LE();
 77        $this->_bitrateMaximum = $this->_reader->readInt32LE();
 78        $this->_bitrateNominal = $this->_reader->readInt32LE();
 79        $this->_bitrateMinimum = $this->_reader->readInt32LE();
 80        $this->_blocksize0 = pow(2, ($tmp = $this->_reader->readUInt8()) & 0xf);
 81        $this->_blocksize1 = pow(2, ($tmp >> 4) & 0xf);
 82        $framingFlag = $this->_reader->readUInt8() & 0x1;
 83        if ($this->_blocksize0 > $this->_blocksize1 || $framingFlag == 0) {
 84            require_once 'Zend/Media/Vorbis/Exception.php';
 85            throw new Zend_Media_Vorbis_Exception('Undecodable Vorbis stream');
 86        }
 87    }
 88
 89    /**
 90     * Returns the vorbis version.
 91     *
 92     * @return integer
 93     */
 94    public function getVorbisVersion()
 95    {
 96        return $this->_vorbisVersion;
 97    }
 98
 99    /**
100     * Returns the number of audio channels.
101     *
102     * @return integer
103     */
104    public function getAudioChannels()
105    {
106        return $this->_audioChannels;
107    }
108
109    /**
110     * Returns the audio sample rate.
111     *
112     * @return integer
113     */
114    public function getAudioSampleRate()
115    {
116        return $this->_audioSampleRate;
117    }
118
119    /**
120     * Returns the maximum bitrate.
121     *
122     * @return integer
123     */
124    public function getBitrateMaximum()
125    {
126        return $this->_bitrateMaximum;
127    }
128
129    /**
130     * Returns the nominal bitrate.
131     *
132     * @return integer
133     */
134    public function getBitrateNominal()
135    {
136        return $this->_bitrateNominal;
137    }
138
139    /**
140     * Returns the minimum bitrate.
141     *
142     * @return integer
143     */
144    public function getBitrateMinimum()
145    {
146        return $this->_bitrateMinimum;
147    }
148
149    /**
150     * Returns the first block size. Allowed final blocksize values are 64, 128, 256, 512, 1024, 2048, 4096 and 8192 in
151     * Vorbis I.
152     *
153     * @return integer
154     */
155    public function getBlocksize1()
156    {
157        return $this->_blocksize1;
158    }
159
160    /**
161     * Returns the second block size. Allowed final blocksize values are 64, 128, 256, 512, 1024, 2048, 4096 and 8192 in
162     * Vorbis I.
163     *
164     * @return integer
165     */
166    public function getBlocksize2()
167    {
168        return $this->_blocksize2;
169    }
170}