Changeset e6f7a4a
- Timestamp:
- Mar 8, 2013, 4:12:17 PM (12 years ago)
- 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:
- 459e46f
- Parents:
- 92c83ccc
- Location:
- python/demos
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
python/demos/demo_onset_plot.py
r92c83ccc re6f7a4a 7 7 win_s = 512 # fft size 8 8 hop_s = win_s / 2 # hop size 9 samplerate = 4410010 downsample = 2 # used to plot n samples / hop_s11 9 12 10 if len(sys.argv) < 2: 13 print "Usage: %s <filename> " % sys.argv[0]11 print "Usage: %s <filename> [samplerate]" % sys.argv[0] 14 12 sys.exit(1) 15 13 16 14 filename = sys.argv[1] 15 16 samplerate = 0 17 if len( sys.argv ) > 2: samplerate = int(sys.argv[2]) 18 19 s = source(filename, samplerate, hop_s) 20 samplerate = s.samplerate 21 o = onset("default", win_s, hop_s) 22 23 # onset detection delay, in blocks 24 delay = 4. * hop_s 25 17 26 onsets = [] 18 27 19 s = source(filename, samplerate, hop_s) 20 o = onset("default", win_s, hop_s) 21 28 # storage for plotted data 22 29 desc = [] 23 30 tdesc = [] 31 allsamples_max = zeros(0,) 32 downsample = 2 # to plot n samples / hop_s 24 33 25 block_read = 0 26 allsamples_max = zeros(0,) 34 total_frames = 0 27 35 while True: 28 36 samples, read = s() 37 is_onset = o(samples) 38 if is_onset: 39 this_onset = int(total_frames - delay + is_onset[0] * hop_s) 40 print "%f" % (this_onset / float(samplerate)) 41 onsets.append(this_onset / float(samplerate)) 42 # keep some data to plot it later 29 43 new_maxes = (abs(samples.reshape(hop_s/downsample, downsample))).max(axis=0) 30 44 allsamples_max = hstack([allsamples_max, new_maxes]) 31 isbeat = o(samples)32 45 desc.append(o.get_descriptor()) 33 46 tdesc.append(o.get_thresholded_descriptor()) 34 if isbeat: 35 thisbeat = (block_read - 4. + isbeat[0]) * hop_s / samplerate 36 print "%.4f" % thisbeat 37 onsets.append (thisbeat) 38 block_read += 1 47 total_frames += read 39 48 if read < hop_s: break 40 49
Note: See TracChangeset
for help on using the changeset viewer.