logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Ogg::Vorbis::Decoder - An object-oriented Ogg Vorbis to decoder

Author Emeritus

       Dan Pemstein <dan@lcws.org>

Constructor

"open($filename)"
       Opens an Ogg Vorbis file for decoding. It opens a handle to the file or uses an existing handle and
       initializes all of the internal vorbis decoding structures.  Note that the object will maintain open file
       descriptors until the object is collected by the garbage handler. Returns "undef" on failure.

Current Author

       Dan Sully <daniel@cpan.org>

Description

       This module provides users with Decoder objects for Ogg Vorbis files.  One can read data in PCM format
       from the stream, seek by raw bytes, pcm samples, or time, and gather decoding-specific information not
       provided by Ogg::Vorbis::Header.  Currently, we provide no support for the callback mechanism provided by
       the Vorbisfile API; this may be included in future releases.

Instance Methods

"read($buffer,[$size,$word,$signed])"
       Reads PCM data from the Vorbis stream into $buffer.  Returns the number of bytes read, 0 when it reaches
       the end of the stream, or a value less than 0 on error.

       The optional parameters include (with corresponding default values):

       "size = 4096" "word = 2" "signed = 1"

       Consult the Vorbisfile API (http://www.xiph.org/ogg/vorbis/doc/vorbisfile/reference.html) for an
       explanation of the various values.

   "sysread($buffer,[$size,$word,$signed])"
       An alias for "read"

   "raw_seek($pos)"
       Seeks through the compressed bitstream to the offset specified by $pos in raw bytes.  Returns 0 on
       success.

   "pcm_seek($pos,[$page])"
       Seeks through the bitstream to the offset specified by $pos in pcm samples.  The optional $page parameter
       is a boolean flag that, if set to true, will cause the method to seek to the closest full page preceding
       the specified location.  Returns 0 on success.

   "time_seek($pos,[$page])"
       Seeks through the bitstream to the offset specified by $pos in seconds.  The optional $page parameter is
       a boolean flag that, if set to true, will cause the method to seek to the closest full page preceding the
       specified location.  Returns 0 on success.

   "current_bitstream()"
       Returns the current logical bitstream of the decoder.  This matches the bitstream paramer optionally
       passed to "read".  Useful for saving a bitstream to jump to later or to pass to various information
       methods.

   "bitrate([$stream])"
       Returns the average bitrate for the specified logical bitstream.  If $stream is left out or set to -1,
       the average bitrate for the entire stream will be reported.

   "bitrate_instant()"
       Returns the most recent bitrate read from the file.  Returns 0 if no read has been performed or bitrate
       has not changed.

   "streams()"
       Returns the number of logical bitstreams in the file.

   "seekable()"
       Returns non-zero value if file is seekable, 0 if not.

   "serialnumber([$stream])"
       Returns the serial number of the specified logical bitstream, or that of the current bitstream if $stream
       is left out or set to -1.

   "raw_total([$stream])"
       Returns the total number of bytes in the physical bitstream or the specified logical bitstream.

   "pcm_total([$stream])"
       Returns the total number of pcm samples in the physical bitstream or the specified logical bitstream.

   "time_total([$stream])"
       Returns the total number of seconds in the physical bitstream or the specified logical bitstream.

   "raw_tell()"
       Returns the current offset in bytes.

   "pcm_tell()"
       Returns the current offset in pcm samples.

   "time_tell()"
       Returns the current offset in seconds.

Name

       Ogg::Vorbis::Decoder - An object-oriented Ogg Vorbis to decoder

Requires

       libogg, libvorbis, libogg-dev, libvorbis-dev

See Also

       Ogg::Vorbis::Header

perl v5.40.0                                       2024-10-20                                       Decoder(3pm)

Synopsis

         use Ogg::Vorbis::Decoder;
         my $decoder = Ogg::Vorbis::Decoder->open("song.ogg");
         my $buffer;
         while ((my $len = $decoder->read($buffer) > 0) {
           # do something with the PCM stream
         }

         OR

         open OGG, "song.ogg" or die $!;
         my $decoder = Ogg::Vorbis::Decoder->open(\*OGG);

         OR

         # can also be IO::Socket or any other IO::Handle subclass.
         my $fh = IO::Handle->new("song.ogg");
         my $decoder = Ogg::Vorbis::Decoder->open($fh);

See Also