134 #if defined(_MSC_VER) && _MSC_VER < 1600
157 #define DRMP3_FALSE 0
159 #define DRMP3_MAX_PCM_FRAMES_PER_MP3_FRAME 1152
160 #define DRMP3_MAX_SAMPLES_PER_FRAME (DRMP3_MAX_PCM_FRAMES_PER_MP3_FRAME*2)
163 #define DRMP3_INLINE __forceinline
164 #elif defined(__GNUC__)
172 #if defined(__STRICT_ANSI__)
173 #define DRMP3_INLINE __inline__ __attribute__((always_inline))
175 #define DRMP3_INLINE inline __attribute__((always_inline))
187 int frame_bytes, channels, hz, layer, bitrate_kbps;
192 float mdct_overlap[2][9*32], qmf_state[15*2*32];
193 int reserv, free_format_bytes;
194 unsigned char header[4], reserv_buf[511];
212 #ifndef DR_MP3_DEFAULT_CHANNELS
213 #define DR_MP3_DEFAULT_CHANNELS 2
215 #ifndef DR_MP3_DEFAULT_SAMPLE_RATE
216 #define DR_MP3_DEFAULT_SAMPLE_RATE 44100
228 #define DRMP3_SRC_CACHE_SIZE_IN_FRAMES 512
290 typedef size_t (*
drmp3_read_proc)(
void* pUserData,
void* pBufferOut,
size_t bytesToRead);
309 void* (* onMalloc)(
size_t sz,
void* pUserData);
310 void* (* onRealloc)(
void* p,
size_t sz,
void* pUserData);
311 void (* onFree)(
void* p,
void* pUserData);
348 size_t currentReadPos;
377 #ifndef DR_MP3_NO_STDIO
469 #ifndef DR_MP3_NO_STDIO
492 #ifdef DR_MP3_IMPLEMENTATION
498 #if defined(__TINYC__)
499 #define DR_MP3_NO_SIMD
502 #define DRMP3_OFFSET_PTR(p, offset) ((void*)((drmp3_uint8*)(p) + (offset)))
504 #define DRMP3_MAX_FREE_FORMAT_FRAME_SIZE 2304
505 #ifndef DRMP3_MAX_FRAME_SYNC_MATCHES
506 #define DRMP3_MAX_FRAME_SYNC_MATCHES 10
509 #define DRMP3_MAX_L3_FRAME_PAYLOAD_BYTES DRMP3_MAX_FREE_FORMAT_FRAME_SIZE
511 #define DRMP3_MAX_BITRESERVOIR_BYTES 511
512 #define DRMP3_SHORT_BLOCK_TYPE 2
513 #define DRMP3_STOP_BLOCK_TYPE 3
514 #define DRMP3_MODE_MONO 3
515 #define DRMP3_MODE_JOINT_STEREO 1
516 #define DRMP3_HDR_SIZE 4
517 #define DRMP3_HDR_IS_MONO(h) (((h[3]) & 0xC0) == 0xC0)
518 #define DRMP3_HDR_IS_MS_STEREO(h) (((h[3]) & 0xE0) == 0x60)
519 #define DRMP3_HDR_IS_FREE_FORMAT(h) (((h[2]) & 0xF0) == 0)
520 #define DRMP3_HDR_IS_CRC(h) (!((h[1]) & 1))
521 #define DRMP3_HDR_TEST_PADDING(h) ((h[2]) & 0x2)
522 #define DRMP3_HDR_TEST_MPEG1(h) ((h[1]) & 0x8)
523 #define DRMP3_HDR_TEST_NOT_MPEG25(h) ((h[1]) & 0x10)
524 #define DRMP3_HDR_TEST_I_STEREO(h) ((h[3]) & 0x10)
525 #define DRMP3_HDR_TEST_MS_STEREO(h) ((h[3]) & 0x20)
526 #define DRMP3_HDR_GET_STEREO_MODE(h) (((h[3]) >> 6) & 3)
527 #define DRMP3_HDR_GET_STEREO_MODE_EXT(h) (((h[3]) >> 4) & 3)
528 #define DRMP3_HDR_GET_LAYER(h) (((h[1]) >> 1) & 3)
529 #define DRMP3_HDR_GET_BITRATE(h) ((h[2]) >> 4)
530 #define DRMP3_HDR_GET_SAMPLE_RATE(h) (((h[2]) >> 2) & 3)
531 #define DRMP3_HDR_GET_MY_SAMPLE_RATE(h) (DRMP3_HDR_GET_SAMPLE_RATE(h) + (((h[1] >> 3) & 1) + ((h[1] >> 4) & 1))*3)
532 #define DRMP3_HDR_IS_FRAME_576(h) ((h[1] & 14) == 2)
533 #define DRMP3_HDR_IS_LAYER_1(h) ((h[1] & 6) == 6)
535 #define DRMP3_BITS_DEQUANTIZER_OUT -1
536 #define DRMP3_MAX_SCF (255 + DRMP3_BITS_DEQUANTIZER_OUT*4 - 210)
537 #define DRMP3_MAX_SCFI ((DRMP3_MAX_SCF + 3) & ~3)
539 #define DRMP3_MIN(a, b) ((a) > (b) ? (b) : (a))
540 #define DRMP3_MAX(a, b) ((a) < (b) ? (b) : (a))
542 #if !defined(DR_MP3_NO_SIMD)
544 #if !defined(DR_MP3_ONLY_SIMD) && (defined(_M_X64) || defined(_M_ARM64) || defined(__x86_64__) || defined(__aarch64__))
546 #define DR_MP3_ONLY_SIMD
549 #if ((defined(_MSC_VER) && _MSC_VER >= 1400) && (defined(_M_IX86) || defined(_M_X64))) || ((defined(__i386__) || defined(__x86_64__)) && defined(__SSE2__))
550 #if defined(_MSC_VER)
553 #include <emmintrin.h>
554 #define DRMP3_HAVE_SSE 1
555 #define DRMP3_HAVE_SIMD 1
556 #define DRMP3_VSTORE _mm_storeu_ps
557 #define DRMP3_VLD _mm_loadu_ps
558 #define DRMP3_VSET _mm_set1_ps
559 #define DRMP3_VADD _mm_add_ps
560 #define DRMP3_VSUB _mm_sub_ps
561 #define DRMP3_VMUL _mm_mul_ps
562 #define DRMP3_VMAC(a, x, y) _mm_add_ps(a, _mm_mul_ps(x, y))
563 #define DRMP3_VMSB(a, x, y) _mm_sub_ps(a, _mm_mul_ps(x, y))
564 #define DRMP3_VMUL_S(x, s) _mm_mul_ps(x, _mm_set1_ps(s))
565 #define DRMP3_VREV(x) _mm_shuffle_ps(x, x, _MM_SHUFFLE(0, 1, 2, 3))
566 typedef __m128 drmp3_f4;
567 #if defined(_MSC_VER) || defined(DR_MP3_ONLY_SIMD)
568 #define drmp3_cpuid __cpuid
570 static __inline__
__attribute__((always_inline))
void drmp3_cpuid(
int CPUInfo[],
const int InfoType)
573 __asm__ __volatile__(
574 #
if defined(__x86_64__)
584 :
"=a" (CPUInfo[0]),
"=r" (CPUInfo[1]),
"=c" (CPUInfo[2]),
"=d" (CPUInfo[3])
587 __asm__ __volatile__(
589 :
"=a" (CPUInfo[0]),
"=b" (CPUInfo[1]),
"=c" (CPUInfo[2]),
"=d" (CPUInfo[3])
594 static int drmp3_have_simd()
596 #ifdef DR_MP3_ONLY_SIMD
599 static int g_have_simd;
602 static int g_counter;
603 if (g_counter++ > 100)
608 drmp3_cpuid(CPUInfo, 0);
611 drmp3_cpuid(CPUInfo, 1);
612 g_have_simd = (CPUInfo[3] & (1 << 26)) + 1;
613 return g_have_simd - 1;
617 return g_have_simd - 1;
620 #elif defined(__ARM_NEON) || defined(__aarch64__)
621 #include <arm_neon.h>
622 #define DRMP3_HAVE_SSE 0
623 #define DRMP3_HAVE_SIMD 1
624 #define DRMP3_VSTORE vst1q_f32
625 #define DRMP3_VLD vld1q_f32
626 #define DRMP3_VSET vmovq_n_f32
627 #define DRMP3_VADD vaddq_f32
628 #define DRMP3_VSUB vsubq_f32
629 #define DRMP3_VMUL vmulq_f32
630 #define DRMP3_VMAC(a, x, y) vmlaq_f32(a, x, y)
631 #define DRMP3_VMSB(a, x, y) vmlsq_f32(a, x, y)
632 #define DRMP3_VMUL_S(x, s) vmulq_f32(x, vmovq_n_f32(s))
633 #define DRMP3_VREV(x) vcombine_f32(vget_high_f32(vrev64q_f32(x)), vget_low_f32(vrev64q_f32(x)))
634 typedef float32x4_t drmp3_f4;
635 static int drmp3_have_simd()
640 #define DRMP3_HAVE_SSE 0
641 #define DRMP3_HAVE_SIMD 0
642 #ifdef DR_MP3_ONLY_SIMD
643 #error DR_MP3_ONLY_SIMD used, but SSE/NEON not enabled
649 #define DRMP3_HAVE_SIMD 0
662 drmp3_uint8 total_bands, stereo_bands, bitalloc[64], scfcod[64];
667 drmp3_uint8 tab_offset, code_tab_width, band_count;
673 drmp3_uint16 part_23_length, big_values, scalefac_compress;
674 drmp3_uint8 global_gain, block_type, mixed_block_flag, n_long_sfb, n_short_sfb;
675 drmp3_uint8 table_select[3], region_count[3], subblock_gain[3];
676 drmp3_uint8 preflag, scalefac_scale, count1_table, scfsi;
684 float grbuf[2][576], scf[40], syn[18 + 15][2*32];
702 next = *p++ & (255 >>
s);
703 while ((shl -= 8) > 0)
705 cache |= next << shl;
708 return cache | (next >> -shl);
713 return h[0] == 0xff &&
714 ((h[1] & 0xF0) == 0xf0 || (h[1] & 0xFE) == 0xe2) &&
723 ((h1[1] ^ h2[1]) & 0xFE) == 0 &&
724 ((h1[2] ^ h2[2]) & 0x0C) == 0 &&
731 { { 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 } },
732 { { 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 } },
739 static const unsigned g_hz[3] = { 44100, 48000, 32000 };
755 return frame_bytes ? frame_bytes : free_format_size;
763 #ifndef DR_MP3_ONLY_MP3
778 alloc = g_alloc_L2M2;
782 static const drmp3_L12_subband_alloc g_alloc_L2M1[] = { { 0, 4, 3 }, { 16, 4, 8 }, { 32, 3, 12 }, { 40, 2, 7 } };
790 alloc = g_alloc_L2M1;
795 alloc = g_alloc_L2M1_lowrate;
796 nbands = sample_rate_idx == 2 ? 12 : 8;
797 }
else if (kbps >= 96 && sample_rate_idx != 1)
811 static const float g_deq_L12[18*3] = {
812 #define DRMP3_DQ(x) 9.53674316e-07f/x, 7.56931807e-07f/x, 6.00777173e-07f/x
813 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)
816 for (i = 0; i < bands; i++)
820 int mask = ba ? 4 + ((19 >> scfcod[i]) & 3) : 0;
821 for (m = 4; m; m >>= 1)
826 s = g_deq_L12[ba*3 - 6 + b % 3]*(int)(1 << 21 >> b/3);
836 0,17, 3, 4, 5,6,7, 8,9,10,11,12,13,14,15,16,
837 0,17,18, 3,19,4,5, 6,7, 8, 9,10,11,12,13,16,
838 0,17,18, 3,19,4,5,16,
840 0,17,18,19, 4,5,6, 7,8, 9,10,11,12,13,14,15,
841 0,17,18, 3,19,4,5, 6,7, 8, 9,10,11,12,13,14,
842 0, 2, 3, 4, 5,6,7, 8,9,10,11,12,13,14,15,16
846 int i, k = 0, ba_bits = 0;
847 const drmp3_uint8 *ba_code_tab = g_bitalloc_code_tab;
856 ba_code_tab = g_bitalloc_code_tab + subband_alloc->
tab_offset;
861 if (i < sci->stereo_bands)
883 int i, j, k, choff = 576;
884 for (j = 0; j < 4; j++)
886 float *dst = grbuf + group_size*j;
894 int half = (1 << (ba - 1)) - 1;
895 for (k = 0; k < group_size; k++)
901 unsigned mod = (2 << (ba - 17)) + 1;
903 for (k = 0; k < group_size; k++, code /= mod)
905 dst[k] = (float)((
int)(code % mod - mod/2));
920 for (i = 0; i < sci->
total_bands; i++, dst += 18, scf += 6)
922 for (k = 0; k < 12; k++)
924 dst[k + 0] *= scf[0];
925 dst[k + 576] *= scf[3];
934 { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
935 { 12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2,0 },
936 { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
937 { 6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,54,62,70,76,36,0 },
938 { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
939 { 4,4,4,4,4,4,6,6,8,8,10,12,16,20,24,28,34,42,50,54,76,158,0 },
940 { 4,4,4,4,4,4,6,6,6,8,10,12,16,18,22,28,34,40,46,54,54,192,0 },
941 { 4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102,26,0 }
944 { 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 },
945 { 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 },
946 { 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 },
947 { 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 },
948 { 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 },
949 { 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 },
950 { 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 },
951 { 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 }
954 { 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 },
955 { 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 },
956 { 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 },
957 { 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 },
958 { 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 },
959 { 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 },
960 { 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 },
961 { 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 }
964 unsigned tables, scfsi = 0;
965 int main_data_begin, part_23_sum = 0;
994 gr->
sfbtab = g_scf_long[sr_idx];
1013 gr->
sfbtab = g_scf_short[sr_idx];
1018 gr->
sfbtab = g_scf_mixed[sr_idx];
1046 }
while(--gr_count);
1048 if (part_23_sum + bs->
pos > bs->
limit + main_data_begin*8)
1053 return main_data_begin;
1059 for (i = 0; i < 4 && scf_count[i]; i++, scfsi *= 2)
1061 int cnt = scf_count[i];
1064 memcpy(scf, ist_pos, cnt);
1067 int bits = scf_size[i];
1070 memset(scf, 0, cnt);
1071 memset(ist_pos, 0, cnt);
1074 int max_scf = (scfsi < 0) ? (1 << bits) - 1 : -1;
1075 for (k = 0; k < cnt; k++)
1078 ist_pos[k] = (
drmp3_uint8)(s == max_scf ? -1 : s);
1086 scf[0] = scf[1] = scf[2] = 0;
1091 static const float g_expfrac[4] = { 9.31322575e-10
f,7.83145814e-10
f,6.58544508e-10
f,5.53767716e-10
f };
1096 y *= g_expfrac[e & 3]*(1 << 30 >> (e >> 2));
1097 }
while ((exp_q2 -= e) > 0);
1103 static const drmp3_uint8 g_scf_partitions[3][28] = {
1104 { 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 },
1105 { 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 },
1106 { 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 }
1115 static const drmp3_uint8 g_scfc_decode[16] = { 0,1,2,3, 12,5,6,7, 9,10,11,13, 14,15,18,19 };
1117 scf_size[1] = scf_size[0] = (
drmp3_uint8)(part >> 2);
1118 scf_size[3] = scf_size[2] = (
drmp3_uint8)(part & 3);
1121 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 };
1124 for (k = ist*3*4; sfc >= 0; sfc -= modprod, k += 4)
1126 for (modprod = 1, i = 3; i >= 0; i--)
1128 scf_size[i] = (
drmp3_uint8)(sfc / modprod % g_mod[k + i]);
1129 modprod *= g_mod[k + i];
1139 int sh = 3 - scf_shift;
1148 static const drmp3_uint8 g_preamp[10] = { 1,1,1,1,2,2,3,3,3,2 };
1149 for (i = 0; i < 10; i++)
1151 iscf[11 + i] += g_preamp[i];
1164 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,
1165 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
1171 int sign, mult = 256;
1185 frac = (float)((x & 63) - sign) / ((x & ~63) + sign);
1186 return g_drmp3_pow43[16 + ((x + sign) >> 6)]*(1.f + frac*((4.f/3) + frac*(2.f/9)))*mult;
1191 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,
1192 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,
1193 -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,
1194 -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,
1195 -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,
1196 -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,
1197 -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,
1198 -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,
1199 -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,
1200 -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,
1201 -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,
1202 -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,
1203 -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,
1204 -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,
1205 -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,
1206 -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 };
1207 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};
1208 static const drmp3_uint8 tab33[] = { 252,236,220,204,188,172,156,140,124,108,92,76,60,44,28,12 };
1209 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 };
1210 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 };
1212 #define DRMP3_PEEK_BITS(n) (bs_cache >> (32 - n))
1213 #define DRMP3_FLUSH_BITS(n) { bs_cache <<= (n); bs_sh += (n); }
1214 #define DRMP3_CHECK_BITS while (bs_sh >= 0) { bs_cache |= (drmp3_uint32)*bs_next_ptr++ << bs_sh; bs_sh -= 8; }
1215 #define DRMP3_BSPOS ((bs_next_ptr - bs->buf)*8 - 24 + bs_sh)
1218 int ireg = 0, big_val_cnt = gr_info->
big_values;
1221 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);
1222 int pairs_to_decode, np, bs_sh = (bs->
pos & 7) - 8;
1225 while (big_val_cnt > 0)
1229 const drmp3_int16 *codebook = tabs + tabindex[tab_num];
1230 int linbits = g_linbits[tab_num];
1236 pairs_to_decode =
DRMP3_MIN(big_val_cnt, np);
1250 for (j = 0; j < 2; j++, dst++, leaf >>= 4)
1252 int lsb = leaf & 0x0F;
1266 }
while (--pairs_to_decode);
1267 }
while ((big_val_cnt -= np) > 0 && --sfb_cnt >= 0);
1273 pairs_to_decode =
DRMP3_MIN(big_val_cnt, np);
1287 for (j = 0; j < 2; j++, dst++, leaf >>= 4)
1289 int lsb = leaf & 0x0F;
1294 }
while (--pairs_to_decode);
1295 }
while ((big_val_cnt -= np) > 0 && --sfb_cnt >= 0);
1299 for (np = 1 - big_val_cnt;; dst += 4)
1305 leaf = codebook_count1[(leaf >> 3) + (bs_cache << 4 >> (32 - (leaf & 3)))];
1312 #define DRMP3_RELOAD_SCALEFACTOR if (!--np) { np = *sfb++/2; if (!np) break; one = *scf++; }
1313 #define DRMP3_DEQ_COUNT1(s) if (leaf & (128 >> s)) { dst[s] = ((drmp3_int32)bs_cache < 0) ? -one : one; DRMP3_FLUSH_BITS(1) }
1323 bs->
pos = layer3gr_limit;
1329 float *right = left + 576;
1331 if (drmp3_have_simd())
for (; i < n - 3; i += 4)
1333 drmp3_f4 vl = DRMP3_VLD(left + i);
1334 drmp3_f4 vr = DRMP3_VLD(right + i);
1335 DRMP3_VSTORE(left + i, DRMP3_VADD(vl, vr));
1336 DRMP3_VSTORE(right + i, DRMP3_VSUB(vl, vr));
1351 for (i = 0; i < n; i++)
1353 left[i + 576] = left[i]*kr;
1354 left[i] = left[i]*kl;
1362 max_band[0] = max_band[1] = max_band[2] = -1;
1364 for (i = 0; i < nbands; i++)
1366 for (k = 0; k < sfb[i]; k += 2)
1368 if (right[k] != 0 || right[k + 1] != 0)
1370 max_band[i % 3] = i;
1380 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 };
1383 for (i = 0; sfb[i]; i++)
1385 unsigned ipos = ist_pos[i];
1386 if ((
int)i > max_band[i % 3] && ipos < max_pos)
1392 kr = g_pan[2*ipos + 1];
1420 max_band[0] = max_band[1] = max_band[2] =
DRMP3_MAX(
DRMP3_MAX(max_band[0], max_band[1]), max_band[2]);
1422 for (i = 0; i < max_blocks; i++)
1425 int itop = n_sfb - max_blocks + i;
1426 int prev = itop - max_blocks;
1427 ist_pos[itop] = (
drmp3_uint8)(max_band[i] >= prev ? default_pos : ist_pos[prev]);
1435 float *src = grbuf, *dst = scratch;
1437 for (;0 != (len = *sfb); sfb += 3, src += 2*len)
1439 for (i = 0; i < len; i++, src++)
1441 *dst++ = src[0*len];
1442 *dst++ = src[1*len];
1443 *dst++ = src[2*len];
1446 memcpy(grbuf, scratch, (dst - scratch)*
sizeof(
float));
1451 static const float g_aa[2][8] = {
1452 {0.85749293f,0.88174200f,0.94962865f,0.98331459f,0.99551782f,0.99916056f,0.99989920f,0.99999316f},
1453 {0.51449576f,0.47173197f,0.31337745f,0.18191320f,0.09457419f,0.04096558f,0.01419856f,0.00369997f}
1456 for (; nbands > 0; nbands--, grbuf += 18)
1460 if (drmp3_have_simd())
for (; i < 8; i += 4)
1462 drmp3_f4 vu = DRMP3_VLD(grbuf + 18 + i);
1463 drmp3_f4 vd = DRMP3_VLD(grbuf + 14 - i);
1464 drmp3_f4 vc0 = DRMP3_VLD(g_aa[0] + i);
1465 drmp3_f4 vc1 = DRMP3_VLD(g_aa[1] + i);
1466 vd = DRMP3_VREV(vd);
1467 DRMP3_VSTORE(grbuf + 18 + i, DRMP3_VSUB(DRMP3_VMUL(vu, vc0), DRMP3_VMUL(vd, vc1)));
1468 vd = DRMP3_VADD(DRMP3_VMUL(vu, vc1), DRMP3_VMUL(vd, vc0));
1469 DRMP3_VSTORE(grbuf + 14 - i, DRMP3_VREV(vd));
1472 #ifndef DR_MP3_ONLY_SIMD
1475 float u = grbuf[18 + i];
1476 float d = grbuf[17 - i];
1477 grbuf[18 + i] = u*g_aa[0][i] -
d*g_aa[1][i];
1478 grbuf[17 - i] = u*g_aa[1][i] +
d*g_aa[0][i];
1486 float s0, s1, s2, s3, s4, s5, s6, s7, s8, t0, t2, t4;
1488 s0 = y[0]; s2 = y[2]; s4 = y[4]; s6 = y[6]; s8 = y[8];
1491 t4 = (s4 + s2)*0.93969262f;
1492 t2 = (s8 + s2)*0.76604444f;
1493 s6 = (s4 - s8)*0.17364818f;
1502 s1 = y[1]; s3 = y[3]; s5 = y[5]; s7 = y[7];
1505 t0 = (s5 + s1)*0.98480775f;
1506 t4 = (s5 - s7)*0.34202014f;
1507 t2 = (s1 + s7)*0.64278761f;
1508 s1 = (s1 - s5 - s7)*0.86602540f;
1524 static void drmp3_L3_imdct36(
float *grbuf,
float *overlap,
const float *window,
int nbands)
1527 static const float g_twid9[18] = {
1528 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
1531 for (j = 0; j < nbands; j++, grbuf += 18, overlap += 9)
1536 for (i = 0; i < 4; i++)
1538 si[8 - 2*i] = grbuf[4*i + 1] - grbuf[4*i + 2];
1539 co[1 + 2*i] = grbuf[4*i + 1] + grbuf[4*i + 2];
1540 si[7 - 2*i] = grbuf[4*i + 4] - grbuf[4*i + 3];
1541 co[2 + 2*i] = -(grbuf[4*i + 3] + grbuf[4*i + 4]);
1554 if (drmp3_have_simd())
for (; i < 8; i += 4)
1556 drmp3_f4 vovl = DRMP3_VLD(overlap + i);
1557 drmp3_f4 vc = DRMP3_VLD(co + i);
1558 drmp3_f4 vs = DRMP3_VLD(si + i);
1559 drmp3_f4 vr0 = DRMP3_VLD(g_twid9 + i);
1560 drmp3_f4 vr1 = DRMP3_VLD(g_twid9 + 9 + i);
1561 drmp3_f4 vw0 = DRMP3_VLD(window + i);
1562 drmp3_f4 vw1 = DRMP3_VLD(window + 9 + i);
1563 drmp3_f4 vsum = DRMP3_VADD(DRMP3_VMUL(vc, vr1), DRMP3_VMUL(vs, vr0));
1564 DRMP3_VSTORE(overlap + i, DRMP3_VSUB(DRMP3_VMUL(vc, vr0), DRMP3_VMUL(vs, vr1)));
1565 DRMP3_VSTORE(grbuf + i, DRMP3_VSUB(DRMP3_VMUL(vovl, vw0), DRMP3_VMUL(vsum, vw1)));
1566 vsum = DRMP3_VADD(DRMP3_VMUL(vovl, vw1), DRMP3_VMUL(vsum, vw0));
1567 DRMP3_VSTORE(grbuf + 14 - i, DRMP3_VREV(vsum));
1572 float ovl = overlap[i];
1573 float sum = co[i]*g_twid9[9 + i] + si[i]*g_twid9[0 + i];
1574 overlap[i] = co[i]*g_twid9[0 + i] - si[i]*g_twid9[9 + i];
1575 grbuf[i] = ovl*window[0 + i] - sum*window[9 + i];
1576 grbuf[17 - i] = ovl*window[9 + i] + sum*window[0 + i];
1581 static void drmp3_L3_idct3(
float x0,
float x1,
float x2,
float *dst)
1583 float m1 = x1*0.86602540f;
1584 float a1 = x0 - x2*0.5f;
1592 static const float g_twid3[6] = { 0.79335334f,0.92387953f,0.99144486f, 0.60876143f,0.38268343f,0.13052619f };
1600 for (i = 0; i < 3; i++)
1602 float ovl = overlap[i];
1603 float sum = co[i]*g_twid3[3 + i] + si[i]*g_twid3[0 + i];
1604 overlap[i] = co[i]*g_twid3[0 + i] - si[i]*g_twid3[3 + i];
1605 dst[i] = ovl*g_twid3[2 - i] - sum*g_twid3[5 - i];
1606 dst[5 - i] = ovl*g_twid3[5 - i] + sum*g_twid3[2 - i];
1612 for (;nbands > 0; nbands--, overlap += 9, grbuf += 18)
1615 memcpy(tmp, grbuf,
sizeof(tmp));
1616 memcpy(grbuf, overlap, 6*
sizeof(
float));
1626 for (b = 0, grbuf += 18; b < 32; b += 2, grbuf += 36)
1627 for (i = 1; i < 18; i += 2)
1628 grbuf[i] = -grbuf[i];
1631 static void drmp3_L3_imdct_gr(
float *grbuf,
float *overlap,
unsigned block_type,
unsigned n_long_bands)
1633 static const float g_mdct_window[2][18] = {
1634 { 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 },
1635 { 1,1,1,1,1,1,0.99144486f,0.92387953f,0.79335334f,0,0,0,0,0,0,0.13052619f,0.38268343f,0.60876143f }
1640 grbuf += 18*n_long_bands;
1641 overlap += 9*n_long_bands;
1651 int pos = (
s->bs.pos + 7)/8u;
1652 int remains =
s->bs.limit/8u - pos;
1660 memmove(h->
reserv_buf,
s->maindata + pos, remains);
1667 int frame_bytes = (bs->
limit - bs->
pos)/8;
1670 memcpy(
s->maindata + bytes_have, bs->
buf + bs->
pos/8, frame_bytes);
1672 return h->
reserv >= main_data_begin;
1679 for (ch = 0; ch < nch; ch++)
1694 for (ch = 0; ch < nch; ch++, gr_info++)
1701 aa_bands = n_long_bands - 1;
1713 static const float g_sec[24] = {
1714 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
1718 if (drmp3_have_simd())
for (; k < n; k += 4)
1720 drmp3_f4 t[4][8], *x;
1721 float *y = grbuf + k;
1723 for (x = t[0], i = 0; i < 8; i++, x++)
1725 drmp3_f4 x0 = DRMP3_VLD(&y[i*18]);
1726 drmp3_f4 x1 = DRMP3_VLD(&y[(15 - i)*18]);
1727 drmp3_f4 x2 = DRMP3_VLD(&y[(16 + i)*18]);
1728 drmp3_f4 x3 = DRMP3_VLD(&y[(31 - i)*18]);
1729 drmp3_f4 t0 = DRMP3_VADD(x0, x3);
1730 drmp3_f4 t1 = DRMP3_VADD(x1, x2);
1731 drmp3_f4 t2 = DRMP3_VMUL_S(DRMP3_VSUB(x1, x2), g_sec[3*i + 0]);
1732 drmp3_f4 t3 = DRMP3_VMUL_S(DRMP3_VSUB(x0, x3), g_sec[3*i + 1]);
1733 x[0] = DRMP3_VADD(t0, t1);
1734 x[8] = DRMP3_VMUL_S(DRMP3_VSUB(t0, t1), g_sec[3*i + 2]);
1735 x[16] = DRMP3_VADD(t3, t2);
1736 x[24] = DRMP3_VMUL_S(DRMP3_VSUB(t3, t2), g_sec[3*i + 2]);
1738 for (x = t[0], i = 0; i < 4; i++, x += 8)
1740 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;
1741 xt = DRMP3_VSUB(x0, x7); x0 = DRMP3_VADD(x0, x7);
1742 x7 = DRMP3_VSUB(x1, x6); x1 = DRMP3_VADD(x1, x6);
1743 x6 = DRMP3_VSUB(x2, x5); x2 = DRMP3_VADD(x2, x5);
1744 x5 = DRMP3_VSUB(x3, x4); x3 = DRMP3_VADD(x3, x4);
1745 x4 = DRMP3_VSUB(x0, x3); x0 = DRMP3_VADD(x0, x3);
1746 x3 = DRMP3_VSUB(x1, x2); x1 = DRMP3_VADD(x1, x2);
1747 x[0] = DRMP3_VADD(x0, x1);
1748 x[4] = DRMP3_VMUL_S(DRMP3_VSUB(x0, x1), 0.70710677f);
1749 x5 = DRMP3_VADD(x5, x6);
1750 x6 = DRMP3_VMUL_S(DRMP3_VADD(x6, x7), 0.70710677f);
1751 x7 = DRMP3_VADD(x7, xt);
1752 x3 = DRMP3_VMUL_S(DRMP3_VADD(x3, x4), 0.70710677f);
1753 x5 = DRMP3_VSUB(x5, DRMP3_VMUL_S(x7, 0.198912367f));
1754 x7 = DRMP3_VADD(x7, DRMP3_VMUL_S(x5, 0.382683432f));
1755 x5 = DRMP3_VSUB(x5, DRMP3_VMUL_S(x7, 0.198912367f));
1756 x0 = DRMP3_VSUB(xt, x6); xt = DRMP3_VADD(xt, x6);
1757 x[1] = DRMP3_VMUL_S(DRMP3_VADD(xt, x7), 0.50979561f);
1758 x[2] = DRMP3_VMUL_S(DRMP3_VADD(x4, x3), 0.54119611f);
1759 x[3] = DRMP3_VMUL_S(DRMP3_VSUB(x0, x5), 0.60134488f);
1760 x[5] = DRMP3_VMUL_S(DRMP3_VADD(x0, x5), 0.89997619f);
1761 x[6] = DRMP3_VMUL_S(DRMP3_VSUB(x4, x3), 1.30656302f);
1762 x[7] = DRMP3_VMUL_S(DRMP3_VSUB(xt, x7), 2.56291556f);
1768 #define DRMP3_VSAVE2(i, v) _mm_storel_pi((__m64 *)(void*)&y[i*18], v)
1770 #define DRMP3_VSAVE2(i, v) vst1_f32((float32_t *)&y[i*18], vget_low_f32(v))
1772 for (i = 0; i < 7; i++, y += 4*18)
1774 drmp3_f4
s = DRMP3_VADD(t[3][i], t[3][i + 1]);
1775 DRMP3_VSAVE2(0, t[0][i]);
1776 DRMP3_VSAVE2(1, DRMP3_VADD(t[2][i], s));
1777 DRMP3_VSAVE2(2, DRMP3_VADD(t[1][i], t[1][i + 1]));
1778 DRMP3_VSAVE2(3, DRMP3_VADD(t[2][1 + i], s));
1780 DRMP3_VSAVE2(0, t[0][7]);
1781 DRMP3_VSAVE2(1, DRMP3_VADD(t[2][7], t[3][7]));
1782 DRMP3_VSAVE2(2, t[1][7]);
1783 DRMP3_VSAVE2(3, t[3][7]);
1786 #define DRMP3_VSAVE4(i, v) DRMP3_VSTORE(&y[i*18], v)
1787 for (i = 0; i < 7; i++, y += 4*18)
1789 drmp3_f4
s = DRMP3_VADD(t[3][i], t[3][i + 1]);
1790 DRMP3_VSAVE4(0, t[0][i]);
1791 DRMP3_VSAVE4(1, DRMP3_VADD(t[2][i], s));
1792 DRMP3_VSAVE4(2, DRMP3_VADD(t[1][i], t[1][i + 1]));
1793 DRMP3_VSAVE4(3, DRMP3_VADD(t[2][1 + i], s));
1795 DRMP3_VSAVE4(0, t[0][7]);
1796 DRMP3_VSAVE4(1, DRMP3_VADD(t[2][7], t[3][7]));
1797 DRMP3_VSAVE4(2, t[1][7]);
1798 DRMP3_VSAVE4(3, t[3][7]);
1802 #ifdef DR_MP3_ONLY_SIMD
1807 float t[4][8], *x, *y = grbuf + k;
1809 for (x = t[0], i = 0; i < 8; i++, x++)
1812 float x1 = y[(15 - i)*18];
1813 float x2 = y[(16 + i)*18];
1814 float x3 = y[(31 - i)*18];
1817 float t2 = (x1 - x2)*g_sec[3*i + 0];
1818 float t3 = (x0 - x3)*g_sec[3*i + 1];
1820 x[8] = (t0 - t1)*g_sec[3*i + 2];
1822 x[24] = (t3 - t2)*g_sec[3*i + 2];
1824 for (x = t[0], i = 0; i < 4; i++, x += 8)
1826 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;
1827 xt = x0 - x7; x0 += x7;
1828 x7 = x1 - x6; x1 += x6;
1829 x6 = x2 - x5; x2 += x5;
1830 x5 = x3 - x4; x3 += x4;
1831 x4 = x0 - x3; x0 += x3;
1832 x3 = x1 - x2; x1 += x2;
1834 x[4] = (x0 - x1)*0.70710677f;
1836 x6 = (x6 + x7)*0.70710677f;
1838 x3 = (x3 + x4)*0.70710677f;
1839 x5 -= x7*0.198912367f;
1840 x7 += x5*0.382683432f;
1841 x5 -= x7*0.198912367f;
1842 x0 = xt - x6; xt += x6;
1843 x[1] = (xt + x7)*0.50979561f;
1844 x[2] = (x4 + x3)*0.54119611f;
1845 x[3] = (x0 - x5)*0.60134488f;
1846 x[5] = (x0 + x5)*0.89997619f;
1847 x[6] = (x4 - x3)*1.30656302f;
1848 x[7] = (xt - x7)*2.56291556f;
1851 for (i = 0; i < 7; i++, y += 4*18)
1854 y[1*18] = t[2][i] + t[3][i] + t[3][i + 1];
1855 y[2*18] = t[1][i] + t[1][i + 1];
1856 y[3*18] = t[2][i + 1] + t[3][i] + t[3][i + 1];
1859 y[1*18] = t[2][7] + t[3][7];
1866 #ifndef DR_MP3_FLOAT_OUTPUT
1872 if (sample >= 32766.5)
return (
drmp3_int16) 32767;
1873 if (sample <= -32767.5)
return (
drmp3_int16)-32768;
1883 return sample*(1.f/32768.f);
1890 a = (z[14*64] - z[ 0]) * 29;
1891 a += (z[ 1*64] + z[13*64]) * 213;
1892 a += (z[12*64] - z[ 2*64]) * 459;
1893 a += (z[ 3*64] + z[11*64]) * 2037;
1894 a += (z[10*64] - z[ 4*64]) * 5153;
1895 a += (z[ 5*64] + z[ 9*64]) * 6574;
1896 a += (z[ 8*64] - z[ 6*64]) * 37489;
1897 a += z[ 7*64] * 75038;
1902 a += z[12*64] * 1567;
1903 a += z[10*64] * 9727;
1904 a += z[ 8*64] * 64019;
1905 a += z[ 6*64] * -9975;
1906 a += z[ 4*64] * -45;
1907 a += z[ 2*64] * 146;
1915 float *xr = xl + 576*(nch - 1);
1918 static const float g_win[] = {
1919 -1,26,-31,208,218,401,-519,2063,2000,4788,-5517,7134,5959,35640,-39336,74992,
1920 -1,24,-35,202,222,347,-581,2080,1952,4425,-5879,7640,5288,33791,-41176,74856,
1921 -1,21,-38,196,225,294,-645,2087,1893,4063,-6237,8092,4561,31947,-43006,74630,
1922 -1,19,-41,190,227,244,-711,2085,1822,3705,-6589,8492,3776,30112,-44821,74313,
1923 -1,17,-45,183,228,197,-779,2075,1739,3351,-6935,8840,2935,28289,-46617,73908,
1924 -1,16,-49,176,228,153,-848,2057,1644,3004,-7271,9139,2037,26482,-48390,73415,
1925 -2,14,-53,169,227,111,-919,2032,1535,2663,-7597,9389,1082,24694,-50137,72835,
1926 -2,13,-58,161,224,72,-991,2001,1414,2330,-7910,9592,70,22929,-51853,72169,
1927 -2,11,-63,154,221,36,-1064,1962,1280,2006,-8209,9750,-998,21189,-53534,71420,
1928 -2,10,-68,147,215,2,-1137,1919,1131,1692,-8491,9863,-2122,19478,-55178,70590,
1929 -3,9,-73,139,208,-29,-1210,1870,970,1388,-8755,9935,-3300,17799,-56778,69679,
1930 -3,8,-79,132,200,-57,-1283,1817,794,1095,-8998,9966,-4533,16155,-58333,68692,
1931 -4,7,-85,125,189,-83,-1356,1759,605,814,-9219,9959,-5818,14548,-59838,67629,
1932 -4,7,-91,117,177,-106,-1428,1698,402,545,-9416,9916,-7154,12980,-61289,66494,
1933 -5,6,-97,111,163,-127,-1498,1634,185,288,-9585,9838,-8540,11455,-62684,65290
1935 float *zlin = lins + 15*64;
1936 const float *w = g_win;
1938 zlin[4*15] = xl[18*16];
1939 zlin[4*15 + 1] = xr[18*16];
1940 zlin[4*15 + 2] = xl[0];
1941 zlin[4*15 + 3] = xr[0];
1943 zlin[4*31] = xl[1 + 18*16];
1944 zlin[4*31 + 1] = xr[1 + 18*16];
1945 zlin[4*31 + 2] = xl[1];
1946 zlin[4*31 + 3] = xr[1];
1954 if (drmp3_have_simd())
for (i = 14; i >= 0; i--)
1956 #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)]);
1957 #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)); }
1958 #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))); }
1959 #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))); }
1961 zlin[4*i] = xl[18*(31 - i)];
1962 zlin[4*i + 1] = xr[18*(31 - i)];
1963 zlin[4*i + 2] = xl[1 + 18*(31 - i)];
1964 zlin[4*i + 3] = xr[1 + 18*(31 - i)];
1965 zlin[4*i + 64] = xl[1 + 18*(1 + i)];
1966 zlin[4*i + 64 + 1] = xr[1 + 18*(1 + i)];
1967 zlin[4*i - 64 + 2] = xl[18*(1 + i)];
1968 zlin[4*i - 64 + 3] = xr[18*(1 + i)];
1970 DRMP3_V0(0) DRMP3_V2(1) DRMP3_V1(2) DRMP3_V2(3) DRMP3_V1(4) DRMP3_V2(5) DRMP3_V1(6) DRMP3_V2(7)
1973 #ifndef DR_MP3_FLOAT_OUTPUT
1975 static const drmp3_f4 g_max = { 32767.0f, 32767.0f, 32767.0f, 32767.0f };
1976 static const drmp3_f4 g_min = { -32768.0f, -32768.0f, -32768.0f, -32768.0f };
1977 __m128i pcm8 = _mm_packs_epi32(_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(a, g_max), g_min)),
1978 _mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(b, g_max), g_min)));
1979 dstr[(15 - i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 1);
1980 dstr[(17 + i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 5);
1981 dstl[(15 - i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 0);
1982 dstl[(17 + i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 4);
1983 dstr[(47 - i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 3);
1984 dstr[(49 + i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 7);
1985 dstl[(47 - i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 2);
1986 dstl[(49 + i)*nch] = (
drmp3_int16)_mm_extract_epi16(pcm8, 6);
1988 int16x4_t pcma, pcmb;
1989 a = DRMP3_VADD(a, DRMP3_VSET(0.5f));
1990 b = DRMP3_VADD(b, DRMP3_VSET(0.5f));
1991 pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, DRMP3_VSET(0)))));
1992 pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, DRMP3_VSET(0)))));
1993 vst1_lane_s16(dstr + (15 - i)*nch, pcma, 1);
1994 vst1_lane_s16(dstr + (17 + i)*nch, pcmb, 1);
1995 vst1_lane_s16(dstl + (15 - i)*nch, pcma, 0);
1996 vst1_lane_s16(dstl + (17 + i)*nch, pcmb, 0);
1997 vst1_lane_s16(dstr + (47 - i)*nch, pcma, 3);
1998 vst1_lane_s16(dstr + (49 + i)*nch, pcmb, 3);
1999 vst1_lane_s16(dstl + (47 - i)*nch, pcma, 2);
2000 vst1_lane_s16(dstl + (49 + i)*nch, pcmb, 2);
2003 static const drmp3_f4 g_scale = { 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f };
2004 a = DRMP3_VMUL(a, g_scale);
2005 b = DRMP3_VMUL(b, g_scale);
2007 _mm_store_ss(dstr + (15 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 1, 1, 1)));
2008 _mm_store_ss(dstr + (17 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(1, 1, 1, 1)));
2009 _mm_store_ss(dstl + (15 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 0, 0, 0)));
2010 _mm_store_ss(dstl + (17 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(0, 0, 0, 0)));
2011 _mm_store_ss(dstr + (47 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(3, 3, 3, 3)));
2012 _mm_store_ss(dstr + (49 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(3, 3, 3, 3)));
2013 _mm_store_ss(dstl + (47 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 2, 2, 2)));
2014 _mm_store_ss(dstl + (49 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(2, 2, 2, 2)));
2016 vst1q_lane_f32(dstr + (15 - i)*nch, a, 1);
2017 vst1q_lane_f32(dstr + (17 + i)*nch, b, 1);
2018 vst1q_lane_f32(dstl + (15 - i)*nch, a, 0);
2019 vst1q_lane_f32(dstl + (17 + i)*nch, b, 0);
2020 vst1q_lane_f32(dstr + (47 - i)*nch, a, 3);
2021 vst1q_lane_f32(dstr + (49 + i)*nch, b, 3);
2022 vst1q_lane_f32(dstl + (47 - i)*nch, a, 2);
2023 vst1q_lane_f32(dstl + (49 + i)*nch, b, 2);
2029 #ifdef DR_MP3_ONLY_SIMD
2032 for (i = 14; i >= 0; i--)
2034 #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];
2035 #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; }
2036 #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; }
2037 #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; }
2040 zlin[4*i] = xl[18*(31 - i)];
2041 zlin[4*i + 1] = xr[18*(31 - i)];
2042 zlin[4*i + 2] = xl[1 + 18*(31 - i)];
2043 zlin[4*i + 3] = xr[1 + 18*(31 - i)];
2044 zlin[4*(i + 16)] = xl[1 + 18*(1 + i)];
2045 zlin[4*(i + 16) + 1] = xr[1 + 18*(1 + i)];
2046 zlin[4*(i - 16) + 2] = xl[18*(1 + i)];
2047 zlin[4*(i - 16) + 3] = xr[18*(1 + i)];
2066 for (i = 0; i < nch; i++)
2071 memcpy(lins, qmf_state,
sizeof(
float)*15*64);
2073 for (i = 0; i < nbands; i += 2)
2075 drmp3d_synth(grbuf + i, pcm + 32*nch*i, nch, lins + i*64);
2077 #ifndef DR_MP3_NONSTANDARD_BUT_LOGICAL
2080 for (i = 0; i < 15*64; i += 2)
2082 qmf_state[i] = lins[nbands*64 + i];
2087 memcpy(qmf_state, lins + nbands*64,
sizeof(
float)*15*64);
2123 frame_and_padding = k;
2125 *free_format_bytes = fb;
2129 if ((frame_bytes && i + frame_and_padding <= mp3_bytes &&
2131 (!i && frame_and_padding == mp3_bytes))
2133 *ptr_frame_bytes = frame_and_padding;
2136 *free_format_bytes = 0;
2139 *ptr_frame_bytes = 0;
2150 int i = 0, igr, frame_size = 0, success = 1;
2167 if (!frame_size || i + frame_size > mp3_bytes)
2188 if (info->
layer == 3)
2191 if (main_data_begin < 0 || bs_frame->pos > bs_frame->
limit)
2197 if (success && pcm !=
NULL)
2201 memset(scratch.
grbuf[0], 0, 576*2*
sizeof(
float));
2209 #ifdef DR_MP3_ONLY_MP3
2220 memset(scratch.
grbuf[0], 0, 576*2*
sizeof(
float));
2221 for (i = 0, igr = 0; igr < 3; igr++)
2228 memset(scratch.
grbuf[0], 0, 576*2*
sizeof(
float));
2231 if (bs_frame->
pos > bs_frame->
limit)
2247 int aligned_count = num_samples & ~7;
2248 for(; i < aligned_count; i+=8)
2250 drmp3_f4 scale = DRMP3_VSET(32768.0f);
2251 drmp3_f4 a = DRMP3_VMUL(DRMP3_VLD(&in[i ]), scale);
2252 drmp3_f4 b = DRMP3_VMUL(DRMP3_VLD(&in[i+4]), scale);
2254 drmp3_f4 s16max = DRMP3_VSET( 32767.0f);
2255 drmp3_f4 s16min = DRMP3_VSET(-32768.0f);
2256 __m128i pcm8 = _mm_packs_epi32(_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(a, s16max), s16min)),
2257 _mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(b, s16max), s16min)));
2258 out[i ] = (
drmp3_int16)_mm_extract_epi16(pcm8, 0);
2259 out[i+1] = (
drmp3_int16)_mm_extract_epi16(pcm8, 1);
2260 out[i+2] = (
drmp3_int16)_mm_extract_epi16(pcm8, 2);
2261 out[i+3] = (
drmp3_int16)_mm_extract_epi16(pcm8, 3);
2262 out[i+4] = (
drmp3_int16)_mm_extract_epi16(pcm8, 4);
2263 out[i+5] = (
drmp3_int16)_mm_extract_epi16(pcm8, 5);
2264 out[i+6] = (
drmp3_int16)_mm_extract_epi16(pcm8, 6);
2265 out[i+7] = (
drmp3_int16)_mm_extract_epi16(pcm8, 7);
2267 int16x4_t pcma, pcmb;
2268 a = DRMP3_VADD(a, DRMP3_VSET(0.5f));
2269 b = DRMP3_VADD(b, DRMP3_VSET(0.5f));
2270 pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, DRMP3_VSET(0)))));
2271 pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, DRMP3_VSET(0)))));
2272 vst1_lane_s16(out+i , pcma, 0);
2273 vst1_lane_s16(out+i+1, pcma, 1);
2274 vst1_lane_s16(out+i+2, pcma, 2);
2275 vst1_lane_s16(out+i+3, pcma, 3);
2276 vst1_lane_s16(out+i+4, pcmb, 0);
2277 vst1_lane_s16(out+i+5, pcmb, 1);
2278 vst1_lane_s16(out+i+6, pcmb, 2);
2279 vst1_lane_s16(out+i+7, pcmb, 3);
2283 for(; i < num_samples; i++)
2285 float sample = in[i] * 32768.0f;
2286 if (sample >= 32766.5)
2288 else if (sample <= -32767.5)
2307 #if defined(SIZE_MAX)
2308 #define DRMP3_SIZE_MAX SIZE_MAX
2310 #if defined(_WIN64) || defined(_LP64) || defined(__LP64__)
2311 #define DRMP3_SIZE_MAX ((drmp3_uint64)0xFFFFFFFFFFFFFFFF)
2313 #define DRMP3_SIZE_MAX 0xFFFFFFFF
2318 #ifndef DRMP3_SEEK_LEADING_MP3_FRAMES
2319 #define DRMP3_SEEK_LEADING_MP3_FRAMES 2
2324 #ifndef DRMP3_ASSERT
2326 #define DRMP3_ASSERT(expression) assert(expression)
2328 #ifndef DRMP3_COPY_MEMORY
2329 #define DRMP3_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
2331 #ifndef DRMP3_ZERO_MEMORY
2332 #define DRMP3_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
2334 #define DRMP3_ZERO_OBJECT(p) DRMP3_ZERO_MEMORY((p), sizeof(*(p)))
2335 #ifndef DRMP3_MALLOC
2336 #define DRMP3_MALLOC(sz) malloc((sz))
2338 #ifndef DRMP3_REALLOC
2339 #define DRMP3_REALLOC(p, sz) realloc((p), (sz))
2342 #define DRMP3_FREE(p) free((p))
2345 #define drmp3_countof(x) (sizeof(x) / sizeof(x[0]))
2346 #define drmp3_max(x, y) (((x) > (y)) ? (x) : (y))
2347 #define drmp3_min(x, y) (((x) < (y)) ? (x) : (y))
2349 #define DRMP3_DATA_CHUNK_SIZE 16384
2353 return x*(1-a) + y*a;
2356 static void drmp3_blend_f32(
float* pOut,
float* pInA,
float* pInB,
float factor,
drmp3_uint32 channels)
2359 for (i = 0; i < channels; ++i) {
2387 if (pAllocationCallbacks ==
NULL) {
2406 if (pAllocationCallbacks ==
NULL) {
2436 if (p ==
NULL || pAllocationCallbacks ==
NULL) {
2448 if (pAllocationCallbacks !=
NULL) {
2450 return *pAllocationCallbacks;
2458 return allocationCallbacks;
2468 pCache->
pSRC = pSRC;
2486 while (frameCount > 0) {
2491 if (framesToReadFromMemory > framesRemainingInMemory) {
2492 framesToReadFromMemory = framesRemainingInMemory;
2498 totalFramesRead += framesToReadFromMemory;
2499 frameCount -= framesToReadFromMemory;
2500 if (frameCount == 0) {
2507 pFramesOut += framesToReadFromMemory * channels;
2526 return totalFramesRead;
2541 if (pConfig ==
NULL || onRead ==
NULL) {
2557 drmp3_src_cache_init(pSRC, &pSRC->
cache);
2568 if (sampleRateIn == 0) {
2583 if (sampleRateOut == 0) {
2595 if (pSRC ==
NULL || frameCount == 0 || pFramesOut ==
NULL) {
2617 return drmp3_src_read_frames_ex(pSRC, frameCount, pFramesOut,
DRMP3_FALSE);
2644 if (framesRead == 0) {
2651 if (framesRead == 0) {
2659 totalFramesRead = 0;
2660 while (frameCount > 0) {
2665 float* pPrevFrame = pSRC->
bin;
2668 drmp3_blend_f32((
float*)pFramesOut, pPrevFrame, pNextFrame, (
float)pSRC->
algo.
linear.alpha, pSRC->
config.
channels);
2676 for (i = 0; i < framesToReadFromClient; ++i) {
2681 pPrevFrame[j] = pNextFrame[j];
2684 framesRead = drmp3_src_cache_read_frames(&pSRC->
cache, 1, pNextFrame);
2685 if (framesRead == 0) {
2705 totalFramesRead += 1;
2708 if (!pSRC->
algo.
linear.isNextFramesLoaded && (!flush || !pSRC->
algo.
linear.isPrevFramesLoaded)) {
2713 return totalFramesRead;
2719 size_t bytesRead = pMP3->
onRead(pMP3->
pUserData, pBufferOut, bytesToRead);
2743 if (offset <= 0x7FFFFFFF) {
2753 offset -= 0x7FFFFFFF;
2754 while (offset > 0) {
2755 if (offset <= 0x7FFFFFFF) {
2764 offset -= 0x7FFFFFFF;
2777 float* pFramesOutF = (
float*)pFramesOut;
2783 while (frameCount > 0) {
2787 #ifndef DR_MP3_FLOAT_OUTPUT
2803 pFramesOutF[0] = sample * 0.5f;
2826 pFramesOutF[0] = sample * 0.5f;
2837 totalFramesRead += 1;
2842 if (frameCount == 0) {
2857 return totalFramesRead;
2868 if (!drmp3_src_init(&srcConfig, drmp3_read_src, pMP3, &pMP3->
src)) {
2889 size_t leftoverDataSize;
2902 if (pNewData ==
NULL) {
2906 pMP3->
pData = pNewData;
2911 if (bytesRead == 0) {
2939 if (pcmFramesRead > 0 || (info.
frame_bytes > 0 && discard)) {
2954 drmp3_init_src(pMP3);
2971 if (pNewData ==
NULL) {
2975 pMP3->
pData = pNewData;
2981 if (bytesRead == 0) {
2990 return pcmFramesRead;
3007 if (pcmFrameCount == 0) {
3016 return pcmFrameCount;
3031 if (pConfig !=
NULL) {
3060 drmp3_init_src(pMP3);
3074 if (pMP3 ==
NULL || onRead ==
NULL) {
3079 return drmp3_init_internal(pMP3, onRead, onSeek, pUserData, pConfig, pAllocationCallbacks);
3086 size_t bytesRemaining;
3092 if (bytesToRead > bytesRemaining) {
3093 bytesToRead = bytesRemaining;
3096 if (bytesToRead > 0) {
3111 if (byteOffset > 0) {
3142 if (pData ==
NULL || dataSize == 0) {
3154 #ifndef DR_MP3_NO_STDIO
3159 return fread(pBufferOut, 1, bytesToRead, (FILE*)pUserData);
3170 #if defined(_MSC_VER) && _MSC_VER >= 1400
3171 if (fopen_s(&pFile, filePath,
"rb") != 0) {
3175 pFile = fopen(filePath,
"rb");
3176 if (pFile ==
NULL) {
3191 #ifndef DR_MP3_NO_STDIO
3208 if (pBufferOut ==
NULL) {
3210 while (framesToRead > 0) {
3213 if (framesToReadRightNow > framesToRead) {
3214 framesToReadRightNow = framesToRead;
3218 if (framesJustRead == 0) {
3222 framesToRead -= framesJustRead;
3223 totalFramesRead += framesJustRead;
3226 totalFramesRead = drmp3_src_read_frames_ex(&pMP3->
src, framesToRead, pBufferOut,
DRMP3_TRUE);
3230 return totalFramesRead;
3235 float tempF32[4096];
3245 drmp3_uint64 pcmFramesToReadThisIteration = (framesToRead - totalPCMFramesRead);
3246 if (pcmFramesToReadThisIteration > drmp3_countof(tempF32)/pMP3->
channels) {
3247 pcmFramesToReadThisIteration = drmp3_countof(tempF32)/pMP3->
channels;
3251 if (pcmFramesJustRead == 0) {
3256 pBufferOut += pcmFramesJustRead * pMP3->
channels;
3258 totalPCMFramesRead += pcmFramesJustRead;
3260 if (pcmFramesJustRead < pcmFramesToReadThisIteration) {
3265 return totalPCMFramesRead;
3304 float drmp3_get_cached_pcm_frame_count_from_src(
drmp3* pMP3)
3309 float drmp3_get_pcm_frames_remaining_in_mp3_frame(
drmp3* pMP3)
3313 return frameCountPreSRC * factor;
3341 while (frameOffset > maxFramesToReadAndDiscard) {
3342 float pcmFramesRemainingInCurrentMP3FrameF = drmp3_get_pcm_frames_remaining_in_mp3_frame(pMP3);
3344 if (frameOffset > pcmFramesRemainingInCurrentMP3Frame) {
3345 frameOffset -= pcmFramesRemainingInCurrentMP3Frame;
3354 if (pcmFrameCount == 0) {
3361 if (framesRead != frameOffset) {
3367 if (framesRead != frameOffset) {
3387 if (frameIndex < pMP3->currentPCMFrame) {
3404 *pSeekPointIndex = 0;
3406 if (frameIndex < pMP3->pSeekPoints[0].pcmFrameIndex) {
3411 for (iSeekPoint = 0; iSeekPoint < pMP3->
seekPointCount; ++iSeekPoint) {
3416 *pSeekPointIndex = iSeekPoint;
3435 seekPoint = pMP3->
pSeekPoints[priorSeekPointIndex];
3464 if (pcmFramesReadPreSRC == 0) {
3497 if (frameIndex == 0) {
3514 float totalPCMFrameCountFractionalPart;
3537 totalPCMFrameCount = 0;
3538 totalMP3FrameCount = 0;
3540 totalPCMFrameCountFractionalPart = 0;
3544 float pcmFramesInCurrentMP3FrameOutF;
3548 if (pcmFramesInCurrentMP3FrameIn == 0) {
3555 pcmFramesInCurrentMP3FrameOutF = totalPCMFrameCountFractionalPart + (pcmFramesInCurrentMP3FrameIn / srcRatio);
3556 pcmFramesInCurrentMP3FrameOut = (
drmp3_uint32)pcmFramesInCurrentMP3FrameOutF;
3557 totalPCMFrameCountFractionalPart = pcmFramesInCurrentMP3FrameOutF - pcmFramesInCurrentMP3FrameOut;
3558 totalPCMFrameCount += pcmFramesInCurrentMP3FrameOut;
3559 totalMP3FrameCount += 1;
3571 if (pMP3FrameCount !=
NULL) {
3572 *pMP3FrameCount = totalMP3FrameCount;
3574 if (pPCMFrameCount !=
NULL) {
3575 *pPCMFrameCount = totalPCMFrameCount;
3588 return totalPCMFrameCount;
3598 return totalMP3FrameCount;
3604 float pcmFrameCountOutF;
3610 pcmFrameCountOutF = *pRunningPCMFrameCountFractionalPart + (pcmFrameCountIn / srcRatio);
3612 *pRunningPCMFrameCountFractionalPart = pcmFrameCountOutF - pcmFrameCountOut;
3613 *pRunningPCMFrameCount += pcmFrameCountOut;
3629 if (pMP3 ==
NULL || pSeekPointCount ==
NULL || pSeekPoints ==
NULL) {
3633 seekPointCount = *pSeekPointCount;
3634 if (seekPointCount == 0) {
3657 float runningPCMFrameCountFractionalPart = 0;
3662 if (seekPointCount > totalMP3FrameCount-1) {
3666 pcmFramesBetweenSeekPoints = totalPCMFrameCount / (seekPointCount+1);
3688 mp3FrameInfo[iMP3Frame].
pcmFrameIndex = runningPCMFrameCount;
3692 if (pcmFramesInCurrentMP3FrameIn == 0) {
3703 nextTargetPCMFrame = 0;
3704 for (iSeekPoint = 0; iSeekPoint < seekPointCount; ++iSeekPoint) {
3705 nextTargetPCMFrame += pcmFramesBetweenSeekPoints;
3708 if (nextTargetPCMFrame < runningPCMFrameCount) {
3723 for (i = 0; i < drmp3_countof(mp3FrameInfo)-1; ++i) {
3724 mp3FrameInfo[i] = mp3FrameInfo[i+1];
3729 mp3FrameInfo[drmp3_countof(mp3FrameInfo)-1].
pcmFrameIndex = runningPCMFrameCount;
3736 if (pcmFramesInCurrentMP3FrameIn == 0) {
3758 *pSeekPointCount = seekPointCount;
3768 if (seekPointCount == 0 || pSeekPoints ==
NULL) {
3786 float* pFrames =
NULL;
3794 if (framesJustRead == 0) {
3799 if (framesCapacity < totalFramesRead + framesJustRead) {
3805 newFramesCap = framesCapacity * 2;
3806 if (newFramesCap < totalFramesRead + framesJustRead) {
3807 newFramesCap = totalFramesRead + framesJustRead;
3810 oldFramesBufferSize = framesCapacity * pMP3->
channels *
sizeof(float);
3811 newFramesBufferSize = newFramesCap * pMP3->
channels *
sizeof(float);
3817 if (pNewFrames ==
NULL) {
3822 pFrames = pNewFrames;
3823 framesCapacity = newFramesCap;
3827 totalFramesRead += framesJustRead;
3830 if (framesJustRead != framesToReadRightNow) {
3835 if (pConfig !=
NULL) {
3842 if (pTotalFrameCount) {
3843 *pTotalFrameCount = totalFramesRead;
3861 if (framesJustRead == 0) {
3866 if (framesCapacity < totalFramesRead + framesJustRead) {
3872 newFramesCap = framesCapacity * 2;
3873 if (newFramesCap < totalFramesRead + framesJustRead) {
3874 newFramesCap = totalFramesRead + framesJustRead;
3884 if (pNewFrames ==
NULL) {
3889 pFrames = pNewFrames;
3890 framesCapacity = newFramesCap;
3894 totalFramesRead += framesJustRead;
3897 if (framesJustRead != framesToReadRightNow) {
3902 if (pConfig !=
NULL) {
3909 if (pTotalFrameCount) {
3910 *pTotalFrameCount = totalFramesRead;
3920 if (!
drmp3_init(&mp3, onRead, onSeek, pUserData, pConfig, pAllocationCallbacks)) {
3930 if (!
drmp3_init(&mp3, onRead, onSeek, pUserData, pConfig, pAllocationCallbacks)) {
3959 #ifndef DR_MP3_NO_STDIO
3963 if (!
drmp3_init_file(&mp3, filePath, pConfig, pAllocationCallbacks)) {
3973 if (!
drmp3_init_file(&mp3, filePath, pConfig, pAllocationCallbacks)) {
3983 if (pAllocationCallbacks !=
NULL) {