Skip to content

Commit

Permalink
updated dr_libs from mainstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Feb 13, 2025
1 parent a580853 commit b273194
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
36 changes: 29 additions & 7 deletions src/dr_flac.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
FLAC audio decoder. Choice of public domain or MIT-0. See license statements at the end of this file.
dr_flac - v0.12.42 - 2023-11-02
dr_flac - v0.12.43 - 2024-12-17

David Reid - mackron@gmail.com

Expand Down Expand Up @@ -179,7 +179,7 @@ reports metadata to the application through the use of a callback, and every met

The main opening APIs (`drflac_open()`, etc.) will fail if the header is not present. The presents a problem in certain scenarios such as broadcast style
streams or internet radio where the header may not be present because the user has started playback mid-stream. To handle this, use the relaxed APIs:

`drflac_open_relaxed()`
`drflac_open_with_metadata_relaxed()`

Expand Down Expand Up @@ -235,7 +235,7 @@ extern "C" {

#define DRFLAC_VERSION_MAJOR 0
#define DRFLAC_VERSION_MINOR 12
#define DRFLAC_VERSION_REVISION 42
#define DRFLAC_VERSION_REVISION 43
#define DRFLAC_VERSION_STRING DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MAJOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MINOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_REVISION)

#include <stddef.h> /* For size_t. */
Expand Down Expand Up @@ -348,11 +348,11 @@ but also more memory. In my testing there is diminishing returns after about 4KB
#define DRFLAC_64BIT
#endif

#if defined(__x86_64__) || defined(_M_X64)
#if defined(__x86_64__) || (defined(_M_X64) && !defined(_M_ARM64EC))
#define DRFLAC_X64
#elif defined(__i386) || defined(_M_IX86)
#define DRFLAC_X86
#elif defined(__arm__) || defined(_M_ARM) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
#elif defined(__arm__) || defined(_M_ARM) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
#define DRFLAC_ARM
#endif
/* End Architecture Detection */
Expand Down Expand Up @@ -5393,6 +5393,12 @@ static drflac_bool32 drflac__read_subframe_header(drflac_bs* bs, drflac_subframe
return DRFLAC_FALSE;
}

/*
Default to 0 for the LPC order. It's important that we always set this to 0 for non LPC
and FIXED subframes because we'll be using it in a generic validation check later.
*/
pSubframe->lpcOrder = 0;

type = (header & 0x7E) >> 1;
if (type == 0) {
pSubframe->subframeType = DRFLAC_SUBFRAME_CONSTANT;
Expand Down Expand Up @@ -5465,6 +5471,18 @@ static drflac_bool32 drflac__decode_subframe(drflac_bs* bs, drflac_frame* frame,

pSubframe->pSamplesS32 = pDecodedSamplesOut;

/*
pDecodedSamplesOut will be pointing to a buffer that was allocated with enough memory to store
maxBlockSizeInPCMFrames samples (as specified in the FLAC header). We need to guard against an
overflow here. At a higher level we are checking maxBlockSizeInPCMFrames from the header, but
here we need to do an additional check to ensure this frame's block size fully encompasses any
warmup samples which is determined by the LPC order. For non LPC and FIXED subframes, the LPC
order will be have been set to 0 in drflac__read_subframe_header().
*/
if (frame->header.blockSizeInPCMFrames < pSubframe->lpcOrder) {
return DRFLAC_FALSE;
}

switch (pSubframe->subframeType)
{
case DRFLAC_SUBFRAME_CONSTANT:
Expand Down Expand Up @@ -6702,10 +6720,10 @@ static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, d

/* Skip to the index point count */
pRunningData += 35;

indexCount = pRunningData[0];
pRunningData += 1;

bufferSize += indexCount * sizeof(drflac_cuesheet_track_index);

/* Quick validation check. */
Expand Down Expand Up @@ -12077,6 +12095,10 @@ DRFLAC_API drflac_bool32 drflac_next_cuesheet_track(drflac_cuesheet_track_iterat
/*
REVISION HISTORY
================
v0.12.43 - 2024-12-17
- Fix a possible buffer overflow during decoding.
- Improve detection of ARM64EC

v0.12.42 - 2023-11-02
- Fix build for ARMv6-M.
- Fix a compilation warning with GCC.
Expand Down
34 changes: 20 additions & 14 deletions src/dr_mp3.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
MP3 audio decoder. Choice of public domain or MIT-0. See license statements at the end of this file.
dr_mp3 - v0.6.38 - 2023-11-02
dr_mp3 - v0.6.40 - 2024-12-17
David Reid - mackron@gmail.com
Expand Down Expand Up @@ -33,7 +33,7 @@ Support for loading a file from a `wchar_t` string has been added via the `drmp3
*/

/*
Introducation
Introduction
=============
dr_mp3 is a single file library. To use it, do something like the following in one .c file.
Expand Down Expand Up @@ -95,7 +95,7 @@ extern "C" {

#define DRMP3_VERSION_MAJOR 0
#define DRMP3_VERSION_MINOR 6
#define DRMP3_VERSION_REVISION 38
#define DRMP3_VERSION_REVISION 40
#define DRMP3_VERSION_STRING DRMP3_XSTRINGIFY(DRMP3_VERSION_MAJOR) "." DRMP3_XSTRINGIFY(DRMP3_VERSION_MINOR) "." DRMP3_XSTRINGIFY(DRMP3_VERSION_REVISION)

#include <stddef.h> /* For size_t. */
Expand Down Expand Up @@ -124,7 +124,7 @@ typedef unsigned int drmp3_uint32;
#pragma GCC diagnostic pop
#endif
#endif
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__powerpc64__)
#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__)
typedef drmp3_uint64 drmp3_uintptr;
#else
typedef drmp3_uint32 drmp3_uintptr;
Expand Down Expand Up @@ -604,7 +604,7 @@ DRMP3_API const char* drmp3_version_string(void)

#if !defined(DR_MP3_NO_SIMD)

#if !defined(DR_MP3_ONLY_SIMD) && (defined(_M_X64) || defined(__x86_64__) || defined(__aarch64__) || defined(_M_ARM64))
#if !defined(DR_MP3_ONLY_SIMD) && (defined(_M_X64) || defined(__x86_64__) || defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC))
/* x64 always have SSE2, arm64 always have neon, no need for generic code */
#define DR_MP3_ONLY_SIMD
#endif
Expand Down Expand Up @@ -680,7 +680,7 @@ static int drmp3_have_simd(void)
return g_have_simd - 1;
#endif
}
#elif defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM64)
#elif defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
#include <arm_neon.h>
#define DRMP3_HAVE_SSE 0
#define DRMP3_HAVE_SIMD 1
Expand Down Expand Up @@ -713,7 +713,7 @@ static int drmp3_have_simd(void)

#endif

#if defined(__ARM_ARCH) && (__ARM_ARCH >= 6) && !defined(__aarch64__) && !defined(_M_ARM64) && !defined(__ARM_ARCH_6M__)
#if defined(__ARM_ARCH) && (__ARM_ARCH >= 6) && !defined(__aarch64__) && !defined(_M_ARM64) && !defined(_M_ARM64EC) && !defined(__ARM_ARCH_6M__)
#define DRMP3_HAVE_ARMV6 1
static __inline__ __attribute__((always_inline)) drmp3_int32 drmp3_clip_int16_arm(drmp3_int32 a)
{
Expand Down Expand Up @@ -1985,8 +1985,8 @@ static drmp3_int16 drmp3d_scale_pcm(float sample)
s32 -= (s32 < 0);
s = (drmp3_int16)drmp3_clip_int16_arm(s32);
#else
if (sample >= 32766.5) return (drmp3_int16) 32767;
if (sample <= -32767.5) return (drmp3_int16)-32768;
if (sample >= 32766.5f) return (drmp3_int16) 32767;
if (sample <= -32767.5f) return (drmp3_int16)-32768;
s = (drmp3_int16)(sample + .5f);
s -= (s < 0); /* away from zero, to be compliant */
#endif
Expand Down Expand Up @@ -2404,9 +2404,9 @@ DRMP3_API void drmp3dec_f32_to_s16(const float *in, drmp3_int16 *out, size_t num
for(; i < num_samples; i++)
{
float sample = in[i] * 32768.0f;
if (sample >= 32766.5)
if (sample >= 32766.5f)
out[i] = (drmp3_int16) 32767;
else if (sample <= -32767.5)
else if (sample <= -32767.5f)
out[i] = (drmp3_int16)-32768;
else
{
Expand Down Expand Up @@ -3564,7 +3564,7 @@ DRMP3_API void drmp3_uninit(drmp3* pMP3)
if (pMP3 == NULL) {
return;
}

#ifndef DR_MP3_NO_STDIO
if (pMP3->onRead == drmp3__on_read_stdio) {
FILE* pFile = (FILE*)pMP3->pUserData;
Expand Down Expand Up @@ -3952,7 +3952,7 @@ DRMP3_API drmp3_bool32 drmp3_get_mp3_and_pcm_frame_count(drmp3* pMP3, drmp3_uint

/* We'll need to seek back to where we were, so grab the PCM frame we're currently sitting on so we can restore later. */
currentPCMFrame = pMP3->currentPCMFrame;

if (!drmp3_seek_to_start_of_stream(pMP3)) {
return DRMP3_FALSE;
}
Expand Down Expand Up @@ -4050,7 +4050,7 @@ DRMP3_API drmp3_bool32 drmp3_calculate_seek_points(drmp3* pMP3, drmp3_uint32* pS

/* We'll need to seek back to the current sample after calculating the seekpoints so we need to go ahead and grab the current location at the top. */
currentPCMFrame = pMP3->currentPCMFrame;

/* We never do more than the total number of MP3 frames and we limit it to 32-bits. */
if (!drmp3_get_mp3_and_pcm_frame_count(pMP3, &totalMP3FrameCount, &totalPCMFrameCount)) {
return DRMP3_FALSE;
Expand Down Expand Up @@ -4495,6 +4495,12 @@ counts rather than sample counts.
/*
REVISION HISTORY
================
v0.6.40 - 2024-12-17
- Improve detection of ARM64EC
v0.6.39 - 2024-02-27
- Fix a Wdouble-promotion warning.
v0.6.38 - 2023-11-02
- Fix build for ARMv6-M.
Expand Down

0 comments on commit b273194

Please sign in to comment.