/src/Zend/Media/Flac/MetadataBlock/Cuesheet.php

http://php-reader.googlecode.com/ · PHP · 189 lines · 64 code · 14 blank · 111 comment · 3 complexity · f512e6c39e41afd41a2b271fcd61dd65 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 FLAC
  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: Cuesheet.php 241 2011-06-11 16:46:52Z svollbehr $
  21. */
  22. /**#@+ @ignore */
  23. require_once 'Zend/Media/Flac/MetadataBlock.php';
  24. /**#@-*/
  25. /**
  26. * This class represents the cuesheet metadata block. This block is for storing various information that can be used in
  27. * a cue sheet. It supports track and index points, compatible with Red Book CD digital audio discs, as well as other
  28. * CD-DA metadata such as media catalog number and track ISRCs. The CUESHEET block is especially useful for backing up
  29. * CD-DA discs, but it can be used as a general purpose cueing mechanism for playback.
  30. *
  31. * @category Zend
  32. * @package Zend_Media
  33. * @subpackage FLAC
  34. * @author Sven Vollbehr <sven@vollbehr.eu>
  35. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @version $Id: Cuesheet.php 241 2011-06-11 16:46:52Z svollbehr $
  38. */
  39. final class Zend_Media_Flac_MetadataBlock_Cuesheet extends Zend_Media_Flac_MetadataBlock
  40. {
  41. /** @var string */
  42. private $_catalogNumber;
  43. /** @var integer */
  44. private $_leadinSamples;
  45. /** @var boolean */
  46. private $_compactDisc;
  47. /** @var Array */
  48. private $_tracks;
  49. /**
  50. * Constructs the class with given parameters and parses object related data.
  51. *
  52. * @param Zend_Io_Reader $reader The reader object.
  53. */
  54. public function __construct($reader)
  55. {
  56. parent::__construct($reader);
  57. $this->_catalogNumber = rtrim($this->_reader->read(128), "\x00");
  58. $this->_leadinSamples = $this->_reader->readInt64BE();
  59. $this->_compactDisc = ($this->_reader->readUInt8() >> 7) & 0x1;
  60. $this->_reader->skip(258);
  61. $tracksLength = $this->_reader->readUInt8();
  62. for ($i = 0; $i < $tracksLength; $i++) {
  63. $this->_tracks[$i] = array(
  64. 'offset' => $this->_reader->readInt64BE(),
  65. 'number' => $this->_reader->readUInt8(),
  66. 'isrc' => rtrim($this->_reader->read(12), "\x00"),
  67. 'type' => (($tmp = $this->_reader->readUInt8()) >> 7 ) & 0x1,
  68. 'pre-emphasis' => (($tmp) >> 6 ) & 0x1,
  69. 'index' => array());
  70. $this->_reader->skip(13);
  71. $indexPointsLength = $this->_reader->readUInt8();
  72. for ($j = 0; $j < $indexPointsLength; $j++) {
  73. $this->_tracks[$i]['index'][$j] = array(
  74. 'offset' => $this->_reader->readInt64BE(),
  75. 'number' => $this->_reader->readUInt8()
  76. );
  77. $this->_reader->skip(3);
  78. }
  79. }
  80. }
  81. /**
  82. * Returns the media catalog number, in ASCII printable characters 0x20-0x7e. In general, the media catalog number
  83. * may be 0 to 128 bytes long; any unused characters should be right-padded with NUL characters. For CD-DA, this is
  84. * a thirteen digit number, followed by 115 NUL bytes.minimum block size (in samples) used in the stream.
  85. *
  86. * @return string
  87. */
  88. public function getCatalogNumber()
  89. {
  90. return $this->_catalogNumber;
  91. }
  92. /**
  93. * Returns the number of lead-in samples. This field has meaning only for CD-DA cuesheets; for other uses it should
  94. * be 0. For CD-DA, the lead-in is the TRACK 00 area where the table of contents is stored; more precisely, it is
  95. * the number of samples from the first sample of the media to the first sample of the first index point of the
  96. * first track. According to the Red Book, the lead-in must be silence and CD grabbing software does not usually
  97. * store it; additionally, the lead-in must be at least two seconds but may be longer. For these reasons the
  98. * lead-in length is stored here so that the absolute position of the first track can be computed. Note that the
  99. * lead-in stored here is the number of samples up to the first index point of the first track, not necessarily to
  100. * INDEX 01 of the first track; even the first track may have INDEX 00 data.
  101. *
  102. * @return integer
  103. */
  104. public function getLeadinSamples()
  105. {
  106. return $this->_leadinSamples;
  107. }
  108. /**
  109. * Returns the minimum frame size (in bytes) used in the stream. May be 0 to imply the value is not known.
  110. *
  111. * @return integer
  112. */
  113. public function getMinimumFrameSize()
  114. {
  115. return $this->_minimumFrameSize;
  116. }
  117. /**
  118. * Returns the maximum frame size (in bytes) used in the stream. May be 0 to imply the value is not known.
  119. *
  120. * @return integer
  121. */
  122. public function getMaximumFrameSize()
  123. {
  124. return $this->_maximumFrameSize;
  125. }
  126. /**
  127. * Returns sample rate in Hz. The maximum sample rate is limited by the structure of frame headers to 655350Hz.
  128. * Also, a value of 0 is invalid.
  129. *
  130. * @return integer
  131. */
  132. public function getSampleRate()
  133. {
  134. return $this->_sampleRate;
  135. }
  136. /**
  137. * Returns whether the CUESHEET corresponds to a Compact Disc or not.
  138. *
  139. * @return boolean
  140. */
  141. public function getCompactDisk()
  142. {
  143. return $this->_compactDisk == 1;
  144. }
  145. /**
  146. * Returns an array of values. Each entry is an array containing the following keys.
  147. * o offset -- Track offset in samples, relative to the beginning of the FLAC audio stream. It is the offset to
  148. * the first index point of the track. (Note how this differs from CD-DA, where the track's offset in the TOC
  149. * is that of the track's INDEX 01 even if there is an INDEX 00.) For CD-DA, the offset must be evenly divisible
  150. * by 588 samples (588 samples = 44100 samples/sec * 1/75th of a sec).
  151. * o number -- Track number. A track number of 0 is not allowed to avoid conflicting with the CD-DA spec, which
  152. * reserves this for the lead-in. For CD-DA the number must be 1-99, or 170 for the lead-out; for non-CD-DA,
  153. * the track number must for 255 for the lead-out. It is not required but encouraged to start with track 1 and
  154. * increase sequentially. Track numbers must be unique within a CUESHEET.
  155. * o isrc -- Track ISRC. This is a 12-digit alphanumeric code or an empty string to denote absence of an ISRC.
  156. * o type -- The track type: 0 for audio, 1 for non-audio. This corresponds to the CD-DA Q-channel control bit 3.
  157. * o pre-emphasis -- The pre-emphasis flag: 0 for no pre-emphasis, 1 for pre-emphasis. This corresponds to the
  158. * CD-DA Q-channel control bit 5.
  159. * o index -- An array of track index points. There must be at least one index in every track in a CUESHEET except
  160. * for the lead-out track, which must have zero. For CD-DA, this number may be no more than 100. Each entry is
  161. * an array containing the following keys.
  162. * o offset -- Offset in samples, relative to the track offset, of the index point. For CD-DA, the offset must
  163. * be evenly divisible by 588 samples (588 samples = 44100 samples/sec * 1/75th of a sec). Note that the
  164. * offset is from the beginning of the track, not the beginning of the audio data.
  165. * o number -- The index point number. For CD-DA, an index number of 0 corresponds to the track pre-gap. The
  166. * first index in a track must have a number of 0 or 1, and subsequently, index numbers must increase by 1.
  167. * Index numbers must be unique within a track.
  168. *
  169. * @return Array
  170. */
  171. public function getTracks()
  172. {
  173. return $this->_tracks;
  174. }
  175. }