PageRenderTime 22ms CodeModel.GetById 18ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Zend/Media/Id3/Frame/Equa.php

http://php-reader.googlecode.com/
PHP | 133 lines | 50 code | 10 blank | 73 comment | 5 complexity | 7cde2ee514024f9f3da72d0cf86f7bdc 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 ID3
 18 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) 
 19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 20 * @version    $Id: Equa.php 177 2010-03-09 13:13:34Z svollbehr $
 21 * @deprecated ID3v2.3.0
 22 */
 23
 24/**#@+ @ignore */
 25require_once 'Zend/Media/Id3/Frame.php';
 26/**#@-*/
 27
 28/**
 29 * The <i>Equalisation</i> frame is another subjective, alignment frame. It
 30 * allows the user to predefine an equalisation curve within the audio file.
 31 * There may only be one EQUA frame in each tag.
 32 *
 33 * @category   Zend
 34 * @package    Zend_Media
 35 * @subpackage ID3
 36 * @author     Sven Vollbehr <sven@vollbehr.eu>
 37 * @author     Ryan Butterfield <buttza@gmail.com>
 38 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) 
 39 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 40 * @version    $Id: Equa.php 177 2010-03-09 13:13:34Z svollbehr $
 41 * @deprecated ID3v2.3.0
 42 */
 43final class Zend_Media_Id3_Frame_Equa extends Zend_Media_Id3_Frame
 44{
 45    /** @var Array */
 46    private $_adjustments;
 47
 48    /**
 49     * Constructs the class with given parameters and parses object related
 50     * data.
 51     *
 52     * @param Zend_Io_Reader $reader The reader object.
 53     * @param Array $options The options array.
 54     */
 55    public function __construct($reader = null, &$options = array())
 56    {
 57        parent::__construct($reader, $options);
 58
 59        if ($this->_reader === null) {
 60            return;
 61        }
 62
 63        $adjustmentBits = $this->_reader->readInt8();
 64        if ($adjustmentBits <= 8 || $adjustmentBits > 16) {
 65            require_once 'Zend/Media/Id3/Exception.php';
 66            throw new Zend_Media_Id3_Exception
 67                ('Unsupported adjustment bit size of: ' . $adjustmentBits);
 68        }
 69
 70        while ($this->_reader->available()) {
 71            $frequency = $this->_reader->readUInt16BE();
 72            $this->_adjustments[($frequency & 0x7fff)] =
 73                ($frequency & 0x8000) == 0x8000 ?
 74                $this->_reader->readUInt16BE() :
 75                -$this->_reader->readUInt16BE();
 76        }
 77        ksort($this->_adjustments);
 78    }
 79
 80    /**
 81     * Returns the array containing adjustments having frequencies as keys and
 82     * their corresponding adjustments as values.
 83     *
 84     * @return Array
 85     */
 86    public function getAdjustments() 
 87    {
 88         return $this->_adjustments; 
 89    }
 90
 91    /**
 92     * Adds a volume adjustment setting for given frequency. The frequency can
 93     * have a value from 0 to 32767 Hz.
 94     *
 95     * @param integer $frequency The frequency, in hertz.
 96     * @param integer $adjustment The adjustment, in dB.
 97     */
 98    public function addAdjustment($frequency, $adjustment)
 99    {
100        $this->_adjustments[$frequency] = $adjustment;
101        ksort($this->_adjustments);
102    }
103
104    /**
105     * Sets the adjustments array. The array must have frequencies as keys and
106     * their corresponding adjustments as values. The frequency can have a value
107     * from 0 to 32767 Hz. One frequency should only be described once in the
108     * frame.
109     *
110     * @param Array $adjustments The adjustments array.
111     */
112    public function setAdjustments($adjustments)
113    {
114        $this->_adjustments = $adjustments;
115        ksort($this->_adjustments);
116    }
117
118    /**
119     * Writes the frame raw data without the header.
120     *
121     * @param Zend_Io_Writer $writer The writer object.
122     * @return void
123     */
124    protected function _writeData($writer)
125    {
126        $writer->writeInt8(16);
127        foreach ($this->_adjustments as $frequency => $adjustment) {
128            $writer->writeUInt16BE
129                ($adjustment > 0 ? $frequency | 0x8000 : $frequency & ~0x8000)
130                   ->writeUInt16BE(abs($adjustment));
131        }
132    }
133}