summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
Diffstat (limited to 'audio')
-rw-r--r--audio/mixeng.c26
-rw-r--r--audio/mixeng_template.h22
2 files changed, 23 insertions, 25 deletions
diff --git a/audio/mixeng.c b/audio/mixeng.c
index c14b0d874c..739a500449 100644
--- a/audio/mixeng.c
+++ b/audio/mixeng.c
@@ -268,17 +268,17 @@ f_sample *mixeng_clip[2][2][2][3] = {
};
#ifdef FLOAT_MIXENG
-#define FLOAT_CONV_TO(x) (x)
-#define FLOAT_CONV_FROM(x) (x)
+#define CONV_NATURAL_FLOAT(x) (x)
+#define CLIP_NATURAL_FLOAT(x) (x)
#else
-static const float float_scale = UINT_MAX;
-#define FLOAT_CONV_TO(x) ((x) * float_scale)
+static const float float_scale = UINT_MAX / 2.f;
+#define CONV_NATURAL_FLOAT(x) ((x) * float_scale)
#ifdef RECIPROCAL
-static const float float_scale_reciprocal = 1.f / UINT_MAX;
-#define FLOAT_CONV_FROM(x) ((x) * float_scale_reciprocal)
+static const float float_scale_reciprocal = 2.f / UINT_MAX;
+#define CLIP_NATURAL_FLOAT(x) ((x) * float_scale_reciprocal)
#else
-#define FLOAT_CONV_FROM(x) ((x) / float_scale)
+#define CLIP_NATURAL_FLOAT(x) ((x) / float_scale)
#endif
#endif
@@ -288,7 +288,7 @@ static void conv_natural_float_to_mono(struct st_sample *dst, const void *src,
float *in = (float *)src;
while (samples--) {
- dst->r = dst->l = FLOAT_CONV_TO(*in++);
+ dst->r = dst->l = CONV_NATURAL_FLOAT(*in++);
dst++;
}
}
@@ -299,8 +299,8 @@ static void conv_natural_float_to_stereo(struct st_sample *dst, const void *src,
float *in = (float *)src;
while (samples--) {
- dst->l = FLOAT_CONV_TO(*in++);
- dst->r = FLOAT_CONV_TO(*in++);
+ dst->l = CONV_NATURAL_FLOAT(*in++);
+ dst->r = CONV_NATURAL_FLOAT(*in++);
dst++;
}
}
@@ -316,7 +316,7 @@ static void clip_natural_float_from_mono(void *dst, const struct st_sample *src,
float *out = (float *)dst;
while (samples--) {
- *out++ = FLOAT_CONV_FROM(src->l) + FLOAT_CONV_FROM(src->r);
+ *out++ = CLIP_NATURAL_FLOAT(src->l + src->r);
src++;
}
}
@@ -327,8 +327,8 @@ static void clip_natural_float_from_stereo(
float *out = (float *)dst;
while (samples--) {
- *out++ = FLOAT_CONV_FROM(src->l);
- *out++ = FLOAT_CONV_FROM(src->r);
+ *out++ = CLIP_NATURAL_FLOAT(src->l);
+ *out++ = CLIP_NATURAL_FLOAT(src->r);
src++;
}
}
diff --git a/audio/mixeng_template.h b/audio/mixeng_template.h
index 77cc89b9e8..bc8509e423 100644
--- a/audio/mixeng_template.h
+++ b/audio/mixeng_template.h
@@ -41,32 +41,31 @@ static inline mixeng_real glue (conv_, ET) (IN_T v)
#ifdef RECIPROCAL
#ifdef SIGNED
- return nv * (1.f / (mixeng_real) (IN_MAX - IN_MIN));
+ return nv * (2.f / ((mixeng_real)IN_MAX - IN_MIN));
#else
- return (nv - HALF) * (1.f / (mixeng_real) IN_MAX);
+ return (nv - HALF) * (2.f / (mixeng_real)IN_MAX);
#endif
#else /* !RECIPROCAL */
#ifdef SIGNED
- return nv / (mixeng_real) ((mixeng_real) IN_MAX - IN_MIN);
+ return nv / (((mixeng_real)IN_MAX - IN_MIN) / 2.f);
#else
- return (nv - HALF) / (mixeng_real) IN_MAX;
+ return (nv - HALF) / ((mixeng_real)IN_MAX / 2.f);
#endif
#endif
}
static inline IN_T glue (clip_, ET) (mixeng_real v)
{
- if (v >= 0.5) {
+ if (v >= 1.f) {
return IN_MAX;
- }
- else if (v < -0.5) {
+ } else if (v < -1.f) {
return IN_MIN;
}
#ifdef SIGNED
- return ENDIAN_CONVERT ((IN_T) (v * ((mixeng_real) IN_MAX - IN_MIN)));
+ return ENDIAN_CONVERT((IN_T)(v * (((mixeng_real)IN_MAX - IN_MIN) / 2.f)));
#else
- return ENDIAN_CONVERT ((IN_T) ((v * IN_MAX) + HALF));
+ return ENDIAN_CONVERT((IN_T)((v * ((mixeng_real)IN_MAX / 2.f)) + HALF));
#endif
}
@@ -84,10 +83,9 @@ static inline int64_t glue (conv_, ET) (IN_T v)
static inline IN_T glue (clip_, ET) (int64_t v)
{
- if (v >= 0x7f000000) {
+ if (v >= 0x7fffffffLL) {
return IN_MAX;
- }
- else if (v < -2147483648LL) {
+ } else if (v < -2147483648LL) {
return IN_MIN;
}