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