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.3.2 -
20101101</p></td>
16 <h1>Example Code: seeking
</h1>
19 The following is a run-through of the seeking example program supplied
20 with vorbisfile -
<a href=
"seeking_test_c.html">seeking_test.c
</a>.
21 This program tests the vorbisfile
<a href=
"ov_time_seek.html">ov_time_seek
</a> function by seeking to random points within the file.
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
<stdlib.h
>
33 #include
"vorbis/codec.h"
34 #include
"vorbis/vorbisfile.h"
40 <p>Inside main(), we declare our primary OggVorbis_File structure. We also declare other helpful variables to track our progress within the file.
42 <table border=
0 width=
100% color=black cellspacing=
0 cellpadding=
7>
54 <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.
56 <table border=
0 width=
100% color=black cellspacing=
0 cellpadding=
7>
60 #ifdef _WIN32 /* We need to set stdin to binary mode under Windows */
61 _setmode( _fileno( stdin ), _O_BINARY );
68 <p><a href=
"ov_open_callbacks.html">ov_open()
</a> must be
69 called to initialize the
<a href=
"OggVorbis_File.html">OggVorbis_File
</a> structure with default values.
70 <a href=
"ov_open_callbacks.html">ov_open_callbacks()
</a> also checks to ensure that we're reading Vorbis format and not something else.
73 <table border=
0 width=
100% color=black cellspacing=
0 cellpadding=
7>
77 if(ov_open_callbacks(stdin,&ov,NULL,-
1, OV_CALLBACKS_NOCLOSE)
<0){
78 printf(
"Could not open input as an OggVorbis file.\n\n");
88 First we check to make sure the stream is seekable using
<a href=
"ov_seekable.html">ov_seekable
</a>.
90 <p>Then we seek to
100 random spots in the bitstream using
<a href=
"ov_time_seek.html">ov_time_seek
</a> with randomly generated values.
93 <table border=
0 width=
100% color=black cellspacing=
0 cellpadding=
7>
98 /* print details about each logical bitstream in the input */
100 double length=ov_time_total(&ov,-
1);
101 printf(
"testing seeking to random places in %g seconds....\n",length);
103 double val=(double)rand()/RAND_MAX*length;
104 ov_time_seek(&ov,val);
105 printf(
"\r\t%d [%gs]... ",i,val);
109 printf(
"\r \nOK.\n\n");
111 printf(
"Standard input was not seekable.\n");
119 When we're done seeking, we need to call
<a href=
"ov_clear.html">ov_clear()
</a> to release the bitstream.
122 <table border=
0 width=
100% color=black cellspacing=
0 cellpadding=
7>
135 The full source for seeking_test.c can be found with the vorbis
136 distribution in
<a href=
"seeking_test_c.html">seeking_test.c
</a>.
140 <table border=
0 width=
100%
>
142 <td><p class=tiny
>copyright
© 2000-
2010 Xiph.Org
</p></td>
143 <td align=right
><p class=tiny
><a href=
"http://www.xiph.org/ogg/vorbis/">Ogg Vorbis
</a></p></td>
145 <td><p class=tiny
>Vorbisfile documentation
</p></td>
146 <td align=right
><p class=tiny
>vorbisfile version
1.3.2 -
20101101</p></td>