view multiple_f0_estimation/silvet/frames.py @ 65:029159daf3f1

Make script robust to spurious note-offs
author Chris Cannam
date Wed, 12 Aug 2015 19:15:29 +0100
parents 2b1e48b14423
children
line wrap: on
line source
#!/usr/bin/env python

import sys

if __name__ == '__main__':

    nargs = len(sys.argv)
    if nargs != 2:
        print("\nUsage: " + sys.argv[0] + " file.txt")
        exit(1)

    fname = sys.argv[1]
    
    f = open(fname, 'r')

    data = [ line.split(' ') for line in f ];
    ms = 0
    extant = {}
    ix = 0

    while ix < len(data):

        sec = ms / 1000.0

        while ix < len(data) and sec >= float(data[ix][0]):
            time, freq, vely = data[ix][:3]
            if vely == "0":
                if freq in extant:
                    del extant[freq]
            else:
                extant[freq] = vely
            ix = ix + 1

        print("\t".join([str(sec)] + list(extant.keys())))
            
        ms = ms + 10