view light8/util.py @ 326:a3267d8c498e

leave in a comment about how to offset the audio time in case your sound card is lying we didn't eventually need this because we found a good-sounding card that could report offset correctly. But if you're stuck with a card that reports offset incorrectly, you can play with this offset for a partial workaround. note that song intros will probably still be corrupted (but you could workaround that by prepending some silence)
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 18 Jun 2006 22:01:41 +0000
parents 71489bb71528
children
line wrap: on
line source

def maxes(dicts):
    '''
    ({'a' : 5, 'b' : 9}, {'a' : 10, 'b' : 943})
    '''
    newdict = {}
    for d in dicts:
        for k,v in d.items():
            newdict[k] = max(v, newdict.get(k, 0))
    return newdict

def scaledict(d,scl):
    # scales all values in dict and returns a new dict
    return dict([(k,v*scl) for k,v in d.items()])
    
# class Setting that scales, maxes        

def subsetdict(d, dkeys, default=0):
    """Subset of dictionary d: only the keys in dkeys.  If you plan on omitting
    keys, make sure you like the default."""
    newd = {} # dirty variables!
    for k in dkeys:
        newd[k] = d.get(k, default)
    return newd