chaining_example.c 2.7 KB

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