summaryrefslogtreecommitdiffstats
path: root/apps/codecs/libspeex/math_approx.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libspeex/math_approx.h')
-rw-r--r--apps/codecs/libspeex/math_approx.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/apps/codecs/libspeex/math_approx.h b/apps/codecs/libspeex/math_approx.h
index 8421d634bb..4f61e8645a 100644
--- a/apps/codecs/libspeex/math_approx.h
+++ b/apps/codecs/libspeex/math_approx.h
@@ -45,8 +45,20 @@
#define spx_cos_norm(x) (cos((.5f*M_PI)*(x)))
#define spx_atan atan
-#endif
+/** Generate a pseudo-random number */
+static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed)
+{
+ const unsigned int jflone = 0x3f800000;
+ const unsigned int jflmsk = 0x007fffff;
+ union {int i; float f;} ran;
+ *seed = 1664525 * *seed + 1013904223;
+ ran.i = jflone | (jflmsk & *seed);
+ ran.f -= 1.5;
+ return 3.4642*std*ran.f;
+}
+
+#endif
static inline spx_int16_t spx_ilog2(spx_uint32_t x)
@@ -106,6 +118,15 @@ static inline spx_int16_t spx_ilog4(spx_uint32_t x)
#ifdef FIXED_POINT
+/** Generate a pseudo-random number */
+static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed)
+{
+ spx_word32_t res;
+ *seed = 1664525 * *seed + 1013904223;
+ res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std);
+ return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14));
+}
+
/* sqrt(x) ~= 0.22178 + 1.29227*x - 0.77070*x^2 + 0.25723*x^3 (for .25 < x < 1) */
/*#define C0 3634
#define C1 21173