shithub: mp3dec

Download patch

ref: 2b07c4b1e659ce8fcbdd83f345aa793e17de0839
parent: e58f5242cb191c17943de3db3ae5cf9368d2cfa3
author: lieff <[email protected]>
date: Sun Jan 14 19:22:15 EST 2018

add MINIMP3_ONLY_MP3 define

--- a/README.md
+++ b/README.md
@@ -36,7 +36,7 @@
 | Keyj minimp3 | Current |
 | ------------ | ------- |
 | Fixed point  | Floating point |
-| source: 84kb | 68kb |
+| source: 84kb | 69kb |
 | no vector opts | SSE/NEON intrinsics |
 
 Below, you can find the benchmark and conformance test for keyj's minimp3: 
@@ -65,6 +65,7 @@
 First, we need to initialize the decoder structure:
 
 ```
+//#define MINIMP3_ONLY_MP3
 #define MINIMP3_IMPLEMENTATION
 #include "minimp3.h"
 ...
@@ -74,6 +75,7 @@
 
 Note that you must define ``MINIMP3_IMPLEMENTATION`` in exactly one source file.
 You can ``#include`` ``minimp3.h`` in as many files as you like.
+Also you can use ``MINIMP3_ONLY_MP3`` define to strip MP1/MP2 decoding code.
 
 Then. we decode the input stream frame-by-frame:
 
--- a/minimp3.h
+++ b/minimp3.h
@@ -290,6 +290,7 @@
     return HDR_TEST_PADDING(h) ? (HDR_IS_LAYER_1(h) ? 4 : 1) : 0;
 }
 
+#ifndef MINIMP3_ONLY_MP3
 static const L12_subband_alloc_t * L12_subband_alloc_table(const uint8_t *hdr, L12_scale_info *sci)
 {
     const L12_subband_alloc_t *alloc;
@@ -455,6 +456,7 @@
         }
     }
 }
+#endif
 
 static int L3_read_side_info(bs_t *bs, L3_gr_info_t *gr, const uint8_t *hdr)
 {
@@ -694,7 +696,6 @@
     }
 }
 
-
 static float L3_pow_43(int x)
 {
     static const float g_pow43[129] = {
@@ -1660,6 +1661,9 @@
         L3_save_reservoir(dec, &scratch);
     } else
     {
+#ifdef MINIMP3_ONLY_MP3
+        return 0;
+#else
         L12_scale_info sci[1];
         L12_read_scale_info(hdr, bs_frame, sci);
 
@@ -1666,7 +1670,7 @@
         memset(scratch.grbuf[0], 0, 576*2*sizeof(float));
         for (i = 0, igr = 0; igr < 3; igr++)
         {
-            if (12 == (i += L12_dequantize_granule(scratch.grbuf[0] + i, bs_frame, sci, info->layer|1)))
+            if (12 == (i += L12_dequantize_granule(scratch.grbuf[0] + i, bs_frame, sci, info->layer | 1)))
             {
                 i = 0;
                 L12_apply_scf_384(sci, sci->scf + igr, scratch.grbuf[0]);
@@ -1680,6 +1684,7 @@
                 return 0;
             }
         }
+#endif
     }
     return success*hdr_frame_samples(dec->header);
 }
--- a/minimp3_test.c
+++ b/minimp3_test.c
@@ -1,3 +1,4 @@
+#define MINIMP3_ONLY_MP3
 #define MINIMP3_IMPLEMENTATION
 #include "minimp3.h"
 #include <stdio.h>