ref: 553167ac25b6b2d81a922b926602eb369a1a3ef6
parent: 4ca9d6e7768e0ab1cd69bf10761cd568f8d26641
author: lieff <[email protected]>
date: Wed Aug 22 14:27:10 EDT 2018
use stdint.h types, int16_t instead of short etc
--- a/minimp3.h
+++ b/minimp3.h
@@ -6,6 +6,7 @@
This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <stdint.h>
#define MINIMP3_MAX_SAMPLES_PER_FRAME (1152*2)
@@ -27,10 +28,10 @@
void mp3dec_init(mp3dec_t *dec);
#ifndef MINIMP3_FLOAT_OUTPUT
-typedef short mp3d_sample_t;
+typedef int16_t mp3d_sample_t;
#else
typedef float mp3d_sample_t;
-void mp3dec_f32_to_s16(const float *in, short *out, int num_samples);
+void mp3dec_f32_to_s16(const float *in, int16_t *out, int num_samples);
#endif
int mp3dec_decode_frame(mp3dec_t *dec, const uint8_t *mp3, int mp3_bytes, mp3d_sample_t *pcm, mp3dec_frame_info_t *info);
@@ -42,7 +43,6 @@
#include <stdlib.h>
#include <string.h>
-#include <stdint.h>
#define MAX_FREE_FORMAT_FRAME_SIZE 2304 /* more than ISO spec's */
#define MAX_FRAME_SYNC_MATCHES 10
@@ -764,7 +764,7 @@
{
int tab_num = gr_info->table_select[ireg];
int sfb_cnt = gr_info->region_count[ireg++];
- const short *codebook = tabs + tabindex[tab_num];
+ const int16_t *codebook = tabs + tabindex[tab_num];
int linbits = g_linbits[tab_num];
do
{
@@ -1371,11 +1371,11 @@
}
#ifndef MINIMP3_FLOAT_OUTPUT
-static short mp3d_scale_pcm(float sample)
+static int16_t mp3d_scale_pcm(float sample)
{
- if (sample >= 32766.5) return (short) 32767;
- if (sample <= -32767.5) return (short)-32768;
- short s = (short)(sample + .5f);
+ if (sample >= 32766.5) return (int16_t) 32767;
+ if (sample <= -32767.5) return (int16_t)-32768;
+ int16_t s = (int16_t)(sample + .5f);
s -= (s < 0); /* away from zero, to be compliant */
return s;
}
@@ -1743,7 +1743,7 @@
}
#ifdef MINIMP3_FLOAT_OUTPUT
-void mp3dec_f32_to_s16(const float *in, short *out, int num_samples)
+void mp3dec_f32_to_s16(const float *in, int16_t *out, int num_samples)
{
if(num_samples > 0)
{
@@ -1786,16 +1786,16 @@
#endif
}
#endif
- for(;i < num_samples;i++)
+ for(; i < num_samples; i++)
{
float sample = in[i] * 32768.0f;
- if(sample >= 32766.5)
- out[i] = (short) 32767;
+ if (sample >= 32766.5)
+ out[i] = (int16_t) 32767;
else if (sample <= -32767.5)
- out[i] = (short)-32768;
+ out[i] = (int16_t)-32768;
else
{
- short s = (short)(sample + .5f);
+ int16_t s = (int16_t)(sample + .5f);
s -= (s < 0); /* away from zero, to be compliant */
out[i] = s;
}
--- a/minimp3_test.c
+++ b/minimp3_test.c
@@ -13,9 +13,9 @@
#include <strings.h>
#endif
-static unsigned short read16le(const void *p)
+static int16_t read16le(const void *p)
{
- const unsigned char *src = (const unsigned char *)p;
+ const uint8_t *src = (const uint8_t *)p;
return ((src[0]) << 0) | ((src[1]) << 8);
}
@@ -26,14 +26,14 @@
unsigned long nAvgBytesPerSec = bips*ch*hz >> 3;
unsigned int nBlockAlign = bips*ch >> 3;
- *(int * )(void*)(hdr + 0x04) = 44 + data_bytes - 8; /* File size - 8 */
- *(short *)(void*)(hdr + 0x14) = 1; /* Integer PCM format */
- *(short *)(void*)(hdr + 0x16) = ch;
- *(int * )(void*)(hdr + 0x18) = hz;
- *(int * )(void*)(hdr + 0x1C) = nAvgBytesPerSec;
- *(short *)(void*)(hdr + 0x20) = nBlockAlign;
- *(short *)(void*)(hdr + 0x22) = bips;
- *(int * )(void*)(hdr + 0x28) = data_bytes;
+ *(int32_t *)(void*)(hdr + 0x04) = 44 + data_bytes - 8; /* File size - 8 */
+ *(int16_t *)(void*)(hdr + 0x14) = 1; /* Integer PCM format */
+ *(int16_t *)(void*)(hdr + 0x16) = ch;
+ *(int32_t *)(void*)(hdr + 0x18) = hz;
+ *(int32_t *)(void*)(hdr + 0x1C) = nAvgBytesPerSec;
+ *(int16_t *)(void*)(hdr + 0x20) = nBlockAlign;
+ *(int16_t *)(void*)(hdr + 0x22) = bips;
+ *(int32_t *)(void*)(hdr + 0x28) = data_bytes;
return hdr;
}
#endif
@@ -112,7 +112,7 @@
exit(1);
}
#ifdef MINIMP3_FLOAT_OUTPUT
- int16_t *buffer = malloc(info.samples*sizeof(short));
+ int16_t *buffer = malloc(info.samples*sizeof(int16_t));
mp3dec_f32_to_s16(info.buffer, buffer, info.samples);
free(info.buffer);
#else
@@ -130,7 +130,7 @@
int max_samples = MINIMP3_MIN((size_t)ref_size/2, info.samples);
for (i = 0; i < max_samples; i++)
{
- int MSEtemp = abs((int)buffer[i] - (int)(short)read16le(&buf_ref[i*sizeof(short)]));
+ int MSEtemp = abs((int)buffer[i] - (int)(int16_t)read16le(&buf_ref[i*sizeof(int16_t)]));
if (MSEtemp > maxdiff)
maxdiff = MSEtemp;
MSE += (float)MSEtemp*(float)MSEtemp;