Commit bd59c523 authored by David Reid's avatar David Reid

Update dr_mp3.

parent f15ddefc
...@@ -91458,7 +91458,7 @@ static void ma_dr_mp3_L3_decode_scalefactors(const ma_uint8 *hdr, ma_uint8 *ist_ ...@@ -91458,7 +91458,7 @@ static void ma_dr_mp3_L3_decode_scalefactors(const ma_uint8 *hdr, ma_uint8 *ist_
scf[i] = ma_dr_mp3_L3_ldexp_q2(gain, iscf[i] << scf_shift); scf[i] = ma_dr_mp3_L3_ldexp_q2(gain, iscf[i] << scf_shift);
} }
} }
static const float g_ma_dr_mp3_pow43[129 + 16] = { static const float g_drmp3_pow43[129 + 16] = {
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, 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,
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 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
}; };
...@@ -91468,7 +91468,7 @@ static float ma_dr_mp3_L3_pow_43(int x) ...@@ -91468,7 +91468,7 @@ static float ma_dr_mp3_L3_pow_43(int x)
int sign, mult = 256; int sign, mult = 256;
if (x < 129) if (x < 129)
{ {
return g_ma_dr_mp3_pow43[16 + x]; return g_drmp3_pow43[16 + x];
} }
if (x < 1024) if (x < 1024)
{ {
...@@ -91477,7 +91477,7 @@ static float ma_dr_mp3_L3_pow_43(int x) ...@@ -91477,7 +91477,7 @@ static float ma_dr_mp3_L3_pow_43(int x)
} }
sign = 2*x & 64; sign = 2*x & 64;
frac = (float)((x & 63) - sign) / ((x & ~63) + sign); frac = (float)((x & 63) - sign) / ((x & ~63) + sign);
return g_ma_dr_mp3_pow43[16 + ((x + sign) >> 6)]*(1.f + frac*((4.f/3) + frac*(2.f/9)))*mult; return g_drmp3_pow43[16 + ((x + sign) >> 6)]*(1.f + frac*((4.f/3) + frac*(2.f/9)))*mult;
} }
static void ma_dr_mp3_L3_huffman(float *dst, ma_dr_mp3_bs *bs, const ma_dr_mp3_L3_gr_info *gr_info, const float *scf, int layer3gr_limit) static void ma_dr_mp3_L3_huffman(float *dst, ma_dr_mp3_bs *bs, const ma_dr_mp3_L3_gr_info *gr_info, const float *scf, int layer3gr_limit)
{ {
...@@ -91547,7 +91547,7 @@ static void ma_dr_mp3_L3_huffman(float *dst, ma_dr_mp3_bs *bs, const ma_dr_mp3_L ...@@ -91547,7 +91547,7 @@ static void ma_dr_mp3_L3_huffman(float *dst, ma_dr_mp3_bs *bs, const ma_dr_mp3_L
*dst = one*ma_dr_mp3_L3_pow_43(lsb)*((ma_int32)bs_cache < 0 ? -1: 1); *dst = one*ma_dr_mp3_L3_pow_43(lsb)*((ma_int32)bs_cache < 0 ? -1: 1);
} else } else
{ {
*dst = g_ma_dr_mp3_pow43[16 + lsb - 16*(bs_cache >> 31)]*one; *dst = g_drmp3_pow43[16 + lsb - 16*(bs_cache >> 31)]*one;
} }
MA_DR_MP3_FLUSH_BITS(lsb ? 1 : 0); MA_DR_MP3_FLUSH_BITS(lsb ? 1 : 0);
} }
...@@ -91575,7 +91575,7 @@ static void ma_dr_mp3_L3_huffman(float *dst, ma_dr_mp3_bs *bs, const ma_dr_mp3_L ...@@ -91575,7 +91575,7 @@ static void ma_dr_mp3_L3_huffman(float *dst, ma_dr_mp3_bs *bs, const ma_dr_mp3_L
for (j = 0; j < 2; j++, dst++, leaf >>= 4) for (j = 0; j < 2; j++, dst++, leaf >>= 4)
{ {
int lsb = leaf & 0x0F; int lsb = leaf & 0x0F;
*dst = g_ma_dr_mp3_pow43[16 + lsb - 16*(bs_cache >> 31)]*one; *dst = g_drmp3_pow43[16 + lsb - 16*(bs_cache >> 31)]*one;
MA_DR_MP3_FLUSH_BITS(lsb ? 1 : 0); MA_DR_MP3_FLUSH_BITS(lsb ? 1 : 0);
} }
MA_DR_MP3_CHECK_BITS; MA_DR_MP3_CHECK_BITS;
...@@ -92815,11 +92815,13 @@ static ma_uint32 ma_dr_mp3_decode_next_frame_ex__memory(ma_dr_mp3* pMP3, ma_dr_m ...@@ -92815,11 +92815,13 @@ static ma_uint32 ma_dr_mp3_decode_next_frame_ex__memory(ma_dr_mp3* pMP3, ma_dr_m
break; break;
} else if (info.frame_bytes > 0) { } else if (info.frame_bytes > 0) {
pMP3->memory.currentReadPos += (size_t)info.frame_bytes; pMP3->memory.currentReadPos += (size_t)info.frame_bytes;
pMP3->streamCursor += (size_t)info.frame_bytes;
} else { } else {
break; break;
} }
} }
pMP3->memory.currentReadPos += (size_t)info.frame_bytes; pMP3->memory.currentReadPos += (size_t)info.frame_bytes;
pMP3->streamCursor += (size_t)info.frame_bytes;
return pcmFramesRead; return pcmFramesRead;
} }
static ma_uint32 ma_dr_mp3_decode_next_frame_ex(ma_dr_mp3* pMP3, ma_dr_mp3d_sample_t* pPCMFrames, ma_dr_mp3dec_frame_info* pMP3FrameInfo, const ma_uint8** ppMP3FrameData) static ma_uint32 ma_dr_mp3_decode_next_frame_ex(ma_dr_mp3* pMP3, ma_dr_mp3d_sample_t* pPCMFrames, ma_dr_mp3dec_frame_info* pMP3FrameInfo, const ma_uint8** ppMP3FrameData)
...@@ -93043,8 +93045,15 @@ static ma_bool32 ma_dr_mp3_init_internal(ma_dr_mp3* pMP3, ma_dr_mp3_read_proc on ...@@ -93043,8 +93045,15 @@ static ma_bool32 ma_dr_mp3_init_internal(ma_dr_mp3* pMP3, ma_dr_mp3_read_proc on
if (pTagData[0]) { if (pTagData[0]) {
pTagData += 21; pTagData += 21;
if (pTagData - pFirstFrameData + 14 < firstFrameInfo.frame_bytes) { if (pTagData - pFirstFrameData + 14 < firstFrameInfo.frame_bytes) {
pMP3->delayInPCMFrames = (( (ma_uint32)pTagData[0] << 4) | ((ma_uint32)pTagData[1] >> 4)) + (528 + 1); int delayInPCMFrames;
pMP3->paddingInPCMFrames = ((((ma_uint32)pTagData[1] & 0xF) << 8) | ((ma_uint32)pTagData[2] )) - (528 + 1); int paddingInPCMFrames;
delayInPCMFrames = (( (ma_uint32)pTagData[0] << 4) | ((ma_uint32)pTagData[1] >> 4)) + (528 + 1);
paddingInPCMFrames = ((((ma_uint32)pTagData[1] & 0xF) << 8) | ((ma_uint32)pTagData[2] )) - (528 + 1);
if (paddingInPCMFrames < 0) {
paddingInPCMFrames = 0;
}
pMP3->delayInPCMFrames = (ma_uint32)delayInPCMFrames;
pMP3->paddingInPCMFrames = (ma_uint32)paddingInPCMFrames;
} }
} }
if (isXing) { if (isXing) {
...@@ -93584,13 +93593,22 @@ MA_API ma_bool32 ma_dr_mp3_get_mp3_and_pcm_frame_count(ma_dr_mp3* pMP3, ma_uint6 ...@@ -93584,13 +93593,22 @@ MA_API ma_bool32 ma_dr_mp3_get_mp3_and_pcm_frame_count(ma_dr_mp3* pMP3, ma_uint6
} }
MA_API ma_uint64 ma_dr_mp3_get_pcm_frame_count(ma_dr_mp3* pMP3) MA_API ma_uint64 ma_dr_mp3_get_pcm_frame_count(ma_dr_mp3* pMP3)
{ {
ma_uint64 totalPCMFrameCount;
if (pMP3 == NULL) { if (pMP3 == NULL) {
return 0; return 0;
} }
if (pMP3->totalPCMFrameCount != MA_UINT64_MAX) { if (pMP3->totalPCMFrameCount != MA_UINT64_MAX) {
return (ma_uint64)pMP3->totalPCMFrameCount - pMP3->paddingInPCMFrames - pMP3->delayInPCMFrames; totalPCMFrameCount = pMP3->totalPCMFrameCount;
if (totalPCMFrameCount >= pMP3->delayInPCMFrames) {
totalPCMFrameCount -= pMP3->delayInPCMFrames;
} else {
}
if (totalPCMFrameCount >= pMP3->paddingInPCMFrames) {
totalPCMFrameCount -= pMP3->paddingInPCMFrames;
} else {
}
return totalPCMFrameCount;
} else { } else {
ma_uint64 totalPCMFrameCount;
if (!ma_dr_mp3_get_mp3_and_pcm_frame_count(pMP3, NULL, &totalPCMFrameCount)) { if (!ma_dr_mp3_get_mp3_and_pcm_frame_count(pMP3, NULL, &totalPCMFrameCount)) {
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment