/src/Zend/Media/Vorbis.php

https://github.com/e-butik/php-reader · PHP · 141 lines · 53 code · 12 blank · 76 comment · 4 complexity · e2147ae91bef810f91ba30558e81fc91 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$
  21. */
  22. /**#@+ @ignore */
  23. require_once 'Zend/Io/Reader.php';
  24. require_once 'Zend/Media/Vorbis/Header/Identification.php';
  25. require_once 'Zend/Media/Vorbis/Header/Comment.php';
  26. require_once 'Zend/Media/Vorbis/Header/Setup.php';
  27. /**#@-*/
  28. /**
  29. * This class represents a file containing Vorbis bitstream as described in
  30. * {@link http://xiph.org/vorbis/doc/Vorbis_I_spec.pdf Vorbis I specification}.
  31. *
  32. * Vorbis is a general purpose perceptual audio CODEC intended to allow maximum encoder exibility, thus allowing it to
  33. * scale competitively over an exceptionally wide range of bitrates. At the high quality/bitrate end of the scale (CD
  34. * or DAT rate stereo, 16/24 bits) it is in the same league as MPEG-2 and MPC. Similarly, the 1.0 encoder can encode
  35. * high-quality CD and DAT rate stereo at below 48kbps without resampling to a lower rate. Vorbis is also intended for
  36. * lower and higher sample rates (from 8kHz telephony to 192kHz digital masters) and a range of channel representations
  37. * (monaural, polyphonic, stereo, quadraphonic, 5.1, ambisonic, or up to 255 discrete channels).
  38. *
  39. * @category Zend
  40. * @package Zend_Media
  41. * @subpackage Vorbis
  42. * @author Sven Vollbehr <sven@vollbehr.eu>
  43. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  44. * @license http://framework.zend.com/license/new-bsd New BSD License
  45. * @version $Id$
  46. * @todo Setup header is not yet supported
  47. */
  48. final class Zend_Media_Vorbis
  49. {
  50. /** @var Zend_Io_Reader */
  51. private $_reader;
  52. /** @var string */
  53. private $_filename = null;
  54. /** @var Zend_Media_Vorbis_Header_Identification */
  55. private $_identificationHeader;
  56. /** @var Zend_Media_Vorbis_Header_Comment */
  57. private $_commentHeader;
  58. /** @var Zend_Media_Vorbis_Header_Setup */
  59. private $_setupHeader;
  60. /**
  61. * Constructs the Zend_Media_Vorbis class with given file.
  62. *
  63. * @param string|resource|Zend_Io_Reader $filename The path to the file,
  64. * file descriptor of an opened file, or a {@link Zend_Io_Reader} instance.
  65. * @throws Zend_Io_Exception if an error occur in stream handling.
  66. * @throws Zend_Media_Vorbis_Exception if an error occurs in vorbis bitstream reading.
  67. */
  68. public function __construct($filename)
  69. {
  70. if ($filename instanceof Zend_Io_Reader) {
  71. $this->_reader = &$filename;
  72. } else {
  73. $this->_filename = $filename;
  74. require_once('Zend/Io/FileReader.php');
  75. try {
  76. $this->_reader = new Zend_Io_FileReader($filename);
  77. } catch (Zend_Io_Exception $e) {
  78. $this->_reader = null;
  79. require_once 'Zend/Media/Vorbis/Exception.php';
  80. throw new Zend_Media_Vorbis_Exception($e->getMessage());
  81. }
  82. }
  83. $this->_identificationHeader = new Zend_Media_Vorbis_Header_Identification($this->_reader);
  84. $this->_commentHeader = new Zend_Media_Vorbis_Header_Comment($this->_reader);
  85. $this->_setupHeader = new Zend_Media_Vorbis_Header_Setup($this->_reader);
  86. }
  87. /**
  88. * Returns the identification header.
  89. *
  90. * @return Zend_Media_Vorbis_Header_Identification
  91. */
  92. public function getIdentificationHeader()
  93. {
  94. return $this->_identificationHeader;
  95. }
  96. /**
  97. * Returns the comment header.
  98. *
  99. * @return Zend_Media_Vorbis_Header_Comment
  100. */
  101. public function getCommentHeader()
  102. {
  103. return $this->_commentHeader;
  104. }
  105. /**
  106. * Returns the setup header.
  107. *
  108. * @return Zend_Media_Vorbis_Header_Setup
  109. */
  110. public function getSetupHeader()
  111. {
  112. return $this->_setupHeader;
  113. }
  114. /**
  115. * Magic function so that $obj->value will work.
  116. *
  117. * @param string $name The field name.
  118. * @return mixed
  119. */
  120. public function __get($name)
  121. {
  122. if (method_exists($this, 'get' . ucfirst($name))) {
  123. return call_user_func(array($this, 'get' . ucfirst($name)));
  124. } else {
  125. require_once('Zend/Media/Vorbis/Exception.php');
  126. throw new Zend_Media_Vorbis_Exception('Unknown field: ' . $name);
  127. }
  128. }
  129. }