summaryrefslogtreecommitdiff
path: root/ivorbisfile_example.c
diff options
context:
space:
mode:
authorMonty <xiphmont@xiph.org>2002-09-02 22:13:55 +0000
committerMonty <xiphmont@xiph.org>2002-09-02 22:13:55 +0000
commit56fbebdcf71ea7c8e64cb18ac3a78e5834134fa3 (patch)
tree55b767ac2280049dd1d7cc8d36cb7589987d92eb /ivorbisfile_example.c
downloadtremor-56fbebdcf71ea7c8e64cb18ac3a78e5834134fa3.tar.gz
Put root level of Tremor in CVS
git-svn-id: https://svn.xiph.org/trunk/Tremor@3890 0101bb08-14d6-0310-b084-bc0e0c8e3800
Diffstat (limited to 'ivorbisfile_example.c')
-rw-r--r--ivorbisfile_example.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/ivorbisfile_example.c b/ivorbisfile_example.c
new file mode 100644
index 0000000..55362f6
--- /dev/null
+++ b/ivorbisfile_example.c
@@ -0,0 +1,83 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
+ * *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
+ * ALL REDISTRIBUTION RIGHTS RESERVED. *
+ * *
+ ********************************************************************
+
+ function: simple example decoder using vorbisidec
+
+ ********************************************************************/
+
+/* Takes a vorbis bitstream from stdin and writes raw stereo PCM to
+ stdout using vorbisfile. Using vorbisfile is much simpler than
+ dealing with libvorbis. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <vorbis/ivorbiscodec.h>
+#include <vorbis/ivorbisfile.h>
+
+#ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */
+#include <io.h>
+#include <fcntl.h>
+#endif
+
+char pcmout[4096]; /* take 4k out of the data segment, not the stack */
+
+int main(){
+ OggVorbis_File vf;
+ int eof=0;
+ int current_section;
+
+#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
+ /* Beware the evil ifdef. We avoid these where we can, but this one we
+ cannot. Don't add any more, you'll probably go to hell if you do. */
+ _setmode( _fileno( stdin ), _O_BINARY );
+ _setmode( _fileno( stdout ), _O_BINARY );
+#endif
+
+ if(ov_open(stdin, &vf, NULL, 0) < 0) {
+ fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
+ exit(1);
+ }
+
+ /* Throw the comments plus a few lines about the bitstream we're
+ decoding */
+ {
+ char **ptr=ov_comment(&vf,-1)->user_comments;
+ vorbis_info *vi=ov_info(&vf,-1);
+ while(*ptr){
+ fprintf(stderr,"%s\n",*ptr);
+ ++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),&current_section);
+ if (ret == 0) {
+ /* EOF */
+ eof=1;
+ } else if (ret < 0) {
+ /* 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*/
+ fwrite(pcmout,1,ret,stdout);
+ }
+ }
+
+ /* cleanup */
+ ov_clear(&vf);
+
+ fprintf(stderr,"Done.\n");
+ return(0);
+}