ref: 263ac5294368475b8aebe1a1e8b616cb69499ac7
parent: cfa88477ffd138e8245c310aa10224b4f7b7ed3b
author: lieff <lieff@users.noreply.github.com>
date: Tue Jan 30 09:55:07 EST 2018
c89 compatibility
--- a/minimp3.h
+++ b/minimp3.h
@@ -29,7 +29,7 @@
#ifdef __cplusplus
extern "C" {
-#endif //__cplusplus
+#endif
void mp3dec_init(mp3dec_t *dec);
int mp3dec_decode_frame(mp3dec_t *dec, const unsigned char *mp3, int mp3_bytes, short *pcm, mp3dec_frame_info_t *info);
@@ -36,7 +36,7 @@
#ifdef __cplusplus
}
-#endif //__cplusplus
+#endif
#ifdef MINIMP3_IMPLEMENTATION
@@ -44,10 +44,10 @@
#include <string.h>
#include <stdint.h>
-#define MAX_FREE_FORMAT_FRAME_SIZE 2304 // more than ISO spec's
+#define MAX_FREE_FORMAT_FRAME_SIZE 2304 /* more than ISO spec's */
#define MAX_FRAME_SYNC_MATCHES 10
-#define MAX_L3_FRAME_PAYLOAD_BYTES MAX_FREE_FORMAT_FRAME_SIZE // MUST be >= 320000/8/32000*1152 = 1440
+#define MAX_L3_FRAME_PAYLOAD_BYTES MAX_FREE_FORMAT_FRAME_SIZE /* MUST be >= 320000/8/32000*1152 = 1440 */
#define MAX_BITRESERVOIR_BYTES 511
#define SHORT_BLOCK_TYPE 2
@@ -81,7 +81,7 @@
#define MINIMP3_MAX(a, b) ((a) < (b) ? (b) : (a))
#if !defined(MINIMP3_ONLY_SIMD) && (defined(_M_X64) || defined(_M_ARM64) || defined(__x86_64__) || defined(__aarch64__))
-// x64 always have SSE2, arm64 always have neon, no need for generic code
+/* x64 always have SSE2, arm64 always have neon, no need for generic code */
#define MINIMP3_ONLY_SIMD
#endif
@@ -145,7 +145,7 @@
if (CPUInfo[0] > 0)
{
minimp3_cpuid(CPUInfo, 1);
- g_have_simd = (CPUInfo[3] & (1 << 26)) + 1; // SSE2
+ g_have_simd = (CPUInfo[3] & (1 << 26)) + 1; /* SSE2 */
return g_have_simd - 1;
}
#ifdef MINIMP3_TEST
@@ -170,7 +170,7 @@
# define VREV(x) vrev64q_f32(x)
typedef float32x4_t f4;
static int have_simd()
-{ // TODO: detect neon for !MINIMP3_ONLY_SIMD
+{ /* TODO: detect neon for !MINIMP3_ONLY_SIMD */
return 1;
}
#else
@@ -297,7 +297,7 @@
int frame_bytes = hdr_frame_samples(h) * hdr_bitrate_kbps(h) * 125 / hdr_sample_rate_hz(h);
if (HDR_IS_LAYER_1(h))
{
- frame_bytes &= ~3; //Slot align
+ frame_bytes &= ~3; /* slot align */
}
return frame_bytes ? frame_bytes : free_format_size;
}
@@ -329,7 +329,7 @@
static const L12_subband_alloc_t g_alloc_L2M1[] = { { 0, 4, 3 }, { 16, 4, 8 }, { 32, 3, 12 }, { 40, 2, 7 } };
int sample_rate_idx = HDR_GET_SAMPLE_RATE(hdr);
unsigned kbps = hdr_bitrate_kbps(hdr) >> (mode != MODE_MONO);
- if (!kbps) // free-format
+ if (!kbps) /* free-format */
{
kbps = 192;
}
@@ -445,8 +445,8 @@
}
} else
{
- unsigned mod = (2 << (ba - 17)) + 1; // 3, 5, 9
- unsigned code = get_bits(bs, mod + 2 - (mod >> 3)); // 5, 7, 10
+ unsigned mod = (2 << (ba - 17)) + 1; /* 3, 5, 9 */
+ unsigned code = get_bits(bs, mod + 2 - (mod >> 3)); /* 5, 7, 10 */
for (k = 0; k < group_size; k++, code /= mod)
{
dst[k] = (float)((int)(code % mod - mod/2));
@@ -1274,7 +1274,7 @@
x6 = VMUL_S(VADD(x6, x7), 0.70710677f);
x7 = VADD(x7, xt);
x3 = VMUL_S(VADD(x3, x4), 0.70710677f);
- x5 = VSUB(x5, VMUL_S(x7, 0.198912367f)); // rotate by PI/8
+ x5 = VSUB(x5, VMUL_S(x7, 0.198912367f)); /* rotate by PI/8 */
x7 = VADD(x7, VMUL_S(x5, 0.382683432f));
x5 = VSUB(x5, VMUL_S(x7, 0.198912367f));
x0 = VSUB(xt, x6); xt = VADD(xt, x6);
@@ -1360,7 +1360,7 @@
x6 = (x6 + x7)*0.70710677f;
x7 = x7 + xt;
x3 = (x3 + x4)*0.70710677f;
- x5 -= x7*0.198912367f; // rotate by PI/8
+ x5 -= x7*0.198912367f; /* rotate by PI/8 */
x7 += x5*0.382683432f;
x5 -= x7*0.198912367f;
x0 = xt - x6; xt += x6;
@@ -1390,7 +1390,7 @@
static short mp3d_scale_pcm(float sample)
{
int s = (int)(sample + .5f);
- s -= (s < 0); // away from zero, to be compliant
+ s -= (s < 0); /* away from zero, to be compliant */
if (s > 32767) return (short) 32767;
if (s < -32768) return (short)-32768;
return (short)s;
@@ -1715,4 +1715,4 @@
}
return success*hdr_frame_samples(dec->header);
}
-#endif //MINIMP3_IMPLEMENTATION
+#endif /*MINIMP3_IMPLEMENTATION*/
--- a/minimp3_test.c
+++ b/minimp3_test.c
@@ -1,10 +1,11 @@
-//#define MINIMP3_ONLY_MP3
-//#define MINIMP3_ONLY_SIMD
+/*#define MINIMP3_ONLY_MP3*/
+/*#define MINIMP3_ONLY_SIMD*/
#define MINIMP3_IMPLEMENTATION
#include "minimp3.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
+#include <strings.h>
#ifndef MINIMP3_NO_WAV
static char *wav_header(int hz, int ch, int bips, int data_bytes)
@@ -13,8 +14,8 @@
unsigned long nAvgBytesPerSec = bips*ch*hz >> 3;
unsigned int nBlockAlign = bips*ch >> 3;
- *(int * )(hdr + 0x04) = 44 + data_bytes - 8; // File size - 8
- *(short *)(hdr + 0x14) = 1; // Integer PCM format
+ *(int * )(hdr + 0x04) = 44 + data_bytes - 8; /* File size - 8 */
+ *(short *)(hdr + 0x14) = 1; /* Integer PCM format */
*(short *)(hdr + 0x16) = ch;
*(int * )(hdr + 0x18) = hz;
*(int * )(hdr + 0x1C) = nAvgBytesPerSec;
@@ -45,7 +46,7 @@
static void decode_file(FILE *file_mp3, FILE *file_ref, FILE *file_out, const int wave_out)
{
static mp3dec_t mp3d;
- mp3dec_frame_info_t info = {};
+ mp3dec_frame_info_t info = { 0, };
int i, data_bytes, samples, total_samples = 0, maxdiff = 0, mp3_size, ref_size;
double MSE = 0.0, psnr;
unsigned char *buf_mp3 = preload(file_mp3, &mp3_size), *buf_ref = preload(file_ref, &ref_size);
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -6,10 +6,10 @@
set -e
-gcc -coverage -O0 -m32 -msse2 -DMINIMP3_TEST -DMINIMP3_NO_WAV -o minimp3 minimp3_test.c -lm
+gcc -coverage -O0 -m32 -std=c89 -msse2 -DMINIMP3_TEST -DMINIMP3_NO_WAV -o minimp3 minimp3_test.c -lm
scripts/test.sh
gcov minimp3_test.c
-gcc -O2 -g -Wall -Wextra -Wmissing-prototypes -Werror -fno-asynchronous-unwind-tables -fno-stack-protector \
+gcc -O2 -g -std=c89 -Wall -Wextra -Wmissing-prototypes -Werror -fno-asynchronous-unwind-tables -fno-stack-protector \
-ffunction-sections -fdata-sections -Wl,--gc-sections -o minimp3 minimp3_test.c -lm
scripts/test.sh