/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. /**#@+ @ignore */
  23. require_once 'Zend/Media/Vorbis/Header.php';
  24. /**#@-*/
  25. /**
  26. * The identication header is a short header of only a few fields used to declare the stream definitively as Vorbis,
  27. * and provide a few externally relevant pieces of information about the audio stream.
  28. *
  29. * @category Zend
  30. * @package Zend_Media
  31. * @subpackage Vorbis
  32. * @author Sven Vollbehr <sven@vollbehr.eu>
  33. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @version $Id: Identification.php 233 2011-05-14 16:00:55Z svollbehr $
  36. */
  37. final class Zend_Media_Vorbis_Header_Identification extends Zend_Media_Vorbis_Header
  38. {
  39. /** @var integer */
  40. private $_vorbisVersion;
  41. /** @var integer */
  42. private $_audioChannels;
  43. /** @var integer */
  44. private $_audioSampleRate;
  45. /** @var integer */
  46. private $_bitrateMaximum;
  47. /** @var integer */
  48. private $_bitrateNominal;
  49. /** @var integer */
  50. private $_bitrateMinimum;
  51. /** @var integer */
  52. private $_blocksize0;
  53. /** @var integer */
  54. private $_blocksize1;
  55. /**
  56. * Constructs the class with given parameters.
  57. *
  58. * @param Zend_Io_Reader $reader The reader object.
  59. */
  60. public function __construct($reader)
  61. {
  62. parent::__construct($reader);
  63. $this->_vorbisVersion = $this->_reader->readUInt32LE();
  64. $this->_audioChannels = $this->_reader->readUInt8();
  65. $this->_audioSampleRate = $this->_reader->readUInt32LE();
  66. $this->_bitrateMaximum = $this->_reader->readInt32LE();
  67. $this->_bitrateNominal = $this->_reader->readInt32LE();
  68. $this->_bitrateMinimum = $this->_reader->readInt32LE();
  69. $this->_blocksize0 = pow(2, ($tmp = $this->_reader->readUInt8()) & 0xf);
  70. $this->_blocksize1 = pow(2, ($tmp >> 4) & 0xf);
  71. $framingFlag = $this->_reader->readUInt8() & 0x1;
  72. if ($this->_blocksize0 > $this->_blocksize1 || $framingFlag == 0) {
  73. require_once 'Zend/Media/Vorbis/Exception.php';
  74. throw new Zend_Media_Vorbis_Exception('Undecodable Vorbis stream');
  75. }
  76. }
  77. /**
  78. * Returns the vorbis version.
  79. *
  80. * @return integer
  81. */
  82. public function getVorbisVersion()
  83. {
  84. return $this->_vorbisVersion;
  85. }
  86. /**
  87. * Returns the number of audio channels.
  88. *
  89. * @return integer
  90. */
  91. public function getAudioChannels()
  92. {
  93. return $this->_audioChannels;
  94. }
  95. /**
  96. * Returns the audio sample rate.
  97. *
  98. * @return integer
  99. */
  100. public function getAudioSampleRate()
  101. {
  102. return $this->_audioSampleRate;
  103. }
  104. /**
  105. * Returns the maximum bitrate.
  106. *
  107. * @return integer
  108. */
  109. public function getBitrateMaximum()
  110. {
  111. return $this->_bitrateMaximum;
  112. }
  113. /**
  114. * Returns the nominal bitrate.
  115. *
  116. * @return integer
  117. */
  118. public function getBitrateNominal()
  119. {
  120. return $this->_bitrateNominal;
  121. }
  122. /**
  123. * Returns the minimum bitrate.
  124. *
  125. * @return integer
  126. */
  127. public function getBitrateMinimum()
  128. {
  129. return $this->_bitrateMinimum;
  130. }
  131. /**
  132. * Returns the first block size. Allowed final blocksize values are 64, 128, 256, 512, 1024, 2048, 4096 and 8192 in
  133. * Vorbis I.
  134. *
  135. * @return integer
  136. */
  137. public function getBlocksize1()
  138. {
  139. return $this->_blocksize1;
  140. }
  141. /**
  142. * Returns the second block size. Allowed final blocksize values are 64, 128, 256, 512, 1024, 2048, 4096 and 8192 in
  143. * Vorbis I.
  144. *
  145. * @return integer
  146. */
  147. public function getBlocksize2()
  148. {
  149. return $this->_blocksize2;
  150. }
  151. }