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