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.25 - 20000615</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><a href="ov_open.html">ov_open()</a> must be
54 called to initialize the <a href="OggVorbis_File.html">OggVorbis_File</a> structure with default values.
55 <a href="ov_open.html">ov_open()</a> also checks to ensure that we're reading Vorbis format and not something else.
58 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
62 if(ov_open(stdin,&ov,NULL,-1)<0){
63 printf("Could not open input as an OggVorbis file.\n\n");
73 First we check to make sure the stream is seekable using <a href="ov_seekable.html">ov_seekable</a>.
75 <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>.
77 <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>.
80 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
85 printf("Input bitstream contained %ld logical bitstream section(s).\n",
87 printf("Total bitstream playing time: %ld seconds\n\n",
88 (long)ov_time_total(&ov,-1));
91 printf("Standard input was not seekable.\n"
92 "First logical bitstream information:\n\n");
100 <p>Now we're going to iterate through each logical bitstream and print information about that bitstream.
102 <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.
104 <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.
107 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
111 for(i=0;i<ov_streams(&ov);i++){
112 vorbis_info *vi=ov_info(&ov,i);
113 printf("\tlogical bitstream section %d information:\n",i+1);
114 printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
115 vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
116 ov_serialnumber(&ov,i));
117 printf("\t\tcompressed length: %ld bytes ",(long)(ov_raw_total(&ov,i)));
118 printf(" play time: %lds\n",(long)ov_time_total(&ov,i));
125 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.
128 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
141 The full source for chaining_example.c can be found with the vorbis
142 distribution in <a href="chaining_example_c.html">chaining_example.c</a>.
146 <table border=0 width=100%>
148 <td><p class=tiny>copyright © 2000 vorbis team</p></td>
149 <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>
151 <td><p class=tiny>vorbisfile documentation</p></td>
152 <td align=right><p class=tiny>vorbisfile version 1.25 - 20000615</p></td>