mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
Remove some old unused code.
This commit is contained in:
@@ -307,9 +307,6 @@ multiple threads comes into play when loading multiple sounds at the time time.
|
|||||||
MA_API void ma_copy_and_apply_volume_factor_per_channel_f32(float* pFramesOut, const float* pFramesIn, ma_uint64 frameCount, ma_uint32 channels, float* pChannelGains);
|
MA_API void ma_copy_and_apply_volume_factor_per_channel_f32(float* pFramesOut, const float* pFramesIn, ma_uint64 frameCount, ma_uint32 channels, float* pChannelGains);
|
||||||
MA_API void ma_apply_volume_factor_per_channel_f32(float* pFramesOut, ma_uint64 frameCount, ma_uint32 channels, float* pChannelGains);
|
MA_API void ma_apply_volume_factor_per_channel_f32(float* pFramesOut, ma_uint64 frameCount, ma_uint32 channels, float* pChannelGains);
|
||||||
|
|
||||||
MA_API size_t ma_get_accumulation_bytes_per_sample(ma_format format);
|
|
||||||
MA_API size_t ma_get_accumulation_bytes_per_frame(ma_format format, ma_uint32 channels);
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -2293,26 +2290,6 @@ MA_API float ma_delay_node_get_decay(const ma_delay_node* pDelayNode);
|
|||||||
|
|
||||||
#if defined(MA_IMPLEMENTATION) || defined(MINIAUDIO_IMPLEMENTATION)
|
#if defined(MA_IMPLEMENTATION) || defined(MINIAUDIO_IMPLEMENTATION)
|
||||||
|
|
||||||
MA_API size_t ma_get_accumulation_bytes_per_sample(ma_format format)
|
|
||||||
{
|
|
||||||
size_t bytesPerSample[ma_format_count] = {
|
|
||||||
0, /* ma_format_unknown */
|
|
||||||
sizeof(ma_int16), /* ma_format_u8 */
|
|
||||||
sizeof(ma_int32), /* ma_format_s16 */
|
|
||||||
sizeof(ma_int64), /* ma_format_s24 */
|
|
||||||
sizeof(ma_int64), /* ma_format_s32 */
|
|
||||||
sizeof(float) /* ma_format_f32 */
|
|
||||||
};
|
|
||||||
|
|
||||||
return bytesPerSample[format];
|
|
||||||
}
|
|
||||||
|
|
||||||
MA_API size_t ma_get_accumulation_bytes_per_frame(ma_format format, ma_uint32 channels)
|
|
||||||
{
|
|
||||||
return ma_get_accumulation_bytes_per_sample(format) * channels;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MA_API ma_gainer_config ma_gainer_config_init(ma_uint32 channels, ma_uint32 smoothTimeInFrames)
|
MA_API ma_gainer_config ma_gainer_config_init(ma_uint32 channels, ma_uint32 smoothTimeInFrames)
|
||||||
{
|
{
|
||||||
@@ -2955,125 +2932,6 @@ MA_API void ma_apply_volume_factor_per_channel_f32(float* pFramesOut, ma_uint64
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Not used right now, but leaving here for reference. */
|
|
||||||
#if 0
|
|
||||||
static ma_result ma_mix_pcm_frames_u8(ma_int16* pDst, const ma_uint8* pSrc, ma_uint64 frameCount, ma_uint32 channels, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_uint64 sampleCount;
|
|
||||||
|
|
||||||
if (pDst == NULL || pSrc == NULL || channels == 0) {
|
|
||||||
return MA_INVALID_ARGS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (volume == 0) {
|
|
||||||
return MA_SUCCESS; /* No changes if the volume is 0. */
|
|
||||||
}
|
|
||||||
|
|
||||||
sampleCount = frameCount * channels;
|
|
||||||
|
|
||||||
if (volume == 1) {
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += ma_pcm_sample_u8_to_s16_no_scale(pSrc[iSample]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ma_int16 volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += ma_apply_volume_unclipped_u8(ma_pcm_sample_u8_to_s16_no_scale(pSrc[iSample]), volumeFixed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return MA_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ma_result ma_mix_pcm_frames_s16(ma_int32* pDst, const ma_int16* pSrc, ma_uint64 frameCount, ma_uint32 channels, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_uint64 sampleCount;
|
|
||||||
|
|
||||||
if (pDst == NULL || pSrc == NULL || channels == 0) {
|
|
||||||
return MA_INVALID_ARGS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (volume == 0) {
|
|
||||||
return MA_SUCCESS; /* No changes if the volume is 0. */
|
|
||||||
}
|
|
||||||
|
|
||||||
sampleCount = frameCount * channels;
|
|
||||||
|
|
||||||
if (volume == 1) {
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += pSrc[iSample];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ma_int16 volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += ma_apply_volume_unclipped_s16(pSrc[iSample], volumeFixed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return MA_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ma_result ma_mix_pcm_frames_s24(ma_int64* pDst, const ma_uint8* pSrc, ma_uint64 frameCount, ma_uint32 channels, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_uint64 sampleCount;
|
|
||||||
|
|
||||||
if (pDst == NULL || pSrc == NULL || channels == 0) {
|
|
||||||
return MA_INVALID_ARGS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (volume == 0) {
|
|
||||||
return MA_SUCCESS; /* No changes if the volume is 0. */
|
|
||||||
}
|
|
||||||
|
|
||||||
sampleCount = frameCount * channels;
|
|
||||||
|
|
||||||
if (volume == 1) {
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += ma_pcm_sample_s24_to_s32_no_scale(&pSrc[iSample*3]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ma_int16 volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += ma_apply_volume_unclipped_s24(ma_pcm_sample_s24_to_s32_no_scale(&pSrc[iSample*3]), volumeFixed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return MA_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ma_result ma_mix_pcm_frames_s32(ma_int64* pDst, const ma_int32* pSrc, ma_uint64 frameCount, ma_uint32 channels, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_uint64 sampleCount;
|
|
||||||
|
|
||||||
if (pDst == NULL || pSrc == NULL || channels == 0) {
|
|
||||||
return MA_INVALID_ARGS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (volume == 0) {
|
|
||||||
return MA_SUCCESS; /* No changes if the volume is 0. */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sampleCount = frameCount * channels;
|
|
||||||
|
|
||||||
if (volume == 1) {
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += pSrc[iSample];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ma_int16 volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += ma_apply_volume_unclipped_s32(pSrc[iSample], volumeFixed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return MA_SUCCESS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static ma_result ma_mix_pcm_frames_f32(float* pDst, const float* pSrc, ma_uint64 frameCount, ma_uint32 channels, float volume)
|
static ma_result ma_mix_pcm_frames_f32(float* pDst, const float* pSrc, ma_uint64 frameCount, ma_uint32 channels, float volume)
|
||||||
{
|
{
|
||||||
@@ -3103,26 +2961,6 @@ static ma_result ma_mix_pcm_frames_f32(float* pDst, const float* pSrc, ma_uint64
|
|||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static ma_result ma_mix_pcm_frames(void* pDst, const void* pSrc, ma_uint64 frameCount, ma_format format, ma_uint32 channels, float volume)
|
|
||||||
{
|
|
||||||
ma_result result;
|
|
||||||
|
|
||||||
switch (format)
|
|
||||||
{
|
|
||||||
case ma_format_u8: result = ma_mix_pcm_frames_u8( (ma_int16*)pDst, (const ma_uint8*)pSrc, frameCount, channels, volume); break;
|
|
||||||
case ma_format_s16: result = ma_mix_pcm_frames_s16((ma_int32*)pDst, (const ma_int16*)pSrc, frameCount, channels, volume); break;
|
|
||||||
case ma_format_s24: result = ma_mix_pcm_frames_s24((ma_int64*)pDst, (const ma_uint8*)pSrc, frameCount, channels, volume); break;
|
|
||||||
case ma_format_s32: result = ma_mix_pcm_frames_s32((ma_int64*)pDst, (const ma_int32*)pSrc, frameCount, channels, volume); break;
|
|
||||||
case ma_format_f32: result = ma_mix_pcm_frames_f32(( float*)pDst, (const float*)pSrc, frameCount, channels, volume); break;
|
|
||||||
default: return MA_INVALID_ARGS; /* Unknown format. */
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MA_API ma_node_graph_config ma_node_graph_config_init(ma_uint32 channels)
|
MA_API ma_node_graph_config ma_node_graph_config_init(ma_uint32 channels)
|
||||||
{
|
{
|
||||||
@@ -5041,73 +4879,6 @@ static ma_uint32 ma_ffs_32(ma_uint32 x)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
static void ma_accumulate_and_clip_u8(ma_uint8* pDst, const ma_int16* 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_u8(ma_pcm_sample_u8_to_s16_no_scale(pDst[iSample]) + pSrc[iSample]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_accumulate_and_clip_s16(ma_int16* pDst, const ma_int32* 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_s16(pDst[iSample] + pSrc[iSample]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_accumulate_and_clip_s24(ma_uint8* pDst, const ma_int64* pSrc, ma_uint64 count)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < count; iSample += 1) {
|
|
||||||
ma_int64 s = ma_clip_s24(ma_pcm_sample_s24_to_s32_no_scale(&pDst[iSample*3]) + pSrc[iSample]);
|
|
||||||
pDst[iSample*3 + 0] = (ma_uint8)((s & 0x000000FF) >> 0);
|
|
||||||
pDst[iSample*3 + 1] = (ma_uint8)((s & 0x0000FF00) >> 8);
|
|
||||||
pDst[iSample*3 + 2] = (ma_uint8)((s & 0x00FF0000) >> 16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_accumulate_and_clip_s32(ma_int32* pDst, const ma_int64* 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_s32(pDst[iSample] + pSrc[iSample]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_accumulate_and_clip_f32(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(pDst[iSample] + pSrc[iSample]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static void ma_clip_samples_u8(ma_uint8* pDst, const ma_int16* pSrc, ma_uint64 count)
|
static void ma_clip_samples_u8(ma_uint8* pDst, const ma_int16* pSrc, ma_uint64 count)
|
||||||
{
|
{
|
||||||
ma_uint64 iSample;
|
ma_uint64 iSample;
|
||||||
@@ -5289,437 +5060,6 @@ static void ma_volume_and_clip_pcm_frames(void* pDst, const void* pSrc, ma_uint6
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Not used at the moment, but leaving it here in case I want to use it again later. */
|
|
||||||
#if 0
|
|
||||||
static void ma_clipped_accumulate_u8(ma_uint8* pDst, const ma_uint8* pSrc, ma_uint64 sampleCount)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] = ma_clip_u8(ma_pcm_sample_u8_to_s16_no_scale(pDst[iSample]) + ma_pcm_sample_u8_to_s16_no_scale(pSrc[iSample]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_clipped_accumulate_s16(ma_int16* pDst, const ma_int16* pSrc, ma_uint64 sampleCount)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] = ma_clip_s16((ma_int32)pDst[iSample] + (ma_int32)pSrc[iSample]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_clipped_accumulate_s24(ma_uint8* pDst, const ma_uint8* pSrc, ma_uint64 sampleCount)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
ma_int64 s = ma_clip_s24(ma_pcm_sample_s24_to_s32_no_scale(&pDst[iSample*3]) + ma_pcm_sample_s24_to_s32_no_scale(&pSrc[iSample*3]));
|
|
||||||
pDst[iSample*3 + 0] = (ma_uint8)((s & 0x000000FF) >> 0);
|
|
||||||
pDst[iSample*3 + 1] = (ma_uint8)((s & 0x0000FF00) >> 8);
|
|
||||||
pDst[iSample*3 + 2] = (ma_uint8)((s & 0x00FF0000) >> 16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_clipped_accumulate_s32(ma_int32* pDst, const ma_int32* pSrc, ma_uint64 sampleCount)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] = ma_clip_s32((ma_int64)pDst[iSample] + (ma_int64)pSrc[iSample]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_clipped_accumulate_f32(float* pDst, const float* pSrc, ma_uint64 sampleCount)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] = ma_clip_f32(pDst[iSample] + pSrc[iSample]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_clipped_accumulate_pcm_frames(void* pDst, const void* pSrc, ma_uint64 frameCount, ma_format format, ma_uint32 channels)
|
|
||||||
{
|
|
||||||
ma_uint64 sampleCount;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
sampleCount = frameCount * channels;
|
|
||||||
|
|
||||||
switch (format) {
|
|
||||||
case ma_format_u8: ma_clipped_accumulate_u8( (ma_uint8*)pDst, (const ma_uint8*)pSrc, sampleCount); break;
|
|
||||||
case ma_format_s16: ma_clipped_accumulate_s16((ma_int16*)pDst, (const ma_int16*)pSrc, sampleCount); break;
|
|
||||||
case ma_format_s24: ma_clipped_accumulate_s24((ma_uint8*)pDst, (const ma_uint8*)pSrc, sampleCount); break;
|
|
||||||
case ma_format_s32: ma_clipped_accumulate_s32((ma_int32*)pDst, (const ma_int32*)pSrc, sampleCount); break;
|
|
||||||
case ma_format_f32: ma_clipped_accumulate_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. */
|
|
||||||
case ma_format_unknown:
|
|
||||||
case ma_format_count:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Not used right now, but leaving here for reference. */
|
|
||||||
#if 0
|
|
||||||
static void ma_unclipped_accumulate_u8(ma_int16* pDst, const ma_uint8* pSrc, ma_uint64 sampleCount)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] = pDst[iSample] + ma_pcm_sample_u8_to_s16_no_scale(pSrc[iSample]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_unclipped_accumulate_s16(ma_int32* pDst, const ma_int16* pSrc, ma_uint64 sampleCount)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] = (ma_int32)pDst[iSample] + (ma_int32)pSrc[iSample];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_unclipped_accumulate_s24(ma_int64* pDst, const ma_uint8* pSrc, ma_uint64 sampleCount)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] = pDst[iSample] + ma_pcm_sample_s24_to_s32_no_scale(&pSrc[iSample*3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_unclipped_accumulate_s32(ma_int64* pDst, const ma_int32* pSrc, ma_uint64 sampleCount)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] = (ma_int64)pDst[iSample] + (ma_int64)pSrc[iSample];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_unclipped_accumulate_f32(float* pDst, const float* pSrc, ma_uint64 sampleCount)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] = pDst[iSample] + pSrc[iSample];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_unclipped_accumulate_pcm_frames(void* pDst, const void* pSrc, ma_uint64 frameCount, ma_format format, ma_uint32 channels)
|
|
||||||
{
|
|
||||||
ma_uint64 sampleCount;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
sampleCount = frameCount * channels;
|
|
||||||
|
|
||||||
switch (format) {
|
|
||||||
case ma_format_u8: ma_unclipped_accumulate_u8( (ma_int16*)pDst, (const ma_uint8*)pSrc, sampleCount); break;
|
|
||||||
case ma_format_s16: ma_unclipped_accumulate_s16((ma_int32*)pDst, (const ma_int16*)pSrc, sampleCount); break;
|
|
||||||
case ma_format_s24: ma_unclipped_accumulate_s24((ma_int64*)pDst, (const ma_uint8*)pSrc, sampleCount); break;
|
|
||||||
case ma_format_s32: ma_unclipped_accumulate_s32((ma_int64*)pDst, (const ma_int32*)pSrc, sampleCount); break;
|
|
||||||
case ma_format_f32: ma_unclipped_accumulate_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. */
|
|
||||||
case ma_format_unknown:
|
|
||||||
case ma_format_count:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Not used right now, but leaving here for reference. */
|
|
||||||
#if 0
|
|
||||||
static void ma_volume_and_accumulate_and_clip_u8(ma_uint8* pDst, const ma_int16* pSrc, ma_uint64 count, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_int16 volumeFixed;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < count; iSample += 1) {
|
|
||||||
pDst[iSample] = ma_clip_u8(ma_pcm_sample_u8_to_s16_no_scale(pDst[iSample]) + ma_apply_volume_unclipped_u8(pSrc[iSample], volumeFixed));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_volume_and_accumulate_and_clip_s16(ma_int16* pDst, const ma_int32* pSrc, ma_uint64 count, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_int16 volumeFixed;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < count; iSample += 1) {
|
|
||||||
pDst[iSample] = ma_clip_s16(pDst[iSample] + ma_apply_volume_unclipped_s16(pSrc[iSample], volumeFixed));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_volume_and_accumulate_and_clip_s24(ma_uint8* pDst, const ma_int64* pSrc, ma_uint64 count, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_int16 volumeFixed;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < count; iSample += 1) {
|
|
||||||
ma_int64 s = ma_clip_s24(ma_pcm_sample_s24_to_s32_no_scale(&pDst[iSample*3]) + ma_apply_volume_unclipped_s24(pSrc[iSample], volumeFixed));
|
|
||||||
pDst[iSample*3 + 0] = (ma_uint8)((s & 0x000000FF) >> 0);
|
|
||||||
pDst[iSample*3 + 1] = (ma_uint8)((s & 0x0000FF00) >> 8);
|
|
||||||
pDst[iSample*3 + 2] = (ma_uint8)((s & 0x00FF0000) >> 16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_volume_and_accumulate_and_clip_s32(ma_int32* dst, const ma_int64* src, ma_uint64 count, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_int16 volumeFixed;
|
|
||||||
|
|
||||||
MA_ASSERT(dst != NULL);
|
|
||||||
MA_ASSERT(src != NULL);
|
|
||||||
|
|
||||||
volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < count; iSample += 1) {
|
|
||||||
dst[iSample] = ma_clip_s32(dst[iSample] + ma_apply_volume_unclipped_s32(src[iSample], volumeFixed));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_volume_and_accumulate_and_clip_f32(float* pDst, const float* pSrc, ma_uint64 count, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < count; iSample += 1) {
|
|
||||||
pDst[iSample] = ma_clip_f32(pDst[iSample] + ma_apply_volume_unclipped_f32(pSrc[iSample], volume));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static ma_result ma_volume_and_accumulate_and_clip_pcm_frames(void* pDst, const void* pSrc, ma_uint64 frameCount, ma_format format, ma_uint32 channels, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 sampleCount;
|
|
||||||
|
|
||||||
if (pDst == NULL || pSrc == NULL) {
|
|
||||||
return MA_INVALID_ARGS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The output buffer cannot be the same as the accumulation buffer. */
|
|
||||||
if (pDst == pSrc) {
|
|
||||||
return MA_INVALID_OPERATION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* No-op if there's no volume. */
|
|
||||||
if (volume == 0) {
|
|
||||||
return MA_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
sampleCount = frameCount * channels;
|
|
||||||
|
|
||||||
/* No need for volume control if the volume is 1. */
|
|
||||||
if (volume == 1) {
|
|
||||||
switch (format) {
|
|
||||||
case ma_format_u8: ma_accumulate_and_clip_u8( pDst, pSrc, sampleCount); break;
|
|
||||||
case ma_format_s16: ma_accumulate_and_clip_s16(pDst, pSrc, sampleCount); break;
|
|
||||||
case ma_format_s24: ma_accumulate_and_clip_s24(pDst, pSrc, sampleCount); break;
|
|
||||||
case ma_format_s32: ma_accumulate_and_clip_s32(pDst, pSrc, sampleCount); break;
|
|
||||||
case ma_format_f32: ma_accumulate_and_clip_f32(pDst, pSrc, sampleCount); break;
|
|
||||||
default: return MA_INVALID_ARGS; /* Unknown format. */
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Getting here means the volume is not 0 nor 1. */
|
|
||||||
MA_ASSERT(volume != 0 && volume != 1);
|
|
||||||
|
|
||||||
switch (format) {
|
|
||||||
case ma_format_u8: ma_volume_and_accumulate_and_clip_u8( pDst, pSrc, sampleCount, volume); break;
|
|
||||||
case ma_format_s16: ma_volume_and_accumulate_and_clip_s16(pDst, pSrc, sampleCount, volume); break;
|
|
||||||
case ma_format_s24: ma_volume_and_accumulate_and_clip_s24(pDst, pSrc, sampleCount, volume); break;
|
|
||||||
case ma_format_s32: ma_volume_and_accumulate_and_clip_s32(pDst, pSrc, sampleCount, volume); break;
|
|
||||||
case ma_format_f32: ma_volume_and_accumulate_and_clip_f32(pDst, pSrc, sampleCount, volume); break;
|
|
||||||
default: return MA_INVALID_ARGS; /* Unknown format. */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return MA_SUCCESS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Not used right now, but leaving here for reference. */
|
|
||||||
#if 0
|
|
||||||
static void ma_mix_accumulation_buffers_u8(ma_int16* pDst, const ma_int16* pSrc, ma_uint64 sampleCount, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_int16 volumeFixed;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += ma_apply_volume_unclipped_u8(pSrc[iSample], volumeFixed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_mix_accumulation_buffers_s16(ma_int32* pDst, const ma_int32* pSrc, ma_uint64 sampleCount, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_int16 volumeFixed;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += ma_apply_volume_unclipped_s16(pSrc[iSample], volumeFixed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_mix_accumulation_buffers_s24(ma_int64* pDst, const ma_int64* pSrc, ma_uint64 sampleCount, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_int16 volumeFixed;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += ma_apply_volume_unclipped_s24(pSrc[iSample], volumeFixed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_mix_accumulation_buffers_s32(ma_int64* pDst, const ma_int64* pSrc, ma_uint64 sampleCount, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
ma_int16 volumeFixed;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
volumeFixed = ma_float_to_fixed_16(volume);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += ma_apply_volume_unclipped_s32(pSrc[iSample], volumeFixed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_mix_accumulation_buffers_f32(float* pDst, const float* pSrc, ma_uint64 sampleCount, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 iSample;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
for (iSample = 0; iSample < sampleCount; iSample += 1) {
|
|
||||||
pDst[iSample] += ma_apply_volume_unclipped_f32(pSrc[iSample], volume);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_mix_accumulation_buffers(void* pDst, const void* pSrc, ma_uint64 frameCount, ma_format formatIn, ma_uint32 channelsIn, float volume)
|
|
||||||
{
|
|
||||||
ma_uint64 sampleCount;
|
|
||||||
|
|
||||||
MA_ASSERT(pDst != NULL);
|
|
||||||
MA_ASSERT(pSrc != NULL);
|
|
||||||
|
|
||||||
sampleCount = frameCount * channelsIn;
|
|
||||||
|
|
||||||
switch (formatIn)
|
|
||||||
{
|
|
||||||
case ma_format_u8: ma_mix_accumulation_buffers_u8( (ma_int16*)pDst, (const ma_int16*)pSrc, sampleCount, volume); break;
|
|
||||||
case ma_format_s16: ma_mix_accumulation_buffers_s16((ma_int32*)pDst, (const ma_int32*)pSrc, sampleCount, volume); break;
|
|
||||||
case ma_format_s24: ma_mix_accumulation_buffers_s24((ma_int64*)pDst, (const ma_int64*)pSrc, sampleCount, volume); break;
|
|
||||||
case ma_format_s32: ma_mix_accumulation_buffers_s32((ma_int64*)pDst, (const ma_int64*)pSrc, sampleCount, volume); break;
|
|
||||||
case ma_format_f32: ma_mix_accumulation_buffers_f32(( float*)pDst, (const float*)pSrc, sampleCount, volume); break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ma_mix_accumulation_buffers_ex(void* pDst, ma_format formatOut, ma_uint32 channelsOut, const void* pSrc, ma_format formatIn, ma_uint32 channelsIn, ma_uint64 frameCount, float volume)
|
|
||||||
{
|
|
||||||
if (formatOut == formatIn && channelsOut == channelsIn) {
|
|
||||||
/* Fast path. No conversion required. */
|
|
||||||
ma_mix_accumulation_buffers(pDst, pSrc, frameCount, formatIn, channelsIn, volume);
|
|
||||||
} else {
|
|
||||||
/* Slow path. Conversion required. The way we're going to do this is clip the input buffer, and then use existing mixing infrastructure to mix as if it were regular input. */
|
|
||||||
ma_uint8 clippedSrcBuffer[MA_DATA_CONVERTER_STACK_BUFFER_SIZE]; /* formatIn, channelsIn */
|
|
||||||
ma_uint32 clippedSrcBufferCapInFrames = sizeof(clippedSrcBuffer) / ma_get_bytes_per_frame(formatIn, channelsIn);
|
|
||||||
ma_uint64 totalFramesProcessed = 0;
|
|
||||||
/* */ void* pRunningDst = pDst;
|
|
||||||
const void* pRunningSrc = pSrc;
|
|
||||||
|
|
||||||
while (totalFramesProcessed < frameCount) {
|
|
||||||
ma_uint64 framesToProcess = frameCount - totalFramesProcessed;
|
|
||||||
if (framesToProcess > clippedSrcBufferCapInFrames) {
|
|
||||||
framesToProcess = clippedSrcBufferCapInFrames;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Volume and clip. */
|
|
||||||
ma_volume_and_clip_pcm_frames(clippedSrcBuffer, pRunningSrc, framesToProcess, formatIn, channelsIn, volume);
|
|
||||||
|
|
||||||
/* Mix. */
|
|
||||||
ma_mix_pcm_frames_ex(pRunningDst, formatOut, channelsOut, clippedSrcBuffer, formatIn, channelsIn, framesToProcess, 1);
|
|
||||||
|
|
||||||
totalFramesProcessed += framesToProcess;
|
|
||||||
pRunningDst = ma_offset_ptr(pRunningDst, framesToProcess * ma_get_accumulation_bytes_per_frame(formatOut, channelsOut));
|
|
||||||
pRunningSrc = ma_offset_ptr(pRunningSrc, framesToProcess * ma_get_accumulation_bytes_per_frame(formatIn, channelsIn ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MA_API ma_result ma_slot_allocator_init(ma_slot_allocator* pAllocator)
|
MA_API ma_result ma_slot_allocator_init(ma_slot_allocator* pAllocator)
|
||||||
|
|||||||
Reference in New Issue
Block a user