def get_btchromas_loudness(h5): """ Similar to btchroma, but adds the loudness back. We use the segments_loudness_max There is no max value constraint, simply no negative values. """ # if string, open and get chromas, if h5, get chromas if type(h5).__name__ == 'str': h5 = GETTERS.open_h5_file_read(h5) chromas = GETTERS.get_segments_pitches(h5) segstarts = GETTERS.get_segments_start(h5) btstarts = GETTERS.get_beats_start(h5) duration = GETTERS.get_duration(h5) loudnessmax = GETTERS.get_segments_loudness_max(h5) h5.close() else: chromas = GETTERS.get_segments_pitches(h5) segstarts = GETTERS.get_segments_start(h5) btstarts = GETTERS.get_beats_start(h5) duration = GETTERS.get_duration(h5) loudnessmax = GETTERS.get_segments_loudness_max(h5) # get the series of starts for segments and beats segstarts = np.array(segstarts).flatten() btstarts = np.array(btstarts).flatten() # add back loudness chromas = chromas.T * idB(loudnessmax) # aligned features btchroma = align_feats(chromas, segstarts, btstarts, duration) if btchroma is None: return None # done (no renormalization) return btchroma
def get_btchromas(h5): """ Get beat-aligned chroma from a song file of the Million Song Dataset INPUT: h5 - filename or open h5 file RETURN: btchromas - beat-aligned chromas, one beat per column or None if something went wrong (e.g. no beats) """ # if string, open and get chromas, if h5, get chromas if type(h5).__name__ == 'str': h5 = GETTERS.open_h5_file_read(h5) chromas = GETTERS.get_segments_pitches(h5) segstarts = GETTERS.get_segments_start(h5) btstarts = GETTERS.get_beats_start(h5) duration = GETTERS.get_duration(h5) h5.close() else: chromas = GETTERS.get_segments_pitches(h5) segstarts = GETTERS.get_segments_start(h5) btstarts = GETTERS.get_beats_start(h5) duration = GETTERS.get_duration(h5) # get the series of starts for segments and beats # NOTE: MAYBE USELESS? # result for track: 'TR0002Q11C3FA8332D' # segstarts.shape = (708,) # btstarts.shape = (304,) segstarts = np.array(segstarts).flatten() btstarts = np.array(btstarts).flatten() # aligned features btchroma = align_feats(chromas.T, segstarts, btstarts, duration) if btchroma is None: return None # Renormalize. Each column max is 1. maxs = btchroma.max(axis=0) maxs[np.where(maxs == 0)] = 1. btchroma = (btchroma / maxs) # done return btchroma