def mapper(self, _, line): """ The mapper loads a track and yields its ramp factor """ t = track.load_track(line) segments = t['segments'] duration = t['duration'] xdata = [] ydata = [] for i in xrange(len(segments)): seg = segments[i] sloudness = seg['loudness_max'] sstart = seg['start'] + seg['loudness_max_time'] xdata.append( sstart ) ydata.append( sloudness ) if duration > 20: idata = tools.interpolate(xdata, ydata, int(duration) * 10) smooth = tools.smooth(idata, 20) samp = tools.sample(smooth, self.SIZE) ndata = tools.rnormalize(samp, -60, 0) if self.DUMP: for i, (x, y) in enumerate(zip(self.MATCH, ndata)): print i, x, y if self.VECTOR: yield (t['artist_name'], t['title'], t['track_id']), ndata else: distance = tools.distance(self.MATCH, ndata) yield (t['artist_name'], t['title'], t['track_id']), distance
def mapper(self, _, line): """ The mapper loads a track and yields its ramp factor """ t = track.load_track(line) segments = t['segments'] duration = t['duration'] xdata = [] ydata = [] for i in xrange(len(segments)): seg = segments[i] sloudness = seg['loudness_max'] sstart = seg['start'] + seg['loudness_max_time'] xdata.append(sstart) ydata.append(sloudness) if duration > 20: idata = tools.interpolate(xdata, ydata, int(duration) * 10) smooth = tools.smooth(idata, 20) samp = tools.sample(smooth, self.SIZE) ndata = tools.rnormalize(samp, -60, 0) if self.DUMP: for i, (x, y) in enumerate(zip(self.MATCH, ndata)): print i, x, y if self.VECTOR: yield (t['artist_name'], t['title'], t['track_id']), ndata else: distance = tools.distance(self.MATCH, ndata) yield (t['artist_name'], t['title'], t['track_id']), distance
def dump(): data = tools.rnormalize(tools.scale(tools.sin2wave(256), 60, -60), -60, 0) for d in data: print d