summaryrefslogtreecommitdiffstats
path: root/src/volscale.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/volscale.c')
-rw-r--r--src/volscale.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/volscale.c b/src/volscale.c
index 2075b90..f29cb0e 100644
--- a/src/volscale.c
+++ b/src/volscale.c
@@ -1,3 +1,7 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <liboil/liboil.h>
#include "macro.h"
@@ -6,11 +10,12 @@
static void volscale_u8(void *_dst, size_t dstr, const void *_src, size_t sstr, int32_t factor, int32_t divisor, size_t bytes) {
uint8_t *dst = _dst;
const uint8_t *src = _src;
-
+
for (; bytes > 0; bytes --) {
int32_t t = (((int32_t) *src - 0x80) * factor) / divisor;
- *dst = t < -0x80 ? 0 : (t > 0x7F ? 0xFF : (int8_t) (t+0x80));
-
+ t = CLAMP(t, -0x80, 0x7F);
+ *dst = (int8_t) (t+0x80);
+
src += sstr;
dst += dstr;
}
@@ -20,11 +25,12 @@ static void volscale_s16(void *_dst, size_t dstr, const void *_src, size_t sstr,
int16_t *dst = _dst;
const int16_t *src = _src;
unsigned n = bytes / sizeof(int16_t);
-
+
for (; n > 0; n--) {
int32_t t = ((int32_t) *src * factor) / divisor;
- *dst = t < -0x8000 ? 0x8000 : (t > 0x7FFF ? 0x7FFF : (int16_t) t);
-
+ t = CLAMP(t, -0x8000, 0x7FFF);
+ *dst = (int16_t) t;
+
src += sstr / sizeof(int16_t);
dst += dstr / sizeof(int16_t);
}
@@ -34,11 +40,12 @@ static void volscale_s32(void *_dst, size_t dstr, const void *_src, size_t sstr,
int32_t *dst = _dst;
const int32_t *src = _src;
unsigned n = bytes / sizeof(int32_t);
-
+
for (; n > 0; n--) {
int64_t t = ((int64_t) *src * factor) / divisor;
- *dst = t < -0x80000000L ? (int32_t) 0x80000000L : (t > 0x7fffffffL ? (int32_t) 0x7fffffffL : (int32_t) t);
-
+ t = CLAMP(t, -0x80000000L, 0x7FFFFFFFL);
+ *dst = (int32_t) t;
+
src += sstr / sizeof(int32_t);
dst += dstr / sizeof(int32_t);
}
@@ -48,12 +55,12 @@ static void volscale_f32(void *_dst, size_t dstr, const void *_src, size_t sstr,
float *dst = _dst;
const float *src = _src;
float f = (float) factor / (float) divisor;
-
+
oil_scalarmult_f32(dst, dstr, src, sstr, &f, size / sizeof(float));
}
sa_volscale_func_t sa_get_volscale_func(sa_pcm_format_t f) {
-
+
static const sa_volscale_func_t funcs[_SA_PCM_FORMAT_MAX] = {
[SA_PCM_FORMAT_U8] = volscale_u8,
[SA_PCM_FORMAT_S16_NE] = volscale_s16,