From d791c16d8d7856fb155d6bdb6269e06c7fb524b1 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 7 Jan 2026 12:05:57 +1000 Subject: [PATCH 1/7] Remove some redundant error checks. --- miniaudio.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 858f55ab..c791829b 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -66278,11 +66278,9 @@ static ma_result ma_decoder_init__internal(ma_decoder_read_proc onRead, ma_decod We use trial and error to open a decoder. We prioritize custom decoders so that if they implement the same encoding format they take priority over the built-in decoders. */ + result = ma_decoder_init_custom__internal(pConfig, pDecoder); if (result != MA_SUCCESS) { - result = ma_decoder_init_custom__internal(pConfig, pDecoder); - if (result != MA_SUCCESS) { - onSeek(pDecoder, 0, ma_seek_origin_start); - } + onSeek(pDecoder, 0, ma_seek_origin_start); } /* @@ -66846,11 +66844,9 @@ MA_API ma_result ma_decoder_init_vfs(ma_vfs* pVFS, const char* pFilePath, const We use trial and error to open a decoder. We prioritize custom decoders so that if they implement the same encoding format they take priority over the built-in decoders. */ + result = ma_decoder_init_custom__internal(&config, pDecoder); if (result != MA_SUCCESS) { - result = ma_decoder_init_custom__internal(&config, pDecoder); - if (result != MA_SUCCESS) { - ma_decoder__on_seek_vfs(pDecoder, 0, ma_seek_origin_start); - } + ma_decoder__on_seek_vfs(pDecoder, 0, ma_seek_origin_start); } /* @@ -66979,11 +66975,9 @@ MA_API ma_result ma_decoder_init_vfs_w(ma_vfs* pVFS, const wchar_t* pFilePath, c We use trial and error to open a decoder. We prioritize custom decoders so that if they implement the same encoding format they take priority over the built-in decoders. */ + result = ma_decoder_init_custom__internal(&config, pDecoder); if (result != MA_SUCCESS) { - result = ma_decoder_init_custom__internal(&config, pDecoder); - if (result != MA_SUCCESS) { - ma_decoder__on_seek_vfs(pDecoder, 0, ma_seek_origin_start); - } + ma_decoder__on_seek_vfs(pDecoder, 0, ma_seek_origin_start); } /* From bd26454c26ee2859f4d3eebccb2a02eb1d5dbc3a Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 7 Jan 2026 12:07:25 +1000 Subject: [PATCH 2/7] Fix a possible null pointer dereference. --- miniaudio.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index c791829b..4ed18de8 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -52305,13 +52305,16 @@ static float ma_calculate_angular_gain(ma_vec3f dirA, ma_vec3f dirB, float coneI MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer, ma_spatializer_listener* pListener, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount) { - ma_channel* pChannelMapIn = pSpatializer->pChannelMapIn; - ma_channel* pChannelMapOut = pListener->config.pChannelMapOut; + ma_channel* pChannelMapIn; + ma_channel* pChannelMapOut; if (pSpatializer == NULL) { return MA_INVALID_ARGS; } + pChannelMapIn = pSpatializer->pChannelMapIn; + pChannelMapOut = pListener->config.pChannelMapOut; + /* If we're not spatializing we need to run an optimized path. */ if (ma_atomic_load_i32(&pSpatializer->attenuationModel) == ma_attenuation_model_none) { if (ma_spatializer_listener_is_enabled(pListener)) { From 32cc6d53cd88f1befc7aca9df112ccbc1a2d28ce Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 7 Jan 2026 12:07:58 +1000 Subject: [PATCH 3/7] Fix a possible null pointer dereference. --- miniaudio.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 4ed18de8..397948f5 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -71529,13 +71529,13 @@ MA_API ma_result ma_resource_manager_data_buffer_get_data_format(ma_resource_man MA_API ma_result ma_resource_manager_data_buffer_get_cursor_in_pcm_frames(ma_resource_manager_data_buffer* pDataBuffer, ma_uint64* pCursor) { - /* We cannot be using the data source after it's been uninitialized. */ - MA_ASSERT(ma_resource_manager_data_buffer_node_result(pDataBuffer->pNode) != MA_UNAVAILABLE); - if (pDataBuffer == NULL || pCursor == NULL) { return MA_INVALID_ARGS; } + /* We cannot be using the data source after it's been uninitialized. */ + MA_ASSERT(ma_resource_manager_data_buffer_node_result(pDataBuffer->pNode) != MA_UNAVAILABLE); + *pCursor = 0; switch (ma_resource_manager_data_buffer_node_get_data_supply_type(pDataBuffer->pNode)) @@ -71569,13 +71569,13 @@ MA_API ma_result ma_resource_manager_data_buffer_get_cursor_in_pcm_frames(ma_res MA_API ma_result ma_resource_manager_data_buffer_get_length_in_pcm_frames(ma_resource_manager_data_buffer* pDataBuffer, ma_uint64* pLength) { - /* We cannot be using the data source after it's been uninitialized. */ - MA_ASSERT(ma_resource_manager_data_buffer_node_result(pDataBuffer->pNode) != MA_UNAVAILABLE); - if (pDataBuffer == NULL || pLength == NULL) { return MA_INVALID_ARGS; } + /* We cannot be using the data source after it's been uninitialized. */ + MA_ASSERT(ma_resource_manager_data_buffer_node_result(pDataBuffer->pNode) != MA_UNAVAILABLE); + if (ma_resource_manager_data_buffer_node_get_data_supply_type(pDataBuffer->pNode) == ma_resource_manager_data_supply_type_unknown) { return MA_BUSY; /* Still loading. */ } From bedfd053cb4133e01e8083bb73818fdedbae5ea6 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 7 Jan 2026 12:13:18 +1000 Subject: [PATCH 4/7] Fix a bug in the gainer where a null pointer can be offset. --- miniaudio.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 397948f5..2de7db58 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -50869,15 +50869,15 @@ static /*__attribute__((noinline))*/ ma_result ma_gainer_process_pcm_frames_inte a += d; } } + + pFramesOut = ma_offset_ptr(pFramesOut, interpolatedFrameCount * sizeof(float)); + pFramesIn = ma_offset_ptr(pFramesIn, interpolatedFrameCount * sizeof(float)); } + frameCount -= interpolatedFrameCount; + /* Make sure the timer is updated. */ pGainer->t = (ma_uint32)ma_min(pGainer->t + interpolatedFrameCount, pGainer->config.smoothTimeInFrames); - - /* Adjust our arguments so the next part can work normally. */ - frameCount -= interpolatedFrameCount; - pFramesOut = ma_offset_ptr(pFramesOut, interpolatedFrameCount * sizeof(float)); - pFramesIn = ma_offset_ptr(pFramesIn, interpolatedFrameCount * sizeof(float)); } /* All we need to do here is apply the new gains using an optimized path. */ From b83869eb09f21d8e8b07144d0df25453444f3722 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 7 Jan 2026 12:24:30 +1000 Subject: [PATCH 5/7] Update the spatializer to require a listener when processing. --- miniaudio.h | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 2de7db58..20fa991b 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -52308,11 +52308,11 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer, ma_channel* pChannelMapIn; ma_channel* pChannelMapOut; - if (pSpatializer == NULL) { + if (pSpatializer == NULL || pListener == NULL) { return MA_INVALID_ARGS; } - pChannelMapIn = pSpatializer->pChannelMapIn; + pChannelMapIn = pSpatializer->pChannelMapIn; pChannelMapOut = pListener->config.pChannelMapOut; /* If we're not spatializing we need to run an optimized path. */ @@ -52359,23 +52359,17 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer, We'll need the listener velocity for doppler pitch calculations. The speed of sound is defined by the listener, so we'll grab that here too. */ - if (pListener != NULL) { - listenerVel = ma_spatializer_listener_get_velocity(pListener); - speedOfSound = pListener->config.speedOfSound; - } else { - listenerVel = ma_vec3f_init_3f(0, 0, 0); - speedOfSound = MA_DEFAULT_SPEED_OF_SOUND; - } + listenerVel = ma_spatializer_listener_get_velocity(pListener); + speedOfSound = pListener->config.speedOfSound; - if (pListener == NULL || ma_spatializer_get_positioning(pSpatializer) == ma_positioning_relative) { - /* There's no listener or we're using relative positioning. */ + if (ma_spatializer_get_positioning(pSpatializer) == ma_positioning_relative) { relativePos = ma_spatializer_get_position(pSpatializer); relativeDir = ma_spatializer_get_direction(pSpatializer); } else { /* - We've found a listener and we're using absolute positioning. We need to transform the - sound's position and direction so that it's relative to listener. Later on we'll use - this for determining the factors to apply to each channel to apply the panning effect. + We're using absolute positioning. We need to transform the sound's position and + direction so that it's relative to listener. Later on we'll use this for determining + the factors to apply to each channel to apply the panning effect. */ ma_spatializer_get_relative_position_and_direction(pSpatializer, pListener, &relativePos, &relativeDir); } From 53116ad6da58ffe5e349c17b662bca7e92fa4bcd Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 7 Jan 2026 12:31:03 +1000 Subject: [PATCH 6/7] Minor change to an enum to make it less error prone. --- miniaudio.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 20fa991b..2b12ef8c 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -4182,9 +4182,13 @@ typedef enum MA_CHANNEL_AUX_29 = 49, MA_CHANNEL_AUX_30 = 50, MA_CHANNEL_AUX_31 = 51, + + /* Count. */ + MA_CHANNEL_POSITION_COUNT, + + /* Aliases. */ MA_CHANNEL_LEFT = MA_CHANNEL_FRONT_LEFT, MA_CHANNEL_RIGHT = MA_CHANNEL_FRONT_RIGHT, - MA_CHANNEL_POSITION_COUNT = (MA_CHANNEL_AUX_31 + 1) } _ma_channel_position; /* Do not use `_ma_channel_position` directly. Use `ma_channel` instead. */ typedef enum From 5f3de510b239da9e9a319349cdc9f88171002a85 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 7 Jan 2026 12:36:18 +1000 Subject: [PATCH 7/7] Make ma_is_spatial_channel_position() a bit more robust. This makes it less error prone when new channel positions are added to the enum. --- miniaudio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 2b12ef8c..8c1e70bb 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -54408,7 +54408,7 @@ static ma_bool32 ma_is_spatial_channel_position(ma_channel channelPosition) return MA_FALSE; } - if (channelPosition >= MA_CHANNEL_AUX_0 && channelPosition <= MA_CHANNEL_AUX_31) { + if (channelPosition >= MA_CHANNEL_AUX_0) { return MA_FALSE; }