final beta 4 commit
[platform/upstream/libvorbis.git] / examples / seeking_example.c
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-2001             *
9  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
10
11  ********************************************************************
12
13  function: illustrate seeking, and test it too
14  last mod: $Id: seeking_example.c,v 1.7 2001/02/26 03:50:38 xiphmont Exp $
15
16  ********************************************************************/
17
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include "vorbis/codec.h"
21 #include "vorbis/vorbisfile.h"
22 #include "../lib/misc.h"
23
24 int main(){
25   OggVorbis_File ov;
26   int i;
27
28   /* open the file/pipe on stdin */
29   if(ov_open(stdin,&ov,NULL,-1)<0){
30     printf("Could not open input as an OggVorbis file.\n\n");
31     exit(1);
32   }
33   
34   /* print details about each logical bitstream in the input */
35   if(ov_seekable(&ov)){
36     double length=ov_time_total(&ov,-1);
37     printf("testing seeking to random places in %g seconds....\n",length);
38     for(i=0;i<100;i++){
39       double val=(double)rand()/RAND_MAX*length;
40       ov_time_seek(&ov,val);
41       printf("\r\t%d [%gs]...     ",i,val);
42       fflush(stdout);
43     }
44     
45     printf("\r                                   \nOK.\n\n");
46   }else{
47     printf("Standard input was not seekable.\n");
48   }
49
50   ov_clear(&ov);
51   return 0;
52 }
53
54
55
56
57
58
59
60
61
62
63
64
65