PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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