Add support for passing in NULL for input frames for linear resampler.

This is equivalent to passing in zeroes.
This commit is contained in:
David Reid
2020-01-26 09:19:24 +10:00
parent b092720bf3
commit 01c41ed329
+40 -30
View File
@@ -439,7 +439,6 @@ static ma_result ma_linear_resampler_process_pcm_frames_s16_downsample(ma_linear
ma_uint64 framesProcessedOut; ma_uint64 framesProcessedOut;
MA_ASSERT(pResampler != NULL); MA_ASSERT(pResampler != NULL);
MA_ASSERT(pFramesIn != NULL);
MA_ASSERT(pFrameCountIn != NULL); MA_ASSERT(pFrameCountIn != NULL);
MA_ASSERT(pFramesOut != NULL); MA_ASSERT(pFramesOut != NULL);
MA_ASSERT(pFrameCountOut != NULL); MA_ASSERT(pFrameCountOut != NULL);
@@ -461,24 +460,24 @@ static ma_result ma_linear_resampler_process_pcm_frames_s16_downsample(ma_linear
ma_uint32 iFilter; ma_uint32 iFilter;
ma_uint32 iChannel; ma_uint32 iChannel;
if (pFramesInS16 != NULL) {
for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) { for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) {
pResampler->x0.s16[iChannel] = pResampler->x1.s16[iChannel]; pResampler->x0.s16[iChannel] = pResampler->x1.s16[iChannel];
}
if (pResampler->config.lpfCount > 0) {
/* Filtering. */
ma_lpf_process_pcm_frame_s16(&pResampler->lpf[0], pResampler->x1.s16, pFramesInS16);
for (iFilter = 1; iFilter < pResampler->config.lpfCount; iFilter += 1) {
ma_lpf_process_pcm_frame_s16(&pResampler->lpf[iFilter], pResampler->x1.s16, pResampler->x1.s16);
}
} else {
/* No filtering. */
for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) {
pResampler->x1.s16[iChannel] = pFramesInS16[iChannel]; pResampler->x1.s16[iChannel] = pFramesInS16[iChannel];
} }
pFramesInS16 += pResampler->config.channels;
} else {
for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) {
pResampler->x0.s16[iChannel] = pResampler->x1.s16[iChannel];
pResampler->x1.s16[iChannel] = 0;
}
}
/* Filter. */
for (iFilter = 0; iFilter < pResampler->config.lpfCount; iFilter += 1) {
ma_lpf_process_pcm_frame_s16(&pResampler->lpf[iFilter], pResampler->x1.s16, pResampler->x1.s16);
} }
pFramesInS16 += pResampler->config.channels;
frameCountIn -= 1; frameCountIn -= 1;
framesProcessedIn += 1; framesProcessedIn += 1;
pResampler->inTimeInt -= 1; pResampler->inTimeInt -= 1;
@@ -520,7 +519,6 @@ static ma_result ma_linear_resampler_process_pcm_frames_s16_upsample(ma_linear_r
ma_uint64 framesProcessedOut; ma_uint64 framesProcessedOut;
MA_ASSERT(pResampler != NULL); MA_ASSERT(pResampler != NULL);
MA_ASSERT(pFramesIn != NULL);
MA_ASSERT(pFrameCountIn != NULL); MA_ASSERT(pFrameCountIn != NULL);
MA_ASSERT(pFramesOut != NULL); MA_ASSERT(pFramesOut != NULL);
MA_ASSERT(pFrameCountOut != NULL); MA_ASSERT(pFrameCountOut != NULL);
@@ -543,12 +541,19 @@ static ma_result ma_linear_resampler_process_pcm_frames_s16_upsample(ma_linear_r
while (pResampler->inTimeInt > 0 && frameCountIn > 0) { while (pResampler->inTimeInt > 0 && frameCountIn > 0) {
ma_uint32 iChannel; ma_uint32 iChannel;
if (pFramesInS16 != NULL) {
for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) { for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) {
pResampler->x0.s16[iChannel] = pResampler->x1.s16[iChannel]; pResampler->x0.s16[iChannel] = pResampler->x1.s16[iChannel];
pResampler->x1.s16[iChannel] = pFramesInS16[iChannel]; pResampler->x1.s16[iChannel] = pFramesInS16[iChannel];
} }
pFramesInS16 += pResampler->config.channels; pFramesInS16 += pResampler->config.channels;
} else {
for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) {
pResampler->x0.s16[iChannel] = pResampler->x1.s16[iChannel];
pResampler->x1.s16[iChannel] = 0;
}
}
frameCountIn -= 1; frameCountIn -= 1;
framesProcessedIn += 1; framesProcessedIn += 1;
pResampler->inTimeInt -= 1; pResampler->inTimeInt -= 1;
@@ -609,7 +614,6 @@ static ma_result ma_linear_resampler_process_pcm_frames_f32_downsample(ma_linear
ma_uint64 framesProcessedOut; ma_uint64 framesProcessedOut;
MA_ASSERT(pResampler != NULL); MA_ASSERT(pResampler != NULL);
MA_ASSERT(pFramesIn != NULL);
MA_ASSERT(pFrameCountIn != NULL); MA_ASSERT(pFrameCountIn != NULL);
MA_ASSERT(pFramesOut != NULL); MA_ASSERT(pFramesOut != NULL);
MA_ASSERT(pFrameCountOut != NULL); MA_ASSERT(pFrameCountOut != NULL);
@@ -631,24 +635,24 @@ static ma_result ma_linear_resampler_process_pcm_frames_f32_downsample(ma_linear
ma_uint32 iFilter; ma_uint32 iFilter;
ma_uint32 iChannel; ma_uint32 iChannel;
if (pFramesInF32 != NULL) {
for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) { for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) {
pResampler->x0.f32[iChannel] = pResampler->x1.f32[iChannel]; pResampler->x0.f32[iChannel] = pResampler->x1.f32[iChannel];
}
if (pResampler->config.lpfCount > 0) {
/* Filtering. */
ma_lpf_process_pcm_frame_f32(&pResampler->lpf[0], pResampler->x1.f32, pFramesInF32);
for (iFilter = 1; iFilter < pResampler->config.lpfCount; iFilter += 1) {
ma_lpf_process_pcm_frame_f32(&pResampler->lpf[iFilter], pResampler->x1.f32, pResampler->x1.f32);
}
} else {
/* No filtering. */
for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) {
pResampler->x1.f32[iChannel] = pFramesInF32[iChannel]; pResampler->x1.f32[iChannel] = pFramesInF32[iChannel];
} }
pFramesInF32 += pResampler->config.channels;
} else {
for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) {
pResampler->x0.f32[iChannel] = pResampler->x1.f32[iChannel];
pResampler->x1.f32[iChannel] = 0;
}
}
/* Filter. */
for (iFilter = 0; iFilter < pResampler->config.lpfCount; iFilter += 1) {
ma_lpf_process_pcm_frame_f32(&pResampler->lpf[iFilter], pResampler->x1.f32, pResampler->x1.f32);
} }
pFramesInF32 += pResampler->config.channels;
frameCountIn -= 1; frameCountIn -= 1;
framesProcessedIn += 1; framesProcessedIn += 1;
pResampler->inTimeInt -= 1; pResampler->inTimeInt -= 1;
@@ -690,7 +694,6 @@ static ma_result ma_linear_resampler_process_pcm_frames_f32_upsample(ma_linear_r
ma_uint64 framesProcessedOut; ma_uint64 framesProcessedOut;
MA_ASSERT(pResampler != NULL); MA_ASSERT(pResampler != NULL);
MA_ASSERT(pFramesIn != NULL);
MA_ASSERT(pFrameCountIn != NULL); MA_ASSERT(pFrameCountIn != NULL);
MA_ASSERT(pFramesOut != NULL); MA_ASSERT(pFramesOut != NULL);
MA_ASSERT(pFrameCountOut != NULL); MA_ASSERT(pFrameCountOut != NULL);
@@ -713,12 +716,19 @@ static ma_result ma_linear_resampler_process_pcm_frames_f32_upsample(ma_linear_r
while (pResampler->inTimeInt > 0 && frameCountIn > 0) { while (pResampler->inTimeInt > 0 && frameCountIn > 0) {
ma_uint32 iChannel; ma_uint32 iChannel;
if (pFramesInF32 != NULL) {
for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) { for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) {
pResampler->x0.f32[iChannel] = pResampler->x1.f32[iChannel]; pResampler->x0.f32[iChannel] = pResampler->x1.f32[iChannel];
pResampler->x1.f32[iChannel] = pFramesInF32[iChannel]; pResampler->x1.f32[iChannel] = pFramesInF32[iChannel];
} }
pFramesInF32 += pResampler->config.channels; pFramesInF32 += pResampler->config.channels;
} else {
for (iChannel = 0; iChannel < pResampler->config.channels; iChannel += 1) {
pResampler->x0.f32[iChannel] = pResampler->x1.f32[iChannel];
pResampler->x1.f32[iChannel] = 0;
}
}
frameCountIn -= 1; frameCountIn -= 1;
framesProcessedIn += 1; framesProcessedIn += 1;
pResampler->inTimeInt -= 1; pResampler->inTimeInt -= 1;