def song_attributes(filename, verbose=True, db=None): if db is None: db = DB_Helper() if db.is_in_db(filename): return msys.updControl('mrs_string/filename', filename) if not get_control(msys, 'bool', 'hasData'): raise RuntimeError( 'It looks like Marsyas was unable to load your file! ' 'Make sure you have the right codec support enabled.') # The StereoPanningSpectrumFeatures will only work # correctly with two channels. if get_control(msys, 'natural', 'channels') == 2: chan_control = 'enableChild' else: chan_control = 'disableChild' msys.updControl('Fanout/timbrepanning/mrs_string/' + chan_control, 'StereoPanningSpectrumFeatures/SPSFeatures') observations = get_control(msys, 'natural', 'onObservations') sum_vals = [0] * observations sum_of_squares = [0] * observations count = 0 while get_control(msys, 'bool', 'hasData'): msys.tick() vals = get_control(msys, 'realvec', 'processedData') sum_vals = [old + new for old, new in izip(sum_vals, vals)] sum_of_squares = [ old + new**2 for old, new in izip(sum_of_squares, vals) ] count += 1 reset_msys(msys) out = {field.name: None for field in attribute_schema} for i, attr in enumerate(obs_names(msys)): avg = sum_vals[i] / count squares_avg = sum_of_squares[i] / count out['mean_' + attr] = avg out['stdev_' + attr] = math.sqrt(squares_avg - avg**2) out[commonPath] = filename out[commonArtist] = None out[commonTitle] = None db.add_song(out)
def song_attributes(songpath, verbose = True, db = None): if db is None: db = DB_Helper() if not db.is_in_db(songpath): fp = open(songpath, 'rb') if verbose: print "Harvesting: " + songpath get_attr(fp, songpath, db)
def song_attributes(songpath, verbose=True, db=None): if db is None: db = DB_Helper() if not db.is_in_db(songpath): fp = open(songpath, 'rb') if verbose: print "Harvesting: " + songpath get_attr(fp, songpath, db)
def song_attributes(filename, verbose=True, db=None): if db is None: db = DB_Helper() if db.is_in_db(filename): return msys.updControl('mrs_string/filename', filename) if not get_control(msys, 'bool', 'hasData'): raise RuntimeError('It looks like Marsyas was unable to load your file! ' 'Make sure you have the right codec support enabled.') # The StereoPanningSpectrumFeatures will only work # correctly with two channels. if get_control(msys, 'natural', 'channels') == 2: chan_control = 'enableChild' else: chan_control = 'disableChild' msys.updControl('Fanout/timbrepanning/mrs_string/' + chan_control, 'StereoPanningSpectrumFeatures/SPSFeatures') observations = get_control(msys, 'natural', 'onObservations') sum_vals = [0] * observations sum_of_squares = [0] * observations count = 0 while get_control(msys, 'bool', 'hasData'): msys.tick() vals = get_control(msys, 'realvec', 'processedData') sum_vals = [old + new for old, new in izip(sum_vals, vals)] sum_of_squares = [old + new**2 for old, new in izip(sum_of_squares, vals)] count += 1 reset_msys(msys) out = {field.name: None for field in attribute_schema} for i, attr in enumerate(obs_names(msys)): avg = sum_vals[i] / count squares_avg = sum_of_squares[i] / count out['mean_' + attr] = avg out['stdev_' + attr] = math.sqrt(squares_avg - avg**2) out[commonPath] = filename out[commonArtist] = None out[commonTitle] = None db.add_song(out)