PageRenderTime 42ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/Vendor/phpvideotoolkit/adapters/ffmpeg-php/php-reader/src/ID3/Frame/RVAD.php

https://github.com/Wargo/reddevil
PHP | 208 lines | 106 code | 18 blank | 84 comment | 19 complexity | 970212e6a1cb01fc6b41cadb9532e26c MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * PHP Reader Library
  4. *
  5. * Copyright (c) 2008 The PHP Reader Project Workgroup. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * - Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * - Neither the name of the project workgroup nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * @package php-reader
  32. * @subpackage ID3
  33. * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
  34. * @license http://code.google.com/p/php-reader/wiki/License New BSD License
  35. * @version $Id: RVAD.php 75 2008-04-14 23:57:21Z svollbehr $
  36. * @deprecated ID3v2.3.0
  37. */
  38. /**#@+ @ignore */
  39. require_once("ID3/Frame.php");
  40. /**#@-*/
  41. /**
  42. * The <i>Relative volume adjustment</i> frame is a more subjective function
  43. * than the previous ones. It allows the user to say how much he wants to
  44. * increase/decrease the volume on each channel while the file is played. The
  45. * purpose is to be able to align all files to a reference volume, so that you
  46. * don't have to change the volume constantly. This frame may also be used to
  47. * balance adjust the audio.
  48. *
  49. * There may only be one RVAD frame in each tag.
  50. *
  51. * @package php-reader
  52. * @subpackage ID3
  53. * @author Sven Vollbehr <svollbehr@gmail.com>
  54. * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
  55. * @license http://code.google.com/p/php-reader/wiki/License New BSD License
  56. * @version $Rev: 75 $
  57. * @deprecated ID3v2.3.0
  58. */
  59. final class ID3_Frame_RVAD extends ID3_Frame
  60. {
  61. /** @var Array */
  62. private $_adjustments;
  63. /**
  64. * Constructs the class with given parameters and parses object related data.
  65. *
  66. * @param Reader $reader The reader object.
  67. * @param Array $options The options array.
  68. */
  69. public function __construct($reader = null, &$options = array())
  70. {
  71. parent::__construct($reader, $options);
  72. if ($reader === null)
  73. return;
  74. $flags = Transform::fromInt8($this->_data[0]);
  75. $descriptionBits = Transform::fromInt8($this->_data[0]); //16
  76. $this->_adjustments["right"] =
  77. ($flags & 0x20) == 0x20 ?
  78. Transform::fromUInt16BE(substr($this->_data, 0, 2)) :
  79. -Transform::fromUInt16BE(substr($this->_data, 0, 2));
  80. $this->_adjustments["left"] =
  81. ($flags & 0x10) == 0x10 ?
  82. Transform::fromUInt16BE(substr($this->_data, 2, 2)) :
  83. -Transform::fromUInt16BE(substr($this->_data, 2, 2));
  84. $this->_adjustments["peakRight"] =
  85. Transform::fromUInt16BE(substr($this->_data, 4, 2));
  86. $this->_adjustments["peakLeft"] =
  87. Transform::fromUInt16BE(substr($this->_data, 6, 2));
  88. if ($this->getSize() <= 8)
  89. return;
  90. $this->_adjustments["rightBack"] =
  91. ($flags & 0x8) == 0x8 ?
  92. Transform::fromUInt16BE(substr($this->_data, 8, 2)) :
  93. -Transform::fromUInt16BE(substr($this->_data, 8, 2));
  94. $this->_adjustments["leftBack"] =
  95. ($flags & 0x4) == 0x4 ?
  96. Transform::fromUInt16BE(substr($this->_data, 10, 2)) :
  97. -Transform::fromUInt16BE(substr($this->_data, 10, 2));
  98. $this->_adjustments["peakRightBack"] =
  99. Transform::fromUInt16BE(substr($this->_data, 12, 2));
  100. $this->_adjustments["peakLeftBack"] =
  101. Transform::fromUInt16BE(substr($this->_data, 14, 2));
  102. if ($this->getSize() <= 16)
  103. return;
  104. $this->_adjustments["center"] =
  105. ($flags & 0x2) == 0x2 ?
  106. Transform::fromUInt16BE(substr($this->_data, 16, 2)) :
  107. -Transform::fromUInt16BE(substr($this->_data, 16, 2));
  108. $this->_adjustments["peakCenter"] =
  109. Transform::fromUInt16BE(substr($this->_data, 18, 2));
  110. if ($this->getSize() <= 20)
  111. return;
  112. $this->_adjustments["bass"] =
  113. ($flags & 0x1) == 0x1 ?
  114. Transform::fromUInt16BE(substr($this->_data, 20, 2)) :
  115. -Transform::fromUInt16BE(substr($this->_data, 20, 2));
  116. $this->_adjustments["peakBass"] =
  117. Transform::fromUInt16BE(substr($this->_data, 22, 2));
  118. }
  119. /**
  120. * Returns the array containing the volume adjustments. The array must contain
  121. * the following keys: right, left, peakRight, peakLeft. It may optionally
  122. * contain the following keys: rightBack, leftBack, peakRightBack,
  123. * peakLeftBack, center, peakCenter, bass, and peakBass.
  124. *
  125. * @return Array
  126. */
  127. public function getAdjustments() { return $this->_adjustments; }
  128. /**
  129. * Sets the array of volume adjustments. The array must contain the following
  130. * keys: right, left, peakRight, peakLeft. It may optionally contain the
  131. * following keys: rightBack, leftBack, peakRightBack, peakLeftBack, center,
  132. * peakCenter, bass, and peakBass.
  133. *
  134. * @param Array $adjustments The volume adjustments array.
  135. */
  136. public function setAdjustments($adjustments)
  137. {
  138. $this->_adjustments = $adjustments;
  139. }
  140. /**
  141. * Returns the frame raw data.
  142. *
  143. * @return string
  144. */
  145. public function __toString()
  146. {
  147. $flags = 0;
  148. if ($this->_adjustments["right"] > 0)
  149. $flags = $flags | 0x20;
  150. if ($this->_adjustments["left"] > 0)
  151. $flags = $flags | 0x10;
  152. $data = Transform::toInt8(16) .
  153. Transform::toUInt16BE(abs($this->_adjustments["right"])) .
  154. Transform::toUInt16BE(abs($this->_adjustments["left"])) .
  155. Transform::toUInt16BE(abs($this->_adjustments["peakRight"])) .
  156. Transform::toUInt16BE(abs($this->_adjustments["peakLeft"]));
  157. if (isset($this->_adjustments["rightBack"]) &&
  158. isset($this->_adjustments["leftBack"]) &&
  159. isset($this->_adjustments["peakRightBack"]) &&
  160. isset($this->_adjustments["peakLeftBack"])) {
  161. if ($this->_adjustments["rightBack"] > 0)
  162. $flags = $flags | 0x8;
  163. if ($this->_adjustments["leftBack"] > 0)
  164. $flags = $flags | 0x4;
  165. $data .=
  166. Transform::toUInt16BE(abs($this->_adjustments["rightBack"])) .
  167. Transform::toUInt16BE(abs($this->_adjustments["leftBack"])) .
  168. Transform::toUInt16BE(abs($this->_adjustments["peakRightBack"])) .
  169. Transform::toUInt16BE(abs($this->_adjustments["peakLeftBack"]));
  170. }
  171. if (isset($this->_adjustments["center"]) &&
  172. isset($this->_adjustments["peakCenter"])) {
  173. if ($this->_adjustments["center"] > 0)
  174. $flags = $flags | 0x2;
  175. $data .=
  176. Transform::toUInt16BE(abs($this->_adjustments["center"])) .
  177. Transform::toUInt16BE(abs($this->_adjustments["peakCenter"]));
  178. }
  179. if (isset($this->_adjustments["bass"]) &&
  180. isset($this->_adjustments["peakBass"])) {
  181. if ($this->_adjustments["bass"] > 0)
  182. $flags = $flags | 0x1;
  183. $data .=
  184. Transform::toUInt16BE(abs($this->_adjustments["bass"])) .
  185. Transform::toUInt16BE(abs($this->_adjustments["peakBass"]));
  186. }
  187. $this->setData(Transform::toInt8($flags) . $data);
  188. return parent::__toString();
  189. }
  190. }