Commit fb9716d9 authored by David Reid's avatar David Reid

API CHANGE: Update ma_clip_samples_f32() to take an input and output.

The previous version only allowed in-place clipping, whereas the new
one supports clipping into a separate buffer. The input and output
buffers can point to the same buffer in which case the clip will be
performed in-place.
parent b0927a44
...@@ -5898,8 +5898,8 @@ static MA_INLINE const float* ma_offset_pcm_frames_const_ptr_f32(const float* p, ...@@ -5898,8 +5898,8 @@ static MA_INLINE const float* ma_offset_pcm_frames_const_ptr_f32(const float* p,
/* /*
Clips f32 samples. Clips f32 samples.
*/ */
MA_API void ma_clip_samples_f32(float* p, ma_uint64 sampleCount); MA_API void ma_clip_samples_f32(float* pDst, const float* pSrc, ma_uint64 count);
static MA_INLINE void ma_clip_pcm_frames_f32(float* p, ma_uint64 frameCount, ma_uint32 channels) { ma_clip_samples_f32(p, frameCount*channels); } static MA_INLINE void ma_clip_pcm_frames_f32(float* p, ma_uint64 frameCount, ma_uint32 channels) { ma_clip_samples_f32(p, p, frameCount*channels); }
/* /*
Helper for applying a volume factor to samples. Helper for applying a volume factor to samples.
...@@ -34115,13 +34115,15 @@ MA_API const void* ma_offset_pcm_frames_const_ptr(const void* p, ma_uint64 offse ...@@ -34115,13 +34115,15 @@ MA_API const void* ma_offset_pcm_frames_const_ptr(const void* p, ma_uint64 offse
} }
MA_API void ma_clip_samples_f32(float* p, ma_uint64 sampleCount) MA_API void ma_clip_samples_f32(float* pDst, const float* pSrc, ma_uint64 count)
{ {
ma_uint32 iSample; ma_uint64 iSample;
/* TODO: Research a branchless SSE implementation. */ MA_ASSERT(pDst != NULL);
for (iSample = 0; iSample < sampleCount; iSample += 1) { MA_ASSERT(pSrc != NULL);
p[iSample] = ma_clip_f32(p[iSample]);
for (iSample = 0; iSample < count; iSample += 1) {
pDst[iSample] = ma_clip_f32(pSrc[iSample]);
} }
} }
...@@ -5629,18 +5629,6 @@ static void ma_clip_samples_s32(ma_int32* pDst, const ma_int64* pSrc, ma_uint64 ...@@ -5629,18 +5629,6 @@ static void ma_clip_samples_s32(ma_int32* pDst, const ma_int64* pSrc, ma_uint64
} }
} }
static void ma_clip_samples_f32_ex(float* pDst, const float* pSrc, ma_uint64 count)
{
ma_uint64 iSample;
MA_ASSERT(pDst != NULL);
MA_ASSERT(pSrc != NULL);
for (iSample = 0; iSample < count; iSample += 1) {
pDst[iSample] = ma_clip_f32(pSrc[iSample]);
}
}
static void ma_volume_and_clip_samples_u8(ma_uint8* pDst, const ma_int16* pSrc, ma_uint64 count, float volume) static void ma_volume_and_clip_samples_u8(ma_uint8* pDst, const ma_int16* pSrc, ma_uint64 count, float volume)
...@@ -5734,7 +5722,7 @@ static void ma_clip_pcm_frames(void* pDst, const void* pSrc, ma_uint64 frameCoun ...@@ -5734,7 +5722,7 @@ static void ma_clip_pcm_frames(void* pDst, const void* pSrc, ma_uint64 frameCoun
case ma_format_s16: ma_clip_samples_s16((ma_int16*)pDst, (const ma_int32*)pSrc, sampleCount); break; case ma_format_s16: ma_clip_samples_s16((ma_int16*)pDst, (const ma_int32*)pSrc, sampleCount); break;
case ma_format_s24: ma_clip_samples_s24((ma_uint8*)pDst, (const ma_int64*)pSrc, sampleCount); break; case ma_format_s24: ma_clip_samples_s24((ma_uint8*)pDst, (const ma_int64*)pSrc, sampleCount); break;
case ma_format_s32: ma_clip_samples_s32((ma_int32*)pDst, (const ma_int64*)pSrc, sampleCount); break; case ma_format_s32: ma_clip_samples_s32((ma_int32*)pDst, (const ma_int64*)pSrc, sampleCount); break;
case ma_format_f32: ma_clip_samples_f32_ex((float*)pDst, (const float*)pSrc, sampleCount); break; case ma_format_f32: ma_clip_samples_f32(( float*)pDst, (const float*)pSrc, sampleCount); break;
/* Do nothing if we don't know the format. We're including these here to silence a compiler warning about enums not being handled by the switch. */ /* Do nothing if we don't know the format. We're including these here to silence a compiler warning about enums not being handled by the switch. */
case ma_format_unknown: case ma_format_unknown:
......
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