annotate src/libvorbis-1.3.3/doc/vorbisfile/chainingexample.html @ 86:98c1576536ae

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