Skip to content

Commit 2886493

Browse files
committed
update to latest drmp3
1 parent 50cd29e commit 2886493

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/codecs/dr_libs/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<h4 align="center">Public domain, single file audio decoding libraries for C and C++.</h4>
22

33
<p align="center">
4-
<a href="https://discord.gg/9vpqbjU"><img src="https://img.shields.io/discord/712952679415939085?label=discord&logo=discord" alt="discord"></a>
5-
<a href="https://twitter.com/mackron"><img src="https://img.shields.io/twitter/follow/mackron?style=flat&label=twitter&color=1da1f2&logo=twitter" alt="twitter"></a>
4+
<a href="https://discord.gg/9vpqbjU"><img src="https://img.shields.io/discord/712952679415939085?label=discord&logo=discord&style=flat-square" alt="discord"></a>
65
</p>
76

7+
All development of released libraries happens on the master branch. There may exist some decoder-specific branches for work in progress. Check tags for the latest version of a particular library.
8+
89

910
Library | Description
1011
----------------------------------------------- | -----------
@@ -19,3 +20,4 @@ Below are some of my other libraries you may be interested in.
1920
Library | Description
2021
------------------------------------------------- | -----------
2122
[miniaudio](https://github.com/mackron/miniaudio) | A public domain, single file library for audio playback and recording.
23+

src/codecs/dr_libs/dr_mp3.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,8 +3202,17 @@ static drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drm
32023202
pTagData += 21;
32033203

32043204
if (pTagData - pFirstFrameData + 14 < firstFrameInfo.frame_bytes) {
3205-
pMP3->delayInPCMFrames = (( (drmp3_uint32)pTagData[0] << 4) | ((drmp3_uint32)pTagData[1] >> 4)) + (528 + 1);
3206-
pMP3->paddingInPCMFrames = ((((drmp3_uint32)pTagData[1] & 0xF) << 8) | ((drmp3_uint32)pTagData[2] )) - (528 + 1);
3205+
int delayInPCMFrames;
3206+
int paddingInPCMFrames;
3207+
3208+
delayInPCMFrames = (( (drmp3_uint32)pTagData[0] << 4) | ((drmp3_uint32)pTagData[1] >> 4)) + (528 + 1);
3209+
paddingInPCMFrames = ((((drmp3_uint32)pTagData[1] & 0xF) << 8) | ((drmp3_uint32)pTagData[2] )) - (528 + 1);
3210+
if (paddingInPCMFrames < 0) {
3211+
paddingInPCMFrames = 0; /* Padding cannot be negative. Probably a malformed file. Ignore. */
3212+
}
3213+
3214+
pMP3->delayInPCMFrames = (drmp3_uint32)delayInPCMFrames;
3215+
pMP3->paddingInPCMFrames = (drmp3_uint32)paddingInPCMFrames;
32073216
}
32083217
}
32093218

@@ -4515,15 +4524,30 @@ DRMP3_API drmp3_bool32 drmp3_get_mp3_and_pcm_frame_count(drmp3* pMP3, drmp3_uint
45154524

45164525
DRMP3_API drmp3_uint64 drmp3_get_pcm_frame_count(drmp3* pMP3)
45174526
{
4527+
drmp3_uint64 totalPCMFrameCount;
4528+
45184529
if (pMP3 == NULL) {
45194530
return 0;
45204531
}
45214532

45224533
if (pMP3->totalPCMFrameCount != DRMP3_UINT64_MAX) {
4523-
return (drmp3_uint64)pMP3->totalPCMFrameCount - pMP3->paddingInPCMFrames - pMP3->delayInPCMFrames;
4534+
totalPCMFrameCount = pMP3->totalPCMFrameCount;
4535+
4536+
if (totalPCMFrameCount >= pMP3->delayInPCMFrames) {
4537+
totalPCMFrameCount -= pMP3->delayInPCMFrames;
4538+
} else {
4539+
/* The delay is greater than the frame count reported by the Xing/Info tag. Assume it's invalid and ignore. */
4540+
}
4541+
4542+
if (totalPCMFrameCount >= pMP3->paddingInPCMFrames) {
4543+
totalPCMFrameCount -= pMP3->paddingInPCMFrames;
4544+
} else {
4545+
/* The padding is greater than the frame count reported by the Xing/Info tag. Assume it's invalid and ignore. */
4546+
}
4547+
4548+
return totalPCMFrameCount;
45244549
} else {
45254550
/* Unknown frame count. Need to calculate it. */
4526-
drmp3_uint64 totalPCMFrameCount;
45274551
if (!drmp3_get_mp3_and_pcm_frame_count(pMP3, NULL, &totalPCMFrameCount)) {
45284552
return 0;
45294553
}

0 commit comments

Comments
 (0)