Home | History | Annotate | Download | only in vorbisfile
      1 <html>
      2 
      3 <head>
      4 <title>vorbisfile - vorbisfile_example.c</title>
      5 <link rel=stylesheet href="style.css" type="text/css">
      6 </head>
      7 
      8 <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
      9 <table border=0 width=100%>
     10 <tr>
     11 <td><p class=tiny>Vorbisfile documentation</p></td>
     12 <td align=right><p class=tiny>vorbisfile version 1.2.0 - 20070723</p></td>
     13 </tr>
     14 </table>
     15 
     16 <h1>vorbisfile_example.c</h1>
     17 
     18 <p>
     19 The example program source:
     20 
     21 <br><br>
     22 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
     23 <tr bgcolor=#cccccc>
     24 	<td>
     25 <pre><b>
     26 #include &lt;stdio.h&gt;
     27 #include &lt;stdlib.h&gt;
     28 #include &lt;math.h&gt;
     29 #include "vorbis/codec.h"
     30 #include "vorbis/vorbisfile.h"
     31 
     32 #ifdef _WIN32
     33 #include &lt;io.h&gt;
     34 #include &lt;fcntl.h&gt;
     35 #endif
     36 
     37 char pcmout[4096];
     38 
     39 int main(int argc, char **argv){
     40   OggVorbis_File vf;
     41   int eof=0;
     42   int current_section;
     43 
     44 #ifdef _WIN32
     45   _setmode( _fileno( stdin ), _O_BINARY );
     46   _setmode( _fileno( stdout ), _O_BINARY );
     47 #endif
     48 
     49   if(ov_open_callbacks(stdin, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) {
     50       fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
     51       exit(1);
     52   }
     53 
     54   {
     55     char **ptr=ov_comment(&vf,-1)->user_comments;
     56     vorbis_info *vi=ov_info(&vf,-1);
     57     while(*ptr){
     58       fprintf(stderr,"%s\n",*ptr);
     59       ++ptr;
     60     }
     61     fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate);
     62     fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor);
     63   }
     64   
     65   while(!eof){
     66     long ret=ov_read(&vf,pcmout,sizeof(pcmout),0,2,1,&current_section);
     67     if (ret == 0) {
     68       /* EOF */
     69       eof=1;
     70     } else if (ret < 0) {
     71       /* error in the stream.  Not a problem, just reporting it in
     72 	 case we (the app) cares.  In this case, we don't. */
     73     } else {
     74       /* we don't bother dealing with sample rate changes, etc, but
     75 	 you'll have to */
     76       fwrite(pcmout,1,ret,stdout);
     77     }
     78   }
     79 
     80   ov_clear(&vf);
     81     
     82   fprintf(stderr,"Done.\n");
     83   return(0);
     84 }
     85 
     86 
87 88 89 90 91 92

93
94 95 96 97 98 99 100 101 102

copyright &copy; 2007 Xiph.org

http://www.xiph.org/ogg/vorbis/index.html">Ogg Vorbis
team (a] vorbis.org

Vorbisfile documentation

vorbisfile version 1.2.0 - 20070723

103 104 105 106 107