Changeset d47a5e19


Ignore:
Timestamp:
Dec 2, 2013, 6:21:43 PM (11 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
c911b12
Parents:
41121f5
Message:

python/demos/demo_tempo_plot.py: update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_tempo_plot.py

    r41121f5 rd47a5e19  
    3333    is_beat = o(samples)
    3434    if is_beat:
    35         this_beat = int(total_frames - delay + is_beat[0] * hop_s)
    36         #print "%f" % (this_beat / float(samplerate))
     35        this_beat = o.get_last_s()
    3736        beats.append(this_beat)
    3837    total_frames += read
    3938    if read < hop_s: break
    4039
    41 #convert samples to seconds
    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):
     40if len(beats) > 1:
    4741    # do plotting
    48     from numpy import array, arange, mean, median
     42    from numpy import array, arange, mean, median, diff
    4943    import matplotlib.pyplot as plt
     44    bpms = 60./ diff(beats)
    5045    print 'mean period:', "%.2f" % mean(bpms), 'bpm', 'median', "%.2f" % median(bpms), 'bpm'
    5146    print 'plotting', filename
     
    8176
    8277else:
    83     print 'mean period:', "%.2f" % 0, 'bpm', 'median', "%.2f" % 0, 'bpm', 
     78    print 'mean period:', "%.2f" % 0, 'bpm', 'median', "%.2f" % 0, 'bpm',
    8479    print 'nothing to plot, file too short?'
Note: See TracChangeset for help on using the changeset viewer.