examples/sfexamples/oggvorbiscodec/src/libvorbis/doc/vorbisfile/seekexample.html

00001 <html>
00002 
00003 <head>
00004 <title>vorbisfile - Example Code</title>
00005 <link rel=stylesheet href="style.css" type="text/css">
00006 </head>
00007 
00008 <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
00009 <table border=0 width=100%>
00010 <tr>
00011 <td><p class=tiny>Vorbisfile documentation</p></td>
00012 <td align=right><p class=tiny>vorbisfile version 1.68 - 20030307</p></td>
00013 </tr>
00014 </table>
00015 
00016 <h1>Example Code: seeking</h1>
00017 
00018 <p>
00019 The following is a run-through of the seeking example program supplied
00020 with vorbisfile - <a href="seeking_test_c.html">seeking_test.c</a>.  
00021 This program tests the vorbisfile <a href="ov_time_seek.html">ov_time_seek</a> function by seeking to random points within the file.
00022 
00023 <p>
00024 First, relevant headers, including vorbis-specific "codec.h" and "vorbisfile.h" have to be included.
00025 
00026 <br><br>
00027 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
00028 <tr bgcolor=#cccccc>
00029         <td>
00030 <pre><b>
00031 #include &lt;stdlib.h>
00032 #include &lt;stdio.h>
00033 #include "vorbis/codec.h"
00034 #include "vorbis/vorbisfile.h"
00035 #include "../lib/misc.h"
00036 </b></pre>
00037         </td>
00038 </tr>
00039 </table>
00040 
00041 <p>Inside main(), we declare our primary OggVorbis_File structure.  We also declare other helpful variables to track our progress within the file.
00042 <br><br>
00043 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
00044 <tr bgcolor=#cccccc>
00045         <td>
00046 <pre><b>
00047 int main(){
00048   OggVorbis_File ov;
00049   int i;
00050 </b></pre>
00051         </td>
00052 </tr>
00053 </table>
00054 
00055 <p><a href="ov_open.html">ov_open()</a> must be
00056 called to initialize the <a href="OggVorbis_File.html">OggVorbis_File</a> structure with default values.  
00057 <a href="ov_open.html">ov_open()</a> also checks to ensure that we're reading Vorbis format and not something else.
00058 
00059 <br><br>
00060 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
00061 <tr bgcolor=#cccccc>
00062         <td>
00063 <pre><b>
00064   if(ov_open(stdin,&ov,NULL,-1)<0){
00065     printf("Could not open input as an OggVorbis file.\n\n");
00066     exit(1);
00067   }
00068 
00069 </b></pre>
00070         </td>
00071 </tr>
00072 </table>
00073 
00074 <p>
00075 First we check to make sure the stream is seekable using <a href="ov_seekable.html">ov_seekable</a>.
00076 
00077 <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.
00078 
00079 <br><br>
00080 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
00081 <tr bgcolor=#cccccc>
00082         <td>
00083 <pre><b>
00084   
00085   /* print details about each logical bitstream in the input */
00086   if(ov_seekable(&ov)){
00087     double length=ov_time_total(&ov,-1);
00088     printf("testing seeking to random places in %g seconds....\n",length);
00089     for(i=0;i<100;i++){
00090       double val=(double)rand()/RAND_MAX*length;
00091       ov_time_seek(&ov,val);
00092       printf("\r\t%d [%gs]...     ",i,val);
00093       fflush(stdout);
00094     }
00095     
00096     printf("\r                                   \nOK.\n\n");
00097   }else{
00098     printf("Standard input was not seekable.\n");
00099   }
00100   
00101 </b></pre>
00102         </td>
00103 </tr>
00104 </table>
00105 <p>
00106 When we're done seeking, we need to call <a href="ov_clear.html">ov_clear()</a> to release the bitstream.
00107 
00108 <br><br>
00109 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
00110 <tr bgcolor=#cccccc>
00111         <td>
00112 <pre><b>
00113   ov_clear(&ov);
00114   return 0;
00115 }
00116 </b></pre>
00117         </td>
00118 </tr>
00119 </table>
00120 
00121 <p>
00122 The full source for seeking_test.c can be found with the vorbis
00123 distribution in <a href="seeking_test_c.html">seeking_test.c</a>.
00124 
00125 <br><br>
00126 <hr noshade>
00127 <table border=0 width=100%>
00128 <tr valign=top>
00129 <td><p class=tiny>copyright &copy; 2003 Xiph.org</p></td>
00130 <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>
00131 </tr><tr>
00132 <td><p class=tiny>Vorbisfile documentation</p></td>
00133 <td align=right><p class=tiny>vorbisfile version 1.68 - 20030307</p></td>
00134 </tr>
00135 </table>
00136 
00137 </body>
00138 
00139 </html>

Generated by  doxygen 1.6.2