4 <title>vorbisfile - Example Code</title>
5 <link rel=stylesheet href="style.css" type="text/css">
8 <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
9 <table border=0 width=100%>
11 <td><p class=tiny>Vorbisfile documentation</p></td>
12 <td align=right><p class=tiny>vorbisfile version 1.2.0 - 20070723</p></td>
16 <h1>Chaining Example Code</h1>
19 The following is a run-through of the chaining example program supplied
20 with vorbisfile - <a href="chaining_example_c.html">chaining_example.c</a>.
21 This program demonstrates how to work with a chained bitstream.
24 First, relevant headers, including vorbis-specific "codec.h" and "vorbisfile.h" have to be included.
27 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
31 #include "vorbis/codec.h"
32 #include "vorbis/vorbisfile.h"
33 #include "../lib/misc.h"
39 <p>Inside main(), we declare our primary OggVorbis_File structure. We also declare a other helpful variables to track our progress within the file.
41 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
53 <p>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.
55 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
59 #ifdef _WIN32 /* We need to set stdin to binary mode under Windows */
60 _setmode( _fileno( stdin ), _O_BINARY );
67 <p>We call <a href="ov_open_callbacks.html">ov_open_callbacks()</a> to
68 initialize the <a href="OggVorbis_File.html">OggVorbis_File</a>
69 structure. <a href="ov_open_callbacks.html">ov_open_callbacks()</a>
70 also checks to ensure that we're reading Vorbis format and not
71 something else. The OV_CALLBACKS_NOCLOSE callbacks instruct
72 libvorbisfile not to close stdin later during cleanup.<p>
75 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
79 if(ov_open_callbacks(stdin,&ov,NULL,-1,OV_CALLBACKS_NOCLOSE)<0){
80 printf("Could not open input as an OggVorbis file.\n\n");
90 First we check to make sure the stream is seekable using <a href="ov_seekable.html">ov_seekable</a>.
92 <p>Then we're going to find the number of logical bitstreams in the physical bitstream using <a href="ov_streams.html">ov_streams</a>.
94 <p>We use <a href="ov_time_total.html">ov_time_total</a> to determine the total length of the physical bitstream. We specify that we want the entire bitstream by using the argument <tt>-1</tt>.
97 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
101 if(ov_seekable(&ov)){
102 printf("Input bitstream contained %ld logical bitstream section(s).\n",
103 ov_streams(&ov));
104 printf("Total bitstream playing time: %ld seconds\n\n",
105 (long)ov_time_total(&ov,-1));
108 printf("Standard input was not seekable.\n"
109 "First logical bitstream information:\n\n");
117 <p>Now we're going to iterate through each logical bitstream and print information about that bitstream.
119 <p>We use <a href="ov_info.html">ov_info</a> to pull out the <a href="vorbis_info.html">vorbis_info</a> struct for each logical bitstream. This struct contains bitstream-specific info.
121 <p><a href="ov_serialnumber.html">ov_serialnumber</a> retrieves the unique serial number for the logical bistream. <a href="ov_raw_total.html">ov_raw_total</a> gives the total compressed bytes for the logical bitstream, and <a href="ov_time_total.html">ov_time_total</a> gives the total time in the logical bitstream.
124 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
128 for(i=0;i<ov_streams(&ov);i++){
129 vorbis_info *vi=ov_info(&ov,i);
130 printf("\tlogical bitstream section %d information:\n",i+1);
131 printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
132 vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
133 ov_serialnumber(&ov,i));
134 printf("\t\tcompressed length: %ld bytes ",(long)(ov_raw_total(&ov,i)));
135 printf(" play time: %lds\n",(long)ov_time_total(&ov,i));
142 When we're done with the entire physical bitstream, we need to call <a href="ov_clear.html">ov_clear()</a> to release the bitstream.
145 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
158 The full source for chaining_example.c can be found with the vorbis
159 distribution in <a href="chaining_example_c.html">chaining_example.c</a>.
163 <table border=0 width=100%>
165 <td><p class=tiny>copyright © 2007 Xiph.org</p></td>
166 <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a><br><a href="mailto:team@vorbis.org">team@vorbis.org</a></p></td>
168 <td><p class=tiny>Vorbisfile documentation</p></td>
169 <td align=right><p class=tiny>vorbisfile version 1.2.0 - 20070723</p></td>