Chris@1
|
1 <html>
|
Chris@1
|
2
|
Chris@1
|
3 <head>
|
Chris@1
|
4 <title>vorbisfile - Example Code</title>
|
Chris@1
|
5 <link rel=stylesheet href="style.css" type="text/css">
|
Chris@1
|
6 </head>
|
Chris@1
|
7
|
Chris@1
|
8 <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
|
Chris@1
|
9 <table border=0 width=100%>
|
Chris@1
|
10 <tr>
|
Chris@1
|
11 <td><p class=tiny>Vorbisfile documentation</p></td>
|
Chris@1
|
12 <td align=right><p class=tiny>vorbisfile version 1.3.2 - 20101101</p></td>
|
Chris@1
|
13 </tr>
|
Chris@1
|
14 </table>
|
Chris@1
|
15
|
Chris@1
|
16 <h1>Chaining Example Code</h1>
|
Chris@1
|
17
|
Chris@1
|
18 <p>
|
Chris@1
|
19 The following is a run-through of the chaining example program supplied
|
Chris@1
|
20 with vorbisfile - <a href="chaining_example_c.html">chaining_example.c</a>.
|
Chris@1
|
21 This program demonstrates how to work with a chained bitstream.
|
Chris@1
|
22
|
Chris@1
|
23 <p>
|
Chris@1
|
24 First, relevant headers, including vorbis-specific "codec.h" and "vorbisfile.h" have to be included.
|
Chris@1
|
25
|
Chris@1
|
26 <br><br>
|
Chris@1
|
27 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
|
Chris@1
|
28 <tr bgcolor=#cccccc>
|
Chris@1
|
29 <td>
|
Chris@1
|
30 <pre><b>
|
Chris@1
|
31 #include "vorbis/codec.h"
|
Chris@1
|
32 #include "vorbis/vorbisfile.h"
|
Chris@1
|
33 #include "../lib/misc.h"
|
Chris@1
|
34 </b></pre>
|
Chris@1
|
35 </td>
|
Chris@1
|
36 </tr>
|
Chris@1
|
37 </table>
|
Chris@1
|
38
|
Chris@1
|
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.
|
Chris@1
|
40 <br><br>
|
Chris@1
|
41 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
|
Chris@1
|
42 <tr bgcolor=#cccccc>
|
Chris@1
|
43 <td>
|
Chris@1
|
44 <pre><b>
|
Chris@1
|
45 int main(){
|
Chris@1
|
46 OggVorbis_File ov;
|
Chris@1
|
47 int i;
|
Chris@1
|
48 </b></pre>
|
Chris@1
|
49 </td>
|
Chris@1
|
50 </tr>
|
Chris@1
|
51 </table>
|
Chris@1
|
52
|
Chris@1
|
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.
|
Chris@1
|
54 <br><br>
|
Chris@1
|
55 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
|
Chris@1
|
56 <tr bgcolor=#cccccc>
|
Chris@1
|
57 <td>
|
Chris@1
|
58 <pre><b>
|
Chris@1
|
59 #ifdef _WIN32 /* We need to set stdin to binary mode under Windows */
|
Chris@1
|
60 _setmode( _fileno( stdin ), _O_BINARY );
|
Chris@1
|
61 #endif
|
Chris@1
|
62 </b></pre>
|
Chris@1
|
63 </td>
|
Chris@1
|
64 </tr>
|
Chris@1
|
65 </table>
|
Chris@1
|
66
|
Chris@1
|
67 <p>We call <a href="ov_open_callbacks.html">ov_open_callbacks()</a> to
|
Chris@1
|
68 initialize the <a href="OggVorbis_File.html">OggVorbis_File</a>
|
Chris@1
|
69 structure. <a href="ov_open_callbacks.html">ov_open_callbacks()</a>
|
Chris@1
|
70 also checks to ensure that we're reading Vorbis format and not
|
Chris@1
|
71 something else. The OV_CALLBACKS_NOCLOSE callbacks instruct
|
Chris@1
|
72 libvorbisfile not to close stdin later during cleanup.<p>
|
Chris@1
|
73
|
Chris@1
|
74 <br><br>
|
Chris@1
|
75 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
|
Chris@1
|
76 <tr bgcolor=#cccccc>
|
Chris@1
|
77 <td>
|
Chris@1
|
78 <pre><b>
|
Chris@1
|
79 if(ov_open_callbacks(stdin,&ov,NULL,-1,OV_CALLBACKS_NOCLOSE)<0){
|
Chris@1
|
80 printf("Could not open input as an OggVorbis file.\n\n");
|
Chris@1
|
81 exit(1);
|
Chris@1
|
82 }
|
Chris@1
|
83
|
Chris@1
|
84 </b></pre>
|
Chris@1
|
85 </td>
|
Chris@1
|
86 </tr>
|
Chris@1
|
87 </table>
|
Chris@1
|
88
|
Chris@1
|
89 <p>
|
Chris@1
|
90 First we check to make sure the stream is seekable using <a href="ov_seekable.html">ov_seekable</a>.
|
Chris@1
|
91
|
Chris@1
|
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>.
|
Chris@1
|
93
|
Chris@1
|
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>.
|
Chris@1
|
95
|
Chris@1
|
96 <br><br>
|
Chris@1
|
97 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
|
Chris@1
|
98 <tr bgcolor=#cccccc>
|
Chris@1
|
99 <td>
|
Chris@1
|
100 <pre><b>
|
Chris@1
|
101 if(ov_seekable(&ov)){
|
Chris@1
|
102 printf("Input bitstream contained %ld logical bitstream section(s).\n",
|
Chris@1
|
103 ov_streams(&ov));
|
Chris@1
|
104 printf("Total bitstream playing time: %ld seconds\n\n",
|
Chris@1
|
105 (long)ov_time_total(&ov,-1));
|
Chris@1
|
106
|
Chris@1
|
107 }else{
|
Chris@1
|
108 printf("Standard input was not seekable.\n"
|
Chris@1
|
109 "First logical bitstream information:\n\n");
|
Chris@1
|
110 }
|
Chris@1
|
111
|
Chris@1
|
112 </b></pre>
|
Chris@1
|
113 </td>
|
Chris@1
|
114 </tr>
|
Chris@1
|
115 </table>
|
Chris@1
|
116
|
Chris@1
|
117 <p>Now we're going to iterate through each logical bitstream and print information about that bitstream.
|
Chris@1
|
118
|
Chris@1
|
119 <p>We use <a href="ov_info.html">ov_info</a> to pull out the <a href="../libvorbis/vorbis_info.html">vorbis_info</a> struct for each logical bitstream. This struct contains bitstream-specific info.
|
Chris@1
|
120
|
Chris@1
|
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.
|
Chris@1
|
122
|
Chris@1
|
123 <br><br>
|
Chris@1
|
124 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
|
Chris@1
|
125 <tr bgcolor=#cccccc>
|
Chris@1
|
126 <td>
|
Chris@1
|
127 <pre><b>
|
Chris@1
|
128 for(i=0;i<ov_streams(&ov);i++){
|
Chris@1
|
129 vorbis_info *vi=ov_info(&ov,i);
|
Chris@1
|
130 printf("\tlogical bitstream section %d information:\n",i+1);
|
Chris@1
|
131 printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
|
Chris@1
|
132 vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
|
Chris@1
|
133 ov_serialnumber(&ov,i));
|
Chris@1
|
134 printf("\t\tcompressed length: %ld bytes ",(long)(ov_raw_total(&ov,i)));
|
Chris@1
|
135 printf(" play time: %lds\n",(long)ov_time_total(&ov,i));
|
Chris@1
|
136 }
|
Chris@1
|
137 </b></pre>
|
Chris@1
|
138 </td>
|
Chris@1
|
139 </tr>
|
Chris@1
|
140 </table>
|
Chris@1
|
141 <p>
|
Chris@1
|
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.
|
Chris@1
|
143
|
Chris@1
|
144 <br><br>
|
Chris@1
|
145 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
|
Chris@1
|
146 <tr bgcolor=#cccccc>
|
Chris@1
|
147 <td>
|
Chris@1
|
148 <pre><b>
|
Chris@1
|
149 ov_clear(&ov);
|
Chris@1
|
150 return 0;
|
Chris@1
|
151 }
|
Chris@1
|
152 </b></pre>
|
Chris@1
|
153 </td>
|
Chris@1
|
154 </tr>
|
Chris@1
|
155 </table>
|
Chris@1
|
156
|
Chris@1
|
157 <p>
|
Chris@1
|
158 The full source for chaining_example.c can be found with the vorbis
|
Chris@1
|
159 distribution in <a href="chaining_example_c.html">chaining_example.c</a>.
|
Chris@1
|
160
|
Chris@1
|
161 <br><br>
|
Chris@1
|
162 <hr noshade>
|
Chris@1
|
163 <table border=0 width=100%>
|
Chris@1
|
164 <tr valign=top>
|
Chris@1
|
165 <td><p class=tiny>copyright © 2000-2010 Xiph.Org</p></td>
|
Chris@1
|
166 <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a></p></td>
|
Chris@1
|
167 </tr><tr>
|
Chris@1
|
168 <td><p class=tiny>Vorbisfile documentation</p></td>
|
Chris@1
|
169 <td align=right><p class=tiny>vorbisfile version 1.3.2 - 20101101</p></td>
|
Chris@1
|
170 </tr>
|
Chris@1
|
171 </table>
|
Chris@1
|
172
|
Chris@1
|
173 </body>
|
Chris@1
|
174
|
Chris@1
|
175 </html>
|