shithub: opus-tools

Download patch

ref: 2f00cc6cde61e434857305e4493df136044ef507
parent: c116d780fd2596474bc19048cdb27009454742d7
author: Mark Harris <mark.hsj@gmail.com>
date: Wed Sep 30 21:35:03 EDT 2015

opusenc: Fix display of percent progress

Fixes https://trac.xiph.org/ticket/2132, initial patch by rillke

--- a/src/audio-in.c
+++ b/src/audio-in.c
@@ -1039,8 +1039,8 @@
     opt->read_samples = read_resampled;
     opt->readdata = rs;
     if(opt->total_samples_per_channel)
-        opt->total_samples_per_channel = (int)((float)opt->total_samples_per_channel *
-            ((float)outfreq/(float)opt->rate));
+        opt->total_samples_per_channel = (opus_int64)
+            ((double)opt->total_samples_per_channel * ((double)outfreq/(double)opt->rate));
     opt->rate = outfreq;
 
     return 0;
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -1036,8 +1036,8 @@
         }else estbitrate=nbBytes*8*((double)coding_rate/frame_size);
         fprintf(stderr,"\r");
         for(i=0;i<last_spin_len;i++)fprintf(stderr," ");
-        if(inopt.total_samples_per_channel>0 && inopt.total_samples_per_channel<nb_encoded){
-          snprintf(sbuf,54,"\r[%c] %02d%% ",spinner[last_spin&3],
+        if(inopt.total_samples_per_channel>0 && nb_encoded<inopt.total_samples_per_channel){
+          snprintf(sbuf,54,"\r[%c] %2d%% ",spinner[last_spin&3],
           (int)floor(nb_encoded/(double)(inopt.total_samples_per_channel+inopt.skip)*100.));
         }else{
           snprintf(sbuf,54,"\r[%c] ",spinner[last_spin&3]);
@@ -1058,6 +1058,7 @@
   }
   stop_time = time(NULL);
 
+  if(last_spin_len)fprintf(stderr,"\r");
   for(i=0;i<last_spin_len;i++)fprintf(stderr," ");
   if(last_spin_len)fprintf(stderr,"\r");
 
@@ -1064,7 +1065,7 @@
   if(!quiet){
     double coded_seconds=nb_encoded/(double)coding_rate;
     double wall_time=(stop_time-start_time)+1e-6;
-    fprintf(stderr,"Encoding complete                                    \n");
+    fprintf(stderr,"Encoding complete\n");
     fprintf(stderr,"-----------------------------------------------------\n");
     fprintf(stderr,"       Encoded:");
     print_time(coded_seconds);