Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/speexdsp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Tomlinson <karlt+@karlt.net>2020-08-29 03:23:29 +0300
committerRalph Giles <giles@thaumas.net>2020-10-02 19:23:27 +0300
commit9617cea1d4d41199a36c664cc268a830aa0f4ba7 (patch)
tree53895c44f43b4d213baa3d61a61f333baf40a6e6
parentdc6394e975ec00618a90a38bfd95b28b8e48405b (diff)
fixed-point: don't truncate 32-bit arg to MULT16_32_Q15
The 32-bit arg and return value have one bit more than required to represent +/-32767 with 15 fractional bits. Keeping the most significant bit allows saturation for 16-bit conversion to sometimes be delayed until after these operations.
-rw-r--r--libspeexdsp/fixed_debug.h4
-rw-r--r--libspeexdsp/fixed_generic.h6
2 files changed, 5 insertions, 5 deletions
diff --git a/libspeexdsp/fixed_debug.h b/libspeexdsp/fixed_debug.h
index 8b2f2ef..25d4ea7 100644
--- a/libspeexdsp/fixed_debug.h
+++ b/libspeexdsp/fixed_debug.h
@@ -279,7 +279,7 @@ static inline int _MULT16_32_QX(int a, long long b, int Q, char *file, int line)
{
fprintf (stderr, "MULT16_32_Q%d: inputs are not short+int: %d %d in %s: line %d\n", Q, (int)a, (int)b, file, line);
}
- if (ABS32(b)>=(EXTEND32(1)<<(15+Q)))
+ if (ABS(b)>>(16+Q))
fprintf (stderr, "MULT16_32_Q%d: second operand too large: %d %d in %s: line %d\n", Q, (int)a, (int)b, file, line);
res = (((long long)a)*(long long)b) >> Q;
if (!VERIFY_INT(res))
@@ -295,7 +295,7 @@ static inline int MULT16_32_PX(int a, long long b, int Q)
{
fprintf (stderr, "MULT16_32_P%d: inputs are not short+int: %d %d\n", Q, (int)a, (int)b);
}
- if (ABS32(b)>=(EXTEND32(1)<<(15+Q)))
+ if (ABS(b)>>(16+Q))
fprintf (stderr, "MULT16_32_Q%d: second operand too large: %d %d\n", Q, (int)a, (int)b);
res = ((((long long)a)*(long long)b) + ((EXTEND32(1)<<Q)>>1))>> Q;
if (!VERIFY_INT(res))
diff --git a/libspeexdsp/fixed_generic.h b/libspeexdsp/fixed_generic.h
index 64f65be..e5d1ce5 100644
--- a/libspeexdsp/fixed_generic.h
+++ b/libspeexdsp/fixed_generic.h
@@ -76,9 +76,9 @@
#define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b))))
-#define MULT16_32_P15(a,b) ADD32(MULT16_16((a),SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15))
-#define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
-#define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
+#define MULT16_32_P15(a,b) ADD32((a)*SHR((b),15), PSHR(MULT16_16((a),((b)&0x00007fff)),15))
+#define MULT16_32_Q15(a,b) ADD32((a)*SHR((b),15), SHR(MULT16_16((a),((b)&0x00007fff)),15))
+#define MAC16_32_Q15(c,a,b) ADD32(c,ADD32((a)*SHR((b),15), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
#define MAC16_16_Q11(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),11)))