source: python/demos/demo_pitch.py @ 22df684

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 22df684 was 5d5d6b9, checked in by Paul Brossier <piem@piem.org>, 12 years ago

python/demos: add demo_pitch.py and demo_waveform_plot.py

  • Property mode set to 100755
File size: 743 bytes
Line 
1#! /usr/bin/env python
2
3import sys
4from aubio import source, pitch
5
6win_s = 1024 # fft size
7hop_s = win_s # hop size
8
9if len(sys.argv) < 2:
10    print "Usage: %s <filename> [samplerate]" % sys.argv[0]
11    sys.exit(1)
12
13filename = sys.argv[1]
14
15samplerate = 0
16if len( sys.argv ) > 2: samplerate = int(sys.argv[2])
17
18s = source(filename, samplerate, hop_s)
19samplerate = s.samplerate
20
21pitch_o = pitch("default", win_s, hop_s, samplerate)
22pitch_o.set_unit("midi")
23
24pitches = []
25
26
27# total number of frames read
28total_frames = 0
29while True:
30    samples, read = s()
31    pitch = pitch_o(samples)[0]
32    print "%f %f" % (total_frames / float(samplerate), pitch)
33    #pitches += [pitches]
34    total_frames += read
35    if read < hop_s: break
36
37#print pitches
Note: See TracBrowser for help on using the repository browser.