Re: [linux-audio-dev] tempo estimator! (lispy version)

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] tempo estimator! (lispy version)
From: est_AT_hyperreal.org
Date: la joulu  11 1999 - 10:52:05 EST


I genericized getting the times (for use with different interfaces) as
follows:

def get_times(waiter, protector=None):
    times = []
    try:
        while waiter():
            when = time.time()
            times.append(when)
            print when
    finally:
        when = time.time()
        times.append(when)
        if protector: protector()
        return times

def grabchar():
    c = os.read(fd, 1)
    return c != 'q'

def reset_term():
    termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old)

times = get_times(grabchar, reset_term)

..and the estimate computation became:

# compute sum-of-differences
sod = reduce(lambda x, y: x + y,
             map(lambda x, y: x - y, times[1:], times[:-1]))

estimate = 60.0 / (sod / (len(times) - 1))

Some might say that's less clear..but I say map() and reduce() are
always worth the learning curve. :D

E


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : pe maalis 10 2000 - 07:23:26 EST