From 0189fa2c592366be291bed3a883a0eba0a6a4868 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 10 Jul 2015 19:51:09 +0200 Subject: [PATCH] (audio_utils.c) Cleanups --- audio/audio_utils.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/audio/audio_utils.c b/audio/audio_utils.c index abd3223f87..6fb1196df4 100644 --- a/audio/audio_utils.c +++ b/audio/audio_utils.c @@ -87,9 +87,9 @@ void audio_convert_float_to_s16_C(int16_t *out, void audio_convert_s16_to_float_SSE2(float *out, const int16_t *in, size_t samples, float gain) { - float fgain = gain / UINT32_C(0x80000000); - __m128 factor = _mm_set1_ps(fgain); size_t i; + float fgain = gain / UINT32_C(0x80000000); + __m128 factor = _mm_set1_ps(fgain); for (i = 0; i + 8 <= samples; i += 8, in += 8, out += 8) { @@ -155,14 +155,15 @@ void audio_convert_s16_to_float_altivec(float *out, const int16_t *in, size_t samples, float gain) { size_t samples_in = samples; - const vector float gain_vec = { gain, gain , gain, gain }; - const vector float zero_vec = { 0.0f, 0.0f, 0.0f, 0.0f}; /* Unaligned loads/store is a bit expensive, so we * optimize for the good path (very likely). */ if (((uintptr_t)out & 15) + ((uintptr_t)in & 15) == 0) { size_t i; + const vector float gain_vec = { gain, gain , gain, gain }; + const vector float zero_vec = { 0.0f, 0.0f, 0.0f, 0.0f}; + for (i = 0; i + 8 <= samples; i += 8, in += 8, out += 8) { vector signed short input = vec_ld(0, in); @@ -386,7 +387,7 @@ void audio_convert_float_to_s16_ALLEGREX(int16_t *out, for (; i < samples; i++) { int32_t val = (int32_t)(in[i] * 0x8000); - out[i] = (val > 0x7FFF) ? 0x7FFF : + out[i] = (val > 0x7FFF) ? 0x7FFF : (val < -0x8000 ? -0x8000 : (int16_t)val); } }