|
Packit |
06404a |
<html>
|
|
Packit |
06404a |
|
|
Packit |
06404a |
<head>
|
|
Packit |
06404a |
<title>vorbisfile - Example Code</title>
|
|
Packit |
06404a |
<link rel=stylesheet href="style.css" type="text/css">
|
|
Packit |
06404a |
</head>
|
|
Packit |
06404a |
|
|
Packit |
06404a |
<body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
Vorbisfile documentation
|
|
Packit |
06404a |
vorbisfile version 1.3.2 - 20101101
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
Chaining Example Code
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
The following is a run-through of the chaining example program supplied
|
|
Packit |
06404a |
with vorbisfile - chaining_example.c.
|
|
Packit |
06404a |
This program demonstrates how to work with a chained bitstream.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
First, relevant headers, including vorbis-specific "codec.h" and "vorbisfile.h" have to be included.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
#include "vorbis/codec.h"
|
|
Packit |
06404a |
#include "vorbis/vorbisfile.h"
|
|
Packit |
06404a |
#include "../lib/misc.h"
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
Inside main(), we declare our primary OggVorbis_File structure. We also declare a other helpful variables to track our progress within the file.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
int main(){
|
|
Packit |
06404a |
OggVorbis_File ov;
|
|
Packit |
06404a |
int i;
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
This example takes its input on stdin which is in 'text' mode by default under Windows; this will corrupt the input data unless set to binary mode. This applies only to Windows.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
#ifdef _WIN32 /* We need to set stdin to binary mode under Windows */
|
|
Packit |
06404a |
_setmode( _fileno( stdin ), _O_BINARY );
|
|
Packit |
06404a |
#endif
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
We call ov_open_callbacks() to
|
|
Packit |
06404a |
initialize the OggVorbis_File
|
|
Packit |
06404a |
structure. ov_open_callbacks()
|
|
Packit |
06404a |
also checks to ensure that we're reading Vorbis format and not
|
|
Packit |
06404a |
something else. The OV_CALLBACKS_NOCLOSE callbacks instruct
|
|
Packit |
06404a |
libvorbisfile not to close stdin later during cleanup.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
if(ov_open_callbacks(stdin,&ov,NULL,-1,OV_CALLBACKS_NOCLOSE)<0){
|
|
Packit |
06404a |
printf("Could not open input as an OggVorbis file.\n\n");
|
|
Packit |
06404a |
exit(1);
|
|
Packit |
06404a |
}
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
First we check to make sure the stream is seekable using ov_seekable.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
Then we're going to find the number of logical bitstreams in the physical bitstream using ov_streams.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
We use ov_time_total to determine the total length of the physical bitstream. We specify that we want the entire bitstream by using the argument <tt>-1</tt>.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
if(ov_seekable(&ov)){
|
|
Packit |
06404a |
printf("Input bitstream contained %ld logical bitstream section(s).\n",
|
|
Packit |
06404a |
ov_streams(&ov));
|
|
Packit |
06404a |
printf("Total bitstream playing time: %ld seconds\n\n",
|
|
Packit |
06404a |
(long)ov_time_total(&ov,-1));
|
|
Packit |
06404a |
|
|
Packit |
06404a |
}else{
|
|
Packit |
06404a |
printf("Standard input was not seekable.\n"
|
|
Packit |
06404a |
"First logical bitstream information:\n\n");
|
|
Packit |
06404a |
}
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
Now we're going to iterate through each logical bitstream and print information about that bitstream.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
We use ov_info to pull out the vorbis_info struct for each logical bitstream. This struct contains bitstream-specific info.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
ov_serialnumber retrieves the unique serial number for the logical bistream. ov_raw_total gives the total compressed bytes for the logical bitstream, and ov_time_total gives the total time in the logical bitstream.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
for(i=0;i<ov_streams(&ov);i++){
|
|
Packit |
06404a |
vorbis_info *vi=ov_info(&ov,i);
|
|
Packit |
06404a |
printf("\tlogical bitstream section %d information:\n",i+1);
|
|
Packit |
06404a |
printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
|
|
Packit |
06404a |
vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
|
|
Packit |
06404a |
ov_serialnumber(&ov,i));
|
|
Packit |
06404a |
printf("\t\tcompressed length: %ld bytes ",(long)(ov_raw_total(&ov,i)));
|
|
Packit |
06404a |
printf(" play time: %lds\n",(long)ov_time_total(&ov,i));
|
|
Packit |
06404a |
}
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
When we're done with the entire physical bitstream, we need to call ov_clear() to release the bitstream.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
ov_clear(&ov);
|
|
Packit |
06404a |
return 0;
|
|
Packit |
06404a |
}
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
The full source for chaining_example.c can be found with the vorbis
|
|
Packit |
06404a |
distribution in chaining_example.c.
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
copyright © 2000-2010 Xiph.Org
|
|
Packit |
06404a |
Ogg Vorbis
|
|
Packit |
06404a |
|
|
Packit |
06404a |
Vorbisfile documentation
|
|
Packit |
06404a |
vorbisfile version 1.3.2 - 20101101
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
|
|
Packit |
06404a |
</body>
|
|
Packit |
06404a |
|
|
Packit |
06404a |
</html>
|