Merge tag 'v1.3.7' into tizen
[platform/upstream/libvorbis.git] / examples / seeking_example.c
index cbd5a9b..9588680 100644 (file)
@@ -6,12 +6,11 @@
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
- * by the Xiph.Org Foundation http://www.xiph.org/                  *
+ * by the Xiph.Org Foundation https://xiph.org/                     *
  *                                                                  *
  ********************************************************************
 
  function: illustrate seeking, and test it too
- last mod: $Id$
 
  ********************************************************************/
 
@@ -127,7 +126,7 @@ int main(){
         exit(1);
       }
     }
-    
+
     /* because we want to do sample-level verification that the seek
        does what it claimed, decode the entire file into memory */
     pcmlength=ov_pcm_total(&ov,-1);
@@ -148,12 +147,12 @@ int main(){
       fprintf(stderr,"\rloading.... [%ld left]              ",
               (long)((pcmlength>>hs)*2-i));
     }
-    
+
     {
       ogg_int64_t length=ov.end;
       fprintf(stderr,"\rtesting raw seeking to random places in %ld bytes....\n",
              (long)length);
-    
+
       for(i=0;i<1000;i++){
         ogg_int64_t val=(double)rand()/RAND_MAX*length;
         fprintf(stderr,"\r\t%d [raw position %ld]...     ",i,(long)val);
@@ -172,9 +171,9 @@ int main(){
     {
       fprintf(stderr,"testing pcm page seeking to random places in %ld samples....\n",
              (long)pcmlength);
-    
+
       for(i=0;i<1000;i++){
-        ogg_int64_t val=(double)rand()/RAND_MAX*pcmlength;
+        ogg_int64_t val= i==0?(ogg_int64_t)0:(double)rand()/RAND_MAX*pcmlength;
         fprintf(stderr,"\r\t%d [pcm position %ld]...     ",i,(long)val);
         ret=ov_pcm_seek_page(&ov,val);
         if(ret<0){
@@ -189,11 +188,10 @@ int main(){
 
     fprintf(stderr,"\r");
     {
-      fprintf(stderr,"testing pcm exact seeking to random places in %ld samples....\n",
-             (long)pcmlength);
-    
+      fprintf(stderr,"testing pcm exact seeking to random places in %f seconds....\n",
+             timelength);
       for(i=0;i<1000;i++){
-        ogg_int64_t val=(double)rand()/RAND_MAX*pcmlength;
+        ogg_int64_t val= i==0?(ogg_int64_t)0:(double)rand()/RAND_MAX*pcmlength;
         fprintf(stderr,"\r\t%d [pcm position %ld]...     ",i,(long)val);
         ret=ov_pcm_seek(&ov,val);
         if(ret<0){
@@ -215,7 +213,7 @@ int main(){
     {
       fprintf(stderr,"testing time page seeking to random places in %f seconds....\n",
              timelength);
-    
+
       for(i=0;i<1000;i++){
         double val=(double)rand()/RAND_MAX*timelength;
         fprintf(stderr,"\r\t%d [time position %f]...     ",i,val);
@@ -234,7 +232,7 @@ int main(){
     {
       fprintf(stderr,"testing time exact seeking to random places in %f seconds....\n",
              timelength);
-    
+
       for(i=0;i<1000;i++){
         double val=(double)rand()/RAND_MAX*timelength;
         fprintf(stderr,"\r\t%d [time position %f]...     ",i,val);
@@ -253,7 +251,7 @@ int main(){
 
       }
     }
-    
+
     fprintf(stderr,"\r                                           \nOK.\n\n");