Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / libvorbis / examples / vorbisfile_example.c
blob3a95130461bdd0ba522f77ff9a2bb9194b7c4c83
1 /********************************************************************
2 * *
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
7 * *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
10 * *
11 ********************************************************************
13 function: simple example decoder using vorbisfile
14 last mod: $Id: vorbisfile_example.c 16037 2009-05-26 21:10:58Z xiphmont $
16 ********************************************************************/
18 /* Takes a vorbis bitstream from stdin and writes raw stereo PCM to
19 stdout using vorbisfile. Using vorbisfile is much simpler than
20 dealing with libvorbis. */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <math.h>
25 #include <vorbis/codec.h>
26 #include <vorbis/vorbisfile.h>
28 #ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */
29 #include <io.h>
30 #include <fcntl.h>
31 #endif
33 char pcmout[4096]; /* take 4k out of the data segment, not the stack */
35 int main(){
36 OggVorbis_File vf;
37 int eof=0;
38 int current_section;
40 #ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
41 /* Beware the evil ifdef. We avoid these where we can, but this one we
42 cannot. Don't add any more, you'll probably go to hell if you do. */
43 _setmode( _fileno( stdin ), _O_BINARY );
44 _setmode( _fileno( stdout ), _O_BINARY );
45 #endif
47 if(ov_open_callbacks(stdin, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) {
48 fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
49 exit(1);
52 /* Throw the comments plus a few lines about the bitstream we're
53 decoding */
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;
61 fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate);
62 fprintf(stderr,"\nDecoded length: %ld samples\n",
63 (long)ov_pcm_total(&vf,-1));
64 fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor);
67 while(!eof){
68 long ret=ov_read(&vf,pcmout,sizeof(pcmout),0,2,1,&current_section);
69 if (ret == 0) {
70 /* EOF */
71 eof=1;
72 } else if (ret < 0) {
73 /* error in the stream. Not a problem, just reporting it in
74 case we (the app) cares. In this case, we don't. */
75 } else {
76 /* we don't bother dealing with sample rate changes, etc, but
77 you'll have to*/
78 fwrite(pcmout,1,ret,stdout);
82 /* cleanup */
83 ov_clear(&vf);
85 fprintf(stderr,"Done.\n");
86 return(0);