Commit cb9505ac authored by David Reid's avatar David Reid

Fix a crash in the linear resampler when LPF order is 0.

Public issue https://github.com/dr-soft/miniaudio/issues/155
parent 90550c9e
...@@ -5160,6 +5160,11 @@ Calculates a buffer size in frames from the specified number of milliseconds and ...@@ -5160,6 +5160,11 @@ Calculates a buffer size in frames from the specified number of milliseconds and
*/ */
MA_API ma_uint32 ma_calculate_buffer_size_in_frames_from_milliseconds(ma_uint32 bufferSizeInMilliseconds, ma_uint32 sampleRate); MA_API ma_uint32 ma_calculate_buffer_size_in_frames_from_milliseconds(ma_uint32 bufferSizeInMilliseconds, ma_uint32 sampleRate);
/*
Copies PCM frames from one buffer to another.
*/
MA_API void ma_copy_pcm_frames(void* dst, const void* src, ma_uint64 frameCount, ma_format format, ma_uint32 channels);
/* /*
Copies silent frames into the given buffer. Copies silent frames into the given buffer.
*/ */
...@@ -8840,6 +8845,11 @@ MA_API ma_uint32 ma_calculate_buffer_size_in_frames_from_milliseconds(ma_uint32 ...@@ -8840,6 +8845,11 @@ MA_API ma_uint32 ma_calculate_buffer_size_in_frames_from_milliseconds(ma_uint32
return bufferSizeInMilliseconds * (sampleRate/1000); return bufferSizeInMilliseconds * (sampleRate/1000);
} }
MA_API void ma_copy_pcm_frames(void* dst, const void* src, ma_uint64 frameCount, ma_format format, ma_uint32 channels)
{
ma_copy_memory_64(dst, src, frameCount * ma_get_bytes_per_frame(format, channels));
}
MA_API void ma_zero_pcm_frames(void* p, ma_uint64 frameCount, ma_format format, ma_uint32 channels) MA_API void ma_zero_pcm_frames(void* p, ma_uint64 frameCount, ma_format format, ma_uint32 channels)
{ {
ma_zero_memory_64(p, frameCount * ma_get_bytes_per_frame(format, channels)); ma_zero_memory_64(p, frameCount * ma_get_bytes_per_frame(format, channels));
...@@ -32759,7 +32769,11 @@ MA_API ma_linear_resampler_config ma_linear_resampler_config_init(ma_format form ...@@ -32759,7 +32769,11 @@ MA_API ma_linear_resampler_config ma_linear_resampler_config_init(ma_format form
static ma_result ma_linear_resampler_set_rate_internal(ma_linear_resampler* pResampler, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut, ma_bool32 isResamplerAlreadyInitialized) static ma_result ma_linear_resampler_set_rate_internal(ma_linear_resampler* pResampler, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut, ma_bool32 isResamplerAlreadyInitialized)
{ {
ma_result result;
ma_uint32 gcf; ma_uint32 gcf;
ma_uint32 lpfSampleRate;
double lpfCutoffFrequency;
ma_lpf_config lpfConfig;
if (pResampler == NULL) { if (pResampler == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
...@@ -32777,12 +32791,7 @@ static ma_result ma_linear_resampler_set_rate_internal(ma_linear_resampler* pRes ...@@ -32777,12 +32791,7 @@ static ma_result ma_linear_resampler_set_rate_internal(ma_linear_resampler* pRes
pResampler->config.sampleRateIn /= gcf; pResampler->config.sampleRateIn /= gcf;
pResampler->config.sampleRateOut /= gcf; pResampler->config.sampleRateOut /= gcf;
if (pResampler->config.lpfOrder > 0) { /* Always initialize the low-pass filter, even when the order is 0. */
ma_result result;
ma_uint32 lpfSampleRate;
double lpfCutoffFrequency;
ma_lpf_config lpfConfig;
if (pResampler->config.lpfOrder > MA_MAX_FILTER_ORDER) { if (pResampler->config.lpfOrder > MA_MAX_FILTER_ORDER) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
...@@ -32805,7 +32814,6 @@ static ma_result ma_linear_resampler_set_rate_internal(ma_linear_resampler* pRes ...@@ -32805,7 +32814,6 @@ static ma_result ma_linear_resampler_set_rate_internal(ma_linear_resampler* pRes
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return result; return result;
} }
}
pResampler->inAdvanceInt = pResampler->config.sampleRateIn / pResampler->config.sampleRateOut; pResampler->inAdvanceInt = pResampler->config.sampleRateIn / pResampler->config.sampleRateOut;
pResampler->inAdvanceFrac = pResampler->config.sampleRateIn % pResampler->config.sampleRateOut; pResampler->inAdvanceFrac = pResampler->config.sampleRateIn % pResampler->config.sampleRateOut;
...@@ -42484,10 +42492,12 @@ REVISION HISTORY ...@@ -42484,10 +42492,12 @@ REVISION HISTORY
================ ================
v0.10.5 - TBD v0.10.5 - TBD
- Change ma_zero_pcm_frames() to take a 64-bit frame count. - Change ma_zero_pcm_frames() to take a 64-bit frame count.
- Add ma_copy_pcm_frames().
- Add MA_NO_GENERATION build option to exclude the `ma_waveform` and `ma_noise` APIs from the build. - Add MA_NO_GENERATION build option to exclude the `ma_waveform` and `ma_noise` APIs from the build.
- Add support for formatted logging to the VC6 build. - Add support for formatted logging to the VC6 build.
- Minor documentation updates. - Fix a crash in the linear resampler when LPF order is 0.
- Fix compilation errors and warnings with older versions of Visual Studio. - Fix compilation errors and warnings with older versions of Visual Studio.
- Minor documentation updates.
v0.10.4 - 2020-04-12 v0.10.4 - 2020-04-12
- Fix a data conversion bug when converting from the client format to the native device format. - Fix a data conversion bug when converting from the client format to the native device format.
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