Package lib :: Module cached_misc
[frames] | no frames]

Source Code for Module lib.cached_misc

 1  """This code is a collection of functions that compute acoustic properties 
 2  and cache them. 
 3  """ 
 4   
 5  import numpy 
 6   
 7  from gmisclib import cache as CC 
 8  from gmisclib import gpkmisc 
 9  from gpk_voicing import emphasis as E 
10  from gpk_voicing import dirty_io 
11  import gpkimgclass 
12   
13  ROOT = '/tmp/cached_loudness' 
14   
15 -def emphasis(data, DT, cache_info=None):
16 """Compute loudness density ('emphasis') from a numpy array. Cache the result. 17 """ 18 ci = None 19 if cache_info is not None: 20 assert isinstance(cache_info, CC.cache_info) 21 ci = cache_info.addinfo(DT, data.get('_NAME', '?'), 'emphasis', mod=E) 22 try: 23 return ci.load() 24 except ci.Errors: 25 pass 26 e = E.simple_emphasis(data.column(0), data.dt(), DT) 27 if ci is not None: 28 ci.dump(e) 29 return e
30 31
32 -def emphasis_f_name(fname, DT, root=ROOT):
33 """Compute loudness density ('emphasis') from a file. Cache the result. 34 """ 35 nm, ch = dirty_io.split_name(fname) 36 cacheinfo = CC.cache_info(root=root, fname=nm, info=(DT, ch, 'emphasis_f_name'), mod=(E,dirty_io)) 37 try: 38 return cacheinfo.load() 39 except cacheinfo.Errors: 40 pass 41 data = dirty_io.wav_read(nm, channel=ch) 42 e = E.simple_emphasis(data.column(0), data.dt(), DT) 43 hdr = data.hdr.copy() 44 hdr['CDELT2'] = DT 45 del hdr['NAXIS2'] 46 return cacheinfo.dump(gpkimgclass.gpk_img(hdr, numpy.transpose([e])))
47 48
49 -def sb_loudness_f_name(fname, DT, root=ROOT):
50 """Compute loudness density ('emphasis') from a file. Cache the result. 51 """ 52 nm, ch = dirty_io.split_name(fname) 53 cacheinfo = CC.cache_info(root=root, fname=nm, info=(DT, ch, 'sb_loudness_f_name'), mod=(E,dirty_io)) 54 try: 55 return cacheinfo.load() 56 except cacheinfo.Errors: 57 pass 58 data = dirty_io.wav_read(fname, channel=ch) 59 e = E.speechband_loudness(data.column(0), data.dt(), DT) 60 hdr = data.hdr.copy() 61 hdr['CDELT2'] = DT 62 del hdr['NAXIS2'] 63 return cacheinfo.dump(gpkimgclass.gpk_img(hdr, numpy.transpose([e])))
64