1 /********************************************************************
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. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
9 * by the XIPHOPHORUS Company http://www.xiph.org/ *
11 ********************************************************************
13 function: simple example decoder using vorbisfile
14 last mod: $Id: vorbisfile_example.c,v 1.10 2002/07/11 06:40:47 xiphmont Exp $
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. */
25 #include <vorbis/codec.h>
26 #include <vorbis/vorbisfile.h>
28 #ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */
33 char pcmout[4096]; /* take 4k out of the data segment, not the stack */
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 );
47 if(ov_open(stdin, &vf, NULL, 0) < 0) {
48 fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
52 /* Throw the comments plus a few lines about the bitstream we're
55 char **ptr=ov_comment(&vf,-1)->user_comments;
56 vorbis_info *vi=ov_info(&vf,-1);
58 fprintf(stderr,"%s\n",*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);
68 long ret=ov_read(&vf,pcmout,sizeof(pcmout),0,2,1,¤t_section);
73 /* error in the stream. Not a problem, just reporting it in
74 case we (the app) cares. In this case, we don't. */
76 /* we don't bother dealing with sample rate changes, etc, but
78 fwrite(pcmout,1,ret,stdout);
85 fprintf(stderr,"Done.\n");