1 package Audio
::Opusfile
; 
   8 use parent qw
/Exporter/; 
  12   qw
/OPUS_CHANNEL_COUNT_MAX
 
  31          OP_GET_SERVER_INFO_REQUEST
 
  34          OP_HTTP_PROXY_HOST_REQUEST
 
  35          OP_HTTP_PROXY_PASS_REQUEST
 
  36          OP_HTTP_PROXY_PORT_REQUEST
 
  37          OP_HTTP_PROXY_USER_REQUEST
 
  43          OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST
 
  46 our @EXPORT_OK = @constants; 
  47 our @EXPORT = @constants; 
  49 our $VERSION = '1.000'; 
  51 sub AUTOLOAD 
{ ## no critic (ProhibitAutoloading) 
  54         ($constname = $AUTOLOAD) =~ s/.*:://s; 
  55         croak 
'&Audio::Opusfile::constant not defined' if $constname eq 'constant'; 
  56         my ($error, $val) = constant($constname); 
  57         if ($error) { croak 
$error; } 
  59                 no strict 
'refs'; ## no critic (ProhibitNoStrict) 
  60                 *$AUTOLOAD = sub { $val }; 
  66 XSLoader
::load
('Audio::Opusfile', $VERSION); 
  67 require Audio
::Opusfile
::Head
; 
  68 require Audio
::Opusfile
::Tags
; 
  69 require Audio
::Opusfile
::PictureTag
; 
  72         my ($class, $file) = @_; 
  77         my ($class, $buf) = @_; 
  88 Audio::Opusfile - partial interface to the libopusfile Ogg Opus library 
  93   my $of = Audio::Opusfile->new_from_file('silence.opus'); 
  95   say $tags->query('TITLE'); # Cellule 
  99 Opus is a totally open, royalty-free, highly versatile audio codec. 
 100 Opus is unmatched for interactive speech and music transmission over 
 101 the Internet, but is also intended for storage and streaming 
 102 applications. It is standardized by the Internet Engineering Task 
 103 Force (IETF) as RFC 6716 which incorporated technology from Skype's 
 104 SILK codec and Xiph.Org's CELT codec. 
 106 libopusfile is a library for decoding and basic manipulation of Ogg 
 109 Audio::Opusfile is an interface to libopusfile. It exports nearly all 
 110 of the functions for obtaining metadata of an Opus file or buffer in 
 111 that library. Future versions will additionally provide functions for 
 112 decoding Opus data into PCM. 
 114 The API might change in future versions. 
 120 =item Audio::Opusfile->B<new_from_file>(I<$file>) 
 122 Creates a new Audio::Opusfile object from an Ogg Opus file. 
 124 Dies if the given file does not exist or is not a valid Ogg Opus file. 
 126 =item Audio::Opusfile->B<new_from_memory>(I<$buffer>) 
 128 Creates a new Audio::Opusfile object from a buffer containing Ogg Opus 
 131 Dies if the given buffer does not contain valid data. 
 133 =item Audio::Opusfile::test(I<$buffer>) 
 135 Returns true if the given buffer looks like the beginning of a valid 
 136 Ogg Opus file, false otherwise. 
 138 Dies if the given buffer does not have sufficient data to tell if it 
 139 is an Opus stream or if it looks like a Opus stream but parsing it 
 144 Returns an L<Audio::Opusfile::Head> object corresponding to the file. 
 148 Returns an L<Audio::Opusfile::Tags> object corresponding to the file. 
 150 =item $of->B<seekable> 
 152 Returns whether or not the data source being read is seekable. 
 154 =item $of->B<link_count> 
 156 Returns the number of links in this chained stream. Always returns 1 
 157 for unseekable sources. 
 159 =item $of->B<serialno>([I<$link_index>]) 
 161 Get the serial number of the given link in a (possibly-chained) Ogg 
 162 Opus stream. If the given index is greater than the total number of 
 163 links, this returns the serial number of the last link. 
 165 If the source is not seekable, I<$link_index> is negative, or 
 166 I<$link_index> is not given, then this function returns the serial 
 167 number of the current link. 
 169 =item $of->B<raw_total>([I<$link_index>]) 
 171 Get the total (compressed) size of the stream (with no arguments), or 
 172 of an individual link in a (possibly-chained) Ogg Opus stream (with 
 173 one nonnegative argument), including all headers and Ogg muxing 
 176 The stream must be seekable to get the total. A negative value is 
 177 returned if the stream is not seekable. 
 179 B<Warning:> If the Opus stream (or link) is concurrently multiplexed 
 180 with other logical streams (e.g., video), this returns the size of the 
 181 entire stream (or link), not just the number of bytes in the first 
 182 logical Opus stream. Returning the latter would require scanning the 
 185 =item $of->B<pcm_total>([I<$link_index>]) 
 187 Get the total PCM length (number of samples at 48 kHz) of the stream 
 188 (with no arguments), or of an individual link in a (possibly-chained) 
 189 Ogg Opus stream (with one nonnegative argument). 
 191 Users looking for op_time_total() should use this function instead. 
 192 Because timestamps in Opus are fixed at 48 kHz, there is no need for a 
 193 separate function to convert this to seconds. 
 195 The stream must be seekable to get the total. A negative value is 
 196 returned if the stream is not seekable. 
 198 =item $of->B<current_link> 
 200 Retrieve the index of the current link. 
 202 This is the link that produced the data most recently read by 
 203 op_read_float() or its associated functions, or, after a seek, the 
 204 link that the seek target landed in. Reading more data may advance the 
 205 link index (even on the first read after a seek). 
 207 =item $of->B<bitrate>([I<$link_index>]) 
 209 Computes the bitrate of the stream (with no arguments), or of an 
 210 individual link in a (possibly-chained) Ogg Opus stream (with one 
 211 nonnegative argument). 
 213 The stream must be seekable to compute the bitrate. A negative value 
 214 is returned if the stream is not seekable. 
 216 B<Warning:> If the Opus stream (or link) is concurrently multiplexed with 
 217 other logical streams (e.g., video), this uses the size of the entire 
 218 stream (or link) to compute the bitrate, not just the number of bytes 
 219 in the first logical Opus stream. 
 221 =item $of->B<bitrate_instant> 
 223 Compute the instantaneous bitrate, measured as the ratio of bits to 
 224 playable samples decoded since a) the last call to B<bitrate_instant>, 
 225 b) the last seek, or c) the start of playback, whichever was most 
 228 This will spike somewhat after a seek or at the start/end of a chain 
 229 boundary, as pre-skip, pre-roll, and end-trimming causes samples to be 
 230 decoded but not played. 
 232 =item $of->B<raw_tell> 
 234 Obtain the current value of the position indicator of I<$of>. This is 
 235 the byte position that is currently being read from. 
 237 =item $of->B<pcm_tell> 
 239 Obtain the PCM offset of the next sample to be read. 
 241 If the stream is not properly timestamped, this might not increment by 
 242 the proper amount between reads, or even return monotonically 
 245 =item $of->B<raw_seek>(I<$offset>) 
 247 Seek to a byte offset relative to the compressed data. 
 249 This also scans packets to update the PCM cursor. It will cross a 
 250 logical bitstream boundary, but only if it can't get any packets out 
 251 of the tail of the link to which it seeks. 
 253 =item $of->B<pcm_seek>(I<$offset>) 
 255 Seek to the specified PCM offset, such that decoding will begin at 
 256 exactly the requested position. The PCM offset is in samples at 48 kHz 
 257 relative to the start of the stream. 
 259 =item $of->B<set_gain_offset>(I<$gain_type>, I<$gain_offset>) 
 261 Sets the gain to be used for decoded output. 
 263 By default, the gain in the header is applied with no additional 
 264 offset. The total gain (including header gain and/or track gain, if 
 265 applicable, and this offset), will be clamped to [-32768,32767]/256 
 266 dB. This is more than enough to saturate or underflow 16-bit PCM. 
 268 B<Note:> The new gain will not be applied to any already buffered, 
 269 decoded output. This means you cannot change it sample-by-sample, as 
 270 at best it will be updated packet-by-packet. It is meant for setting a 
 271 target volume level, rather than applying smooth fades, etc. 
 273 I<$gain_type> is one of OP_HEADER_GAIN, OP_TRACK_GAIN, or 
 274 OP_ABSOLUTE_GAIN. I<$gain_offset> is in 1/256ths of a dB. 
 276 =item $of->B<set_dither_enabled>(I<$enabled>) 
 278 Sets whether or not dithering is enabled for 16-bit decoding. 
 280 By default, when libopusfile is compiled to use floating-point 
 281 internally, calling read() or read_stereo() will first decode to 
 282 float, and then convert to fixed-point using noise-shaping dithering. 
 283 This flag can be used to disable that dithering. When the application 
 284 uses read_float() or read_float_stereo(), or when the library has been 
 285 compiled to decode directly to fixed point, this flag has no effect. 
 287 =item $of->B<read>([I<$bufsize>]) 
 289 It is recommended to use B<read_float> instead of this method if the 
 290 rest of your audio processing chain can handle floating point. 
 292 Reads more samples from the stream. I<$bufsize> is the maximum number 
 293 of samples read, and it defaults to 1048576. Returns a list whose 
 294 first element is the link index this data was decoded from, and the 
 295 rest of the elements are PCM samples, as signed 16-bit values at 48 
 296 kHz with a nominal range of [-32768,32767). Multiple channels are 
 297 interleaved using the L<Vorbis channel ordering|https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-810004.3.9>. 
 299 You can use C<< $of->head($li)->channel_count >> to find out the 
 300 channel count of a given link index. 
 302 =item $of->B<read_float>([I<$bufsize>]) 
 304 Like B<read>, but samples are signed floats with a nominal range of 
 307 =item $of->B<read_stereo>([I<$bufsize>]) 
 309 Like B<read>, but downmixes the stream to stereo (therefore you will 
 310 always get two channels) and does NOT return the link index (the first 
 311 return value is the first sample). 
 313 =item $of->B<read_float_stereo>([I<$bufsize>]) 
 315 Like B<read_float>, but downmixes the stream to stereo (therefore you 
 316 will always get two channels) and does NOT return the link index (the 
 317 first return value is the first sample). 
 323 All constants are exported by default: 
 325   OPUS_CHANNEL_COUNT_MAX 
 344   OP_GET_SERVER_INFO_REQUEST 
 347   OP_HTTP_PROXY_HOST_REQUEST 
 348   OP_HTTP_PROXY_PASS_REQUEST 
 349   OP_HTTP_PROXY_PORT_REQUEST 
 350   OP_HTTP_PROXY_USER_REQUEST 
 354   OP_PIC_FORMAT_UNKNOWN 
 356   OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST 
 362 L<Audio::Opusfile::Head>, 
 363 L<Audio::Opusfile::Tags>, 
 364 L<http://opus-codec.org/>, 
 365 L<http://opus-codec.org/docs/opusfile_api-0.7/index.html> 
 369 Marius Gavrilescu, E<lt>marius@ieval.roE<gt> 
 371 =head1 COPYRIGHT AND LICENSE 
 373 Copyright (C) 2016-2017 by Marius Gavrilescu 
 375 This library is free software; you can redistribute it and/or modify 
 376 it under the same terms as Perl itself, either Perl version 5.24.0 or, 
 377 at your option, any later version of Perl 5 you may have available.