home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Extras / Ogg Vorbis / vorbis_sdk / examples / vorbis / chaining_example.c next >
Encoding:
C/C++ Source or Header  |  2002-07-10  |  2.7 KB  |  72 lines

  1. /********************************************************************
  2.  *                                                                  *
  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.       *
  7.  *                                                                  *
  8.  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
  9.  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
  10.  *                                                                  *
  11.  ********************************************************************
  12.  
  13.  function: illustrate simple use of chained bitstream and vorbisfile.a
  14.  last mod: $Id: chaining_example.c,v 1.17 2002/07/11 06:40:47 xiphmont Exp $
  15.  
  16.  ********************************************************************/
  17.  
  18. #include <stdlib.h>
  19. #include <vorbis/codec.h>
  20. #include <vorbis/vorbisfile.h>
  21.  
  22. #ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */
  23. #include <io.h>
  24. #include <fcntl.h>
  25. #endif
  26.  
  27. int main(){
  28.   OggVorbis_File ov;
  29.   int i;
  30.  
  31. #ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
  32.   /* Beware the evil ifdef. We avoid these where we can, but this one we 
  33.      cannot. Don't add any more, you'll probably go to hell if you do. */
  34.   _setmode( _fileno( stdin ), _O_BINARY );
  35.   _setmode( _fileno( stdout ), _O_BINARY );
  36. #endif
  37.  
  38.   /* open the file/pipe on stdin */
  39.   if(ov_open(stdin,&ov,NULL,-1)<0){
  40.     printf("Could not open input as an OggVorbis file.\n\n");
  41.     exit(1);
  42.   }
  43.   
  44.   /* print details about each logical bitstream in the input */
  45.   if(ov_seekable(&ov)){
  46.     printf("Input bitstream contained %ld logical bitstream section(s).\n",
  47.        ov_streams(&ov));
  48.     printf("Total bitstream playing time: %ld seconds\n\n",
  49.        (long)ov_time_total(&ov,-1));
  50.  
  51.   }else{
  52.     printf("Standard input was not seekable.\n"
  53.        "First logical bitstream information:\n\n");
  54.   }
  55.  
  56.   for(i=0;i<ov_streams(&ov);i++){
  57.     vorbis_info *vi=ov_info(&ov,i);
  58.     printf("\tlogical bitstream section %d information:\n",i+1);
  59.     printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
  60.        vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
  61.        ov_serialnumber(&ov,i));
  62.     printf("\t\theader length: %ld bytes\n",(long)
  63.        (ov.dataoffsets[i]-ov.offsets[i]));
  64.     printf("\t\tcompressed length: %ld bytes\n",(long)(ov_raw_total(&ov,i)));
  65.     printf("\t\tplay time: %lds\n",(long)ov_time_total(&ov,i));
  66.   }
  67.  
  68.   ov_clear(&ov);
  69.   return 0;
  70. }
  71.  
  72.