shithub: mp3dec

Download patch

ref: 5904e0f2d75f9bc900224692f12793a9a00f78b5
parent: 8e8866ed91937b607b7cfce0ac7f220ecadb458f
author: lieff <[email protected]>
date: Tue Feb 4 14:43:32 EST 2020

mp3dec_ex: PSNR test may fail in case of seek at very end of file (to few samples readed) and max_diff=1,
so make some room to calculate RSNR and read at least 150 samples

--- a/minimp3_test.c
+++ b/minimp3_test.c
@@ -116,6 +116,7 @@
     } else if (MODE_STREAM == mode)
     {
         mp3dec_ex_t dec;
+        size_t readed;
         res = mp3dec_ex_open(&dec, input_file_name, MP3D_SEEK_TO_SAMPLE);
         info.samples = dec.samples;
         info.buffer  = malloc(dec.samples*sizeof(int16_t));
@@ -124,7 +125,7 @@
         if (position < 0)
         {
             srand(time(0));
-            position = info.samples ? (uint64_t)(info.samples - 1)*rand()/RAND_MAX : 0;
+            position = info.samples > 150 ? (uint64_t)(info.samples - 150)*rand()/RAND_MAX : 0;
             printf("info: seek to %d/%d\n", position, (int)info.samples);
         }
         if (position)
@@ -135,11 +136,16 @@
             ref_size -= skip_ref;
             mp3dec_ex_seek(&dec, position);
         }
-        mp3dec_ex_read(&dec, info.buffer, info.samples);
+        readed = mp3dec_ex_read(&dec, info.buffer, info.samples);
+        if (readed != info.samples)
+        {
+            printf("error: mp3dec_ex_read() readed less than expected\n");
+            exit(1);
+        }
         mp3dec_ex_close(&dec);
     } else
     {
-        printf("error: unknown mode");
+        printf("error: unknown mode\n");
         exit(1);
     }
     if (res)
@@ -146,7 +152,7 @@
     {
         if (ref_size)
         {
-            printf("error: file not found or read error");
+            printf("error: file not found or read error\n");
             exit(1);
         }
     }