cvs: pear /File_Ogg/File Ogg.php /File_Ogg/File/Ogg Flac.php Speex.php Theora.php Vorbis.php

From: Date: Wed, 16 Nov 2005 20:43:27 +0000
Subject: cvs: pear /File_Ogg/File Ogg.php /File_Ogg/File/Ogg Flac.php Speex.php Theora.php Vorbis.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-36331@lists.php.net to get a copy of this message
djg Wed Nov 16 15:43:27 2005 EDT Modified files: /pear/File_Ogg/File Ogg.php /pear/File_Ogg/File/Ogg Flac.php Speex.php Theora.php Vorbis.php Log: Documentation changes.

http://cvs.php.net/diff.php/pear/File_Ogg/File/Ogg.php?r1=1.12&r2=1.13&ty=u Index: pear/File_Ogg/File/Ogg.php diff -u pear/File_Ogg/File/Ogg.php:1.12 pear/File_Ogg/File/Ogg.php:1.13 --- pear/File_Ogg/File/Ogg.php:1.12 Thu Nov 10 04:20:51 2005 +++ pear/File_Ogg/File/Ogg.php Wed Nov 16 15:43:26 2005 @@ -26,7 +26,7 @@ * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL * @link http://pear.php.net/package/File_Ogg * @package File_Ogg - * @version CVS: $Id: Ogg.php,v 1.12 2005/11/10 09:20:51 djg Exp $ + * @version CVS: $Id: Ogg.php,v 1.13 2005/11/16 20:43:26 djg Exp $ */ require_once('PEAR.php'); @@ -150,6 +150,7 @@ return; } + // Open this file as a binary, and split the file into streams. $this->_filePointer = fopen($fileLocation, "rb"); if (is_resource($this->_filePointer)) $this->_splitStreams(); @@ -164,11 +165,11 @@ { // Extract the various bits and pieces found in each packet header. if (substr($pageData, 0, 4) != OGG_CAPTURE_PATTERN) - return (FALSE); + return (false); $stream_version = unpack("c1data", substr($pageData, 4, 1)); if ($stream_version['data'] != 0x00) - return (FALSE); + return (falses); $header_flag = unpack("cdata", substr($pageData, 5, 1)); $abs_granual_pos = unpack("Vdata", substr($pageData, 6, 8)); @@ -179,7 +180,7 @@ $page_segments = unpack("cdata", substr($pageData, 26, 1)); $segments_total = 0; for ($i = 0; $i < $page_segments['data']; ++$i) { - $segments = unpack("Cdata", substr($pageData, 26 + ($i + 1), 1)); + $segments = unpack("Cdata", substr($pageData, 26 + ($i + 1), 1)); $segments_total += $segments['data']; } $this->_streamList[$stream_serial['data']]['stream_page'][$page_sequence['data']]['stream_version'] = $stream_version['data']; @@ -192,7 +193,7 @@ $this->_streamList[$stream_serial['data']]['stream_page'][$page_sequence['data']]['body_finish'] = $pageFinish; $this->_streamList[$stream_serial['data']]['stream_page'][$page_sequence['data']]['data_length'] = $pageFinish - $pageOffset; - return (TRUE); + return (true); } /** @@ -201,12 +202,12 @@ function _splitStreams() { // Loop through the physical stream until there are no more pages to read. - while (TRUE) { + while (true) { $this_page_offset = ftell($this->_filePointer); $next_page_offset = $this_page_offset; // Read in 65311 bytes from the physical stream. Ogg documentation - // states that a page has a maximum size of 65304 bytes. An extra + // states that a page has a maximum size of 65307 bytes. An extra // 4 bytes are added to ensure that the capture pattern of the next // pages comes through. if (! ($stream_data = fread($this->_filePointer, OGG_MAXIMUM_PAGE_SIZE))) @@ -254,6 +255,26 @@ } /** + * Returns the overead percentage used by the Ogg headers. + * + * This function returns the percentage of the total stream size + * used for Ogg headers. + * + * @return float + */ + function getOverhead() { + $header_size = 0; + $stream_size = 0; + foreach ($this->_streamList as $stream) { + foreach ($stream['stream_page'] as $offset => $stream_data) { + $header_size += $stream_data['body_offset'] - $stream_data['head_offset']; + $stream_size = $stream_data['body_finish']; + } + } + return sprintf("%0.2f", ($header_size / $stream_size) * 100); + } + + /** * Returns the appropriate logical bitstream that corresponds to the provided serial. * * This function returns a logical bitstream contained within the Ogg physical @@ -270,16 +291,16 @@ switch ($this->_streamList[$streamSerial]['stream_type']) { case (OGG_STREAM_VORBIS): - require_once("Ogg/Vorbis.php"); + require_once("File/Ogg/Vorbis.php"); return (new File_Ogg_Vorbis($streamSerial, $this->_streamList[$streamSerial], $this->_filePointer)); case (OGG_STREAM_SPEEX): - require_once("Ogg/Speex.php"); + require_once("File/Ogg/Speex.php"); return (new File_Ogg_Speex($streamSerial, $this->_streamList[$streamSerial], $this->_filePointer)); case (OGG_STREAM_FLAC): - require_once("Ogg/Flac.php"); + require_once("File/Ogg/Flac.php"); return (new File_Ogg_Flac($streamSerial, $this->_streamList[$streamSerial], $this->_filePointer)); case (OGG_STREAM_THEORA): - require_once("Ogg/Theora.php"); + require_once("File/Ogg/Theora.php"); return (new File_Ogg_Theora($streamSerial, $this->_streamList[$streamSerial], $this->_filePointer)); default: PEAR::raiseError("This stream could not be identified.", OGG_ERROR_UNSUPPORTED); http://cvs.php.net/diff.php/pear/File_Ogg/File/Ogg/Flac.php?r1=1.8&r2=1.9&ty=u Index: pear/File_Ogg/File/Ogg/Flac.php diff -u pear/File_Ogg/File/Ogg/Flac.php:1.8 pear/File_Ogg/File/Ogg/Flac.php:1.9 --- pear/File_Ogg/File/Ogg/Flac.php:1.8 Thu Nov 10 04:20:51 2005 +++ pear/File_Ogg/File/Ogg/Flac.php Wed Nov 16 15:43:27 2005 @@ -19,7 +19,7 @@ // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | // +----------------------------------------------------------------------------+ -require_once('Bitstream.php'); +require_once('File/Ogg/Bitstream.php'); /** * @author David Grant <david@grant.org.uk> @@ -29,7 +29,7 @@ * @link http://pear.php.net/package/File_Ogg * @link http://flac.sourceforge.net/documentation.html * @package File_Ogg - * @version CVS: $Id: Flac.php,v 1.8 2005/11/10 09:20:51 djg Exp $ + * @version CVS: $Id: Flac.php,v 1.9 2005/11/16 20:43:27 djg Exp $ */ class File_Ogg_Flac extends File_Ogg_Bitstream { http://cvs.php.net/diff.php/pear/File_Ogg/File/Ogg/Speex.php?r1=1.9&r2=1.10&ty=u Index: pear/File_Ogg/File/Ogg/Speex.php diff -u pear/File_Ogg/File/Ogg/Speex.php:1.9 pear/File_Ogg/File/Ogg/Speex.php:1.10 --- pear/File_Ogg/File/Ogg/Speex.php:1.9 Thu Nov 10 04:20:51 2005 +++ pear/File_Ogg/File/Ogg/Speex.php Wed Nov 16 15:43:27 2005 @@ -19,7 +19,7 @@ // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | // +----------------------------------------------------------------------------+ -require_once('Bitstream.php'); +require_once('File/Ogg/Bitstream.php'); /** * @author David Grant <david@grant.org.uk> @@ -29,7 +29,7 @@ * @link http://pear.php.net/package/File_Ogg * @link http://www.speex.org/docs.html * @package File_Ogg - * @version CVS: $Id: Speex.php,v 1.9 2005/11/10 09:20:51 djg Exp $ + * @version CVS: $Id: Speex.php,v 1.10 2005/11/16 20:43:27 djg Exp $ */ class File_Ogg_Speex extends File_Ogg_Bitstream { http://cvs.php.net/diff.php/pear/File_Ogg/File/Ogg/Theora.php?r1=1.8&r2=1.9&ty=u Index: pear/File_Ogg/File/Ogg/Theora.php diff -u pear/File_Ogg/File/Ogg/Theora.php:1.8 pear/File_Ogg/File/Ogg/Theora.php:1.9 --- pear/File_Ogg/File/Ogg/Theora.php:1.8 Thu Nov 10 04:20:51 2005 +++ pear/File_Ogg/File/Ogg/Theora.php Wed Nov 16 15:43:27 2005 @@ -19,7 +19,7 @@ // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | // +----------------------------------------------------------------------------+ -require_once('Bitstream.php'); +require_once('File/Ogg/Bitstream.php'); /** * @author David Grant <david@grant.org.uk> @@ -29,7 +29,7 @@ * @link http://pear.php.net/package/File_Ogg * @link http://www.xiph.org/theora/ * @package File_Ogg - * @version CVS: $Id: Theora.php,v 1.8 2005/11/10 09:20:51 djg Exp $ + * @version CVS: $Id: Theora.php,v 1.9 2005/11/16 20:43:27 djg Exp $ */ class File_Ogg_Theora extends File_Ogg_Bitstream { http://cvs.php.net/diff.php/pear/File_Ogg/File/Ogg/Vorbis.php?r1=1.11&r2=1.12&ty=u Index: pear/File_Ogg/File/Ogg/Vorbis.php diff -u pear/File_Ogg/File/Ogg/Vorbis.php:1.11 pear/File_Ogg/File/Ogg/Vorbis.php:1.12 --- pear/File_Ogg/File/Ogg/Vorbis.php:1.11 Thu Nov 10 04:20:51 2005 +++ pear/File_Ogg/File/Ogg/Vorbis.php Wed Nov 16 15:43:27 2005 @@ -19,7 +19,7 @@ // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | // +----------------------------------------------------------------------------+ -require_once('Bitstream.php'); +require_once('File/Ogg/Bitstream.php'); /** * Check number for the first header in a Vorbis stream. @@ -68,7 +68,7 @@ * @link http://pear.php.net/package/File_Ogg * @link http://www.xiph.org/vorbis/doc/ * @package File_Ogg - * @version CVS: $Id: Vorbis.php,v 1.11 2005/11/10 09:20:51 djg Exp $ + * @version CVS: $Id: Vorbis.php,v 1.12 2005/11/16 20:43:27 djg Exp $ */ class File_Ogg_Vorbis extends File_Ogg_Bitstream { @@ -290,7 +290,7 @@ $this->_vendor = fread($this->_filePointer, $vendor_len['data']); // Decode the size of the comments list. $comment_list_length = unpack("Vdata", fread($this->_filePointer, 4)); - for ($i = 0; $i < $comment_list_length['data']; $i++) { + for ($i = 0; $i < $comment_list_length['data']; ++$i) { $comment_length = unpack("Vdata", fread($this->_filePointer, 4)); // Comments are in the format 'ARTIST=Super Furry Animals', so split it on the equals character. // NOTE: Equals characters are strictly prohibited in either the COMMENT or DATA parts. @@ -304,12 +304,12 @@ // multiple instances (e.g. ARTIST for a collaboration) and we should not // overwrite the previous value. if (isset($this->_comments[$comment_title])) { - if (is_array($this->_comments[$comment_title])) - $this->_comments[$comment_title][] = $comment_value; - else - $this->_comments[$comment_title] = array($this->_comments[$comment_title], $comment_value); + if (is_array($this->_comments[$comment_title])) + $this->_comments[$comment_title][] = $comment_value; + else + $this->_comments[$comment_title] = array($this->_comments[$comment_title], $comment_value); } else - $this->_comments[$comment_title] = $comment_value; + $this->_comments[$comment_title] = $comment_value; } // The framing bit MUST be set to mark the end of the comments header. @@ -346,19 +346,40 @@ * * @access public * @param string $commentTitle Comment title to search for, e.g. TITLE. + * @param string $separator String to separate multiple values. * @return string */ - function getField($commentTitle) + function getField($commentTitle, $separator = ", ") { if (isset($this->_comments[$commentTitle])) { if (is_array($this->_comments[$commentTitle])) - return (implode(", ", $this->_comments[$commentTitle])); + return (implode($separator, $this->_comments[$commentTitle])); else return ($this->_comments[$commentTitle]); } else // The comment doesn't exist in this file. The user should've called getCommentList first. return (""); } + + /** + * Set a field for this stream's meta description. + * + * @access public + * @param string $field + * @param mixed $value + * @param boolean $replace + */ + function setField($field, $value, $replace = true) + { + if ($replace || ! isset($this->_comments[$field])) { + $this->_comments[$field] = $value; + } else { + if (is_array($this->_comments[$field])) + $this->_comments[$field][] = $value; + else + $this->_comments[$field] = array($this->_comments[$field], $value); + } + } /** * Version of the Vorbis specification referred to in the encoding of this stream. @@ -379,9 +400,8 @@ * Vendor of software used to encode this stream. * * Gives the vendor string for the software used to encode this stream. - * It is common to find libVorbis here. A previous version of this package - * compared this vendor string against a release table, but this has been - * removed, as encoding software is not limited to libvorbis. + * It is common to find libVorbis here. The majority of encoders appear + * to use libvorbis from Xiph.org. * * @access public * @return string @@ -512,6 +532,18 @@ } /** + * Set the title of this track. + * + * @access public + * @param string $title + * @param boolean $replace + */ + function setTitle($title, $replace = true) + { + $this->setField("TITLE", $title, $replace); + } + + /** * The version of the track, such as a remix. * * @access public @@ -523,6 +555,18 @@ } /** + * Set the version of this track. + * + * @access public + * @param string $version + * @param boolean $replace + */ + function setVersion($version, $replace = true) + { + $this->setField("VERSION", $version, $replace); + } + + /** * The album or collection from which this track comes. * * @access public @@ -534,6 +578,18 @@ } /** + * Set the album or collection for this track. + * + * @access public + * @param string $album + * @param boolean $replace + */ + function setAlbum($album, $replace = true) + { + $this->setField("ALBUM", $album, $replace); + } + + /** * The number of this track if it is part of a larger collection. * * @access public @@ -545,6 +601,18 @@ } /** + * Set the number of this relative to the collection. + * + * @access public + * @param int $number + * @param boolean $replace + */ + function setTrackNumber($number, $replace = true) + { + $this->setField("TRACKNUMBER", $number, $replace); + } + + /** * The artist responsible for this track. * * This function returns the name of the artist responsible for this @@ -559,6 +627,18 @@ } /** + * Set the artist of this track. + * + * @access public + * @param string $artist + * @param boolean $replace + */ + function setArtist($artist, $replace = true) + { + $this->setField("ARTIST", $artist, $replace = true); + } + + /** * The performer of this track, such as an orchestra * * @access public @@ -570,6 +650,18 @@ } /** + * Set the performer of this track. + * + * @access public + * @param string $performer + * @param boolean $replace + */ + function setPerformer($performer, $replace = true) + { + $this->setField("PERFORMER", $performer, $replace); + } + + /** * The copyright attribution for this track. * * @access public @@ -581,6 +673,18 @@ } /** + * Set the copyright attribution for this track. + * + * @access public + * @param string $copyright + * @param boolean $replace + */ + function setCopyright($copyright, $replace = true) + { + $this->setField("COPYRIGHT", $copyright, $replace); + } + + /** * The rights of distribution for this track. * * This funtion returns the license for this track, and may include @@ -595,6 +699,18 @@ } /** + * Set the distribution rights for this track. + * + * @access public + * @param string $license + * @param boolean $replace + */ + function setLicense($license, $replace = true) + { + $this->setField("LICENSE", $license, $replace); + } + + /** * The organisation responsible for this track. * * This function returns the name of the organisation responsible for @@ -609,6 +725,18 @@ } /** + * Set the organisation responsible for this track. + * + * @access public + * @param string $organization + * @param boolean $replace + */ + function setOrganziation($organization, $replace = true) + { + $this->setField("ORGANIZATION", $organization, $replace); + } + + /** * A short description of the contents of this track. * * This function returns a short description of this track, which might @@ -623,6 +751,18 @@ } /** + * Set the description of this track. + * + * @access public + * @param string $description + * @param boolean $replace + */ + function setDescription($description, $replace = true) + { + $this->setField("DESCRIPTION", $replace); + } + + /** * The genre of this recording (e.g. Rock) * * This function returns the genre of this recording. There are no pre- @@ -637,6 +777,18 @@ } /** + * Set the genre of this track. + * + * @access public + * @param string $genre + * @param boolean $replace + */ + function setGenre($genre, $replace = true) + { + $this->setField("GENRE", $genre, $replace); + } + + /** * The date of the recording of this track. * * This function returns the date on which this recording was made. There @@ -651,6 +803,18 @@ } /** + * Set the date of recording for this track. + * + * @access public + * @param string $date + * @param boolean $replace + */ + function setDate($date, $replace = true) + { + $this->setField("DATE", $date, $replace); + } + + /** * Where this recording was made. * * This function returns where this recording was made, such as a recording @@ -665,6 +829,18 @@ } /** + * Set the location of the recording of this track. + * + * @access public + * @param string $location + * @param boolean $replace + */ + function setLocation($location, $replace = true) + { + $this->setField("LOCATION", $location, $replace); + } + + /** * @access public * @return string */ @@ -674,6 +850,18 @@ } /** + * Set the contact information for this track. + * + * @access public + * @param string $contact + * @param boolean $replace + */ + function setContact($contact, $replace = true) + { + $this->setField("CONTACT", $contact, $replace); + } + + /** * International Standard Recording Code. * * Returns the International Standard Recording Code. This code can be @@ -686,5 +874,17 @@ { return ($this->getField("ISRC")); } + + /** + * Set the ISRC for this track. + * + * @access public + * @param string $isrc + * @param boolean $replace + */ + function setIsrc($isrc, $replace = true) + { + $this->setField("ISRC", $isrc, $replace); + } } ?> \ No newline at end of file
« previous php.pear.cvs (#36331) next »