]> git.parisson.com Git - timeside-diadems.git/commitdiff
Level analyzer : fix Inf issue
authorThomas Fillon <thomas@parisson.com>
Wed, 19 Mar 2014 16:55:57 +0000 (17:55 +0100)
committerThomas Fillon <thomas@parisson.com>
Wed, 19 Mar 2014 16:55:57 +0000 (17:55 +0100)
timeside/analyzer/utils.py

index 6299a9c7b586fb3685c3bdfe1771a262a037fc96..6b033068ce7fa2d5a5f885dd3a70bdb1310e0e85 100644 (file)
@@ -21,6 +21,8 @@
 
 import numpy as np
 
+MACHINE_EPSILON = np.finfo(np.float32).eps
+
 def downsample_blocking(frames, hop_s, dtype='float32'):
     # downmixing to one channel
     if len(frames.shape) != 1:
@@ -53,15 +55,12 @@ def computeModulation(serie, wLen, withLog=True):
         modul = np.zeros((sLen,))
         w = int(wLen/2)
 
-        if withLog:
-            machine_epsilon = np.finfo(np.float32).eps
-
         for i in range(w, sLen-w):
 
             d = serie[i-w:i+w]
             if withLog:
                 if not (d > 0).all():
-                    d[d <= 0] = machine_epsilon  # prevent log(0)=inf
+                    d[d <= 0] = MACHINE_EPSILON  # prevent log(0)=inf
                 d = np.log(d)
 
             modul[i] = np.var(d)