annotate src/libvorbis-1.3.3/doc/vorbisfile/seekexample.html @ 1:05aa0afa9217

Bring in flac, ogg, vorbis
author Chris Cannam
date Tue, 19 Mar 2013 17:37:49 +0000
parents
children
rev   line source
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>Example Code: seeking</h1>
Chris@1 17
Chris@1 18 <p>
Chris@1 19 The following is a run-through of the seeking example program supplied
Chris@1 20 with vorbisfile - <a href="seeking_test_c.html">seeking_test.c</a>.
Chris@1 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.
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 &lt;stdlib.h>
Chris@1 32 #include &lt;stdio.h>
Chris@1 33 #include "vorbis/codec.h"
Chris@1 34 #include "vorbis/vorbisfile.h"
Chris@1 35 </b></pre>
Chris@1 36 </td>
Chris@1 37 </tr>
Chris@1 38 </table>
Chris@1 39
Chris@1 40 <p>Inside main(), we declare our primary OggVorbis_File structure. We also declare other helpful variables to track our progress within the file.
Chris@1 41 <br><br>
Chris@1 42 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
Chris@1 43 <tr bgcolor=#cccccc>
Chris@1 44 <td>
Chris@1 45 <pre><b>
Chris@1 46 int main(){
Chris@1 47 OggVorbis_File ov;
Chris@1 48 int i;
Chris@1 49 </b></pre>
Chris@1 50 </td>
Chris@1 51 </tr>
Chris@1 52 </table>
Chris@1 53
Chris@1 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.
Chris@1 55 <br><br>
Chris@1 56 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
Chris@1 57 <tr bgcolor=#cccccc>
Chris@1 58 <td>
Chris@1 59 <pre><b>
Chris@1 60 #ifdef _WIN32 /* We need to set stdin to binary mode under Windows */
Chris@1 61 _setmode( _fileno( stdin ), _O_BINARY );
Chris@1 62 #endif
Chris@1 63 </b></pre>
Chris@1 64 </td>
Chris@1 65 </tr>
Chris@1 66 </table>
Chris@1 67
Chris@1 68 <p><a href="ov_open_callbacks.html">ov_open()</a> must be
Chris@1 69 called to initialize the <a href="OggVorbis_File.html">OggVorbis_File</a> structure with default values.
Chris@1 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.
Chris@1 71
Chris@1 72 <br><br>
Chris@1 73 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
Chris@1 74 <tr bgcolor=#cccccc>
Chris@1 75 <td>
Chris@1 76 <pre><b>
Chris@1 77 if(ov_open_callbacks(stdin,&ov,NULL,-1, OV_CALLBACKS_NOCLOSE)<0){
Chris@1 78 printf("Could not open input as an OggVorbis file.\n\n");
Chris@1 79 exit(1);
Chris@1 80 }
Chris@1 81
Chris@1 82 </b></pre>
Chris@1 83 </td>
Chris@1 84 </tr>
Chris@1 85 </table>
Chris@1 86
Chris@1 87 <p>
Chris@1 88 First we check to make sure the stream is seekable using <a href="ov_seekable.html">ov_seekable</a>.
Chris@1 89
Chris@1 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.
Chris@1 91
Chris@1 92 <br><br>
Chris@1 93 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
Chris@1 94 <tr bgcolor=#cccccc>
Chris@1 95 <td>
Chris@1 96 <pre><b>
Chris@1 97
Chris@1 98 /* print details about each logical bitstream in the input */
Chris@1 99 if(ov_seekable(&ov)){
Chris@1 100 double length=ov_time_total(&ov,-1);
Chris@1 101 printf("testing seeking to random places in %g seconds....\n",length);
Chris@1 102 for(i=0;i<100;i++){
Chris@1 103 double val=(double)rand()/RAND_MAX*length;
Chris@1 104 ov_time_seek(&ov,val);
Chris@1 105 printf("\r\t%d [%gs]... ",i,val);
Chris@1 106 fflush(stdout);
Chris@1 107 }
Chris@1 108
Chris@1 109 printf("\r \nOK.\n\n");
Chris@1 110 }else{
Chris@1 111 printf("Standard input was not seekable.\n");
Chris@1 112 }
Chris@1 113
Chris@1 114 </b></pre>
Chris@1 115 </td>
Chris@1 116 </tr>
Chris@1 117 </table>
Chris@1 118 <p>
Chris@1 119 When we're done seeking, we need to call <a href="ov_clear.html">ov_clear()</a> to release the bitstream.
Chris@1 120
Chris@1 121 <br><br>
Chris@1 122 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
Chris@1 123 <tr bgcolor=#cccccc>
Chris@1 124 <td>
Chris@1 125 <pre><b>
Chris@1 126 ov_clear(&ov);
Chris@1 127 return 0;
Chris@1 128 }
Chris@1 129 </b></pre>
Chris@1 130 </td>
Chris@1 131 </tr>
Chris@1 132 </table>
Chris@1 133
Chris@1 134 <p>
Chris@1 135 The full source for seeking_test.c can be found with the vorbis
Chris@1 136 distribution in <a href="seeking_test_c.html">seeking_test.c</a>.
Chris@1 137
Chris@1 138 <br><br>
Chris@1 139 <hr noshade>
Chris@1 140 <table border=0 width=100%>
Chris@1 141 <tr valign=top>
Chris@1 142 <td><p class=tiny>copyright &copy; 2000-2010 Xiph.Org</p></td>
Chris@1 143 <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a></p></td>
Chris@1 144 </tr><tr>
Chris@1 145 <td><p class=tiny>Vorbisfile documentation</p></td>
Chris@1 146 <td align=right><p class=tiny>vorbisfile version 1.3.2 - 20101101</p></td>
Chris@1 147 </tr>
Chris@1 148 </table>
Chris@1 149
Chris@1 150 </body>
Chris@1 151
Chris@1 152 </html>