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> 19The 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 <stdio.h> 27#include <stdlib.h> 28#include <math.h> 29#include "vorbis/codec.h" 30#include "vorbis/vorbisfile.h" 31 32#ifdef _WIN32 33#include <io.h> 34#include <fcntl.h> 35#endif 36 37char pcmout[4096]; 38 39int 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,¤t_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</b></pre> 87 </td> 88</tr> 89</table> 90 91 92<br><br> 93<hr noshade> 94<table border=0 width=100%> 95<tr valign=top> 96<td><p class=tiny>copyright © 2007 Xiph.org</p></td> 97<td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/index.html">Ogg Vorbis</a><br><a href="mailto:team@vorbis.org">team@vorbis.org</a></p></td> 98</tr><tr> 99<td><p class=tiny>Vorbisfile documentation</p></td> 100<td align=right><p class=tiny>vorbisfile version 1.2.0 - 20070723</p></td> 101</tr> 102</table> 103 104</body> 105 106</html> 107