70#define DRMP3_STRINGIFY(x) #x
71#define DRMP3_XSTRINGIFY(x) DRMP3_STRINGIFY(x)
73#define DRMP3_VERSION_MAJOR 0
74#define DRMP3_VERSION_MINOR 7
75#define DRMP3_VERSION_REVISION 0
76#define DRMP3_VERSION_STRING DRMP3_XSTRINGIFY(DRMP3_VERSION_MAJOR) "." DRMP3_XSTRINGIFY(DRMP3_VERSION_MINOR) "." DRMP3_XSTRINGIFY(DRMP3_VERSION_REVISION)
87#if defined(_MSC_VER) && !defined(__clang__)
91 #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
92 #pragma GCC diagnostic push
93 #pragma GCC diagnostic ignored "-Wlong-long"
94 #if defined(__clang__)
95 #pragma GCC diagnostic ignored "-Wc++11-long-long"
100 #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
101 #pragma GCC diagnostic pop
104#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) || defined(__powerpc64__)
115#define DRMP3_UINT64_MAX (((drmp3_uint64)0xFFFFFFFF << 32) | (drmp3_uint64)0xFFFFFFFF)
119#if !defined(DRMP3_API)
120 #if defined(DRMP3_DLL)
122 #define DRMP3_DLL_IMPORT __declspec(dllimport)
123 #define DRMP3_DLL_EXPORT __declspec(dllexport)
124 #define DRMP3_DLL_PRIVATE static
126 #if defined(__GNUC__) && __GNUC__ >= 4
127 #define DRMP3_DLL_IMPORT __attribute__((visibility("default")))
128 #define DRMP3_DLL_EXPORT __attribute__((visibility("default")))
129 #define DRMP3_DLL_PRIVATE __attribute__((visibility("hidden")))
131 #define DRMP3_DLL_IMPORT
132 #define DRMP3_DLL_EXPORT
133 #define DRMP3_DLL_PRIVATE static
137 #if defined(DR_MP3_IMPLEMENTATION)
138 #define DRMP3_API DRMP3_DLL_EXPORT
140 #define DRMP3_API DRMP3_DLL_IMPORT
142 #define DRMP3_PRIVATE DRMP3_DLL_PRIVATE
144 #define DRMP3_API extern
145 #define DRMP3_PRIVATE static
152#define DRMP3_SUCCESS 0
153#define DRMP3_ERROR -1
154#define DRMP3_INVALID_ARGS -2
155#define DRMP3_INVALID_OPERATION -3
156#define DRMP3_OUT_OF_MEMORY -4
157#define DRMP3_OUT_OF_RANGE -5
158#define DRMP3_ACCESS_DENIED -6
159#define DRMP3_DOES_NOT_EXIST -7
160#define DRMP3_ALREADY_EXISTS -8
161#define DRMP3_TOO_MANY_OPEN_FILES -9
162#define DRMP3_INVALID_FILE -10
163#define DRMP3_TOO_BIG -11
164#define DRMP3_PATH_TOO_LONG -12
165#define DRMP3_NAME_TOO_LONG -13
166#define DRMP3_NOT_DIRECTORY -14
167#define DRMP3_IS_DIRECTORY -15
168#define DRMP3_DIRECTORY_NOT_EMPTY -16
169#define DRMP3_END_OF_FILE -17
170#define DRMP3_NO_SPACE -18
171#define DRMP3_BUSY -19
172#define DRMP3_IO_ERROR -20
173#define DRMP3_INTERRUPT -21
174#define DRMP3_UNAVAILABLE -22
175#define DRMP3_ALREADY_IN_USE -23
176#define DRMP3_BAD_ADDRESS -24
177#define DRMP3_BAD_SEEK -25
178#define DRMP3_BAD_PIPE -26
179#define DRMP3_DEADLOCK -27
180#define DRMP3_TOO_MANY_LINKS -28
181#define DRMP3_NOT_IMPLEMENTED -29
182#define DRMP3_NO_MESSAGE -30
183#define DRMP3_BAD_MESSAGE -31
184#define DRMP3_NO_DATA_AVAILABLE -32
185#define DRMP3_INVALID_DATA -33
186#define DRMP3_TIMEOUT -34
187#define DRMP3_NO_NETWORK -35
188#define DRMP3_NOT_UNIQUE -36
189#define DRMP3_NOT_SOCKET -37
190#define DRMP3_NO_ADDRESS -38
191#define DRMP3_BAD_PROTOCOL -39
192#define DRMP3_PROTOCOL_UNAVAILABLE -40
193#define DRMP3_PROTOCOL_NOT_SUPPORTED -41
194#define DRMP3_PROTOCOL_FAMILY_NOT_SUPPORTED -42
195#define DRMP3_ADDRESS_FAMILY_NOT_SUPPORTED -43
196#define DRMP3_SOCKET_NOT_SUPPORTED -44
197#define DRMP3_CONNECTION_RESET -45
198#define DRMP3_ALREADY_CONNECTED -46
199#define DRMP3_NOT_CONNECTED -47
200#define DRMP3_CONNECTION_REFUSED -48
201#define DRMP3_NO_HOST -49
202#define DRMP3_IN_PROGRESS -50
203#define DRMP3_CANCELLED -51
204#define DRMP3_MEMORY_ALREADY_MAPPED -52
205#define DRMP3_AT_END -53
208#define DRMP3_MAX_PCM_FRAMES_PER_MP3_FRAME 1152
209#define DRMP3_MAX_SAMPLES_PER_FRAME (DRMP3_MAX_PCM_FRAMES_PER_MP3_FRAME*2)
213 #define DRMP3_INLINE __forceinline
214#elif defined(__GNUC__)
222 #if defined(__STRICT_ANSI__)
223 #define DRMP3_GNUC_INLINE_HINT __inline__
225 #define DRMP3_GNUC_INLINE_HINT inline
228 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)) || defined(__clang__)
229 #define DRMP3_INLINE DRMP3_GNUC_INLINE_HINT __attribute__((always_inline))
231 #define DRMP3_INLINE DRMP3_GNUC_INLINE_HINT
233#elif defined(__WATCOMC__)
234 #define DRMP3_INLINE __inline
249 void* (* onMalloc)(
size_t sz,
void* pUserData);
250 void* (* onRealloc)(
void* p,
size_t sz,
void* pUserData);
251 void (* onFree)(
void* p,
void* pUserData);
267 float mdct_overlap[2][9*32], qmf_state[15*2*32];
436#ifndef DR_MP3_NO_STDIO
532#ifndef DR_MP3_NO_STDIO
560#if defined(DR_MP3_IMPLEMENTATION)
589#if defined(__TINYC__)
590#define DR_MP3_NO_SIMD
593#define DRMP3_OFFSET_PTR(p, offset) ((void*)((drmp3_uint8*)(p) + (offset)))
595#define DRMP3_MAX_FREE_FORMAT_FRAME_SIZE 2304
596#ifndef DRMP3_MAX_FRAME_SYNC_MATCHES
597#define DRMP3_MAX_FRAME_SYNC_MATCHES 10
600#define DRMP3_MAX_L3_FRAME_PAYLOAD_BYTES DRMP3_MAX_FREE_FORMAT_FRAME_SIZE
602#define DRMP3_MAX_BITRESERVOIR_BYTES 511
603#define DRMP3_SHORT_BLOCK_TYPE 2
604#define DRMP3_STOP_BLOCK_TYPE 3
605#define DRMP3_MODE_MONO 3
606#define DRMP3_MODE_JOINT_STEREO 1
607#define DRMP3_HDR_SIZE 4
608#define DRMP3_HDR_IS_MONO(h) (((h[3]) & 0xC0) == 0xC0)
609#define DRMP3_HDR_IS_MS_STEREO(h) (((h[3]) & 0xE0) == 0x60)
610#define DRMP3_HDR_IS_FREE_FORMAT(h) (((h[2]) & 0xF0) == 0)
611#define DRMP3_HDR_IS_CRC(h) (!((h[1]) & 1))
612#define DRMP3_HDR_TEST_PADDING(h) ((h[2]) & 0x2)
613#define DRMP3_HDR_TEST_MPEG1(h) ((h[1]) & 0x8)
614#define DRMP3_HDR_TEST_NOT_MPEG25(h) ((h[1]) & 0x10)
615#define DRMP3_HDR_TEST_I_STEREO(h) ((h[3]) & 0x10)
616#define DRMP3_HDR_TEST_MS_STEREO(h) ((h[3]) & 0x20)
617#define DRMP3_HDR_GET_STEREO_MODE(h) (((h[3]) >> 6) & 3)
618#define DRMP3_HDR_GET_STEREO_MODE_EXT(h) (((h[3]) >> 4) & 3)
619#define DRMP3_HDR_GET_LAYER(h) (((h[1]) >> 1) & 3)
620#define DRMP3_HDR_GET_BITRATE(h) ((h[2]) >> 4)
621#define DRMP3_HDR_GET_SAMPLE_RATE(h) (((h[2]) >> 2) & 3)
622#define DRMP3_HDR_GET_MY_SAMPLE_RATE(h) (DRMP3_HDR_GET_SAMPLE_RATE(h) + (((h[1] >> 3) & 1) + ((h[1] >> 4) & 1))*3)
623#define DRMP3_HDR_IS_FRAME_576(h) ((h[1] & 14) == 2)
624#define DRMP3_HDR_IS_LAYER_1(h) ((h[1] & 6) == 6)
626#define DRMP3_BITS_DEQUANTIZER_OUT -1
627#define DRMP3_MAX_SCF (255 + DRMP3_BITS_DEQUANTIZER_OUT*4 - 210)
628#define DRMP3_MAX_SCFI ((DRMP3_MAX_SCF + 3) & ~3)
630#define DRMP3_MIN(a, b) ((a) > (b) ? (b) : (a))
631#define DRMP3_MAX(a, b) ((a) < (b) ? (b) : (a))
633#if !defined(DR_MP3_NO_SIMD)
635#if !defined(DR_MP3_ONLY_SIMD) && (defined(_M_X64) || defined(__x86_64__) || defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC))
637#define DR_MP3_ONLY_SIMD
640#if ((defined(_MSC_VER) && _MSC_VER >= 1400) && defined(_M_X64)) || ((defined(__i386) || defined(_M_IX86) || defined(__i386__) || defined(__x86_64__)) && ((defined(_M_IX86_FP) && _M_IX86_FP == 2) || defined(__SSE2__)))
644#include <emmintrin.h>
645#define DRMP3_HAVE_SSE 1
646#define DRMP3_HAVE_SIMD 1
647#define DRMP3_VSTORE _mm_storeu_ps
648#define DRMP3_VLD _mm_loadu_ps
649#define DRMP3_VSET _mm_set1_ps
650#define DRMP3_VADD _mm_add_ps
651#define DRMP3_VSUB _mm_sub_ps
652#define DRMP3_VMUL _mm_mul_ps
653#define DRMP3_VMAC(a, x, y) _mm_add_ps(a, _mm_mul_ps(x, y))
654#define DRMP3_VMSB(a, x, y) _mm_sub_ps(a, _mm_mul_ps(x, y))
655#define DRMP3_VMUL_S(x, s) _mm_mul_ps(x, _mm_set1_ps(s))
656#define DRMP3_VREV(x) _mm_shuffle_ps(x, x, _MM_SHUFFLE(0, 1, 2, 3))
657typedef __m128 drmp3_f4;
658#if defined(_MSC_VER) || defined(DR_MP3_ONLY_SIMD)
659#define drmp3_cpuid __cpuid
661static __inline__ __attribute__((always_inline))
void drmp3_cpuid(
int CPUInfo[],
const int InfoType)
664 __asm__ __volatile__(
665#
if defined(__x86_64__)
675 :
"=a" (CPUInfo[0]),
"=r" (CPUInfo[1]),
"=c" (CPUInfo[2]),
"=d" (CPUInfo[3])
678 __asm__ __volatile__(
680 :
"=a" (CPUInfo[0]),
"=b" (CPUInfo[1]),
"=c" (CPUInfo[2]),
"=d" (CPUInfo[3])
685static int drmp3_have_simd(
void)
687#ifdef DR_MP3_ONLY_SIMD
690 static int g_have_simd;
693 static int g_counter;
694 if (g_counter++ > 100)
699 drmp3_cpuid(CPUInfo, 0);
702 drmp3_cpuid(CPUInfo, 1);
703 g_have_simd = (CPUInfo[3] & (1 << 26)) + 1;
704 return g_have_simd - 1;
708 return g_have_simd - 1;
711#elif defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
713#define DRMP3_HAVE_SSE 0
714#define DRMP3_HAVE_SIMD 1
715#define DRMP3_VSTORE vst1q_f32
716#define DRMP3_VLD vld1q_f32
717#define DRMP3_VSET vmovq_n_f32
718#define DRMP3_VADD vaddq_f32
719#define DRMP3_VSUB vsubq_f32
720#define DRMP3_VMUL vmulq_f32
721#define DRMP3_VMAC(a, x, y) vmlaq_f32(a, x, y)
722#define DRMP3_VMSB(a, x, y) vmlsq_f32(a, x, y)
723#define DRMP3_VMUL_S(x, s) vmulq_f32(x, vmovq_n_f32(s))
724#define DRMP3_VREV(x) vcombine_f32(vget_high_f32(vrev64q_f32(x)), vget_low_f32(vrev64q_f32(x)))
725typedef float32x4_t drmp3_f4;
726static int drmp3_have_simd(
void)
731#define DRMP3_HAVE_SSE 0
732#define DRMP3_HAVE_SIMD 0
733#ifdef DR_MP3_ONLY_SIMD
734#error DR_MP3_ONLY_SIMD used, but SSE/NEON not enabled
740#define DRMP3_HAVE_SIMD 0
744#if defined(__ARM_ARCH) && (__ARM_ARCH >= 6) && !defined(__aarch64__) && !defined(_M_ARM64) && !defined(_M_ARM64EC) && !defined(__ARM_ARCH_6M__)
745#define DRMP3_HAVE_ARMV6 1
749 __asm__ (
"ssat %0, #16, %1" :
"=r"(x) :
"r"(a));
753#define DRMP3_HAVE_ARMV6 0
760#define DRMP3_ASSERT(expression) assert(expression)
762#ifndef DRMP3_COPY_MEMORY
763#define DRMP3_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
765#ifndef DRMP3_MOVE_MEMORY
766#define DRMP3_MOVE_MEMORY(dst, src, sz) memmove((dst), (src), (sz))
768#ifndef DRMP3_ZERO_MEMORY
769#define DRMP3_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
771#define DRMP3_ZERO_OBJECT(p) DRMP3_ZERO_MEMORY((p), sizeof(*(p)))
773#define DRMP3_MALLOC(sz) malloc((sz))
776#define DRMP3_REALLOC(p, sz) realloc((p), (sz))
779#define DRMP3_FREE(p) free((p))
791 drmp3_uint8 total_bands, stereo_bands, bitalloc[64], scfcod[64];
792} drmp3_L12_scale_info;
796 drmp3_uint8 tab_offset, code_tab_width, band_count;
797} drmp3_L12_subband_alloc;
802 drmp3_uint16 part_23_length, big_values, scalefac_compress;
803 drmp3_uint8 global_gain, block_type, mixed_block_flag, n_long_sfb, n_short_sfb;
804 drmp3_uint8 table_select[3], region_count[3], subblock_gain[3];
805 drmp3_uint8 preflag, scalefac_scale, count1_table, scfsi;
811 drmp3_uint8 maindata[DRMP3_MAX_BITRESERVOIR_BYTES + DRMP3_MAX_L3_FRAME_PAYLOAD_BYTES];
812 drmp3_L3_gr_info gr_info[4];
813 float grbuf[2][576], scf[40], syn[18 + 15][2*32];
817static void drmp3_bs_init(drmp3_bs *bs,
const drmp3_uint8 *data,
int bytes)
824static drmp3_uint32 drmp3_bs_get_bits(drmp3_bs *bs,
int n)
829 if ((bs->pos += n) > bs->limit)
831 next = *p++ & (255 >> s);
832 while ((shl -= 8) > 0)
834 cache |= next << shl;
837 return cache | (next >> -shl);
842 return h[0] == 0xff &&
843 ((h[1] & 0xF0) == 0xf0 || (h[1] & 0xFE) == 0xe2) &&
844 (DRMP3_HDR_GET_LAYER(h) != 0) &&
845 (DRMP3_HDR_GET_BITRATE(h) != 15) &&
846 (DRMP3_HDR_GET_SAMPLE_RATE(h) != 3);
851 return drmp3_hdr_valid(h2) &&
852 ((h1[1] ^ h2[1]) & 0xFE) == 0 &&
853 ((h1[2] ^ h2[2]) & 0x0C) == 0 &&
854 !(DRMP3_HDR_IS_FREE_FORMAT(h1) ^ DRMP3_HDR_IS_FREE_FORMAT(h2));
857static unsigned drmp3_hdr_bitrate_kbps(
const drmp3_uint8 *h)
860 { { 0,4,8,12,16,20,24,28,32,40,48,56,64,72,80 }, { 0,4,8,12,16,20,24,28,32,40,48,56,64,72,80 }, { 0,16,24,28,32,40,48,56,64,72,80,88,96,112,128 } },
861 { { 0,16,20,24,28,32,40,48,56,64,80,96,112,128,160 }, { 0,16,24,28,32,40,48,56,64,80,96,112,128,160,192 }, { 0,16,32,48,64,80,96,112,128,144,160,176,192,208,224 } },
863 return 2*halfrate[!!DRMP3_HDR_TEST_MPEG1(h)][DRMP3_HDR_GET_LAYER(h) - 1][DRMP3_HDR_GET_BITRATE(h)];
866static unsigned drmp3_hdr_sample_rate_hz(
const drmp3_uint8 *h)
868 static const unsigned g_hz[3] = { 44100, 48000, 32000 };
869 return g_hz[DRMP3_HDR_GET_SAMPLE_RATE(h)] >> (int)!DRMP3_HDR_TEST_MPEG1(h) >> (int)!DRMP3_HDR_TEST_NOT_MPEG25(h);
872static unsigned drmp3_hdr_frame_samples(
const drmp3_uint8 *h)
874 return DRMP3_HDR_IS_LAYER_1(h) ? 384 : (1152 >> (int)DRMP3_HDR_IS_FRAME_576(h));
877static int drmp3_hdr_frame_bytes(
const drmp3_uint8 *h,
int free_format_size)
879 int frame_bytes = drmp3_hdr_frame_samples(h)*drmp3_hdr_bitrate_kbps(h)*125/drmp3_hdr_sample_rate_hz(h);
880 if (DRMP3_HDR_IS_LAYER_1(h))
884 return frame_bytes ? frame_bytes : free_format_size;
889 return DRMP3_HDR_TEST_PADDING(h) ? (DRMP3_HDR_IS_LAYER_1(h) ? 4 : 1) : 0;
892#ifndef DR_MP3_ONLY_MP3
893static const drmp3_L12_subband_alloc *drmp3_L12_subband_alloc_table(
const drmp3_uint8 *hdr, drmp3_L12_scale_info *sci)
895 const drmp3_L12_subband_alloc *alloc;
896 int mode = DRMP3_HDR_GET_STEREO_MODE(hdr);
897 int nbands, stereo_bands = (mode == DRMP3_MODE_MONO) ? 0 : (mode == DRMP3_MODE_JOINT_STEREO) ? (DRMP3_HDR_GET_STEREO_MODE_EXT(hdr) << 2) + 4 : 32;
899 if (DRMP3_HDR_IS_LAYER_1(hdr))
901 static const drmp3_L12_subband_alloc g_alloc_L1[] = { { 76, 4, 32 } };
904 }
else if (!DRMP3_HDR_TEST_MPEG1(hdr))
906 static const drmp3_L12_subband_alloc g_alloc_L2M2[] = { { 60, 4, 4 }, { 44, 3, 7 }, { 44, 2, 19 } };
907 alloc = g_alloc_L2M2;
911 static const drmp3_L12_subband_alloc g_alloc_L2M1[] = { { 0, 4, 3 }, { 16, 4, 8 }, { 32, 3, 12 }, { 40, 2, 7 } };
912 int sample_rate_idx = DRMP3_HDR_GET_SAMPLE_RATE(hdr);
913 unsigned kbps = drmp3_hdr_bitrate_kbps(hdr) >> (int)(mode != DRMP3_MODE_MONO);
919 alloc = g_alloc_L2M1;
923 static const drmp3_L12_subband_alloc g_alloc_L2M1_lowrate[] = { { 44, 4, 2 }, { 44, 3, 10 } };
924 alloc = g_alloc_L2M1_lowrate;
925 nbands = sample_rate_idx == 2 ? 12 : 8;
926 }
else if (kbps >= 96 && sample_rate_idx != 1)
933 sci->stereo_bands = (
drmp3_uint8)DRMP3_MIN(stereo_bands, nbands);
938static void drmp3_L12_read_scalefactors(drmp3_bs *bs,
drmp3_uint8 *pba,
drmp3_uint8 *scfcod,
int bands,
float *scf)
940 static const float g_deq_L12[18*3] = {
941#define DRMP3_DQ(x) 9.53674316e-07f/x, 7.56931807e-07f/x, 6.00777173e-07f/x
942 DRMP3_DQ(3),DRMP3_DQ(7),DRMP3_DQ(15),DRMP3_DQ(31),DRMP3_DQ(63),DRMP3_DQ(127),DRMP3_DQ(255),DRMP3_DQ(511),DRMP3_DQ(1023),DRMP3_DQ(2047),DRMP3_DQ(4095),DRMP3_DQ(8191),DRMP3_DQ(16383),DRMP3_DQ(32767),DRMP3_DQ(65535),DRMP3_DQ(3),DRMP3_DQ(5),DRMP3_DQ(9)
945 for (i = 0; i < bands; i++)
949 int mask = ba ? 4 + ((19 >> scfcod[i]) & 3) : 0;
950 for (m = 4; m; m >>= 1)
954 int b = drmp3_bs_get_bits(bs, 6);
955 s = g_deq_L12[ba*3 - 6 + b % 3]*(int)(1 << 21 >> b/3);
962static void drmp3_L12_read_scale_info(
const drmp3_uint8 *hdr, drmp3_bs *bs, drmp3_L12_scale_info *sci)
965 0,17, 3, 4, 5,6,7, 8,9,10,11,12,13,14,15,16,
966 0,17,18, 3,19,4,5, 6,7, 8, 9,10,11,12,13,16,
967 0,17,18, 3,19,4,5,16,
969 0,17,18,19, 4,5,6, 7,8, 9,10,11,12,13,14,15,
970 0,17,18, 3,19,4,5, 6,7, 8, 9,10,11,12,13,14,
971 0, 2, 3, 4, 5,6,7, 8,9,10,11,12,13,14,15,16
973 const drmp3_L12_subband_alloc *subband_alloc = drmp3_L12_subband_alloc_table(hdr, sci);
975 int i, k = 0, ba_bits = 0;
976 const drmp3_uint8 *ba_code_tab = g_bitalloc_code_tab;
978 for (i = 0; i < sci->total_bands; i++)
983 k += subband_alloc->band_count;
984 ba_bits = subband_alloc->code_tab_width;
985 ba_code_tab = g_bitalloc_code_tab + subband_alloc->tab_offset;
988 ba = ba_code_tab[drmp3_bs_get_bits(bs, ba_bits)];
989 sci->bitalloc[2*i] = ba;
990 if (i < sci->stereo_bands)
992 ba = ba_code_tab[drmp3_bs_get_bits(bs, ba_bits)];
994 sci->bitalloc[2*i + 1] = sci->stereo_bands ? ba : 0;
997 for (i = 0; i < 2*sci->total_bands; i++)
999 sci->scfcod[i] = (
drmp3_uint8)(sci->bitalloc[i] ? DRMP3_HDR_IS_LAYER_1(hdr) ? 2 : drmp3_bs_get_bits(bs, 2) : 6);
1002 drmp3_L12_read_scalefactors(bs, sci->bitalloc, sci->scfcod, sci->total_bands*2, sci->scf);
1004 for (i = sci->stereo_bands; i < sci->total_bands; i++)
1006 sci->bitalloc[2*i + 1] = 0;
1010static int drmp3_L12_dequantize_granule(
float *grbuf, drmp3_bs *bs, drmp3_L12_scale_info *sci,
int group_size)
1012 int i, j, k, choff = 576;
1013 for (j = 0; j < 4; j++)
1015 float *dst = grbuf + group_size*j;
1016 for (i = 0; i < 2*sci->total_bands; i++)
1018 int ba = sci->bitalloc[i];
1023 int half = (1 << (ba - 1)) - 1;
1024 for (k = 0; k < group_size; k++)
1026 dst[k] = (float)((
int)drmp3_bs_get_bits(bs, ba) - half);
1030 unsigned mod = (2 << (ba - 17)) + 1;
1031 unsigned code = drmp3_bs_get_bits(bs, mod + 2 - (mod >> 3));
1032 for (k = 0; k < group_size; k++, code /= mod)
1034 dst[k] = (float)((
int)(code % mod - mod/2));
1042 return group_size*4;
1045static void drmp3_L12_apply_scf_384(drmp3_L12_scale_info *sci,
const float *scf,
float *dst)
1048 DRMP3_COPY_MEMORY(dst + 576 + sci->stereo_bands*18, dst + sci->stereo_bands*18, (sci->total_bands - sci->stereo_bands)*18*
sizeof(
float));
1049 for (i = 0; i < sci->total_bands; i++, dst += 18, scf += 6)
1051 for (k = 0; k < 12; k++)
1053 dst[k + 0] *= scf[0];
1054 dst[k + 576] *= scf[3];
1060static int drmp3_L3_read_side_info(drmp3_bs *bs, drmp3_L3_gr_info *gr,
const drmp3_uint8 *hdr)
1063 { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
1064 { 12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2,0 },
1065 { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
1066 { 6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,54,62,70,76,36,0 },
1067 { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
1068 { 4,4,4,4,4,4,6,6,8,8,10,12,16,20,24,28,34,42,50,54,76,158,0 },
1069 { 4,4,4,4,4,4,6,6,6,8,10,12,16,18,22,28,34,40,46,54,54,192,0 },
1070 { 4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102,26,0 }
1073 { 4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
1074 { 8,8,8,8,8,8,8,8,8,12,12,12,16,16,16,20,20,20,24,24,24,28,28,28,36,36,36,2,2,2,2,2,2,2,2,2,26,26,26,0 },
1075 { 4,4,4,4,4,4,4,4,4,6,6,6,6,6,6,8,8,8,10,10,10,14,14,14,18,18,18,26,26,26,32,32,32,42,42,42,18,18,18,0 },
1076 { 4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,32,32,32,44,44,44,12,12,12,0 },
1077 { 4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
1078 { 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,22,22,22,30,30,30,56,56,56,0 },
1079 { 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,6,6,6,10,10,10,12,12,12,14,14,14,16,16,16,20,20,20,26,26,26,66,66,66,0 },
1080 { 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,12,12,12,16,16,16,20,20,20,26,26,26,34,34,34,42,42,42,12,12,12,0 }
1083 { 6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
1084 { 12,12,12,4,4,4,8,8,8,12,12,12,16,16,16,20,20,20,24,24,24,28,28,28,36,36,36,2,2,2,2,2,2,2,2,2,26,26,26,0 },
1085 { 6,6,6,6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,14,14,14,18,18,18,26,26,26,32,32,32,42,42,42,18,18,18,0 },
1086 { 6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,32,32,32,44,44,44,12,12,12,0 },
1087 { 6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
1088 { 4,4,4,4,4,4,6,6,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,22,22,22,30,30,30,56,56,56,0 },
1089 { 4,4,4,4,4,4,6,6,4,4,4,6,6,6,6,6,6,10,10,10,12,12,12,14,14,14,16,16,16,20,20,20,26,26,26,66,66,66,0 },
1090 { 4,4,4,4,4,4,6,6,4,4,4,6,6,6,8,8,8,12,12,12,16,16,16,20,20,20,26,26,26,34,34,34,42,42,42,12,12,12,0 }
1093 unsigned tables, scfsi = 0;
1094 int main_data_begin, part_23_sum = 0;
1095 int gr_count = DRMP3_HDR_IS_MONO(hdr) ? 1 : 2;
1096 int sr_idx = DRMP3_HDR_GET_MY_SAMPLE_RATE(hdr); sr_idx -= (sr_idx != 0);
1098 if (DRMP3_HDR_TEST_MPEG1(hdr))
1101 main_data_begin = drmp3_bs_get_bits(bs, 9);
1102 scfsi = drmp3_bs_get_bits(bs, 7 + gr_count);
1105 main_data_begin = drmp3_bs_get_bits(bs, 8 + gr_count) >> gr_count;
1110 if (DRMP3_HDR_IS_MONO(hdr))
1114 gr->part_23_length = (
drmp3_uint16)drmp3_bs_get_bits(bs, 12);
1115 part_23_sum += gr->part_23_length;
1116 gr->big_values = (
drmp3_uint16)drmp3_bs_get_bits(bs, 9);
1117 if (gr->big_values > 288)
1121 gr->global_gain = (
drmp3_uint8)drmp3_bs_get_bits(bs, 8);
1122 gr->scalefac_compress = (
drmp3_uint16)drmp3_bs_get_bits(bs, DRMP3_HDR_TEST_MPEG1(hdr) ? 4 : 9);
1123 gr->sfbtab = g_scf_long[sr_idx];
1124 gr->n_long_sfb = 22;
1125 gr->n_short_sfb = 0;
1126 if (drmp3_bs_get_bits(bs, 1))
1128 gr->block_type = (
drmp3_uint8)drmp3_bs_get_bits(bs, 2);
1129 if (!gr->block_type)
1133 gr->mixed_block_flag = (
drmp3_uint8)drmp3_bs_get_bits(bs, 1);
1134 gr->region_count[0] = 7;
1135 gr->region_count[1] = 255;
1136 if (gr->block_type == DRMP3_SHORT_BLOCK_TYPE)
1139 if (!gr->mixed_block_flag)
1141 gr->region_count[0] = 8;
1142 gr->sfbtab = g_scf_short[sr_idx];
1144 gr->n_short_sfb = 39;
1147 gr->sfbtab = g_scf_mixed[sr_idx];
1148 gr->n_long_sfb = DRMP3_HDR_TEST_MPEG1(hdr) ? 8 : 6;
1149 gr->n_short_sfb = 30;
1152 tables = drmp3_bs_get_bits(bs, 10);
1154 gr->subblock_gain[0] = (
drmp3_uint8)drmp3_bs_get_bits(bs, 3);
1155 gr->subblock_gain[1] = (
drmp3_uint8)drmp3_bs_get_bits(bs, 3);
1156 gr->subblock_gain[2] = (
drmp3_uint8)drmp3_bs_get_bits(bs, 3);
1160 gr->mixed_block_flag = 0;
1161 tables = drmp3_bs_get_bits(bs, 15);
1162 gr->region_count[0] = (
drmp3_uint8)drmp3_bs_get_bits(bs, 4);
1163 gr->region_count[1] = (
drmp3_uint8)drmp3_bs_get_bits(bs, 3);
1164 gr->region_count[2] = 255;
1166 gr->table_select[0] = (
drmp3_uint8)(tables >> 10);
1167 gr->table_select[1] = (
drmp3_uint8)((tables >> 5) & 31);
1168 gr->table_select[2] = (
drmp3_uint8)((tables) & 31);
1169 gr->preflag = (
drmp3_uint8)(DRMP3_HDR_TEST_MPEG1(hdr) ? drmp3_bs_get_bits(bs, 1) : (gr->scalefac_compress >= 500));
1170 gr->scalefac_scale = (
drmp3_uint8)drmp3_bs_get_bits(bs, 1);
1171 gr->count1_table = (
drmp3_uint8)drmp3_bs_get_bits(bs, 1);
1175 }
while(--gr_count);
1177 if (part_23_sum + bs->pos > bs->limit + main_data_begin*8)
1182 return main_data_begin;
1188 for (i = 0; i < 4 && scf_count[i]; i++, scfsi *= 2)
1190 int cnt = scf_count[i];
1193 DRMP3_COPY_MEMORY(scf, ist_pos, cnt);
1196 int bits = scf_size[i];
1199 DRMP3_ZERO_MEMORY(scf, cnt);
1200 DRMP3_ZERO_MEMORY(ist_pos, cnt);
1203 int max_scf = (scfsi < 0) ? (1 << bits) - 1 : -1;
1204 for (k = 0; k < cnt; k++)
1206 int s = drmp3_bs_get_bits(bitbuf, bits);
1207 ist_pos[k] = (
drmp3_uint8)(s == max_scf ? -1 : s);
1215 scf[0] = scf[1] = scf[2] = 0;
1218static float drmp3_L3_ldexp_q2(
float y,
int exp_q2)
1220 static const float g_expfrac[4] = { 9.31322575e-10f,7.83145814e-10f,6.58544508e-10f,5.53767716e-10f };
1224 e = DRMP3_MIN(30*4, exp_q2);
1225 y *= g_expfrac[e & 3]*(1 << 30 >> (e >> 2));
1226 }
while ((exp_q2 -= e) > 0);
1230static void drmp3_L3_decode_scalefactors(
const drmp3_uint8 *hdr,
drmp3_uint8 *ist_pos, drmp3_bs *bs,
const drmp3_L3_gr_info *gr,
float *scf,
int ch)
1232 static const drmp3_uint8 g_scf_partitions[3][28] = {
1233 { 6,5,5, 5,6,5,5,5,6,5, 7,3,11,10,0,0, 7, 7, 7,0, 6, 6,6,3, 8, 8,5,0 },
1234 { 8,9,6,12,6,9,9,9,6,9,12,6,15,18,0,0, 6,15,12,0, 6,12,9,6, 6,18,9,0 },
1235 { 9,9,6,12,9,9,9,9,9,9,12,6,18,18,0,0,12,12,12,0,12, 9,9,6,15,12,9,0 }
1237 const drmp3_uint8 *scf_partition = g_scf_partitions[!!gr->n_short_sfb + !gr->n_long_sfb];
1239 int i, scf_shift = gr->scalefac_scale + 1, gain_exp, scfsi = gr->scfsi;
1242 if (DRMP3_HDR_TEST_MPEG1(hdr))
1244 static const drmp3_uint8 g_scfc_decode[16] = { 0,1,2,3, 12,5,6,7, 9,10,11,13, 14,15,18,19 };
1245 int part = g_scfc_decode[gr->scalefac_compress];
1246 scf_size[1] = scf_size[0] = (
drmp3_uint8)(part >> 2);
1247 scf_size[3] = scf_size[2] = (
drmp3_uint8)(part & 3);
1250 static const drmp3_uint8 g_mod[6*4] = { 5,5,4,4,5,5,4,1,4,3,1,1,5,6,6,1,4,4,4,1,4,3,1,1 };
1251 int k, modprod, sfc, ist = DRMP3_HDR_TEST_I_STEREO(hdr) && ch;
1252 sfc = gr->scalefac_compress >> ist;
1253 for (k = ist*3*4; sfc >= 0; sfc -= modprod, k += 4)
1255 for (modprod = 1, i = 3; i >= 0; i--)
1257 scf_size[i] = (
drmp3_uint8)(sfc / modprod % g_mod[k + i]);
1258 modprod *= g_mod[k + i];
1264 drmp3_L3_read_scalefactors(iscf, ist_pos, scf_size, scf_partition, bs, scfsi);
1266 if (gr->n_short_sfb)
1268 int sh = 3 - scf_shift;
1269 for (i = 0; i < gr->n_short_sfb; i += 3)
1271 iscf[gr->n_long_sfb + i + 0] = (
drmp3_uint8)(iscf[gr->n_long_sfb + i + 0] + (gr->subblock_gain[0] << sh));
1272 iscf[gr->n_long_sfb + i + 1] = (
drmp3_uint8)(iscf[gr->n_long_sfb + i + 1] + (gr->subblock_gain[1] << sh));
1273 iscf[gr->n_long_sfb + i + 2] = (
drmp3_uint8)(iscf[gr->n_long_sfb + i + 2] + (gr->subblock_gain[2] << sh));
1275 }
else if (gr->preflag)
1277 static const drmp3_uint8 g_preamp[10] = { 1,1,1,1,2,2,3,3,3,2 };
1278 for (i = 0; i < 10; i++)
1280 iscf[11 + i] = (
drmp3_uint8)(iscf[11 + i] + g_preamp[i]);
1284 gain_exp = gr->global_gain + DRMP3_BITS_DEQUANTIZER_OUT*4 - 210 - (DRMP3_HDR_IS_MS_STEREO(hdr) ? 2 : 0);
1285 gain = drmp3_L3_ldexp_q2(1 << (DRMP3_MAX_SCFI/4), DRMP3_MAX_SCFI - gain_exp);
1286 for (i = 0; i < (int)(gr->n_long_sfb + gr->n_short_sfb); i++)
1288 scf[i] = drmp3_L3_ldexp_q2(gain, iscf[i] << scf_shift);
1292static const float g_drmp3_pow43[129 + 16] = {
1293 0,-1,-2.519842f,-4.326749f,-6.349604f,-8.549880f,-10.902724f,-13.390518f,-16.000000f,-18.720754f,-21.544347f,-24.463781f,-27.473142f,-30.567351f,-33.741992f,-36.993181f,
1294 0,1,2.519842f,4.326749f,6.349604f,8.549880f,10.902724f,13.390518f,16.000000f,18.720754f,21.544347f,24.463781f,27.473142f,30.567351f,33.741992f,36.993181f,40.317474f,43.711787f,47.173345f,50.699631f,54.288352f,57.937408f,61.644865f,65.408941f,69.227979f,73.100443f,77.024898f,81.000000f,85.024491f,89.097188f,93.216975f,97.382800f,101.593667f,105.848633f,110.146801f,114.487321f,118.869381f,123.292209f,127.755065f,132.257246f,136.798076f,141.376907f,145.993119f,150.646117f,155.335327f,160.060199f,164.820202f,169.614826f,174.443577f,179.305980f,184.201575f,189.129918f,194.090580f,199.083145f,204.107210f,209.162385f,214.248292f,219.364564f,224.510845f,229.686789f,234.892058f,240.126328f,245.389280f,250.680604f,256.000000f,261.347174f,266.721841f,272.123723f,277.552547f,283.008049f,288.489971f,293.998060f,299.532071f,305.091761f,310.676898f,316.287249f,321.922592f,327.582707f,333.267377f,338.976394f,344.709550f,350.466646f,356.247482f,362.051866f,367.879608f,373.730522f,379.604427f,385.501143f,391.420496f,397.362314f,403.326427f,409.312672f,415.320884f,421.350905f,427.402579f,433.475750f,439.570269f,445.685987f,451.822757f,457.980436f,464.158883f,470.357960f,476.577530f,482.817459f,489.077615f,495.357868f,501.658090f,507.978156f,514.317941f,520.677324f,527.056184f,533.454404f,539.871867f,546.308458f,552.764065f,559.238575f,565.731879f,572.243870f,578.774440f,585.323483f,591.890898f,598.476581f,605.080431f,611.702349f,618.342238f,625.000000f,631.675540f,638.368763f,645.079578f
1297static float drmp3_L3_pow_43(
int x)
1300 int sign, mult = 256;
1304 return g_drmp3_pow43[16 + x];
1314 frac = (float)((x & 63) -
sign) / ((x & ~63) +
sign);
1315 return g_drmp3_pow43[16 + ((x +
sign) >> 6)]*(1.f + frac*((4.f/3) + frac*(2.f/9)))*mult;
1318static void drmp3_L3_huffman(
float *dst, drmp3_bs *bs,
const drmp3_L3_gr_info *gr_info,
const float *scf,
int layer3gr_limit)
1320 static const drmp3_int16 tabs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1321 785,785,785,785,784,784,784,784,513,513,513,513,513,513,513,513,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,
1322 -255,1313,1298,1282,785,785,785,785,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,290,288,
1323 -255,1313,1298,1282,769,769,769,769,529,529,529,529,529,529,529,529,528,528,528,528,528,528,528,528,512,512,512,512,512,512,512,512,290,288,
1324 -253,-318,-351,-367,785,785,785,785,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,819,818,547,547,275,275,275,275,561,560,515,546,289,274,288,258,
1325 -254,-287,1329,1299,1314,1312,1057,1057,1042,1042,1026,1026,784,784,784,784,529,529,529,529,529,529,529,529,769,769,769,769,768,768,768,768,563,560,306,306,291,259,
1326 -252,-413,-477,-542,1298,-575,1041,1041,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-383,-399,1107,1092,1106,1061,849,849,789,789,1104,1091,773,773,1076,1075,341,340,325,309,834,804,577,577,532,532,516,516,832,818,803,816,561,561,531,531,515,546,289,289,288,258,
1327 -252,-429,-493,-559,1057,1057,1042,1042,529,529,529,529,529,529,529,529,784,784,784,784,769,769,769,769,512,512,512,512,512,512,512,512,-382,1077,-415,1106,1061,1104,849,849,789,789,1091,1076,1029,1075,834,834,597,581,340,340,339,324,804,833,532,532,832,772,818,803,817,787,816,771,290,290,290,290,288,258,
1328 -253,-349,-414,-447,-463,1329,1299,-479,1314,1312,1057,1057,1042,1042,1026,1026,785,785,785,785,784,784,784,784,769,769,769,769,768,768,768,768,-319,851,821,-335,836,850,805,849,341,340,325,336,533,533,579,579,564,564,773,832,578,548,563,516,321,276,306,291,304,259,
1329 -251,-572,-733,-830,-863,-879,1041,1041,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-511,-527,-543,1396,1351,1381,1366,1395,1335,1380,-559,1334,1138,1138,1063,1063,1350,1392,1031,1031,1062,1062,1364,1363,1120,1120,1333,1348,881,881,881,881,375,374,359,373,343,358,341,325,791,791,1123,1122,-703,1105,1045,-719,865,865,790,790,774,774,1104,1029,338,293,323,308,-799,-815,833,788,772,818,803,816,322,292,307,320,561,531,515,546,289,274,288,258,
1330 -251,-525,-605,-685,-765,-831,-846,1298,1057,1057,1312,1282,785,785,785,785,784,784,784,784,769,769,769,769,512,512,512,512,512,512,512,512,1399,1398,1383,1367,1382,1396,1351,-511,1381,1366,1139,1139,1079,1079,1124,1124,1364,1349,1363,1333,882,882,882,882,807,807,807,807,1094,1094,1136,1136,373,341,535,535,881,775,867,822,774,-591,324,338,-671,849,550,550,866,864,609,609,293,336,534,534,789,835,773,-751,834,804,308,307,833,788,832,772,562,562,547,547,305,275,560,515,290,290,
1331 -252,-397,-477,-557,-622,-653,-719,-735,-750,1329,1299,1314,1057,1057,1042,1042,1312,1282,1024,1024,785,785,785,785,784,784,784,784,769,769,769,769,-383,1127,1141,1111,1126,1140,1095,1110,869,869,883,883,1079,1109,882,882,375,374,807,868,838,881,791,-463,867,822,368,263,852,837,836,-543,610,610,550,550,352,336,534,534,865,774,851,821,850,805,593,533,579,564,773,832,578,578,548,548,577,577,307,276,306,291,516,560,259,259,
1332 -250,-2107,-2507,-2764,-2909,-2974,-3007,-3023,1041,1041,1040,1040,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-767,-1052,-1213,-1277,-1358,-1405,-1469,-1535,-1550,-1582,-1614,-1647,-1662,-1694,-1726,-1759,-1774,-1807,-1822,-1854,-1886,1565,-1919,-1935,-1951,-1967,1731,1730,1580,1717,-1983,1729,1564,-1999,1548,-2015,-2031,1715,1595,-2047,1714,-2063,1610,-2079,1609,-2095,1323,1323,1457,1457,1307,1307,1712,1547,1641,1700,1699,1594,1685,1625,1442,1442,1322,1322,-780,-973,-910,1279,1278,1277,1262,1276,1261,1275,1215,1260,1229,-959,974,974,989,989,-943,735,478,478,495,463,506,414,-1039,1003,958,1017,927,942,987,957,431,476,1272,1167,1228,-1183,1256,-1199,895,895,941,941,1242,1227,1212,1135,1014,1014,490,489,503,487,910,1013,985,925,863,894,970,955,1012,847,-1343,831,755,755,984,909,428,366,754,559,-1391,752,486,457,924,997,698,698,983,893,740,740,908,877,739,739,667,667,953,938,497,287,271,271,683,606,590,712,726,574,302,302,738,736,481,286,526,725,605,711,636,724,696,651,589,681,666,710,364,467,573,695,466,466,301,465,379,379,709,604,665,679,316,316,634,633,436,436,464,269,424,394,452,332,438,363,347,408,393,448,331,422,362,407,392,421,346,406,391,376,375,359,1441,1306,-2367,1290,-2383,1337,-2399,-2415,1426,1321,-2431,1411,1336,-2447,-2463,-2479,1169,1169,1049,1049,1424,1289,1412,1352,1319,-2495,1154,1154,1064,1064,1153,1153,416,390,360,404,403,389,344,374,373,343,358,372,327,357,342,311,356,326,1395,1394,1137,1137,1047,1047,1365,1392,1287,1379,1334,1364,1349,1378,1318,1363,792,792,792,792,1152,1152,1032,1032,1121,1121,1046,1046,1120,1120,1030,1030,-2895,1106,1061,1104,849,849,789,789,1091,1076,1029,1090,1060,1075,833,833,309,324,532,532,832,772,818,803,561,561,531,560,515,546,289,274,288,258,
1333 -250,-1179,-1579,-1836,-1996,-2124,-2253,-2333,-2413,-2477,-2542,-2574,-2607,-2622,-2655,1314,1313,1298,1312,1282,785,785,785,785,1040,1040,1025,1025,768,768,768,768,-766,-798,-830,-862,-895,-911,-927,-943,-959,-975,-991,-1007,-1023,-1039,-1055,-1070,1724,1647,-1103,-1119,1631,1767,1662,1738,1708,1723,-1135,1780,1615,1779,1599,1677,1646,1778,1583,-1151,1777,1567,1737,1692,1765,1722,1707,1630,1751,1661,1764,1614,1736,1676,1763,1750,1645,1598,1721,1691,1762,1706,1582,1761,1566,-1167,1749,1629,767,766,751,765,494,494,735,764,719,749,734,763,447,447,748,718,477,506,431,491,446,476,461,505,415,430,475,445,504,399,460,489,414,503,383,474,429,459,502,502,746,752,488,398,501,473,413,472,486,271,480,270,-1439,-1455,1357,-1471,-1487,-1503,1341,1325,-1519,1489,1463,1403,1309,-1535,1372,1448,1418,1476,1356,1462,1387,-1551,1475,1340,1447,1402,1386,-1567,1068,1068,1474,1461,455,380,468,440,395,425,410,454,364,467,466,464,453,269,409,448,268,432,1371,1473,1432,1417,1308,1460,1355,1446,1459,1431,1083,1083,1401,1416,1458,1445,1067,1067,1370,1457,1051,1051,1291,1430,1385,1444,1354,1415,1400,1443,1082,1082,1173,1113,1186,1066,1185,1050,-1967,1158,1128,1172,1097,1171,1081,-1983,1157,1112,416,266,375,400,1170,1142,1127,1065,793,793,1169,1033,1156,1096,1141,1111,1155,1080,1126,1140,898,898,808,808,897,897,792,792,1095,1152,1032,1125,1110,1139,1079,1124,882,807,838,881,853,791,-2319,867,368,263,822,852,837,866,806,865,-2399,851,352,262,534,534,821,836,594,594,549,549,593,593,533,533,848,773,579,579,564,578,548,563,276,276,577,576,306,291,516,560,305,305,275,259,
1334 -251,-892,-2058,-2620,-2828,-2957,-3023,-3039,1041,1041,1040,1040,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-511,-527,-543,-559,1530,-575,-591,1528,1527,1407,1526,1391,1023,1023,1023,1023,1525,1375,1268,1268,1103,1103,1087,1087,1039,1039,1523,-604,815,815,815,815,510,495,509,479,508,463,507,447,431,505,415,399,-734,-782,1262,-815,1259,1244,-831,1258,1228,-847,-863,1196,-879,1253,987,987,748,-767,493,493,462,477,414,414,686,669,478,446,461,445,474,429,487,458,412,471,1266,1264,1009,1009,799,799,-1019,-1276,-1452,-1581,-1677,-1757,-1821,-1886,-1933,-1997,1257,1257,1483,1468,1512,1422,1497,1406,1467,1496,1421,1510,1134,1134,1225,1225,1466,1451,1374,1405,1252,1252,1358,1480,1164,1164,1251,1251,1238,1238,1389,1465,-1407,1054,1101,-1423,1207,-1439,830,830,1248,1038,1237,1117,1223,1148,1236,1208,411,426,395,410,379,269,1193,1222,1132,1235,1221,1116,976,976,1192,1162,1177,1220,1131,1191,963,963,-1647,961,780,-1663,558,558,994,993,437,408,393,407,829,978,813,797,947,-1743,721,721,377,392,844,950,828,890,706,706,812,859,796,960,948,843,934,874,571,571,-1919,690,555,689,421,346,539,539,944,779,918,873,932,842,903,888,570,570,931,917,674,674,-2575,1562,-2591,1609,-2607,1654,1322,1322,1441,1441,1696,1546,1683,1593,1669,1624,1426,1426,1321,1321,1639,1680,1425,1425,1305,1305,1545,1668,1608,1623,1667,1592,1638,1666,1320,1320,1652,1607,1409,1409,1304,1304,1288,1288,1664,1637,1395,1395,1335,1335,1622,1636,1394,1394,1319,1319,1606,1621,1392,1392,1137,1137,1137,1137,345,390,360,375,404,373,1047,-2751,-2767,-2783,1062,1121,1046,-2799,1077,-2815,1106,1061,789,789,1105,1104,263,355,310,340,325,354,352,262,339,324,1091,1076,1029,1090,1060,1075,833,833,788,788,1088,1028,818,818,803,803,561,561,531,531,816,771,546,546,289,274,288,258,
1335 -253,-317,-381,-446,-478,-509,1279,1279,-811,-1179,-1451,-1756,-1900,-2028,-2189,-2253,-2333,-2414,-2445,-2511,-2526,1313,1298,-2559,1041,1041,1040,1040,1025,1025,1024,1024,1022,1007,1021,991,1020,975,1019,959,687,687,1018,1017,671,671,655,655,1016,1015,639,639,758,758,623,623,757,607,756,591,755,575,754,559,543,543,1009,783,-575,-621,-685,-749,496,-590,750,749,734,748,974,989,1003,958,988,973,1002,942,987,957,972,1001,926,986,941,971,956,1000,910,985,925,999,894,970,-1071,-1087,-1102,1390,-1135,1436,1509,1451,1374,-1151,1405,1358,1480,1420,-1167,1507,1494,1389,1342,1465,1435,1450,1326,1505,1310,1493,1373,1479,1404,1492,1464,1419,428,443,472,397,736,526,464,464,486,457,442,471,484,482,1357,1449,1434,1478,1388,1491,1341,1490,1325,1489,1463,1403,1309,1477,1372,1448,1418,1433,1476,1356,1462,1387,-1439,1475,1340,1447,1402,1474,1324,1461,1371,1473,269,448,1432,1417,1308,1460,-1711,1459,-1727,1441,1099,1099,1446,1386,1431,1401,-1743,1289,1083,1083,1160,1160,1458,1445,1067,1067,1370,1457,1307,1430,1129,1129,1098,1098,268,432,267,416,266,400,-1887,1144,1187,1082,1173,1113,1186,1066,1050,1158,1128,1143,1172,1097,1171,1081,420,391,1157,1112,1170,1142,1127,1065,1169,1049,1156,1096,1141,1111,1155,1080,1126,1154,1064,1153,1140,1095,1048,-2159,1125,1110,1137,-2175,823,823,1139,1138,807,807,384,264,368,263,868,838,853,791,867,822,852,837,866,806,865,790,-2319,851,821,836,352,262,850,805,849,-2399,533,533,835,820,336,261,578,548,563,577,532,532,832,772,562,562,547,547,305,275,560,515,290,290,288,258 };
1336 static const drmp3_uint8 tab32[] = { 130,162,193,209,44,28,76,140,9,9,9,9,9,9,9,9,190,254,222,238,126,94,157,157,109,61,173,205};
1337 static const drmp3_uint8 tab33[] = { 252,236,220,204,188,172,156,140,124,108,92,76,60,44,28,12 };
1338 static const drmp3_int16 tabindex[2*16] = { 0,32,64,98,0,132,180,218,292,364,426,538,648,746,0,1126,1460,1460,1460,1460,1460,1460,1460,1460,1842,1842,1842,1842,1842,1842,1842,1842 };
1339 static const drmp3_uint8 g_linbits[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,6,8,10,13,4,5,6,7,8,9,11,13 };
1341#define DRMP3_PEEK_BITS(n) (bs_cache >> (32 - (n)))
1342#define DRMP3_FLUSH_BITS(n) { bs_cache <<= (n); bs_sh += (n); }
1343#define DRMP3_CHECK_BITS while (bs_sh >= 0) { bs_cache |= (drmp3_uint32)*bs_next_ptr++ << bs_sh; bs_sh -= 8; }
1344#define DRMP3_BSPOS ((bs_next_ptr - bs->buf)*8 - 24 + bs_sh)
1347 int ireg = 0, big_val_cnt = gr_info->big_values;
1349 const drmp3_uint8 *bs_next_ptr = bs->buf + bs->pos/8;
1350 drmp3_uint32 bs_cache = (((bs_next_ptr[0]*256u + bs_next_ptr[1])*256u + bs_next_ptr[2])*256u + bs_next_ptr[3]) << (bs->pos & 7);
1351 int pairs_to_decode, np, bs_sh = (bs->pos & 7) - 8;
1354 while (big_val_cnt > 0)
1356 int tab_num = gr_info->table_select[ireg];
1357 int sfb_cnt = gr_info->region_count[ireg++];
1358 const drmp3_int16 *codebook = tabs + tabindex[tab_num];
1359 int linbits = g_linbits[tab_num];
1365 pairs_to_decode = DRMP3_MIN(big_val_cnt, np);
1370 int leaf = codebook[DRMP3_PEEK_BITS(w)];
1373 DRMP3_FLUSH_BITS(w);
1375 leaf = codebook[DRMP3_PEEK_BITS(w) - (leaf >> 3)];
1377 DRMP3_FLUSH_BITS(leaf >> 8);
1379 for (j = 0; j < 2; j++, dst++, leaf >>= 4)
1381 int lsb = leaf & 0x0F;
1384 lsb += DRMP3_PEEK_BITS(linbits);
1385 DRMP3_FLUSH_BITS(linbits);
1387 *dst = one*drmp3_L3_pow_43(lsb)*((
drmp3_int32)bs_cache < 0 ? -1: 1);
1390 *dst = g_drmp3_pow43[16 + lsb - 16*(bs_cache >> 31)]*one;
1392 DRMP3_FLUSH_BITS(lsb ? 1 : 0);
1395 }
while (--pairs_to_decode);
1396 }
while ((big_val_cnt -= np) > 0 && --sfb_cnt >= 0);
1402 pairs_to_decode = DRMP3_MIN(big_val_cnt, np);
1407 int leaf = codebook[DRMP3_PEEK_BITS(w)];
1410 DRMP3_FLUSH_BITS(w);
1412 leaf = codebook[DRMP3_PEEK_BITS(w) - (leaf >> 3)];
1414 DRMP3_FLUSH_BITS(leaf >> 8);
1416 for (j = 0; j < 2; j++, dst++, leaf >>= 4)
1418 int lsb = leaf & 0x0F;
1419 *dst = g_drmp3_pow43[16 + lsb - 16*(bs_cache >> 31)]*one;
1420 DRMP3_FLUSH_BITS(lsb ? 1 : 0);
1423 }
while (--pairs_to_decode);
1424 }
while ((big_val_cnt -= np) > 0 && --sfb_cnt >= 0);
1428 for (np = 1 - big_val_cnt;; dst += 4)
1430 const drmp3_uint8 *codebook_count1 = (gr_info->count1_table) ? tab33 : tab32;
1431 int leaf = codebook_count1[DRMP3_PEEK_BITS(4)];
1434 leaf = codebook_count1[(leaf >> 3) + (bs_cache << 4 >> (32 - (leaf & 3)))];
1436 DRMP3_FLUSH_BITS(leaf & 7);
1437 if (DRMP3_BSPOS > layer3gr_limit)
1441#define DRMP3_RELOAD_SCALEFACTOR if (!--np) { np = *sfb++/2; if (!np) break; one = *scf++; }
1442#define DRMP3_DEQ_COUNT1(s) if (leaf & (128 >> s)) { dst[s] = ((drmp3_int32)bs_cache < 0) ? -one : one; DRMP3_FLUSH_BITS(1) }
1443 DRMP3_RELOAD_SCALEFACTOR;
1444 DRMP3_DEQ_COUNT1(0);
1445 DRMP3_DEQ_COUNT1(1);
1446 DRMP3_RELOAD_SCALEFACTOR;
1447 DRMP3_DEQ_COUNT1(2);
1448 DRMP3_DEQ_COUNT1(3);
1452 bs->pos = layer3gr_limit;
1455static void drmp3_L3_midside_stereo(
float *left,
int n)
1458 float *right = left + 576;
1460 if (drmp3_have_simd())
1462 for (; i < n - 3; i += 4)
1464 drmp3_f4 vl = DRMP3_VLD(left + i);
1465 drmp3_f4 vr = DRMP3_VLD(right + i);
1466 DRMP3_VSTORE(left + i, DRMP3_VADD(vl, vr));
1467 DRMP3_VSTORE(right + i, DRMP3_VSUB(vl, vr));
1473 if (__builtin_constant_p(n % 4 == 0) && n % 4 == 0)
1487static void drmp3_L3_intensity_stereo_band(
float *left,
int n,
float kl,
float kr)
1490 for (i = 0; i < n; i++)
1492 left[i + 576] = left[i]*kr;
1493 left[i] = left[i]*kl;
1497static void drmp3_L3_stereo_top_band(
const float *right,
const drmp3_uint8 *sfb,
int nbands,
int max_band[3])
1501 max_band[0] = max_band[1] = max_band[2] = -1;
1503 for (i = 0; i < nbands; i++)
1505 for (k = 0; k < sfb[i]; k += 2)
1507 if (right[k] != 0 || right[k + 1] != 0)
1509 max_band[i % 3] = i;
1519 static const float g_pan[7*2] = { 0,1,0.21132487f,0.78867513f,0.36602540f,0.63397460f,0.5f,0.5f,0.63397460f,0.36602540f,0.78867513f,0.21132487f,1,0 };
1520 unsigned i, max_pos = DRMP3_HDR_TEST_MPEG1(hdr) ? 7 : 64;
1522 for (i = 0; sfb[i]; i++)
1524 unsigned ipos = ist_pos[i];
1525 if ((
int)i > max_band[i % 3] && ipos < max_pos)
1527 float kl, kr, s = DRMP3_HDR_TEST_MS_STEREO(hdr) ? 1.41421356f : 1;
1528 if (DRMP3_HDR_TEST_MPEG1(hdr))
1531 kr = g_pan[2*ipos + 1];
1535 kr = drmp3_L3_ldexp_q2(1, (ipos + 1) >> 1 << mpeg2_sh);
1542 drmp3_L3_intensity_stereo_band(left, sfb[i], kl*s, kr*s);
1543 }
else if (DRMP3_HDR_TEST_MS_STEREO(hdr))
1545 drmp3_L3_midside_stereo(left, sfb[i]);
1551static void drmp3_L3_intensity_stereo(
float *left,
drmp3_uint8 *ist_pos,
const drmp3_L3_gr_info *gr,
const drmp3_uint8 *hdr)
1553 int max_band[3], n_sfb = gr->n_long_sfb + gr->n_short_sfb;
1554 int i, max_blocks = gr->n_short_sfb ? 3 : 1;
1556 drmp3_L3_stereo_top_band(left + 576, gr->sfbtab, n_sfb, max_band);
1559 max_band[0] = max_band[1] = max_band[2] = DRMP3_MAX(DRMP3_MAX(max_band[0], max_band[1]), max_band[2]);
1561 for (i = 0; i < max_blocks; i++)
1563 int default_pos = DRMP3_HDR_TEST_MPEG1(hdr) ? 3 : 0;
1564 int itop = n_sfb - max_blocks + i;
1565 int prev = itop - max_blocks;
1566 ist_pos[itop] = (
drmp3_uint8)(max_band[i] >= prev ? default_pos : ist_pos[prev]);
1568 drmp3_L3_stereo_process(left, ist_pos, gr->sfbtab, hdr, max_band, gr[1].scalefac_compress & 1);
1571static void drmp3_L3_reorder(
float *grbuf,
float *scratch,
const drmp3_uint8 *sfb)
1574 float *src = grbuf, *dst = scratch;
1576 for (;0 != (len = *sfb); sfb += 3, src += 2*len)
1578 for (i = 0; i < len; i++, src++)
1580 *dst++ = src[0*len];
1581 *dst++ = src[1*len];
1582 *dst++ = src[2*len];
1585 DRMP3_COPY_MEMORY(grbuf, scratch, (dst - scratch)*
sizeof(
float));
1588static void drmp3_L3_antialias(
float *grbuf,
int nbands)
1590 static const float g_aa[2][8] = {
1591 {0.85749293f,0.88174200f,0.94962865f,0.98331459f,0.99551782f,0.99916056f,0.99989920f,0.99999316f},
1592 {0.51449576f,0.47173197f,0.31337745f,0.18191320f,0.09457419f,0.04096558f,0.01419856f,0.00369997f}
1595 for (; nbands > 0; nbands--, grbuf += 18)
1599 if (drmp3_have_simd())
for (; i < 8; i += 4)
1601 drmp3_f4 vu = DRMP3_VLD(grbuf + 18 + i);
1602 drmp3_f4 vd = DRMP3_VLD(grbuf + 14 - i);
1603 drmp3_f4 vc0 = DRMP3_VLD(g_aa[0] + i);
1604 drmp3_f4 vc1 = DRMP3_VLD(g_aa[1] + i);
1605 vd = DRMP3_VREV(vd);
1606 DRMP3_VSTORE(grbuf + 18 + i, DRMP3_VSUB(DRMP3_VMUL(vu, vc0), DRMP3_VMUL(vd, vc1)));
1607 vd = DRMP3_VADD(DRMP3_VMUL(vu, vc1), DRMP3_VMUL(vd, vc0));
1608 DRMP3_VSTORE(grbuf + 14 - i, DRMP3_VREV(vd));
1611#ifndef DR_MP3_ONLY_SIMD
1614 float u = grbuf[18 + i];
1615 float d = grbuf[17 - i];
1616 grbuf[18 + i] = u*g_aa[0][i] - d*g_aa[1][i];
1617 grbuf[17 - i] = u*g_aa[1][i] + d*g_aa[0][i];
1623static void drmp3_L3_dct3_9(
float *y)
1625 float s0, s1, s2, s3, s4, s5, s6, s7, s8, t0, t2, t4;
1627 s0 = y[0]; s2 = y[2]; s4 = y[4]; s6 = y[6]; s8 = y[8];
1630 t4 = (s4 + s2)*0.93969262f;
1631 t2 = (s8 + s2)*0.76604444f;
1632 s6 = (s4 - s8)*0.17364818f;
1641 s1 = y[1]; s3 = y[3]; s5 = y[5]; s7 = y[7];
1644 t0 = (s5 + s1)*0.98480775f;
1645 t4 = (s5 - s7)*0.34202014f;
1646 t2 = (s1 + s7)*0.64278761f;
1647 s1 = (s1 - s5 - s7)*0.86602540f;
1663static void drmp3_L3_imdct36(
float *grbuf,
float *overlap,
const float *window,
int nbands)
1666 static const float g_twid9[18] = {
1667 0.73727734f,0.79335334f,0.84339145f,0.88701083f,0.92387953f,0.95371695f,0.97629601f,0.99144486f,0.99904822f,0.67559021f,0.60876143f,0.53729961f,0.46174861f,0.38268343f,0.30070580f,0.21643961f,0.13052619f,0.04361938f
1670 for (j = 0; j < nbands; j++, grbuf += 18, overlap += 9)
1675 for (i = 0; i < 4; i++)
1677 si[8 - 2*i] = grbuf[4*i + 1] - grbuf[4*i + 2];
1678 co[1 + 2*i] = grbuf[4*i + 1] + grbuf[4*i + 2];
1679 si[7 - 2*i] = grbuf[4*i + 4] - grbuf[4*i + 3];
1680 co[2 + 2*i] = -(grbuf[4*i + 3] + grbuf[4*i + 4]);
1682 drmp3_L3_dct3_9(co);
1683 drmp3_L3_dct3_9(si);
1693 if (drmp3_have_simd())
for (; i < 8; i += 4)
1695 drmp3_f4 vovl = DRMP3_VLD(overlap + i);
1696 drmp3_f4 vc = DRMP3_VLD(co + i);
1697 drmp3_f4 vs = DRMP3_VLD(si + i);
1698 drmp3_f4 vr0 = DRMP3_VLD(g_twid9 + i);
1699 drmp3_f4 vr1 = DRMP3_VLD(g_twid9 + 9 + i);
1700 drmp3_f4 vw0 = DRMP3_VLD(window + i);
1701 drmp3_f4 vw1 = DRMP3_VLD(window + 9 + i);
1702 drmp3_f4 vsum = DRMP3_VADD(DRMP3_VMUL(vc, vr1), DRMP3_VMUL(vs, vr0));
1703 DRMP3_VSTORE(overlap + i, DRMP3_VSUB(DRMP3_VMUL(vc, vr0), DRMP3_VMUL(vs, vr1)));
1704 DRMP3_VSTORE(grbuf + i, DRMP3_VSUB(DRMP3_VMUL(vovl, vw0), DRMP3_VMUL(vsum, vw1)));
1705 vsum = DRMP3_VADD(DRMP3_VMUL(vovl, vw1), DRMP3_VMUL(vsum, vw0));
1706 DRMP3_VSTORE(grbuf + 14 - i, DRMP3_VREV(vsum));
1711 float ovl = overlap[i];
1712 float sum = co[i]*g_twid9[9 + i] + si[i]*g_twid9[0 + i];
1713 overlap[i] = co[i]*g_twid9[0 + i] - si[i]*g_twid9[9 + i];
1714 grbuf[i] = ovl*window[0 + i] -
sum*window[9 + i];
1715 grbuf[17 - i] = ovl*window[9 + i] +
sum*window[0 + i];
1720static void drmp3_L3_idct3(
float x0,
float x1,
float x2,
float *dst)
1722 float m1 = x1*0.86602540f;
1723 float a1 = x0 - x2*0.5f;
1729static void drmp3_L3_imdct12(
float *x,
float *dst,
float *overlap)
1731 static const float g_twid3[6] = { 0.79335334f,0.92387953f,0.99144486f, 0.60876143f,0.38268343f,0.13052619f };
1735 drmp3_L3_idct3(-x[0], x[6] + x[3], x[12] + x[9], co);
1736 drmp3_L3_idct3(x[15], x[12] - x[9], x[6] - x[3], si);
1739 for (i = 0; i < 3; i++)
1741 float ovl = overlap[i];
1742 float sum = co[i]*g_twid3[3 + i] + si[i]*g_twid3[0 + i];
1743 overlap[i] = co[i]*g_twid3[0 + i] - si[i]*g_twid3[3 + i];
1744 dst[i] = ovl*g_twid3[2 - i] -
sum*g_twid3[5 - i];
1745 dst[5 - i] = ovl*g_twid3[5 - i] +
sum*g_twid3[2 - i];
1749static void drmp3_L3_imdct_short(
float *grbuf,
float *overlap,
int nbands)
1751 for (;nbands > 0; nbands--, overlap += 9, grbuf += 18)
1754 DRMP3_COPY_MEMORY(tmp, grbuf,
sizeof(tmp));
1755 DRMP3_COPY_MEMORY(grbuf, overlap, 6*
sizeof(
float));
1756 drmp3_L3_imdct12(tmp, grbuf + 6, overlap + 6);
1757 drmp3_L3_imdct12(tmp + 1, grbuf + 12, overlap + 6);
1758 drmp3_L3_imdct12(tmp + 2, overlap, overlap + 6);
1762static void drmp3_L3_change_sign(
float *grbuf)
1765 for (b = 0, grbuf += 18; b < 32; b += 2, grbuf += 36)
1766 for (i = 1; i < 18; i += 2)
1767 grbuf[i] = -grbuf[i];
1770static void drmp3_L3_imdct_gr(
float *grbuf,
float *overlap,
unsigned block_type,
unsigned n_long_bands)
1772 static const float g_mdct_window[2][18] = {
1773 { 0.99904822f,0.99144486f,0.97629601f,0.95371695f,0.92387953f,0.88701083f,0.84339145f,0.79335334f,0.73727734f,0.04361938f,0.13052619f,0.21643961f,0.30070580f,0.38268343f,0.46174861f,0.53729961f,0.60876143f,0.67559021f },
1774 { 1,1,1,1,1,1,0.99144486f,0.92387953f,0.79335334f,0,0,0,0,0,0,0.13052619f,0.38268343f,0.60876143f }
1778 drmp3_L3_imdct36(grbuf, overlap, g_mdct_window[0], n_long_bands);
1779 grbuf += 18*n_long_bands;
1780 overlap += 9*n_long_bands;
1782 if (block_type == DRMP3_SHORT_BLOCK_TYPE)
1783 drmp3_L3_imdct_short(grbuf, overlap, 32 - n_long_bands);
1785 drmp3_L3_imdct36(grbuf, overlap, g_mdct_window[block_type == DRMP3_STOP_BLOCK_TYPE], 32 - n_long_bands);
1788static void drmp3_L3_save_reservoir(
drmp3dec *h, drmp3dec_scratch *s)
1790 int pos = (s->bs.pos + 7)/8u;
1791 int remains = s->bs.limit/8u - pos;
1792 if (remains > DRMP3_MAX_BITRESERVOIR_BYTES)
1794 pos += remains - DRMP3_MAX_BITRESERVOIR_BYTES;
1795 remains = DRMP3_MAX_BITRESERVOIR_BYTES;
1799 DRMP3_MOVE_MEMORY(h->
reserv_buf, s->maindata + pos, remains);
1804static int drmp3_L3_restore_reservoir(
drmp3dec *h, drmp3_bs *bs, drmp3dec_scratch *s,
int main_data_begin)
1806 int frame_bytes = (bs->limit - bs->pos)/8;
1807 int bytes_have = DRMP3_MIN(h->
reserv, main_data_begin);
1808 DRMP3_COPY_MEMORY(s->maindata, h->
reserv_buf + DRMP3_MAX(0, h->
reserv - main_data_begin), DRMP3_MIN(h->
reserv, main_data_begin));
1809 DRMP3_COPY_MEMORY(s->maindata + bytes_have, bs->buf + bs->pos/8, frame_bytes);
1810 drmp3_bs_init(&s->bs, s->maindata, bytes_have + frame_bytes);
1811 return h->
reserv >= main_data_begin;
1814static void drmp3_L3_decode(
drmp3dec *h, drmp3dec_scratch *s, drmp3_L3_gr_info *gr_info,
int nch)
1818 for (ch = 0; ch < nch; ch++)
1820 int layer3gr_limit = s->bs.pos + gr_info[ch].part_23_length;
1821 drmp3_L3_decode_scalefactors(h->
header, s->ist_pos[ch], &s->bs, gr_info + ch, s->scf, ch);
1822 drmp3_L3_huffman(s->grbuf[ch], &s->bs, gr_info + ch, s->scf, layer3gr_limit);
1825 if (DRMP3_HDR_TEST_I_STEREO(h->
header))
1827 drmp3_L3_intensity_stereo(s->grbuf[0], s->ist_pos[1], gr_info, h->
header);
1828 }
else if (DRMP3_HDR_IS_MS_STEREO(h->
header))
1830 drmp3_L3_midside_stereo(s->grbuf[0], 576);
1833 for (ch = 0; ch < nch; ch++, gr_info++)
1836 int n_long_bands = (gr_info->mixed_block_flag ? 2 : 0) << (
int)(DRMP3_HDR_GET_MY_SAMPLE_RATE(h->
header) == 2);
1838 if (gr_info->n_short_sfb)
1840 aa_bands = n_long_bands - 1;
1841 drmp3_L3_reorder(s->grbuf[ch] + n_long_bands*18, s->syn[0], gr_info->sfbtab + gr_info->n_long_sfb);
1844 drmp3_L3_antialias(s->grbuf[ch], aa_bands);
1845 drmp3_L3_imdct_gr(s->grbuf[ch], h->
mdct_overlap[ch], gr_info->block_type, n_long_bands);
1846 drmp3_L3_change_sign(s->grbuf[ch]);
1850static void drmp3d_DCT_II(
float *grbuf,
int n)
1852 static const float g_sec[24] = {
1853 10.19000816f,0.50060302f,0.50241929f,3.40760851f,0.50547093f,0.52249861f,2.05778098f,0.51544732f,0.56694406f,1.48416460f,0.53104258f,0.64682180f,1.16943991f,0.55310392f,0.78815460f,0.97256821f,0.58293498f,1.06067765f,0.83934963f,0.62250412f,1.72244716f,0.74453628f,0.67480832f,5.10114861f
1857 if (drmp3_have_simd())
for (; k < n; k += 4)
1859 drmp3_f4 t[4][8], *x;
1860 float *y = grbuf + k;
1862 for (x = t[0], i = 0; i < 8; i++, x++)
1864 drmp3_f4 x0 = DRMP3_VLD(&y[i*18]);
1865 drmp3_f4 x1 = DRMP3_VLD(&y[(15 - i)*18]);
1866 drmp3_f4 x2 = DRMP3_VLD(&y[(16 + i)*18]);
1867 drmp3_f4 x3 = DRMP3_VLD(&y[(31 - i)*18]);
1868 drmp3_f4 t0 = DRMP3_VADD(x0, x3);
1869 drmp3_f4 t1 = DRMP3_VADD(x1, x2);
1870 drmp3_f4 t2 = DRMP3_VMUL_S(DRMP3_VSUB(x1, x2), g_sec[3*i + 0]);
1871 drmp3_f4 t3 = DRMP3_VMUL_S(DRMP3_VSUB(x0, x3), g_sec[3*i + 1]);
1872 x[0] = DRMP3_VADD(t0, t1);
1873 x[8] = DRMP3_VMUL_S(DRMP3_VSUB(t0, t1), g_sec[3*i + 2]);
1874 x[16] = DRMP3_VADD(t3, t2);
1875 x[24] = DRMP3_VMUL_S(DRMP3_VSUB(t3, t2), g_sec[3*i + 2]);
1877 for (x = t[0], i = 0; i < 4; i++, x += 8)
1879 drmp3_f4 x0 = x[0], x1 = x[1], x2 = x[2], x3 = x[3], x4 = x[4], x5 = x[5], x6 = x[6], x7 = x[7], xt;
1880 xt = DRMP3_VSUB(x0, x7); x0 = DRMP3_VADD(x0, x7);
1881 x7 = DRMP3_VSUB(x1, x6); x1 = DRMP3_VADD(x1, x6);
1882 x6 = DRMP3_VSUB(x2, x5); x2 = DRMP3_VADD(x2, x5);
1883 x5 = DRMP3_VSUB(x3, x4); x3 = DRMP3_VADD(x3, x4);
1884 x4 = DRMP3_VSUB(x0, x3); x0 = DRMP3_VADD(x0, x3);
1885 x3 = DRMP3_VSUB(x1, x2); x1 = DRMP3_VADD(x1, x2);
1886 x[0] = DRMP3_VADD(x0, x1);
1887 x[4] = DRMP3_VMUL_S(DRMP3_VSUB(x0, x1), 0.70710677f);
1888 x5 = DRMP3_VADD(x5, x6);
1889 x6 = DRMP3_VMUL_S(DRMP3_VADD(x6, x7), 0.70710677f);
1890 x7 = DRMP3_VADD(x7, xt);
1891 x3 = DRMP3_VMUL_S(DRMP3_VADD(x3, x4), 0.70710677f);
1892 x5 = DRMP3_VSUB(x5, DRMP3_VMUL_S(x7, 0.198912367f));
1893 x7 = DRMP3_VADD(x7, DRMP3_VMUL_S(x5, 0.382683432f));
1894 x5 = DRMP3_VSUB(x5, DRMP3_VMUL_S(x7, 0.198912367f));
1895 x0 = DRMP3_VSUB(xt, x6); xt = DRMP3_VADD(xt, x6);
1896 x[1] = DRMP3_VMUL_S(DRMP3_VADD(xt, x7), 0.50979561f);
1897 x[2] = DRMP3_VMUL_S(DRMP3_VADD(x4, x3), 0.54119611f);
1898 x[3] = DRMP3_VMUL_S(DRMP3_VSUB(x0, x5), 0.60134488f);
1899 x[5] = DRMP3_VMUL_S(DRMP3_VADD(x0, x5), 0.89997619f);
1900 x[6] = DRMP3_VMUL_S(DRMP3_VSUB(x4, x3), 1.30656302f);
1901 x[7] = DRMP3_VMUL_S(DRMP3_VSUB(xt, x7), 2.56291556f);
1907#define DRMP3_VSAVE2(i, v) _mm_storel_pi((__m64 *)(void*)&y[i*18], v)
1909#define DRMP3_VSAVE2(i, v) vst1_f32((float32_t *)&y[(i)*18], vget_low_f32(v))
1911 for (i = 0; i < 7; i++, y += 4*18)
1913 drmp3_f4 s = DRMP3_VADD(t[3][i], t[3][i + 1]);
1914 DRMP3_VSAVE2(0, t[0][i]);
1915 DRMP3_VSAVE2(1, DRMP3_VADD(t[2][i], s));
1916 DRMP3_VSAVE2(2, DRMP3_VADD(t[1][i], t[1][i + 1]));
1917 DRMP3_VSAVE2(3, DRMP3_VADD(t[2][1 + i], s));
1919 DRMP3_VSAVE2(0, t[0][7]);
1920 DRMP3_VSAVE2(1, DRMP3_VADD(t[2][7], t[3][7]));
1921 DRMP3_VSAVE2(2, t[1][7]);
1922 DRMP3_VSAVE2(3, t[3][7]);
1925#define DRMP3_VSAVE4(i, v) DRMP3_VSTORE(&y[(i)*18], v)
1926 for (i = 0; i < 7; i++, y += 4*18)
1928 drmp3_f4 s = DRMP3_VADD(t[3][i], t[3][i + 1]);
1929 DRMP3_VSAVE4(0, t[0][i]);
1930 DRMP3_VSAVE4(1, DRMP3_VADD(t[2][i], s));
1931 DRMP3_VSAVE4(2, DRMP3_VADD(t[1][i], t[1][i + 1]));
1932 DRMP3_VSAVE4(3, DRMP3_VADD(t[2][1 + i], s));
1934 DRMP3_VSAVE4(0, t[0][7]);
1935 DRMP3_VSAVE4(1, DRMP3_VADD(t[2][7], t[3][7]));
1936 DRMP3_VSAVE4(2, t[1][7]);
1937 DRMP3_VSAVE4(3, t[3][7]);
1941#ifdef DR_MP3_ONLY_SIMD
1946 float t[4][8], *x, *y = grbuf + k;
1948 for (x = t[0], i = 0; i < 8; i++, x++)
1951 float x1 = y[(15 - i)*18];
1952 float x2 = y[(16 + i)*18];
1953 float x3 = y[(31 - i)*18];
1956 float t2 = (x1 - x2)*g_sec[3*i + 0];
1957 float t3 = (x0 - x3)*g_sec[3*i + 1];
1959 x[8] = (t0 - t1)*g_sec[3*i + 2];
1961 x[24] = (t3 - t2)*g_sec[3*i + 2];
1963 for (x = t[0], i = 0; i < 4; i++, x += 8)
1965 float x0 = x[0], x1 = x[1], x2 = x[2], x3 = x[3], x4 = x[4], x5 = x[5], x6 = x[6], x7 = x[7], xt;
1966 xt = x0 - x7; x0 += x7;
1967 x7 = x1 - x6; x1 += x6;
1968 x6 = x2 - x5; x2 += x5;
1969 x5 = x3 - x4; x3 += x4;
1970 x4 = x0 - x3; x0 += x3;
1971 x3 = x1 - x2; x1 += x2;
1973 x[4] = (x0 - x1)*0.70710677f;
1975 x6 = (x6 + x7)*0.70710677f;
1977 x3 = (x3 + x4)*0.70710677f;
1978 x5 -= x7*0.198912367f;
1979 x7 += x5*0.382683432f;
1980 x5 -= x7*0.198912367f;
1981 x0 = xt - x6; xt += x6;
1982 x[1] = (xt + x7)*0.50979561f;
1983 x[2] = (x4 + x3)*0.54119611f;
1984 x[3] = (x0 - x5)*0.60134488f;
1985 x[5] = (x0 + x5)*0.89997619f;
1986 x[6] = (x4 - x3)*1.30656302f;
1987 x[7] = (xt - x7)*2.56291556f;
1990 for (i = 0; i < 7; i++, y += 4*18)
1993 y[1*18] = t[2][i] + t[3][i] + t[3][i + 1];
1994 y[2*18] = t[1][i] + t[1][i + 1];
1995 y[3*18] = t[2][i + 1] + t[3][i] + t[3][i + 1];
1998 y[1*18] = t[2][7] + t[3][7];
2005#ifndef DR_MP3_FLOAT_OUTPUT
2016 if (sample >= 32766.5f)
return (
drmp3_int16) 32767;
2017 if (sample <= -32767.5f)
return (
drmp3_int16)-32768;
2024typedef float drmp3d_sample_t;
2026static float drmp3d_scale_pcm(
float sample)
2028 return sample*(1.f/32768.f);
2032static void drmp3d_synth_pair(drmp3d_sample_t *pcm,
int nch,
const float *z)
2035 a = (z[14*64] - z[ 0]) * 29;
2036 a += (z[ 1*64] + z[13*64]) * 213;
2037 a += (z[12*64] - z[ 2*64]) * 459;
2038 a += (z[ 3*64] + z[11*64]) * 2037;
2039 a += (z[10*64] - z[ 4*64]) * 5153;
2040 a += (z[ 5*64] + z[ 9*64]) * 6574;
2041 a += (z[ 8*64] - z[ 6*64]) * 37489;
2042 a += z[ 7*64] * 75038;
2043 pcm[0] = drmp3d_scale_pcm(a);
2047 a += z[12*64] * 1567;
2048 a += z[10*64] * 9727;
2049 a += z[ 8*64] * 64019;
2050 a += z[ 6*64] * -9975;
2051 a += z[ 4*64] * -45;
2052 a += z[ 2*64] * 146;
2054 pcm[16*nch] = drmp3d_scale_pcm(a);
2057static void drmp3d_synth(
float *xl, drmp3d_sample_t *dstl,
int nch,
float *lins)
2060 float *xr = xl + 576*(nch - 1);
2061 drmp3d_sample_t *dstr = dstl + (nch - 1);
2063 static const float g_win[] = {
2064 -1,26,-31,208,218,401,-519,2063,2000,4788,-5517,7134,5959,35640,-39336,74992,
2065 -1,24,-35,202,222,347,-581,2080,1952,4425,-5879,7640,5288,33791,-41176,74856,
2066 -1,21,-38,196,225,294,-645,2087,1893,4063,-6237,8092,4561,31947,-43006,74630,
2067 -1,19,-41,190,227,244,-711,2085,1822,3705,-6589,8492,3776,30112,-44821,74313,
2068 -1,17,-45,183,228,197,-779,2075,1739,3351,-6935,8840,2935,28289,-46617,73908,
2069 -1,16,-49,176,228,153,-848,2057,1644,3004,-7271,9139,2037,26482,-48390,73415,
2070 -2,14,-53,169,227,111,-919,2032,1535,2663,-7597,9389,1082,24694,-50137,72835,
2071 -2,13,-58,161,224,72,-991,2001,1414,2330,-7910,9592,70,22929,-51853,72169,
2072 -2,11,-63,154,221,36,-1064,1962,1280,2006,-8209,9750,-998,21189,-53534,71420,
2073 -2,10,-68,147,215,2,-1137,1919,1131,1692,-8491,9863,-2122,19478,-55178,70590,
2074 -3,9,-73,139,208,-29,-1210,1870,970,1388,-8755,9935,-3300,17799,-56778,69679,
2075 -3,8,-79,132,200,-57,-1283,1817,794,1095,-8998,9966,-4533,16155,-58333,68692,
2076 -4,7,-85,125,189,-83,-1356,1759,605,814,-9219,9959,-5818,14548,-59838,67629,
2077 -4,7,-91,117,177,-106,-1428,1698,402,545,-9416,9916,-7154,12980,-61289,66494,
2078 -5,6,-97,111,163,-127,-1498,1634,185,288,-9585,9838,-8540,11455,-62684,65290
2080 float *zlin = lins + 15*64;
2081 const float *w = g_win;
2083 zlin[4*15] = xl[18*16];
2084 zlin[4*15 + 1] = xr[18*16];
2085 zlin[4*15 + 2] = xl[0];
2086 zlin[4*15 + 3] = xr[0];
2088 zlin[4*31] = xl[1 + 18*16];
2089 zlin[4*31 + 1] = xr[1 + 18*16];
2090 zlin[4*31 + 2] = xl[1];
2091 zlin[4*31 + 3] = xr[1];
2093 drmp3d_synth_pair(dstr, nch, lins + 4*15 + 1);
2094 drmp3d_synth_pair(dstr + 32*nch, nch, lins + 4*15 + 64 + 1);
2095 drmp3d_synth_pair(dstl, nch, lins + 4*15);
2096 drmp3d_synth_pair(dstl + 32*nch, nch, lins + 4*15 + 64);
2099 if (drmp3_have_simd())
for (i = 14; i >= 0; i--)
2101#define DRMP3_VLOAD(k) drmp3_f4 w0 = DRMP3_VSET(*w++); drmp3_f4 w1 = DRMP3_VSET(*w++); drmp3_f4 vz = DRMP3_VLD(&zlin[4*i - 64*k]); drmp3_f4 vy = DRMP3_VLD(&zlin[4*i - 64*(15 - k)]);
2102#define DRMP3_V0(k) { DRMP3_VLOAD(k) b = DRMP3_VADD(DRMP3_VMUL(vz, w1), DRMP3_VMUL(vy, w0)) ; a = DRMP3_VSUB(DRMP3_VMUL(vz, w0), DRMP3_VMUL(vy, w1)); }
2103#define DRMP3_V1(k) { DRMP3_VLOAD(k) b = DRMP3_VADD(b, DRMP3_VADD(DRMP3_VMUL(vz, w1), DRMP3_VMUL(vy, w0))); a = DRMP3_VADD(a, DRMP3_VSUB(DRMP3_VMUL(vz, w0), DRMP3_VMUL(vy, w1))); }
2104#define DRMP3_V2(k) { DRMP3_VLOAD(k) b = DRMP3_VADD(b, DRMP3_VADD(DRMP3_VMUL(vz, w1), DRMP3_VMUL(vy, w0))); a = DRMP3_VADD(a, DRMP3_VSUB(DRMP3_VMUL(vy, w1), DRMP3_VMUL(vz, w0))); }
2106 zlin[4*i] = xl[18*(31 - i)];
2107 zlin[4*i + 1] = xr[18*(31 - i)];
2108 zlin[4*i + 2] = xl[1 + 18*(31 - i)];
2109 zlin[4*i + 3] = xr[1 + 18*(31 - i)];
2110 zlin[4*i + 64] = xl[1 + 18*(1 + i)];
2111 zlin[4*i + 64 + 1] = xr[1 + 18*(1 + i)];
2112 zlin[4*i - 64 + 2] = xl[18*(1 + i)];
2113 zlin[4*i - 64 + 3] = xr[18*(1 + i)];
2115 DRMP3_V0(0) DRMP3_V2(1) DRMP3_V1(2) DRMP3_V2(3) DRMP3_V1(4) DRMP3_V2(5) DRMP3_V1(6) DRMP3_V2(7)
2118#ifndef DR_MP3_FLOAT_OUTPUT
2120 static const drmp3_f4 g_max = { 32767.0f, 32767.0f, 32767.0f, 32767.0f };
2121 static const drmp3_f4 g_min = { -32768.0f, -32768.0f, -32768.0f, -32768.0f };
2122 __m128i pcm8 = _mm_packs_epi32(_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(a, g_max), g_min)),
2123 _mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(b, g_max), g_min)));
2124 dstr[(15 - i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 1);
2125 dstr[(17 + i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 5);
2126 dstl[(15 - i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 0);
2127 dstl[(17 + i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 4);
2128 dstr[(47 - i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 3);
2129 dstr[(49 + i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 7);
2130 dstl[(47 - i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 2);
2131 dstl[(49 + i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 6);
2133 int16x4_t pcma, pcmb;
2134 a = DRMP3_VADD(a, DRMP3_VSET(0.5f));
2135 b = DRMP3_VADD(b, DRMP3_VSET(0.5f));
2136 pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, DRMP3_VSET(0)))));
2137 pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, DRMP3_VSET(0)))));
2138 vst1_lane_s16(dstr + (15 - i)*nch, pcma, 1);
2139 vst1_lane_s16(dstr + (17 + i)*nch, pcmb, 1);
2140 vst1_lane_s16(dstl + (15 - i)*nch, pcma, 0);
2141 vst1_lane_s16(dstl + (17 + i)*nch, pcmb, 0);
2142 vst1_lane_s16(dstr + (47 - i)*nch, pcma, 3);
2143 vst1_lane_s16(dstr + (49 + i)*nch, pcmb, 3);
2144 vst1_lane_s16(dstl + (47 - i)*nch, pcma, 2);
2145 vst1_lane_s16(dstl + (49 + i)*nch, pcmb, 2);
2149 static const drmp3_f4 g_scale = { 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f };
2151 const drmp3_f4 g_scale = vdupq_n_f32(1.0f/32768.0f);
2153 a = DRMP3_VMUL(a, g_scale);
2154 b = DRMP3_VMUL(b, g_scale);
2156 _mm_store_ss(dstr + (15 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 1, 1, 1)));
2157 _mm_store_ss(dstr + (17 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(1, 1, 1, 1)));
2158 _mm_store_ss(dstl + (15 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 0, 0, 0)));
2159 _mm_store_ss(dstl + (17 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(0, 0, 0, 0)));
2160 _mm_store_ss(dstr + (47 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(3, 3, 3, 3)));
2161 _mm_store_ss(dstr + (49 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(3, 3, 3, 3)));
2162 _mm_store_ss(dstl + (47 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 2, 2, 2)));
2163 _mm_store_ss(dstl + (49 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(2, 2, 2, 2)));
2165 vst1q_lane_f32(dstr + (15 - i)*nch, a, 1);
2166 vst1q_lane_f32(dstr + (17 + i)*nch, b, 1);
2167 vst1q_lane_f32(dstl + (15 - i)*nch, a, 0);
2168 vst1q_lane_f32(dstl + (17 + i)*nch, b, 0);
2169 vst1q_lane_f32(dstr + (47 - i)*nch, a, 3);
2170 vst1q_lane_f32(dstr + (49 + i)*nch, b, 3);
2171 vst1q_lane_f32(dstl + (47 - i)*nch, a, 2);
2172 vst1q_lane_f32(dstl + (49 + i)*nch, b, 2);
2178#ifdef DR_MP3_ONLY_SIMD
2181 for (i = 14; i >= 0; i--)
2183#define DRMP3_LOAD(k) float w0 = *w++; float w1 = *w++; float *vz = &zlin[4*i - k*64]; float *vy = &zlin[4*i - (15 - k)*64];
2184#define DRMP3_S0(k) { int j; DRMP3_LOAD(k); for (j = 0; j < 4; j++) b[j] = vz[j]*w1 + vy[j]*w0, a[j] = vz[j]*w0 - vy[j]*w1; }
2185#define DRMP3_S1(k) { int j; DRMP3_LOAD(k); for (j = 0; j < 4; j++) b[j] += vz[j]*w1 + vy[j]*w0, a[j] += vz[j]*w0 - vy[j]*w1; }
2186#define DRMP3_S2(k) { int j; DRMP3_LOAD(k); for (j = 0; j < 4; j++) b[j] += vz[j]*w1 + vy[j]*w0, a[j] += vy[j]*w1 - vz[j]*w0; }
2189 zlin[4*i] = xl[18*(31 - i)];
2190 zlin[4*i + 1] = xr[18*(31 - i)];
2191 zlin[4*i + 2] = xl[1 + 18*(31 - i)];
2192 zlin[4*i + 3] = xr[1 + 18*(31 - i)];
2193 zlin[4*(i + 16)] = xl[1 + 18*(1 + i)];
2194 zlin[4*(i + 16) + 1] = xr[1 + 18*(1 + i)];
2195 zlin[4*(i - 16) + 2] = xl[18*(1 + i)];
2196 zlin[4*(i - 16) + 3] = xr[18*(1 + i)];
2198 DRMP3_S0(0) DRMP3_S2(1) DRMP3_S1(2) DRMP3_S2(3) DRMP3_S1(4) DRMP3_S2(5) DRMP3_S1(6) DRMP3_S2(7)
2200 dstr[(15 - i)*nch] = drmp3d_scale_pcm(a[1]);
2201 dstr[(17 + i)*nch] = drmp3d_scale_pcm(b[1]);
2202 dstl[(15 - i)*nch] = drmp3d_scale_pcm(a[0]);
2203 dstl[(17 + i)*nch] = drmp3d_scale_pcm(b[0]);
2204 dstr[(47 - i)*nch] = drmp3d_scale_pcm(a[3]);
2205 dstr[(49 + i)*nch] = drmp3d_scale_pcm(b[3]);
2206 dstl[(47 - i)*nch] = drmp3d_scale_pcm(a[2]);
2207 dstl[(49 + i)*nch] = drmp3d_scale_pcm(b[2]);
2212static void drmp3d_synth_granule(
float *qmf_state,
float *grbuf,
int nbands,
int nch, drmp3d_sample_t *pcm,
float *lins)
2215 for (i = 0; i < nch; i++)
2217 drmp3d_DCT_II(grbuf + 576*i, nbands);
2220 DRMP3_COPY_MEMORY(lins, qmf_state,
sizeof(
float)*15*64);
2222 for (i = 0; i < nbands; i += 2)
2224 drmp3d_synth(grbuf + i, pcm + 32*nch*i, nch, lins + i*64);
2226#ifndef DR_MP3_NONSTANDARD_BUT_LOGICAL
2229 for (i = 0; i < 15*64; i += 2)
2231 qmf_state[i] = lins[nbands*64 + i];
2236 DRMP3_COPY_MEMORY(qmf_state, lins + nbands*64,
sizeof(
float)*15*64);
2240static int drmp3d_match_frame(
const drmp3_uint8 *hdr,
int mp3_bytes,
int frame_bytes)
2243 for (i = 0, nmatch = 0; nmatch < DRMP3_MAX_FRAME_SYNC_MATCHES; nmatch++)
2245 i += drmp3_hdr_frame_bytes(hdr + i, frame_bytes) + drmp3_hdr_padding(hdr + i);
2246 if (i + DRMP3_HDR_SIZE > mp3_bytes)
2248 if (!drmp3_hdr_compare(hdr, hdr + i))
2254static int drmp3d_find_frame(
const drmp3_uint8 *mp3,
int mp3_bytes,
int *free_format_bytes,
int *ptr_frame_bytes)
2257 for (i = 0; i < mp3_bytes - DRMP3_HDR_SIZE; i++, mp3++)
2259 if (drmp3_hdr_valid(mp3))
2261 int frame_bytes = drmp3_hdr_frame_bytes(mp3, *free_format_bytes);
2262 int frame_and_padding = frame_bytes + drmp3_hdr_padding(mp3);
2264 for (k = DRMP3_HDR_SIZE; !frame_bytes && k < DRMP3_MAX_FREE_FORMAT_FRAME_SIZE && i + 2*k < mp3_bytes - DRMP3_HDR_SIZE; k++)
2266 if (drmp3_hdr_compare(mp3, mp3 + k))
2268 int fb = k - drmp3_hdr_padding(mp3);
2269 int nextfb = fb + drmp3_hdr_padding(mp3 + k);
2270 if (i + k + nextfb + DRMP3_HDR_SIZE > mp3_bytes || !drmp3_hdr_compare(mp3, mp3 + k + nextfb))
2272 frame_and_padding = k;
2274 *free_format_bytes = fb;
2278 if ((frame_bytes && i + frame_and_padding <= mp3_bytes &&
2279 drmp3d_match_frame(mp3, mp3_bytes - i, frame_bytes)) ||
2280 (!i && frame_and_padding == mp3_bytes))
2282 *ptr_frame_bytes = frame_and_padding;
2285 *free_format_bytes = 0;
2288 *ptr_frame_bytes = 0;
2299 int i = 0, igr, frame_size = 0, success = 1;
2301 drmp3_bs bs_frame[1];
2302 drmp3dec_scratch scratch;
2304 if (mp3_bytes > 4 && dec->
header[0] == 0xff && drmp3_hdr_compare(dec->
header, mp3))
2306 frame_size = drmp3_hdr_frame_bytes(mp3, dec->
free_format_bytes) + drmp3_hdr_padding(mp3);
2307 if (frame_size != mp3_bytes && (frame_size + DRMP3_HDR_SIZE > mp3_bytes || !drmp3_hdr_compare(mp3, mp3 + frame_size)))
2314 DRMP3_ZERO_MEMORY(dec,
sizeof(
drmp3dec));
2316 if (!frame_size || i + frame_size > mp3_bytes)
2318 info->frame_bytes = i;
2324 DRMP3_COPY_MEMORY(dec->
header, hdr, DRMP3_HDR_SIZE);
2325 info->frame_bytes = i + frame_size;
2326 info->channels = DRMP3_HDR_IS_MONO(hdr) ? 1 : 2;
2327 info->sample_rate = drmp3_hdr_sample_rate_hz(hdr);
2328 info->layer = 4 - DRMP3_HDR_GET_LAYER(hdr);
2329 info->bitrate_kbps = drmp3_hdr_bitrate_kbps(hdr);
2331 drmp3_bs_init(bs_frame, hdr + DRMP3_HDR_SIZE, frame_size - DRMP3_HDR_SIZE);
2332 if (DRMP3_HDR_IS_CRC(hdr))
2334 drmp3_bs_get_bits(bs_frame, 16);
2337 if (
info->layer == 3)
2339 int main_data_begin = drmp3_L3_read_side_info(bs_frame, scratch.gr_info, hdr);
2340 if (main_data_begin < 0 || bs_frame->pos > bs_frame->limit)
2345 success = drmp3_L3_restore_reservoir(dec, bs_frame, &scratch, main_data_begin);
2346 if (success && pcm != NULL)
2348 for (igr = 0; igr < (DRMP3_HDR_TEST_MPEG1(hdr) ? 2 : 1); igr++, pcm = DRMP3_OFFSET_PTR(pcm,
sizeof(drmp3d_sample_t)*576*
info->channels))
2350 DRMP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*
sizeof(
float));
2351 drmp3_L3_decode(dec, &scratch, scratch.gr_info + igr*
info->channels,
info->channels);
2352 drmp3d_synth_granule(dec->
qmf_state, scratch.grbuf[0], 18,
info->channels, (drmp3d_sample_t*)pcm, scratch.syn[0]);
2355 drmp3_L3_save_reservoir(dec, &scratch);
2358#ifdef DR_MP3_ONLY_MP3
2361 drmp3_L12_scale_info sci[1];
2364 return drmp3_hdr_frame_samples(hdr);
2367 drmp3_L12_read_scale_info(hdr, bs_frame, sci);
2369 DRMP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*
sizeof(
float));
2370 for (i = 0, igr = 0; igr < 3; igr++)
2372 if (12 == (i += drmp3_L12_dequantize_granule(scratch.grbuf[0] + i, bs_frame, sci,
info->layer | 1)))
2375 drmp3_L12_apply_scf_384(sci, sci->scf + igr, scratch.grbuf[0]);
2376 drmp3d_synth_granule(dec->
qmf_state, scratch.grbuf[0], 12,
info->channels, (drmp3d_sample_t*)pcm, scratch.syn[0]);
2377 DRMP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*
sizeof(
float));
2378 pcm = DRMP3_OFFSET_PTR(pcm,
sizeof(drmp3d_sample_t)*384*
info->channels);
2380 if (bs_frame->pos > bs_frame->limit)
2389 return success*drmp3_hdr_frame_samples(dec->
header);
2396 size_t aligned_count = num_samples & ~7;
2397 for(; i < aligned_count; i+=8)
2399 drmp3_f4 scale = DRMP3_VSET(32768.0f);
2400 drmp3_f4 a = DRMP3_VMUL(DRMP3_VLD(&in[i ]), scale);
2401 drmp3_f4 b = DRMP3_VMUL(DRMP3_VLD(&in[i+4]), scale);
2403 drmp3_f4 s16max = DRMP3_VSET( 32767.0f);
2404 drmp3_f4 s16min = DRMP3_VSET(-32768.0f);
2405 __m128i pcm8 = _mm_packs_epi32(_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(a, s16max), s16min)),
2406 _mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(b, s16max), s16min)));
2407 out[i ] = (
drmp3_int16)_mm_extract_epi16(pcm8, 0);
2408 out[i+1] = (
drmp3_int16)_mm_extract_epi16(pcm8, 1);
2409 out[i+2] = (
drmp3_int16)_mm_extract_epi16(pcm8, 2);
2410 out[i+3] = (
drmp3_int16)_mm_extract_epi16(pcm8, 3);
2411 out[i+4] = (
drmp3_int16)_mm_extract_epi16(pcm8, 4);
2412 out[i+5] = (
drmp3_int16)_mm_extract_epi16(pcm8, 5);
2413 out[i+6] = (
drmp3_int16)_mm_extract_epi16(pcm8, 6);
2414 out[i+7] = (
drmp3_int16)_mm_extract_epi16(pcm8, 7);
2416 int16x4_t pcma, pcmb;
2417 a = DRMP3_VADD(a, DRMP3_VSET(0.5f));
2418 b = DRMP3_VADD(b, DRMP3_VSET(0.5f));
2419 pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, DRMP3_VSET(0)))));
2420 pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, DRMP3_VSET(0)))));
2421 vst1_lane_s16(out+i , pcma, 0);
2422 vst1_lane_s16(out+i+1, pcma, 1);
2423 vst1_lane_s16(out+i+2, pcma, 2);
2424 vst1_lane_s16(out+i+3, pcma, 3);
2425 vst1_lane_s16(out+i+4, pcmb, 0);
2426 vst1_lane_s16(out+i+5, pcmb, 1);
2427 vst1_lane_s16(out+i+6, pcmb, 2);
2428 vst1_lane_s16(out+i+7, pcmb, 3);
2432 for(; i < num_samples; i++)
2434 float sample = in[i] * 32768.0f;
2435 if (sample >= 32766.5f)
2437 else if (sample <= -32767.5f)
2456#if defined(SIZE_MAX)
2457 #define DRMP3_SIZE_MAX SIZE_MAX
2459 #if defined(_WIN64) || defined(_LP64) || defined(__LP64__)
2460 #define DRMP3_SIZE_MAX ((drmp3_uint64)0xFFFFFFFFFFFFFFFF)
2462 #define DRMP3_SIZE_MAX 0xFFFFFFFF
2468#ifndef DRMP3_SEEK_LEADING_MP3_FRAMES
2469#define DRMP3_SEEK_LEADING_MP3_FRAMES 2
2472#define DRMP3_MIN_DATA_CHUNK_SIZE 16384
2475#ifndef DRMP3_DATA_CHUNK_SIZE
2476#define DRMP3_DATA_CHUNK_SIZE (DRMP3_MIN_DATA_CHUNK_SIZE*4)
2480#define DRMP3_COUNTOF(x) (sizeof(x) / sizeof(x[0]))
2481#define DRMP3_CLAMP(x, lo, hi) (DRMP3_MAX(lo, DRMP3_MIN(x, hi)))
2484#define DRMP3_PI_D 3.14159265358979323846264
2487#define DRMP3_DEFAULT_RESAMPLER_LPF_ORDER 2
2489static DRMP3_INLINE float drmp3_mix_f32(
float x,
float y,
float a)
2491 return x*(1-a) + y*a;
2493static DRMP3_INLINE float drmp3_mix_f32_fast(
float x,
float y,
float a)
2521static void* drmp3__malloc_default(
size_t sz,
void* pUserData)
2524 return DRMP3_MALLOC(sz);
2527static void* drmp3__realloc_default(
void* p,
size_t sz,
void* pUserData)
2530 return DRMP3_REALLOC(p, sz);
2533static void drmp3__free_default(
void* p,
void* pUserData)
2542 if (pAllocationCallbacks == NULL) {
2546 if (pAllocationCallbacks->
onMalloc != NULL) {
2551 if (pAllocationCallbacks->
onRealloc != NULL) {
2558static void* drmp3__realloc_from_callbacks(
void* p,
size_t szNew,
size_t szOld,
const drmp3_allocation_callbacks* pAllocationCallbacks)
2560 if (pAllocationCallbacks == NULL) {
2564 if (pAllocationCallbacks->
onRealloc != NULL) {
2569 if (pAllocationCallbacks->
onMalloc != NULL && pAllocationCallbacks->
onFree != NULL) {
2578 DRMP3_COPY_MEMORY(p2, p, szOld);
2590 if (p == NULL || pAllocationCallbacks == NULL) {
2594 if (pAllocationCallbacks->
onFree != NULL) {
2602 if (pAllocationCallbacks != NULL) {
2604 return *pAllocationCallbacks;
2609 allocationCallbacks.
onMalloc = drmp3__malloc_default;
2610 allocationCallbacks.
onRealloc = drmp3__realloc_default;
2611 allocationCallbacks.
onFree = drmp3__free_default;
2612 return allocationCallbacks;
2618static size_t drmp3__on_read(
drmp3* pMP3,
void* pBufferOut,
size_t bytesToRead)
2622 DRMP3_ASSERT(pMP3 != NULL);
2623 DRMP3_ASSERT(pMP3->
onRead != NULL);
2629 if (bytesToRead == 0) {
2639static size_t drmp3__on_read_clamped(
drmp3* pMP3,
void* pBufferOut,
size_t bytesToRead)
2641 DRMP3_ASSERT(pMP3 != NULL);
2642 DRMP3_ASSERT(pMP3->
onRead != NULL);
2645 return drmp3__on_read(pMP3, pBufferOut, bytesToRead);
2650 if (bytesToRead > bytesRemaining) {
2651 bytesToRead = (
size_t)bytesRemaining;
2654 return drmp3__on_read(pMP3, pBufferOut, bytesToRead);
2660 DRMP3_ASSERT(offset >= 0);
2678 if (offset <= 0x7FFFFFFF) {
2679 return drmp3__on_seek(pMP3, (
int)offset, origin);
2687 offset -= 0x7FFFFFFF;
2688 while (offset > 0) {
2689 if (offset <= 0x7FFFFFFF) {
2698 offset -= 0x7FFFFFFF;
2710 DRMP3_ZERO_OBJECT(&metadata);
2711 metadata.
type = type;
2724 DRMP3_ASSERT(pMP3 != NULL);
2725 DRMP3_ASSERT(pMP3->
onRead != NULL);
2735 if (pMP3->
dataSize < DRMP3_MIN_DATA_CHUNK_SIZE) {
2739 if (pMP3->
pData != NULL) {
2749 newDataCap = DRMP3_DATA_CHUNK_SIZE;
2752 if (pNewData == NULL) {
2756 pMP3->
pData = pNewData;
2761 if (bytesRead == 0) {
2776 DRMP3_ASSERT(pMP3->
pData != NULL);
2780 if (pMP3->
pData == NULL) {
2791 if (pcmFramesRead > 0) {
2792 pcmFramesRead = drmp3_hdr_frame_samples(pMP3->
decoder.
header);
2798 if (pMP3FrameInfo != NULL) {
2799 *pMP3FrameInfo =
info;
2802 if (ppMP3FrameData != NULL) {
2807 }
else if (
info.frame_bytes == 0) {
2820 newDataCap = pMP3->
dataCapacity + DRMP3_DATA_CHUNK_SIZE;
2823 if (pNewData == NULL) {
2827 pMP3->
pData = pNewData;
2833 if (bytesRead == 0) {
2842 return pcmFramesRead;
2850 DRMP3_ASSERT(pMP3 != NULL);
2859 if (pcmFramesRead > 0) {
2860 pcmFramesRead = drmp3_hdr_frame_samples(pMP3->
decoder.
header);
2866 if (pMP3FrameInfo != NULL) {
2867 *pMP3FrameInfo =
info;
2870 if (ppMP3FrameData != NULL) {
2875 }
else if (
info.frame_bytes > 0) {
2889 return pcmFramesRead;
2895 return drmp3_decode_next_frame_ex__memory(pMP3, pPCMFrames, pMP3FrameInfo, ppMP3FrameData);
2897 return drmp3_decode_next_frame_ex__callbacks(pMP3, pPCMFrames, pMP3FrameInfo, ppMP3FrameData);
2903 DRMP3_ASSERT(pMP3 != NULL);
2904 return drmp3_decode_next_frame_ex(pMP3, (drmp3d_sample_t*)pMP3->
pcmFrames, NULL, NULL);
2912 DRMP3_ASSERT(pMP3 != NULL);
2914 pcmFrameCount = drmp3_decode_next_frame_ex(pMP3, NULL, NULL, NULL);
2915 if (pcmFrameCount == 0) {
2924 return pcmFrameCount;
2935 DRMP3_ASSERT(pMP3 != NULL);
2936 DRMP3_ASSERT(onRead != NULL);
2946 pMP3->
allocationCallbacks = drmp3_copy_allocation_callbacks_or_defaults(pAllocationCallbacks);
2961 if (onSeek != NULL && onTell != NULL) {
2964 int streamEndOffset = 0;
2967 if (onTell(pUserData, &streamLen)) {
2969 if (streamLen > 128) {
2972 if (onRead(pUserData, id3, 3) == 3 && id3[0] ==
'T' && id3[1] ==
'A' && id3[2] ==
'G') {
2974 streamEndOffset -= 128;
2978 if (onMeta != NULL) {
2980 tag[0] =
'T'; tag[1] =
'A'; tag[2] =
'G';
2982 if (onRead(pUserData, tag + 3, 125) == 125) {
2997 if (streamLen > 32) {
3000 if (onRead(pUserData, ape, 32) == 32 && ape[0] ==
'A' && ape[1] ==
'P' && ape[2] ==
'E' && ape[3] ==
'T' && ape[4] ==
'A' && ape[5] ==
'G' && ape[6] ==
'E' && ape[7] ==
'X') {
3008 streamEndOffset -= 32 + tagSize;
3009 streamLen -= 32 + tagSize;
3012 if (onMeta != NULL) {
3015 size_t apeTagSize = (
size_t)tagSize + 32;
3017 if (pTagData != NULL) {
3018 if (onRead(pUserData, pTagData, apeTagSize) == apeTagSize) {
3061 if (onRead(pUserData, header, 10) == 10) {
3062 if (header[0] ==
'I' && header[1] ==
'D' && header[2] ==
'3') {
3070 if (header[5] & 0x10) {
3075 if (onMeta != NULL) {
3076 size_t tagSizeWithHeader = 10 + tagSize;
3078 if (pTagData != NULL) {
3079 DRMP3_COPY_MEMORY(pTagData, header, 10);
3081 if (onRead(pUserData, pTagData + 10, tagSize) == tagSize) {
3089 if (onSeek != NULL) {
3097 while (tagSize > 0) {
3098 size_t bytesToRead = tagSize;
3099 if (bytesToRead >
sizeof(discard)) {
3100 bytesToRead =
sizeof(discard);
3103 if (onRead(pUserData, discard, bytesToRead) != bytesToRead) {
3116 if (onSeek != NULL) {
3140 firstFramePCMFrameCount = drmp3_decode_next_frame_ex(pMP3, (drmp3d_sample_t*)pMP3->
pcmFrames, &firstFrameInfo, &pFirstFrameData);
3141 if (firstFramePCMFrameCount > 0) {
3142 DRMP3_ASSERT(pFirstFrameData != NULL);
3155 drmp3_L3_gr_info grInfo[4];
3158 drmp3_bs_init(&bs, pFirstFrameData + DRMP3_HDR_SIZE, firstFrameInfo.
frame_bytes - DRMP3_HDR_SIZE);
3160 if (DRMP3_HDR_IS_CRC(pFirstFrameData)) {
3161 drmp3_bs_get_bits(&bs, 16);
3164 if (drmp3_L3_read_side_info(&bs, grInfo, pFirstFrameData) >= 0) {
3169 pTagDataBeg = pFirstFrameData + DRMP3_HDR_SIZE + (bs.pos/8);
3170 pTagData = pTagDataBeg;
3173 isXing = (pTagData[0] ==
'X' && pTagData[1] ==
'i' && pTagData[2] ==
'n' && pTagData[3] ==
'g');
3174 isInfo = (pTagData[0] ==
'I' && pTagData[1] ==
'n' && pTagData[2] ==
'f' && pTagData[3] ==
'o');
3176 if (isXing || isInfo) {
3206 if (pTagData - pFirstFrameData + 14 < firstFrameInfo.
frame_bytes) {
3207 int delayInPCMFrames;
3208 int paddingInPCMFrames;
3212 if (paddingInPCMFrames < 0) {
3213 paddingInPCMFrames = 0;
3228 }
else if (isInfo) {
3233 if (onMeta != NULL) {
3238 tagDataSize -= (
size_t)(pTagDataBeg - pFirstFrameData);
3240 drmp3__on_meta(pMP3, metadataType, pTagDataBeg, tagDataSize);
3261 if (detectedMP3FrameCount != 0xFFFFFFFF) {
3273 if (pMP3 == NULL || onRead == NULL) {
3277 DRMP3_ZERO_OBJECT(pMP3);
3278 return drmp3_init_internal(pMP3, onRead, onSeek, onTell, onMeta, pUserData, pUserData, pAllocationCallbacks);
3282static size_t drmp3__on_read_memory(
void* pUserData,
void* pBufferOut,
size_t bytesToRead)
3285 size_t bytesRemaining;
3287 DRMP3_ASSERT(pMP3 != NULL);
3291 if (bytesToRead > bytesRemaining) {
3292 bytesToRead = bytesRemaining;
3295 if (bytesToRead > 0) {
3307 DRMP3_ASSERT(pMP3 != NULL);
3310 if (byteOffset > 0) {
3323 if ((
drmp3_uint32)byteOffset <= pMP3->memory.dataSize) {
3329 if (byteOffset > 0) {
3347 DRMP3_ASSERT(pMP3 != NULL);
3348 DRMP3_ASSERT(pCursor != NULL);
3362 DRMP3_ZERO_OBJECT(pMP3);
3364 if (pData == NULL || dataSize == 0) {
3372 result = drmp3_init_internal(pMP3, drmp3__on_read_memory, drmp3__on_seek_memory, drmp3__on_tell_memory, onMeta, pMP3, pUserDataMeta, pAllocationCallbacks);
3395#ifndef DR_MP3_NO_STDIO
3521 #if defined(ENOTEMPTY) && ENOTEMPTY != EEXIST
3677 #ifdef EPROTONOSUPPORT
3680 #ifdef ESOCKTNOSUPPORT
3695 #ifdef EADDRNOTAVAIL
3791 #ifdef ENOTRECOVERABLE
3806static drmp3_result drmp3_fopen(FILE** ppFile,
const char* pFilePath,
const char* pOpenMode)
3808#if defined(_MSC_VER) && _MSC_VER >= 1400
3812 if (ppFile != NULL) {
3816 if (pFilePath == NULL || pOpenMode == NULL || ppFile == NULL) {
3820#if defined(_MSC_VER) && _MSC_VER >= 1400
3821 err = fopen_s(ppFile, pFilePath, pOpenMode);
3823 return drmp3_result_from_errno(err);
3826#if defined(_WIN32) || defined(__APPLE__)
3827 *ppFile = fopen(pFilePath, pOpenMode);
3829 #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && defined(_LARGEFILE64_SOURCE)
3830 *ppFile = fopen64(pFilePath, pOpenMode);
3832 *ppFile = fopen(pFilePath, pOpenMode);
3835 if (*ppFile == NULL) {
3861 #if defined(_MSC_VER) || defined(__MINGW64__) || (!defined(__STRICT_ANSI__) && !defined(_NO_EXT_KEYS))
3862 #define DRMP3_HAS_WFOPEN
3868 if (ppFile != NULL) {
3872 if (pFilePath == NULL || pOpenMode == NULL || ppFile == NULL) {
3876#if defined(DRMP3_HAS_WFOPEN)
3879 #if defined(_MSC_VER) && _MSC_VER >= 1400
3880 errno_t err = _wfopen_s(ppFile, pFilePath, pOpenMode);
3882 return drmp3_result_from_errno(err);
3885 *ppFile = _wfopen(pFilePath, pOpenMode);
3886 if (*ppFile == NULL) {
3887 return drmp3_result_from_errno(errno);
3890 (void)pAllocationCallbacks;
3906 #if defined(__DJGPP__)
3914 const wchar_t* pFilePathTemp = pFilePath;
3915 char* pFilePathMB = NULL;
3916 char pOpenModeMB[32] = {0};
3919 DRMP3_ZERO_OBJECT(&mbs);
3920 lenMB = wcsrtombs(NULL, &pFilePathTemp, 0, &mbs);
3921 if (lenMB == (
size_t)-1) {
3922 return drmp3_result_from_errno(errno);
3925 pFilePathMB = (
char*)drmp3__malloc_from_callbacks(lenMB + 1, pAllocationCallbacks);
3926 if (pFilePathMB == NULL) {
3930 pFilePathTemp = pFilePath;
3931 DRMP3_ZERO_OBJECT(&mbs);
3932 wcsrtombs(pFilePathMB, &pFilePathTemp, lenMB + 1, &mbs);
3938 if (pOpenMode[i] == 0) {
3939 pOpenModeMB[i] =
'\0';
3943 pOpenModeMB[i] = (char)pOpenMode[i];
3948 *ppFile = fopen(pFilePathMB, pOpenModeMB);
3950 drmp3__free_from_callbacks(pFilePathMB, pAllocationCallbacks);
3954 if (*ppFile == NULL) {
3964static size_t drmp3__on_read_stdio(
void* pUserData,
void* pBufferOut,
size_t bytesToRead)
3966 return fread(pBufferOut, 1, bytesToRead, (FILE*)pUserData);
3971 int whence = SEEK_SET;
3978 return fseek((FILE*)pUserData, offset, whence) == 0;
3983 FILE* pFileStdio = (FILE*)pUserData;
3987 DRMP3_ASSERT(pFileStdio != NULL);
3988 DRMP3_ASSERT(pCursor != NULL);
3991 #if defined(_MSC_VER) && _MSC_VER > 1200
3992 result = _ftelli64(pFileStdio);
3994 result = ftell(pFileStdio);
3997 result = ftell(pFileStdio);
4014 DRMP3_ZERO_OBJECT(pMP3);
4016 if (drmp3_fopen(&pFile, pFilePath,
"rb") !=
DRMP3_SUCCESS) {
4020 result = drmp3_init_internal(pMP3, drmp3__on_read_stdio, drmp3__on_seek_stdio, drmp3__on_tell_stdio, onMeta, (
void*)pFile, pUserDataMeta, pAllocationCallbacks);
4038 DRMP3_ZERO_OBJECT(pMP3);
4040 if (drmp3_wfopen(&pFile, pFilePath, L
"rb", pAllocationCallbacks) !=
DRMP3_SUCCESS) {
4044 result = drmp3_init_internal(pMP3, drmp3__on_read_stdio, drmp3__on_seek_stdio, drmp3__on_tell_stdio, onMeta, (
void*)pFile, pUserDataMeta, pAllocationCallbacks);
4070#ifndef DR_MP3_NO_STDIO
4071 if (pMP3->
onRead == drmp3__on_read_stdio) {
4073 if (pFile != NULL) {
4083#if defined(DR_MP3_FLOAT_OUTPUT)
4092 sampleCount4 = sampleCount >> 2;
4093 for (i4 = 0; i4 < sampleCount4; i4 += 1) {
4094 float x0 = src[i+0];
4095 float x1 = src[i+1];
4096 float x2 = src[i+2];
4097 float x3 = src[i+3];
4099 x0 = ((x0 < -1) ? -1 : ((x0 > 1) ? 1 : x0));
4100 x1 = ((x1 < -1) ? -1 : ((x1 > 1) ? 1 : x1));
4101 x2 = ((x2 < -1) ? -1 : ((x2 > 1) ? 1 : x2));
4102 x3 = ((x3 < -1) ? -1 : ((x3 > 1) ? 1 : x3));
4118 for (; i < sampleCount; i += 1) {
4120 x = ((x < -1) ? -1 : ((x > 1) ? 1 : x));
4128#if !defined(DR_MP3_FLOAT_OUTPUT)
4132 for (i = 0; i < sampleCount; i += 1) {
4133 float x = (float)src[i];
4134 x = x * 0.000030517578125f;
4145 DRMP3_ASSERT(pMP3 != NULL);
4146 DRMP3_ASSERT(pMP3->
onRead != NULL);
4148 while (framesToRead > 0) {
4166 if (framesToConsume > framesRemainigToPadding) {
4167 framesToConsume = (
drmp3_uint32)framesRemainigToPadding;
4175 if (pBufferOut != NULL) {
4176 #if defined(DR_MP3_FLOAT_OUTPUT)
4179 float* pFramesOutF32 = (
float*)DRMP3_OFFSET_PTR(pBufferOut,
sizeof(
float) * totalFramesRead * pMP3->
channels);
4181 DRMP3_COPY_MEMORY(pFramesOutF32, pFramesInF32,
sizeof(
float) * framesToConsume * pMP3->
channels);
4188 DRMP3_COPY_MEMORY(pFramesOutS16, pFramesInS16,
sizeof(
drmp3_int16) * framesToConsume * pMP3->
channels);
4196 totalFramesRead += framesToConsume;
4197 framesToRead -= framesToConsume;
4199 if (framesToRead == 0) {
4211 if (drmp3_decode_next_frame(pMP3) == 0) {
4216 return totalFramesRead;
4222 if (pMP3 == NULL || pMP3->
onRead == NULL) {
4226#if defined(DR_MP3_FLOAT_OUTPUT)
4228 return drmp3_read_pcm_frames_raw(pMP3, framesToRead, pBufferOut);
4235 while (totalPCMFramesRead < framesToRead) {
4237 drmp3_uint64 framesRemaining = framesToRead - totalPCMFramesRead;
4239 if (framesToReadNow > framesRemaining) {
4240 framesToReadNow = framesRemaining;
4243 framesJustRead = drmp3_read_pcm_frames_raw(pMP3, framesToReadNow, pTempS16);
4244 if (framesJustRead == 0) {
4248 drmp3_s16_to_f32((
float*)DRMP3_OFFSET_PTR(pBufferOut,
sizeof(
float) * totalPCMFramesRead * pMP3->
channels), pTempS16, framesJustRead * pMP3->
channels);
4249 totalPCMFramesRead += framesJustRead;
4252 return totalPCMFramesRead;
4259 if (pMP3 == NULL || pMP3->
onRead == NULL) {
4263#if !defined(DR_MP3_FLOAT_OUTPUT)
4265 return drmp3_read_pcm_frames_raw(pMP3, framesToRead, pBufferOut);
4269 float pTempF32[4096];
4272 while (totalPCMFramesRead < framesToRead) {
4274 drmp3_uint64 framesRemaining = framesToRead - totalPCMFramesRead;
4276 if (framesToReadNow > framesRemaining) {
4277 framesToReadNow = framesRemaining;
4280 framesJustRead = drmp3_read_pcm_frames_raw(pMP3, framesToReadNow, pTempF32);
4281 if (framesJustRead == 0) {
4286 totalPCMFramesRead += framesJustRead;
4289 return totalPCMFramesRead;
4294static void drmp3_reset(
drmp3* pMP3)
4296 DRMP3_ASSERT(pMP3 != NULL);
4308 DRMP3_ASSERT(pMP3 != NULL);
4309 DRMP3_ASSERT(pMP3->
onSeek != NULL);
4331#if defined(DR_MP3_FLOAT_OUTPUT)
4336 if (framesRead != frameOffset) {
4345 DRMP3_ASSERT(pMP3 != NULL);
4355 if (frameIndex < pMP3->currentPCMFrame) {
4357 if (!drmp3_seek_to_start_of_stream(pMP3)) {
4363 return drmp3_seek_forward_by_pcm_frames__brute_force(pMP3, (frameIndex - pMP3->
currentPCMFrame));
4370 DRMP3_ASSERT(pSeekPointIndex != NULL);
4372 *pSeekPointIndex = 0;
4374 if (frameIndex < pMP3->pSeekPoints[0].pcmFrameIndex) {
4379 for (iSeekPoint = 0; iSeekPoint < pMP3->
seekPointCount; ++iSeekPoint) {
4384 *pSeekPointIndex = iSeekPoint;
4397 DRMP3_ASSERT(pMP3 != NULL);
4402 if (drmp3_find_closest_seek_point(pMP3, frameIndex, &priorSeekPointIndex)) {
4403 seekPoint = pMP3->
pSeekPoints[priorSeekPointIndex];
4422 drmp3d_sample_t* pPCMFrames;
4427 pPCMFrames = (drmp3d_sample_t*)pMP3->
pcmFrames;
4431 pcmFramesRead = drmp3_decode_next_frame_ex(pMP3, pPCMFrames, NULL, NULL);
4432 if (pcmFramesRead == 0) {
4445 return drmp3_seek_forward_by_pcm_frames__brute_force(pMP3, leftoverFrames);
4450 if (pMP3 == NULL || pMP3->
onSeek == NULL) {
4454 if (frameIndex == 0) {
4455 return drmp3_seek_to_start_of_stream(pMP3);
4460 return drmp3_seek_to_pcm_frame__seek_table(pMP3, frameIndex);
4462 return drmp3_seek_to_pcm_frame__brute_force(pMP3, frameIndex);
4482 if (pMP3->
onSeek == NULL) {
4489 if (!drmp3_seek_to_start_of_stream(pMP3)) {
4493 totalPCMFrameCount = 0;
4494 totalMP3FrameCount = 0;
4499 pcmFramesInCurrentMP3Frame = drmp3_decode_next_frame_ex(pMP3, NULL, NULL, NULL);
4500 if (pcmFramesInCurrentMP3Frame == 0) {
4504 totalPCMFrameCount += pcmFramesInCurrentMP3Frame;
4505 totalMP3FrameCount += 1;
4509 if (!drmp3_seek_to_start_of_stream(pMP3)) {
4517 if (pMP3FrameCount != NULL) {
4518 *pMP3FrameCount = totalMP3FrameCount;
4520 if (pPCMFrameCount != NULL) {
4521 *pPCMFrameCount = totalPCMFrameCount;
4550 return totalPCMFrameCount;
4557 return totalPCMFrameCount;
4568 return totalMP3FrameCount;
4571static void drmp3__accumulate_running_pcm_frame_count(
drmp3* pMP3,
drmp3_uint32 pcmFrameCountIn,
drmp3_uint64* pRunningPCMFrameCount,
float* pRunningPCMFrameCountFractionalPart)
4574 float pcmFrameCountOutF;
4578 DRMP3_ASSERT(srcRatio > 0);
4580 pcmFrameCountOutF = *pRunningPCMFrameCountFractionalPart + (pcmFrameCountIn / srcRatio);
4582 *pRunningPCMFrameCountFractionalPart = pcmFrameCountOutF - pcmFrameCountOut;
4583 *pRunningPCMFrameCount += pcmFrameCountOut;
4590} drmp3__seeking_mp3_frame_info;
4599 if (pMP3 == NULL || pSeekPointCount == NULL || pSeekPoints == NULL) {
4603 seekPointCount = *pSeekPointCount;
4604 if (seekPointCount == 0) {
4617 if (totalMP3FrameCount < DRMP3_SEEK_LEADING_MP3_FRAMES+1) {
4625 drmp3__seeking_mp3_frame_info mp3FrameInfo[DRMP3_SEEK_LEADING_MP3_FRAMES+1];
4627 float runningPCMFrameCountFractionalPart = 0;
4632 if (seekPointCount > totalMP3FrameCount-1) {
4636 pcmFramesBetweenSeekPoints = totalPCMFrameCount / (seekPointCount+1);
4642 if (!drmp3_seek_to_start_of_stream(pMP3)) {
4652 for (iMP3Frame = 0; iMP3Frame < DRMP3_SEEK_LEADING_MP3_FRAMES+1; ++iMP3Frame) {
4658 mp3FrameInfo[iMP3Frame].pcmFrameIndex = runningPCMFrameCount;
4661 pcmFramesInCurrentMP3FrameIn = drmp3_decode_next_frame_ex(pMP3, NULL, NULL, NULL);
4662 if (pcmFramesInCurrentMP3FrameIn == 0) {
4666 drmp3__accumulate_running_pcm_frame_count(pMP3, pcmFramesInCurrentMP3FrameIn, &runningPCMFrameCount, &runningPCMFrameCountFractionalPart);
4673 nextTargetPCMFrame = 0;
4674 for (iSeekPoint = 0; iSeekPoint < seekPointCount; ++iSeekPoint) {
4675 nextTargetPCMFrame += pcmFramesBetweenSeekPoints;
4678 if (nextTargetPCMFrame < runningPCMFrameCount) {
4680 pSeekPoints[iSeekPoint].
seekPosInBytes = mp3FrameInfo[0].bytePos;
4693 for (i = 0; i < DRMP3_COUNTOF(mp3FrameInfo)-1; ++i) {
4694 mp3FrameInfo[i] = mp3FrameInfo[i+1];
4699 mp3FrameInfo[DRMP3_COUNTOF(mp3FrameInfo)-1].pcmFrameIndex = runningPCMFrameCount;
4705 pcmFramesInCurrentMP3FrameIn = drmp3_decode_next_frame_ex(pMP3, NULL, NULL, NULL);
4706 if (pcmFramesInCurrentMP3FrameIn == 0) {
4707 pSeekPoints[iSeekPoint].
seekPosInBytes = mp3FrameInfo[0].bytePos;
4714 drmp3__accumulate_running_pcm_frame_count(pMP3, pcmFramesInCurrentMP3FrameIn, &runningPCMFrameCount, &runningPCMFrameCountFractionalPart);
4720 if (!drmp3_seek_to_start_of_stream(pMP3)) {
4728 *pSeekPointCount = seekPointCount;
4738 if (seekPointCount == 0 || pSeekPoints == NULL) {
4756 float* pFrames = NULL;
4759 DRMP3_ASSERT(pMP3 != NULL);
4764 if (framesJustRead == 0) {
4769 if (framesCapacity < totalFramesRead + framesJustRead) {
4775 newFramesCap = framesCapacity * 2;
4776 if (newFramesCap < totalFramesRead + framesJustRead) {
4777 newFramesCap = totalFramesRead + framesJustRead;
4780 oldFramesBufferSize = framesCapacity * pMP3->
channels *
sizeof(float);
4781 newFramesBufferSize = newFramesCap * pMP3->
channels *
sizeof(float);
4782 if (newFramesBufferSize > (
drmp3_uint64)DRMP3_SIZE_MAX) {
4786 pNewFrames = (
float*)drmp3__realloc_from_callbacks(pFrames, (
size_t)newFramesBufferSize, (
size_t)oldFramesBufferSize, &pMP3->
allocationCallbacks);
4787 if (pNewFrames == NULL) {
4792 pFrames = pNewFrames;
4793 framesCapacity = newFramesCap;
4796 DRMP3_COPY_MEMORY(pFrames + totalFramesRead*pMP3->
channels, temp, (
size_t)(framesJustRead*pMP3->
channels*
sizeof(
float)));
4797 totalFramesRead += framesJustRead;
4800 if (framesJustRead != framesToReadRightNow) {
4805 if (pConfig != NULL) {
4812 if (pTotalFrameCount) {
4813 *pTotalFrameCount = totalFramesRead;
4826 DRMP3_ASSERT(pMP3 != NULL);
4831 if (framesJustRead == 0) {
4836 if (framesCapacity < totalFramesRead + framesJustRead) {
4842 newFramesCap = framesCapacity * 2;
4843 if (newFramesCap < totalFramesRead + framesJustRead) {
4844 newFramesCap = totalFramesRead + framesJustRead;
4849 if (newFramesBufferSize > (
drmp3_uint64)DRMP3_SIZE_MAX) {
4854 if (pNewFrames == NULL) {
4859 pFrames = pNewFrames;
4860 framesCapacity = newFramesCap;
4864 totalFramesRead += framesJustRead;
4867 if (framesJustRead != framesToReadRightNow) {
4872 if (pConfig != NULL) {
4879 if (pTotalFrameCount) {
4880 *pTotalFrameCount = totalFramesRead;
4890 if (!
drmp3_init(&mp3, onRead, onSeek, onTell, NULL, pUserData, pAllocationCallbacks)) {
4894 return drmp3__full_read_and_close_f32(&mp3, pConfig, pTotalFrameCount);
4900 if (!
drmp3_init(&mp3, onRead, onSeek, onTell, NULL, pUserData, pAllocationCallbacks)) {
4904 return drmp3__full_read_and_close_s16(&mp3, pConfig, pTotalFrameCount);
4915 return drmp3__full_read_and_close_f32(&mp3, pConfig, pTotalFrameCount);
4925 return drmp3__full_read_and_close_s16(&mp3, pConfig, pTotalFrameCount);
4929#ifndef DR_MP3_NO_STDIO
4937 return drmp3__full_read_and_close_f32(&mp3, pConfig, pTotalFrameCount);
4947 return drmp3__full_read_and_close_s16(&mp3, pConfig, pTotalFrameCount);
4953 if (pAllocationCallbacks != NULL) {
4954 return drmp3__malloc_from_callbacks(sz, pAllocationCallbacks);
4956 return drmp3__malloc_default(sz, NULL);
4962 if (pAllocationCallbacks != NULL) {
4963 drmp3__free_from_callbacks(p, pAllocationCallbacks);
4965 drmp3__free_default(p, NULL);
#define DRMP3_ALREADY_CONNECTED
unsigned char drmp3_uint8
#define DRMP3_INVALID_OPERATION
drmp3_bool32 drmp3_init_memory(drmp3 *pMP3, const void *pData, size_t dataSize, const drmp3_allocation_callbacks *pAllocationCallbacks)
float * drmp3_open_file_and_read_pcm_frames_f32(const char *filePath, drmp3_config *pConfig, drmp3_uint64 *pTotalFrameCount, const drmp3_allocation_callbacks *pAllocationCallbacks)
#define DRMP3_DOES_NOT_EXIST
@ drmp3_seek_origin_start
@ drmp3_seek_origin_current
drmp3_bool32 drmp3_bind_seek_table(drmp3 *pMP3, drmp3_uint32 seekPointCount, drmp3_seek_point *pSeekPoints)
#define DRMP3_UNAVAILABLE
unsigned short drmp3_uint16
#define DRMP3_NOT_DIRECTORY
#define DRMP3_ALREADY_IN_USE
#define DRMP3_IN_PROGRESS
drmp3_int16 * drmp3_open_and_read_pcm_frames_s16(drmp3_read_proc onRead, drmp3_seek_proc onSeek, drmp3_tell_proc onTell, void *pUserData, drmp3_config *pConfig, drmp3_uint64 *pTotalFrameCount, const drmp3_allocation_callbacks *pAllocationCallbacks)
float * drmp3_open_and_read_pcm_frames_f32(drmp3_read_proc onRead, drmp3_seek_proc onSeek, drmp3_tell_proc onTell, void *pUserData, drmp3_config *pConfig, drmp3_uint64 *pTotalFrameCount, const drmp3_allocation_callbacks *pAllocationCallbacks)
#define DRMP3_BAD_MESSAGE
void drmp3_uninit(drmp3 *pMP3)
#define DRMP3_PROTOCOL_FAMILY_NOT_SUPPORTED
#define DRMP3_PATH_TOO_LONG
drmp3_bool32 drmp3_calculate_seek_points(drmp3 *pMP3, drmp3_uint32 *pSeekPointCount, drmp3_seek_point *pSeekPoints)
#define DRMP3_BAD_ADDRESS
drmp3_uint64 drmp3_get_pcm_frame_count(drmp3 *pMP3)
#define DRMP3_PROTOCOL_UNAVAILABLE
drmp3_bool32(* drmp3_seek_proc)(void *pUserData, int offset, drmp3_seek_origin origin)
#define DRMP3_INVALID_ARGS
void(* drmp3_meta_proc)(void *pUserData, const drmp3_metadata *pMetadata)
#define DRMP3_IS_DIRECTORY
#define DRMP3_CONNECTION_RESET
#define DRMP3_PROTOCOL_NOT_SUPPORTED
#define DRMP3_ALREADY_EXISTS
void drmp3_free(void *p, const drmp3_allocation_callbacks *pAllocationCallbacks)
#define DRMP3_OUT_OF_MEMORY
drmp3_uint64 drmp3_read_pcm_frames_f32(drmp3 *pMP3, drmp3_uint64 framesToRead, float *pBufferOut)
#define DRMP3_NOT_CONNECTED
@ DRMP3_METADATA_TYPE_APE
@ DRMP3_METADATA_TYPE_ID3V1
@ DRMP3_METADATA_TYPE_VBRI
@ DRMP3_METADATA_TYPE_ID3V2
@ DRMP3_METADATA_TYPE_XING
#define DRMP3_INVALID_FILE
#define DRMP3_VERSION_MINOR
#define DRMP3_ADDRESS_FAMILY_NOT_SUPPORTED
#define DRMP3_MAX_SAMPLES_PER_FRAME
drmp3_bool32 drmp3_seek_to_pcm_frame(drmp3 *pMP3, drmp3_uint64 frameIndex)
drmp3_bool32 drmp3_init_file_with_metadata(drmp3 *pMP3, const char *pFilePath, drmp3_meta_proc onMeta, void *pUserDataMeta, const drmp3_allocation_callbacks *pAllocationCallbacks)
drmp3_uint64 drmp3_read_pcm_frames_s16(drmp3 *pMP3, drmp3_uint64 framesToRead, drmp3_int16 *pBufferOut)
size_t(* drmp3_read_proc)(void *pUserData, void *pBufferOut, size_t bytesToRead)
void drmp3dec_init(drmp3dec *dec)
drmp3_uint64 drmp3_get_mp3_frame_count(drmp3 *pMP3)
void drmp3dec_f32_to_s16(const float *in, drmp3_int16 *out, size_t num_samples)
void * drmp3_malloc(size_t sz, const drmp3_allocation_callbacks *pAllocationCallbacks)
drmp3_bool32 drmp3_init_file(drmp3 *pMP3, const char *pFilePath, const drmp3_allocation_callbacks *pAllocationCallbacks)
unsigned int drmp3_uint32
int drmp3dec_decode_frame(drmp3dec *dec, const drmp3_uint8 *mp3, int mp3_bytes, void *pcm, drmp3dec_frame_info *info)
#define DRMP3_VERSION_MAJOR
drmp3_uint32 drmp3_uintptr
#define DRMP3_INVALID_DATA
drmp3_bool32 drmp3_init(drmp3 *pMP3, drmp3_read_proc onRead, drmp3_seek_proc onSeek, drmp3_tell_proc onTell, drmp3_meta_proc onMeta, void *pUserData, const drmp3_allocation_callbacks *pAllocationCallbacks)
drmp3_int16 * drmp3_open_file_and_read_pcm_frames_s16(const char *filePath, drmp3_config *pConfig, drmp3_uint64 *pTotalFrameCount, const drmp3_allocation_callbacks *pAllocationCallbacks)
drmp3_bool32(* drmp3_tell_proc)(void *pUserData, drmp3_int64 *pCursor)
#define DRMP3_VERSION_REVISION
#define DRMP3_CONNECTION_REFUSED
const char * drmp3_version_string(void)
drmp3_bool32 drmp3_init_file_w(drmp3 *pMP3, const wchar_t *pFilePath, const drmp3_allocation_callbacks *pAllocationCallbacks)
signed long long drmp3_int64
void drmp3_version(drmp3_uint32 *pMajor, drmp3_uint32 *pMinor, drmp3_uint32 *pRevision)
#define DRMP3_NO_DATA_AVAILABLE
drmp3_bool32 drmp3_init_memory_with_metadata(drmp3 *pMP3, const void *pData, size_t dataSize, drmp3_meta_proc onMeta, void *pUserDataMeta, const drmp3_allocation_callbacks *pAllocationCallbacks)
#define DRMP3_BAD_PROTOCOL
#define DRMP3_VERSION_STRING
#define DRMP3_TOO_MANY_OPEN_FILES
drmp3_int16 * drmp3_open_memory_and_read_pcm_frames_s16(const void *pData, size_t dataSize, drmp3_config *pConfig, drmp3_uint64 *pTotalFrameCount, const drmp3_allocation_callbacks *pAllocationCallbacks)
unsigned long long drmp3_uint64
float * drmp3_open_memory_and_read_pcm_frames_f32(const void *pData, size_t dataSize, drmp3_config *pConfig, drmp3_uint64 *pTotalFrameCount, const drmp3_allocation_callbacks *pAllocationCallbacks)
#define DRMP3_ACCESS_DENIED
#define DRMP3_TOO_MANY_LINKS
#define DRMP3_SOCKET_NOT_SUPPORTED
#define DRMP3_DIRECTORY_NOT_EMPTY
#define DRMP3_OUT_OF_RANGE
drmp3_uint32 drmp3_bool32
drmp3_bool32 drmp3_get_mp3_and_pcm_frame_count(drmp3 *pMP3, drmp3_uint64 *pMP3FrameCount, drmp3_uint64 *pPCMFrameCount)
#define DRMP3_NOT_IMPLEMENTED
drmp3_bool32 drmp3_init_file_with_metadata_w(drmp3 *pMP3, const wchar_t *pFilePath, drmp3_meta_proc onMeta, void *pUserDataMeta, const drmp3_allocation_callbacks *pAllocationCallbacks)
double sign(const double &v)
Invert a symmetric and positive definite matrix using Cholesky decomposition (defined in Math....
bool sum(yarp::sig::Image &OutImg, const yarp::sig::Image &InImg, bool colorkey_enable, int colorkey, bool alpha_enable, float alpha, size_t off_x, size_t off_y)
applies an image on the top over another image.
void(* onFree)(void *p, void *pUserData)
void *(* onRealloc)(void *p, size_t sz, void *pUserData)
void *(* onMalloc)(size_t sz, void *pUserData)
drmp3_uint64 seekPosInBytes
drmp3_uint64 pcmFrameIndex
drmp3_uint16 mp3FramesToDiscard
drmp3_uint16 pcmFramesToDiscard
drmp3_uint64 totalPCMFrameCount
drmp3_uint32 pcmFramesConsumedInMP3Frame
drmp3_uint64 streamStartOffset
drmp3_uint32 paddingInPCMFrames
drmp3_uint64 currentPCMFrame
const drmp3_uint8 * pData
drmp3_uint64 streamCursor
drmp3_uint64 streamLength
drmp3_uint8 pcmFrames[sizeof(float) *(1152 *2)]
drmp3_allocation_callbacks allocationCallbacks
drmp3_uint32 mp3FrameSampleRate
drmp3_seek_point * pSeekPoints
drmp3_uint32 pcmFramesRemainingInMP3Frame
drmp3_uint32 seekPointCount
drmp3_uint32 mp3FrameChannels
drmp3_uint32 delayInPCMFrames
drmp3_uint8 reserv_buf[511]
float mdct_overlap[2][9 *32]
float qmf_state[15 *2 *32]