1 src/opusdec.c | 24 +++++++++++++++++++++---
2 src/opusenc.c | 17 +++++++----------
3 2 files changed, 134 insertions(+), 71 deletions(-)
5 diff --git a/src/opusdec.c b/src/opusdec.c
6 index 397ecb5..ade69fc 100644
12 # define I64FORMAT "I64d"
13 +# define ftello64(_x) _ftelli64((_x))
15 # define I64FORMAT "lld"
16 # define fopen_utf8(_x,_y) fopen((_x),(_y))
17 @@ -658,6 +659,7 @@ int main(int argc, char **argv)
18 {"force-wav", no_argument, NULL, 0},
19 {"packet-loss", required_argument, NULL, 0},
20 {"save-range", required_argument, NULL, 0},
21 + {"no-resample", no_argument, NULL, 0},
25 @@ -667,6 +669,7 @@ int main(int argc, char **argv)
28 ogg_int64_t audio_size=0;
29 + ogg_int64_t input_size=0;
30 double last_coded_seconds=0;
31 float loss_percent=-1;
33 @@ -681,6 +684,7 @@ int main(int argc, char **argv)
36 SpeexResamplerState *resampler=NULL;
37 + int no_resample = 0;
41 @@ -743,6 +747,9 @@ int main(int argc, char **argv)
42 } else if (strcmp(long_options[option_index].name,"rate")==0)
45 + } else if (strcmp(long_options[option_index].name,"no-resample")==0)
48 } else if (strcmp(long_options[option_index].name,"gain")==0)
50 manual_gain=atof (optarg);
51 @@ -824,6 +831,16 @@ int main(int argc, char **argv)
55 + /*detect input size*/
58 + struct _stat64 info;
59 + if(_fstati64(_fileno(fin), &info) == 0)
61 + input_size = info.st_size;
65 /* .opus files use the Ogg container to provide framing and timekeeping.
66 * http://tools.ietf.org/html/draft-terriberry-oggopus
67 * The easiest way to decode the Ogg container is to use libogg, so
68 @@ -914,7 +931,7 @@ int main(int argc, char **argv)
69 as described in the OggOpus spec. But for commandline tools
70 like opusdec it can be desirable to exactly preserve the original
71 sampling rate and duration, so we have a resampler here.*/
73 + if ((rate != 48000) && (!no_resample))
76 resampler = speex_resampler_init(channels, 48000, rate, 5, &err);
77 @@ -971,10 +988,11 @@ int main(int argc, char **argv)
78 /*Display a progress spinner while decoding.*/
79 static const char spinner[]="|/-\\";
80 double coded_seconds = (double)audio_size/(channels*rate*sizeof(short));
81 + double percent = (input_size>0) ? ((double)ftello64(fin))/((double)input_size) : 0.0;
82 if(coded_seconds>=last_coded_seconds+1){
83 - fprintf(stderr,"\r[%c] %02d:%02d:%02d", spinner[last_spin&3],
84 + fprintf(stderr,"\r[%c] %02d:%02d:%02d (%.f%%)", spinner[last_spin&3],
85 (int)(coded_seconds/3600),(int)(coded_seconds/60)%60,
86 - (int)(coded_seconds)%60);
87 + (int)(coded_seconds)%60,percent*100.0);
90 last_coded_seconds=coded_seconds;
91 diff --git a/src/opusenc.c b/src/opusenc.c
92 index 749760a..2b472b0 100644
95 @@ -954,6 +954,7 @@ int main(int argc, char **argv)
97 double coded_seconds=nb_encoded/(double)coding_rate;
98 double wall_time=(stop_time-start_time)+1e-6;
99 + double percent = 0.0;
101 static const char spinner[]="|/-\\";
103 @@ -961,20 +962,16 @@ int main(int argc, char **argv)
104 estbitrate=(total_bytes*8.0/coded_seconds)*tweight+
105 bitrate*(1.-tweight);
106 }else estbitrate=nbBytes*8*((double)coding_rate/frame_size);
107 + if(inopt.total_samples_per_channel>0){
108 + percent = ((double)nb_encoded) / ((double)inopt.total_samples_per_channel);
110 fprintf(stderr,"\r");
111 for(i=0;i<last_spin_len;i++)fprintf(stderr," ");
112 - if(inopt.total_samples_per_channel>0 && inopt.total_samples_per_channel<nb_encoded){
113 - snprintf(sbuf,54,"\r[%c] %02d%% ",spinner[last_spin&3],
114 - (int)floor(nb_encoded/(double)(inopt.total_samples_per_channel+inopt.skip)*100.));
116 - snprintf(sbuf,54,"\r[%c] ",spinner[last_spin&3]);
118 - last_spin_len=strlen(sbuf);
119 - snprintf(sbuf+last_spin_len,54-last_spin_len,
120 - "%02d:%02d:%02d.%02d %4.3gx realtime, %5.4gkbit/s",
121 + snprintf(sbuf,54,"\r[%c] %02d:%02d:%02d.%02d (%.f%%) %4.3gx realtime, %5.4gkbit/s",
122 + spinner[last_spin&3],
123 (int)(coded_seconds/3600),(int)(coded_seconds/60)%60,
124 (int)(coded_seconds)%60,(int)(coded_seconds*100)%100,
125 - coded_seconds/wall_time,
126 + percent*100.0,coded_seconds/wall_time,
128 fprintf(stderr,"%s",sbuf);