ref: 475fa4a98c7f4be57e507f55a37ef3fce79692a6
parent: 4b6af2da93379da6ea4778889d678ee6cea964d8
author: Jean-Marc Valin <[email protected]>
date: Mon Feb 19 20:54:33 EST 2018
Fix divide-by-zeros in opus_demo stats code
--- a/src/opus_demo.c
+++ b/src/opus_demo.c
@@ -865,19 +865,28 @@
toggle = (toggle + use_inbandfec) & 1;
}
- /* Print out bitrate statistics */
- if(decode_only)
+ if(decode_only && count > 0)
frame_size = (int)(tot_samples / count);
count -= use_inbandfec;
- fprintf (stderr, "average bitrate: %7.3f kb/s\n",
- 1e-3*bits*sampling_rate/tot_samples);
- fprintf (stderr, "maximum bitrate: %7.3f kb/s\n",
- 1e-3*bits_max*sampling_rate/frame_size);
- if (!decode_only)
- fprintf (stderr, "active bitrate: %7.3f kb/s\n",
- 1e-3*bits_act*sampling_rate/(1e-15+frame_size*(double)count_act));
- fprintf (stderr, "bitrate standard deviation: %7.3f kb/s\n",
- 1e-3*sqrt(bits2/count - bits*bits/(count*(double)count))*sampling_rate/frame_size);
+ if (tot_samples >= 1 && count > 0 && frame_size)
+ {
+ /* Print out bitrate statistics */
+ double var;
+ fprintf (stderr, "average bitrate: %7.3f kb/s\n",
+ 1e-3*bits*sampling_rate/tot_samples);
+ fprintf (stderr, "maximum bitrate: %7.3f kb/s\n",
+ 1e-3*bits_max*sampling_rate/frame_size);
+ if (!decode_only)
+ fprintf (stderr, "active bitrate: %7.3f kb/s\n",
+ 1e-3*bits_act*sampling_rate/(1e-15+frame_size*(double)count_act));
+ var = bits2/count - bits*bits/(count*(double)count);
+ if (var < 0)
+ var = 0;
+ fprintf (stderr, "bitrate standard deviation: %7.3f kb/s\n",
+ 1e-3*sqrt(var)*sampling_rate/frame_size);
+ } else {
+ fprintf(stderr, "bitrate statistics are undefined\n");
+ }
silk_TimerSave("opus_timing.txt");
opus_encoder_destroy(enc);
opus_decoder_destroy(dec);