1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
5 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
6 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
7 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
9 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
10 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
12 ********************************************************************
14 function: simple example decoder using vorbisidec
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. */
24 #include <vorbis/ivorbiscodec.h>
25 #include <vorbis/ivorbisfile.h>
27 #ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */
32 char pcmout
[4096]; /* take 4k out of the data segment, not the stack */
39 #ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
40 /* Beware the evil ifdef. We avoid these where we can, but this one we
41 cannot. Don't add any more, you'll probably go to hell if you do. */
42 _setmode( _fileno( stdin
), _O_BINARY
);
43 _setmode( _fileno( stdout
), _O_BINARY
);
46 if(ov_open(stdin
, &vf
, NULL
, 0) < 0) {
47 fprintf(stderr
,"Input does not appear to be an Ogg bitstream.\n");
51 /* Throw the comments plus a few lines about the bitstream we're
54 char **ptr
=ov_comment(&vf
,-1)->user_comments
;
55 vorbis_info
*vi
=ov_info(&vf
,-1);
57 fprintf(stderr
,"%s\n",*ptr
);
60 fprintf(stderr
,"\nBitstream is %d channel, %ldHz\n",vi
->channels
,vi
->rate
);
61 fprintf(stderr
,"\nDecoded length: %ld samples\n",
62 (long)ov_pcm_total(&vf
,-1));
63 fprintf(stderr
,"Encoded by: %s\n\n",ov_comment(&vf
,-1)->vendor
);
67 long ret
=ov_read(&vf
,pcmout
,sizeof(pcmout
),¤t_section
);
72 /* error in the stream. Not a problem, just reporting it in
73 case we (the app) cares. In this case, we don't. */
75 /* we don't bother dealing with sample rate changes, etc, but
77 fwrite(pcmout
,1,ret
,stdout
);
84 fprintf(stderr
,"Done.\n");