annotate src/libvorbis-1.3.3/doc/vorbisfile/seekexample.html @ 127:7867fa7e1b6b

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