shithub: mp3dec

Download patch

ref: 2515e1a7b2bbcf880871b412238415edf388d719
parent: 0b0a94a8121dd0d11274274622b9c0ae05d58107
author: lieff <[email protected]>
date: Tue Mar 13 14:19:51 EDT 2018

add mp4 mode test

--- a/minimp3_test.c
+++ b/minimp3_test.c
@@ -70,7 +70,27 @@
     do
     {
         short pcm[MINIMP3_MAX_SAMPLES_PER_FRAME];
+#ifdef MP4_MODE
+        int free_format_bytes = 0, frame_size = 0;
+        i = mp3d_find_frame(buf_mp3, mp3_size, &free_format_bytes, &frame_size);
+        buf_mp3  += i;
+        mp3_size -= i;
+        if (i && !frame_size)
+        {
+            printf("warning: skipping %d bytes, frame_size=%d\n", i, frame_size);
+            continue;
+        }
+        if (frame_size > mp3_size)
+        {
+            printf("error: demux mp3 frame failed: i=%d, frame_size=%d\n", i, frame_size);
+            exit(1);
+        }
+        if (!frame_size)
+            break;
+        samples = mp3dec_decode_frame(&mp3d, buf_mp3, frame_size, pcm, &info);
+#else
         samples = mp3dec_decode_frame(&mp3d, buf_mp3, mp3_size, pcm, &info);
+#endif
         if (samples)
         {
             if (buf_ref && ref_size >= samples*info.channels*2)
@@ -111,6 +131,13 @@
         data_bytes = ftell(file_out) - 44;
         rewind(file_out);
         fwrite(wav_header(info.hz, info.channels, 16, data_bytes), 1, 44, file_out);
+    }
+#endif
+#ifdef MP4_MODE
+    if (!total_samples)
+    {
+        printf("error: mp4 test should decode some samples\n");
+        exit(1);
     }
 #endif
 }
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -6,6 +6,10 @@
 
 set -e
 
+echo testing mp4 mode...
+gcc -O2 -std=c89 -DMP4_MODE -o minimp3 minimp3_test.c -lm
+scripts/test_mp4_mode.sh
+
 echo testing coverage x86 w sse...
 gcc -coverage -O0 -m32 -std=c89 -msse2 -DMINIMP3_TEST -DMINIMP3_NO_WAV -o minimp3 minimp3_test.c -lm
 scripts/test.sh
--- /dev/null
+++ b/scripts/test_mp4_mode.sh
@@ -1,0 +1,20 @@
+_FILENAME=${0##*/}
+CUR_DIR=${0/${_FILENAME}}
+CUR_DIR=$(cd $(dirname ${CUR_DIR}); pwd)/$(basename ${CUR_DIR})/
+
+pushd $CUR_DIR/..
+
+APP=./minimp3
+
+set +e
+for i in vectors/l3-compl.bit vectors/l3-he_32khz.bit vectors/l3-he_44khz.bit vectors/l3-he_48khz.bit \
+vectors/l3-hecommon.bit vectors/l3-he_mode.bit vectors/l3-si.bit vectors/l3-si_block.bit vectors/l3-si_huff.bit \
+vectors/l3-sin1k0db.bit vectors/l3-test45.bit vectors/l3-test46.bit vectors/M2L3_bitrate_16_all.bit \
+vectors/M2L3_bitrate_22_all.bit vectors/M2L3_bitrate_24_all.bit vectors/M2L3_compl24.bit vectors/M2L3_noise.bit; do
+$APP $i ${i%.*}.pcm
+retval=$?
+echo $i exited with code=$retval
+if [ ! $retval -eq 0 ]; then
+  exit 1
+fi
+done