annotate src/libvorbis-1.3.3/examples/vorbisfile_example.c @ 148:b4bfdf10c4b3

Update Win64 capnp builds to v0.6
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 22 May 2017 18:56:49 +0100
parents 98c1576536ae
children
rev   line source
cannam@86 1 /********************************************************************
cannam@86 2 * *
cannam@86 3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
cannam@86 4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
cannam@86 5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
cannam@86 6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
cannam@86 7 * *
cannam@86 8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
cannam@86 9 * by the Xiph.Org Foundation http://www.xiph.org/ *
cannam@86 10 * *
cannam@86 11 ********************************************************************
cannam@86 12
cannam@86 13 function: simple example decoder using vorbisfile
cannam@86 14 last mod: $Id: vorbisfile_example.c 16328 2009-07-24 01:51:10Z xiphmont $
cannam@86 15
cannam@86 16 ********************************************************************/
cannam@86 17
cannam@86 18 /* Takes a vorbis bitstream from stdin and writes raw stereo PCM to
cannam@86 19 stdout using vorbisfile. Using vorbisfile is much simpler than
cannam@86 20 dealing with libvorbis. */
cannam@86 21
cannam@86 22 #include <stdio.h>
cannam@86 23 #include <stdlib.h>
cannam@86 24 #include <math.h>
cannam@86 25 #include <vorbis/codec.h>
cannam@86 26 #include <vorbis/vorbisfile.h>
cannam@86 27
cannam@86 28 #ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */
cannam@86 29 #include <io.h>
cannam@86 30 #include <fcntl.h>
cannam@86 31 #endif
cannam@86 32
cannam@86 33 char pcmout[4096]; /* take 4k out of the data segment, not the stack */
cannam@86 34
cannam@86 35 int main(){
cannam@86 36 OggVorbis_File vf;
cannam@86 37 int eof=0;
cannam@86 38 int current_section;
cannam@86 39
cannam@86 40 #ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
cannam@86 41 /* Beware the evil ifdef. We avoid these where we can, but this one we
cannam@86 42 cannot. Don't add any more, you'll probably go to hell if you do. */
cannam@86 43 _setmode( _fileno( stdin ), _O_BINARY );
cannam@86 44 _setmode( _fileno( stdout ), _O_BINARY );
cannam@86 45 #endif
cannam@86 46
cannam@86 47 if(ov_open_callbacks(stdin, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) {
cannam@86 48 fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
cannam@86 49 exit(1);
cannam@86 50 }
cannam@86 51
cannam@86 52 /* Throw the comments plus a few lines about the bitstream we're
cannam@86 53 decoding */
cannam@86 54 {
cannam@86 55 char **ptr=ov_comment(&vf,-1)->user_comments;
cannam@86 56 vorbis_info *vi=ov_info(&vf,-1);
cannam@86 57 while(*ptr){
cannam@86 58 fprintf(stderr,"%s\n",*ptr);
cannam@86 59 ++ptr;
cannam@86 60 }
cannam@86 61 fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate);
cannam@86 62 fprintf(stderr,"\nDecoded length: %ld samples\n",
cannam@86 63 (long)ov_pcm_total(&vf,-1));
cannam@86 64 fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor);
cannam@86 65 }
cannam@86 66
cannam@86 67 while(!eof){
cannam@86 68 long ret=ov_read(&vf,pcmout,sizeof(pcmout),0,2,1,&current_section);
cannam@86 69 if (ret == 0) {
cannam@86 70 /* EOF */
cannam@86 71 eof=1;
cannam@86 72 } else if (ret < 0) {
cannam@86 73 if(ret==OV_EBADLINK){
cannam@86 74 fprintf(stderr,"Corrupt bitstream section! Exiting.\n");
cannam@86 75 exit(1);
cannam@86 76 }
cannam@86 77
cannam@86 78 /* some other error in the stream. Not a problem, just reporting it in
cannam@86 79 case we (the app) cares. In this case, we don't. */
cannam@86 80 } else {
cannam@86 81 /* we don't bother dealing with sample rate changes, etc, but
cannam@86 82 you'll have to*/
cannam@86 83 fwrite(pcmout,1,ret,stdout);
cannam@86 84 }
cannam@86 85 }
cannam@86 86
cannam@86 87 /* cleanup */
cannam@86 88 ov_clear(&vf);
cannam@86 89
cannam@86 90 fprintf(stderr,"Done.\n");
cannam@86 91 return(0);
cannam@86 92 }