Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -32,21 +32,16 @@ while True: · 31 unmodified lines | |||
| 32 | samples, read = s() | 32 | samples, read = s() |
| 33 | is_beat = o(samples) | 33 | is_beat = o(samples) |
| 34 | if is_beat: | 34 | if is_beat: |
| 35 | this_beat = int(total_frames - delay + is_beat[0] * hop_s) | 35 | this_beat = o.get_last_s() |
| 36 | #print "%f" % (this_beat / float(samplerate)) | ||
| 37 | beats.append(this_beat) | 36 | beats.append(this_beat) |
| 38 | total_frames += read | 37 | total_frames += read |
| 39 | if read < hop_s: break | 38 | if read < hop_s: break |
| 40 | 39 | ||
| 41 | #convert samples to seconds | 40 | if len(beats) > 1: |
| 42 | beats = map( lambda x: x / float(samplerate), beats) | ||
| 43 | |||
| 44 | bpms = [60./(b - a) for a,b in zip(beats[:-1],beats[1:])] | ||
| 45 | |||
| 46 | if len(bpms): | ||
| 47 | # do plotting | 41 | # do plotting |
| 48 | from numpy import array, arange, mean, median | 42 | from numpy import array, arange, mean, median, diff |
| 49 | import matplotlib.pyplot as plt | 43 | import matplotlib.pyplot as plt |
| 44 | bpms = 60./ diff(beats) | ||
| 50 | print 'mean period:', "%.2f" % mean(bpms), 'bpm', 'median', "%.2f" % median(bpms), 'bpm' | 45 | print 'mean period:', "%.2f" % mean(bpms), 'bpm', 'median', "%.2f" % median(bpms), 'bpm' |
| 51 | print 'plotting', filename | 46 | print 'plotting', filename |
| 52 | plt1 = plt.axes([0.1, 0.75, 0.8, 0.19]) | 47 | plt1 = plt.axes([0.1, 0.75, 0.8, 0.19]) |
| @@ -80,5 +75,5 @@ if len(bpms): · 27 unmodified lines | |||
| 80 | plt.show() | 75 | plt.show() |
| 81 | 76 | ||
| 82 | else: | 77 | else: |
| 83 | print 'mean period:', "%.2f" % 0, 'bpm', 'median', "%.2f" % 0, 'bpm', | 78 | print 'mean period:', "%.2f" % 0, 'bpm', 'median', "%.2f" % 0, 'bpm', |
| 84 | print 'nothing to plot, file too short?' | 79 | print 'nothing to plot, file too short?' |