History

python/demos: remove unused import and variables

Paul Brossier committed 10 years ago

Commit 8fb567c1 parent 143682b14 files · +57 −19Browse files

Showing the changes to python (14 of 14 files). Show all

Unified · Split

14 files
  1. python/demos/demo_filterbank.py +1 −1
  2. python/demos/demo_filterbank_slaney.py +1 −1
  3. python/demos/demo_keyboard.py +0 −1
  4. python/demos/demo_mel-energy.py +1 −1
  5. python/demos/demo_mfcc.py +1 −1
  6. python/demos/demo_onset_plot.py +1 −1
  7. python/demos/demo_pitch.py +1 −1
  8. python/demos/demo_pitch_sinusoid.py +1 −2
  9. python/demos/demo_pysoundcard_record.py +1 −2
  10. python/demos/demo_reading_speed.py +45 −5
  11. python/demos/demo_sink_create_woodblock.py +1 −1
  12. python/demos/demo_tempo_plot.py +1 −1
  13. python/demos/demo_tss.py +1 −0
  14. python/demos/demo_waveform_plot.py +1 −1
python/demos/demo_filterbank.py+1−1
@@ -1,7 +1,7 @@
11 #! /usr/bin/env python
22
33 from aubio import filterbank, fvec
4−from pylab import loglog, show, subplot, xlim, ylim, xlabel, ylabel, title
4+from pylab import loglog, show, xlim, ylim, xlabel, ylabel, title
55 from numpy import vstack, arange
66
77 win_s = 2048
python/demos/demo_filterbank_slaney.py+1−1
@@ -1,7 +1,7 @@
11 #! /usr/bin/env python
22
33 from aubio import filterbank
4−from numpy import array, arange, vstack
4+from numpy import arange, vstack
55
66 win_s = 8192
77 samplerate = 16000
python/demos/demo_keyboard.py+0−1
@@ -25,7 +25,6 @@ def get_keyboard_edges(firstnote = 21, lastnote = 108): · 24 unmodified lines
2525 return xb, xw, 2/3. *scaleb, 1/2. * scalew
2626
2727 def create_keyboard_patches(firstnote, lastnote, ax = None):
28− import numpy as np
2928 import matplotlib.pyplot as plt
3029 from matplotlib.path import Path
3130 import matplotlib.patches as mpatches
python/demos/demo_mel-energy.py+1−1
@@ -1,7 +1,7 @@
11 #! /usr/bin/env python
22
33 import sys
4−from aubio import fvec, source, pvoc, filterbank
4+from aubio import source, pvoc, filterbank
55 from numpy import vstack, zeros
66
77 win_s = 512 # fft size
python/demos/demo_mfcc.py+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
22
33 import sys
44 from aubio import source, pvoc, mfcc
5−from numpy import array, vstack, zeros
5+from numpy import vstack, zeros
66
77 win_s = 512 # fft size
88 hop_s = win_s / 4 # hop size
python/demos/demo_onset_plot.py+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
22
33 import sys
44 from aubio import onset, source
5−from numpy import array, hstack, zeros
5+from numpy import hstack, zeros
66
77 win_s = 512 # fft size
88 hop_s = win_s / 2 # hop size
python/demos/demo_pitch.py+1−1
@@ -1,7 +1,7 @@
11 #! /usr/bin/env python
22
33 import sys
4−from aubio import source, pitch, freqtomidi
4+from aubio import source, pitch
55
66 if len(sys.argv) < 2:
77 print "Usage: %s <filename> [samplerate]" % sys.argv[0]
python/demos/demo_pitch_sinusoid.py+1−2
@@ -1,6 +1,6 @@
11 #! /usr/bin/env python
22
3−from numpy import random, sin, arange, ones, zeros
3+from numpy import random, sin, arange, zeros
44 from math import pi
55 from aubio import fvec, pitch
66
@@ -10,7 +10,6 @@ def build_sinusoid(length, freqs, samplerate): · 3 unmodified lines
1010 def run_pitch(p, input_vec):
1111 f = fvec (p.hop_size)
1212 cands = []
13− count = 0
1413 for vec_slice in input_vec.reshape((-1, p.hop_size)):
1514 f[:] = vec_slice
1615 cands.append(p(f))
python/demos/demo_pysoundcard_record.py+1−2
@@ -21,9 +21,8 @@ def record_sink(sink_path): · 20 unmodified lines
2121 mono_vec = vec.sum(-1) / float(s.channels[0])
2222 g(mono_vec, hop_size)
2323 total_frames += hop_size
24− except KeyboardInterrupt, e:
24+ except KeyboardInterrupt:
2525 print "stopped after", "%.2f seconds" % (total_frames / s.samplerate)
26− pass
2726 s.stop()
2827
2928 if __name__ == '__main__':
python/demos/demo_reading_speed.py+45−5
@@ -5,16 +5,22 @@ · 4 unmodified lines
55
66 Compare the speed of several methods for reading and loading a sound file.
77
8−This file depends on audioread and librosa:
9− https://github.com/beetbox/audioread
10− https://github.com/bmcfee/librosa
8+This file depends on the following packages:
9+
10+ - audioread https://github.com/beetbox/audioread
11+ - librosa https://github.com/bmcfee/librosa
12+ - pydub https://github.com/jiaaro/pydub
1113
1214 """
1315
1416 import numpy as np
1517 import aubio
18+"""
1619 import audioread
1720 import librosa
21+import scipy.io.wavfile
22+from pydub import AudioSegment
23+"""
1824
1925 def read_file_audioread(filename):
2026 # taken from librosa.util.utils
@@ -25,20 +31,43 @@ def read_file_audioread(filename): · 4 unmodified lines
2531 fmt = '<i{:d}'.format(n_bytes)
2632 # Rescale and format the data buffer
2733 out = scale * np.frombuffer(buf, fmt).astype(dtype)
28− out = out.reshape(2, -1)
2934 return out
3035
3136 with audioread.audio_open(filename) as f:
3237 total_frames = 0
3338 for buf in f:
3439 samples = convert_buffer_to_float(buf)
40+ samples = samples.reshape(f.channels, -1)
3541 total_frames += samples.shape[1]
3642 return total_frames, f.samplerate
3743
3844 def load_file_librosa(filename):
3945 y, sr = librosa.load(filename, sr = None)
46+ #print y.mean(), y.shape
47+ return len(y), sr
48+
49+def load_file_scipy(filename):
50+ sr, y = scipy.io.wavfile.read(filename)
51+ y = y.astype('float32') / 32767
52+ #print y.mean(), y.shape
4053 return len(y), sr
4154
55+def load_file_scipy_mmap(filename):
56+ sr, y = scipy.io.wavfile.read(filename, mmap = True)
57+ #print y.mean(), y.shape
58+ return len(y), sr
59+
60+def read_file_pydub(filename):
61+ song = AudioSegment.from_file(filename)
62+ song.get_array_of_samples()
63+ return song.frame_count(), song.frame_rate
64+
65+def load_file_pydub(filename):
66+ song = AudioSegment.from_file(filename)
67+ y = np.asarray(song.get_array_of_samples(), dtype = 'float32')
68+ y = y.reshape(song.channels, -1) / 32767.
69+ return song.frame_count(), song.frame_rate
70+
4271 def read_file_aubio(filename):
4372 f = aubio.source(filename, hop_size = 1024)
4473 total_frames = 0
@@ -58,6 +87,7 @@ def load_file_aubio(filename): · 13 unmodified lines
5887 total_frames += read
5988 if read < f.hop_size: break
6089 assert len(y) == total_frames
90+ #print y.mean(), y.shape
6191 return total_frames, f.samplerate
6292
6393 def test_speed(function, filename):
@@ -81,6 +111,16 @@ if __name__ == '__main__': · 17 unmodified lines
81111 sys.exit(1)
82112 filename = sys.argv[1]
83113
84− functions = [read_file_aubio, load_file_aubio, read_file_audioread, load_file_librosa]
114+ functions = [
115+ read_file_aubio,
116+ load_file_aubio,
117+ #load_file_scipy,
118+ #load_file_scipy_mmap,
119+ #read_file_audioread,
120+ #load_file_librosa,
121+ #read_file_pydub,
122+ #load_file_pydub,
123+ ]
124+
85125 for f in functions:
86126 test_speed(f, filename)
python/demos/demo_sink_create_woodblock.py+1−1
@@ -3,7 +3,7 @@ · 2 unmodified lines
33 import sys
44 from math import pi, e
55 from aubio import sink
6−from numpy import arange, resize, sin, exp, zeros
6+from numpy import arange, sin, exp, zeros
77
88 if len(sys.argv) < 2:
99 print 'usage: %s <outputfile> [samplerate]' % sys.argv[0]
python/demos/demo_tempo_plot.py+1−1
@@ -39,7 +39,7 @@ while True: · 38 unmodified lines
3939
4040 if len(beats) > 1:
4141 # do plotting
42− from numpy import array, arange, mean, median, diff
42+ from numpy import mean, median, diff
4343 import matplotlib.pyplot as plt
4444 bpms = 60./ diff(beats)
4545 print 'mean period:', "%.2f" % mean(bpms), 'bpm', 'median', "%.2f" % median(bpms), 'bpm'
python/demos/demo_tss.py+1−0
@@ -44,3 +44,4 @@ if __name__ == '__main__': · 43 unmodified lines
4444 get_spectrogram(sys.argv[2])
4545 subplot(313)
4646 get_spectrogram(sys.argv[3])
47+ show()
python/demos/demo_waveform_plot.py+1−1
@@ -1,7 +1,7 @@
11 #! /usr/bin/env python
22
33 import sys
4−from aubio import pvoc, source
4+from aubio import source
55 from numpy import zeros, hstack
66
77 def get_waveform_plot(filename, samplerate = 0, block_size = 4096, ax = None, downsample = 2**4):

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t