seeking_example.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
  5. * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
  6. * PLEASE READ THESE TERMS DISTRIBUTING. *
  7. * *
  8. * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
  9. * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
  10. * http://www.xiph.org/ *
  11. * *
  12. ********************************************************************
  13. function: illustrate seeking, and test it too
  14. last mod: $Id: seeking_example.c,v 1.3.6.2 2000/09/07 01:02:21 jack Exp $
  15. ********************************************************************/
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <vorbis/codec.h>
  19. #include <vorbis/vorbisfile.h>
  20. int main(){
  21. OggVorbis_File ov;
  22. int i;
  23. /* open the file/pipe on stdin */
  24. if(ov_open(stdin,&ov,NULL,-1)==-1){
  25. printf("Could not open input as an OggVorbis file.\n\n");
  26. exit(1);
  27. }
  28. /* print details about each logical bitstream in the input */
  29. if(ov_seekable(&ov)){
  30. double length=ov_time_total(&ov,-1);
  31. printf("testing seeking to random places in %g seconds....\n",length);
  32. for(i=0;i<100;i++){
  33. double val=(double)rand()/RAND_MAX*length;
  34. ov_time_seek(&ov,val);
  35. printf("\r\t%d [%gs]... ",i,val);
  36. fflush(stdout);
  37. }
  38. printf("\r \nOK.\n\n");
  39. }else{
  40. printf("Standard input was not seekable.\n");
  41. }
  42. ov_clear(&ov);
  43. return 0;
  44. }