ref: 800a659cc978610f164872ea214c0855e5773eb0
parent: 677182fcaad641dae4a988861713c9b8fe2f9282
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Sat Dec 29 11:13:20 EST 2018
Using log approximations
--- a/dnn/common.h
+++ b/dnn/common.h
@@ -12,6 +12,26 @@
float lpc_from_cepstrum(float *lpc, const float *cepstrum);
+#define LOG256 5.5451774445f
+static RNN_INLINE float log2_approx(float x)
+{+ int integer;
+ float frac;
+ union {+ float f;
+ int i;
+ } in;
+ in.f = x;
+ integer = (in.i>>23)-127;
+ in.i -= integer<<23;
+ frac = in.f - 1.5f;
+ frac = -0.41445418f + frac*(0.95909232f
+ + frac*(-0.33951290f + frac*0.16541097f));
+ return 1+integer+frac;
+}
+
+#define log_approx(x) (0.69315f*log2_approx(x))
+
static RNN_INLINE float ulaw2lin(float u)
{float s;
@@ -19,7 +39,7 @@
u = u - 128;
s = u >= 0 ? 1 : -1;
u = fabs(u);
- return s*scale_1*(exp(u/128.*log(256))-1);
+ return s*scale_1*(exp(u/128.*LOG256)-1);
}
static RNN_INLINE int lin2ulaw(float x)
@@ -28,7 +48,7 @@
float scale = 255.f/32768.f;
int s = x >= 0 ? 1 : -1;
x = fabs(x);
- u = (s*(128*log(1+scale*x)/log(256)));
+ u = (s*(128*log_approx(1+scale*x)/LOG256));
u = 128 + u;
if (u < 0) u = 0;
if (u > 255) u = 255;
--- a/dnn/dump_data.c
+++ b/dnn/dump_data.c
@@ -219,7 +219,7 @@
/* Excitation out. */
data[4*i+3] = e;
/* Simulate error on excitation. */
- noise = (int)floor(.5 + noise_std*.707*(log((float)rand()/RAND_MAX)-log((float)rand()/RAND_MAX)));
+ noise = (int)floor(.5 + noise_std*.707*(log_approx((float)rand()/RAND_MAX)-log_approx((float)rand()/RAND_MAX)));
e += noise;
e = IMIN(255, IMAX(0, e));
--
⑨