X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fvorbisfile_example.c;h=4c27fa47e784f51db39553e3dd8ad5276051e4ce;hb=d8ffc480787fcd8b5bb7203d6e0acf3bbfb2dd02;hp=ff7d9152669be72a460605e22108b7b25a15555a;hpb=6375a47d7d60689ffcb47b570bd75c1bb2f3a7a1;p=platform%2Fupstream%2Flibvorbis.git diff --git a/examples/vorbisfile_example.c b/examples/vorbisfile_example.c index ff7d915..4c27fa4 100644 --- a/examples/vorbisfile_example.c +++ b/examples/vorbisfile_example.c @@ -1,18 +1,17 @@ /******************************************************************** * * - * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY * - * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. * - * PLEASE READ THESE TERMS DISTRIBUTING. * + * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * - * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 * - * by Monty and The XIPHOPHORUS Company * - * http://www.xiph.org/ * + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * + * by the Xiph.Org Foundation http://www.xiph.org/ * * * ******************************************************************** function: simple example decoder using vorbisfile - last mod: $Id: vorbisfile_example.c,v 1.1 2000/06/19 10:05:57 xiphmont Exp $ + last mod: $Id$ ********************************************************************/ @@ -23,8 +22,8 @@ #include #include #include -#include "vorbis/codec.h" -#include "vorbis/vorbisfile.h" +#include +#include #ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */ #include @@ -33,7 +32,7 @@ char pcmout[4096]; /* take 4k out of the data segment, not the stack */ -int main(int argc, char **argv){ +int main(){ OggVorbis_File vf; int eof=0; int current_section; @@ -45,7 +44,7 @@ int main(int argc, char **argv){ _setmode( _fileno( stdout ), _O_BINARY ); #endif - if(ov_open(stdin, &vf, NULL, 0) < 0) { + if(ov_open_callbacks(stdin, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) { fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n"); exit(1); } @@ -60,25 +59,28 @@ int main(int argc, char **argv){ ++ptr; } fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate); + fprintf(stderr,"\nDecoded length: %ld samples\n", + (long)ov_pcm_total(&vf,-1)); fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor); } while(!eof){ long ret=ov_read(&vf,pcmout,sizeof(pcmout),0,2,1,¤t_section); - switch(ret){ - case 0: + if (ret == 0) { /* EOF */ eof=1; - break; - case -1: - /* error in the stream. Not a problem, just reporting it in - case we (the app) cares. In this case, we don't. */ - break; - default: + } else if (ret < 0) { + if(ret==OV_EBADLINK){ + fprintf(stderr,"Corrupt bitstream section! Exiting.\n"); + exit(1); + } + + /* some other error in the stream. Not a problem, just reporting it in + case we (the app) cares. In this case, we don't. */ + } else { /* we don't bother dealing with sample rate changes, etc, but - you'll have to*/ + you'll have to*/ fwrite(pcmout,1,ret,stdout); - break; } } @@ -88,4 +90,3 @@ int main(int argc, char **argv){ fprintf(stderr,"Done.\n"); return(0); } -