]> git.jsancho.org Git - lugaru.git/blob - libvorbis-1.0.1/doc/vorbisfile/chainingexample.html
First shot at an OpenAL renderer. Sound effects work, no music.
[lugaru.git] / libvorbis-1.0.1 / doc / vorbisfile / chainingexample.html
1 <html>
2
3 <head>
4 <title>vorbisfile - Example Code</title>
5 <link rel=stylesheet href="style.css" type="text/css">
6 </head>
7
8 <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
9 <table border=0 width=100%>
10 <tr>
11 <td><p class=tiny>Vorbisfile documentation</p></td>
12 <td align=right><p class=tiny>vorbisfile version 1.68 - 20030307</p></td>
13 </tr>
14 </table>
15
16 <h1>Chaining Example Code</h1>
17
18 <p>
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.
22
23 <p>
24 First, relevant headers, including vorbis-specific "codec.h" and "vorbisfile.h" have to be included.
25
26 <br><br>
27 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
28 <tr bgcolor=#cccccc>
29         <td>
30 <pre><b>
31 #include "vorbis/codec.h"
32 #include "vorbis/vorbisfile.h"
33 #include "../lib/misc.h"
34 </b></pre>
35         </td>
36 </tr>
37 </table>
38
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.
40 <br><br>
41 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
42 <tr bgcolor=#cccccc>
43         <td>
44 <pre><b>
45 int main(){
46   OggVorbis_File ov;
47   int i;
48 </b></pre>
49         </td>
50 </tr>
51 </table>
52
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.
56
57 <br><br>
58 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
59 <tr bgcolor=#cccccc>
60         <td>
61 <pre><b>
62   if(ov_open(stdin,&ov,NULL,-1)<0){
63     printf("Could not open input as an OggVorbis file.\n\n");
64     exit(1);
65   }
66
67 </b></pre>
68         </td>
69 </tr>
70 </table>
71
72 <p>
73 First we check to make sure the stream is seekable using <a href="ov_seekable.html">ov_seekable</a>.
74
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>.
76
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>.
78
79 <br><br>
80 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
81 <tr bgcolor=#cccccc>
82         <td>
83 <pre><b>
84   if(ov_seekable(&ov)){
85     printf("Input bitstream contained %ld logical bitstream section(s).\n",
86            ov_streams(&ov));
87     printf("Total bitstream playing time: %ld seconds\n\n",
88            (long)ov_time_total(&ov,-1));
89
90   }else{
91     printf("Standard input was not seekable.\n"
92            "First logical bitstream information:\n\n");
93   }
94   
95 </b></pre>
96         </td>
97 </tr>
98 </table>
99
100 <p>Now we're going to iterate through each logical bitstream and print information about that bitstream.
101
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.
103
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.
105
106 <br><br>
107 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
108 <tr bgcolor=#cccccc>
109         <td>
110 <pre><b>
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));
119   } 
120 </b></pre>
121         </td>
122 </tr>
123 </table>
124 <p>
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.
126
127 <br><br>
128 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
129 <tr bgcolor=#cccccc>
130         <td>
131 <pre><b>
132   ov_clear(&ov);
133   return 0;
134 }
135 </b></pre>
136         </td>
137 </tr>
138 </table>
139
140 <p>
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>.
143
144 <br><br>
145 <hr noshade>
146 <table border=0 width=100%>
147 <tr valign=top>
148 <td><p class=tiny>copyright &copy; 2003 Xiph.org</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>
150 </tr><tr>
151 <td><p class=tiny>Vorbisfile documentation</p></td>
152 <td align=right><p class=tiny>vorbisfile version 1.68 - 20030307</p></td>
153 </tr>
154 </table>
155
156 </body>
157
158 </html>