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 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from aubio import filterbank, fvec3from aubio import filterbank, fvec
4from pylab import loglog, show, subplot, xlim, ylim, xlabel, ylabel, title4from pylab import loglog, show, xlim, ylim, xlabel, ylabel, title
5from numpy import vstack, arange5from numpy import vstack, arange
6 6
7win_s = 20487win_s = 2048
python/demos/demo_filterbank_slaney.py+1−1
@@ -1,7 +1,7 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from aubio import filterbank3from aubio import filterbank
4from numpy import array, arange, vstack4from numpy import arange, vstack
5 5
6win_s = 81926win_s = 8192
7samplerate = 160007samplerate = 16000
python/demos/demo_keyboard.py+0−1
@@ -25,7 +25,6 @@ def get_keyboard_edges(firstnote = 21, lastnote = 108): · 24 unmodified lines
25 return xb, xw, 2/3. *scaleb, 1/2. * scalew25 return xb, xw, 2/3. *scaleb, 1/2. * scalew
26 26
27def create_keyboard_patches(firstnote, lastnote, ax = None):27def create_keyboard_patches(firstnote, lastnote, ax = None):
28 import numpy as np
29 import matplotlib.pyplot as plt28 import matplotlib.pyplot as plt
30 from matplotlib.path import Path29 from matplotlib.path import Path
31 import matplotlib.patches as mpatches30 import matplotlib.patches as mpatches
python/demos/demo_mel-energy.py+1−1
@@ -1,7 +1,7 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3import sys3import sys
4from aubio import fvec, source, pvoc, filterbank4from aubio import source, pvoc, filterbank
5from numpy import vstack, zeros5from numpy import vstack, zeros
6 6
7win_s = 512 # fft size7win_s = 512 # fft size
python/demos/demo_mfcc.py+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
2 2
3import sys3import sys
4from aubio import source, pvoc, mfcc4from aubio import source, pvoc, mfcc
5from numpy import array, vstack, zeros5from numpy import vstack, zeros
6 6
7win_s = 512 # fft size7win_s = 512 # fft size
8hop_s = win_s / 4 # hop size8hop_s = win_s / 4 # hop size
python/demos/demo_onset_plot.py+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
2 2
3import sys3import sys
4from aubio import onset, source4from aubio import onset, source
5from numpy import array, hstack, zeros5from numpy import hstack, zeros
6 6
7win_s = 512 # fft size7win_s = 512 # fft size
8hop_s = win_s / 2 # hop size8hop_s = win_s / 2 # hop size
python/demos/demo_pitch.py+1−1
@@ -1,7 +1,7 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3import sys3import sys
4from aubio import source, pitch, freqtomidi4from aubio import source, pitch
5 5
6if len(sys.argv) < 2:6if len(sys.argv) < 2:
7 print "Usage: %s <filename> [samplerate]" % sys.argv[0]7 print "Usage: %s <filename> [samplerate]" % sys.argv[0]
python/demos/demo_pitch_sinusoid.py+1−2
@@ -1,6 +1,6 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from numpy import random, sin, arange, ones, zeros3from numpy import random, sin, arange, zeros
4from math import pi4from math import pi
5from aubio import fvec, pitch5from aubio import fvec, pitch
6 6
@@ -10,7 +10,6 @@ def build_sinusoid(length, freqs, samplerate): · 3 unmodified lines
10def run_pitch(p, input_vec):10def run_pitch(p, input_vec):
11 f = fvec (p.hop_size)11 f = fvec (p.hop_size)
12 cands = []12 cands = []
13 count = 0
14 for vec_slice in input_vec.reshape((-1, p.hop_size)):13 for vec_slice in input_vec.reshape((-1, p.hop_size)):
15 f[:] = vec_slice14 f[:] = vec_slice
16 cands.append(p(f))15 cands.append(p(f))
python/demos/demo_pysoundcard_record.py+1−2
@@ -21,9 +21,8 @@ def record_sink(sink_path): · 20 unmodified lines
21 mono_vec = vec.sum(-1) / float(s.channels[0])21 mono_vec = vec.sum(-1) / float(s.channels[0])
22 g(mono_vec, hop_size)22 g(mono_vec, hop_size)
23 total_frames += hop_size23 total_frames += hop_size
24 except KeyboardInterrupt, e:24 except KeyboardInterrupt:
25 print "stopped after", "%.2f seconds" % (total_frames / s.samplerate)25 print "stopped after", "%.2f seconds" % (total_frames / s.samplerate)
26 pass
27 s.stop()26 s.stop()
28 27
29if __name__ == '__main__':28if __name__ == '__main__':
python/demos/demo_reading_speed.py+45−5
@@ -5,16 +5,22 @@ · 4 unmodified lines
5 5
6Compare the speed of several methods for reading and loading a sound file.6Compare the speed of several methods for reading and loading a sound file.
7 7
8This file depends on audioread and librosa:8This file depends on the following packages:
9 https://github.com/beetbox/audioread9
10 https://github.com/bmcfee/librosa10 - audioread https://github.com/beetbox/audioread
11 - librosa https://github.com/bmcfee/librosa
12 - pydub https://github.com/jiaaro/pydub
11 13
12"""14"""
13 15
14import numpy as np16import numpy as np
15import aubio17import aubio
18"""
16import audioread19import audioread
17import librosa20import librosa
21import scipy.io.wavfile
22from pydub import AudioSegment
23"""
18 24
19def read_file_audioread(filename):25def read_file_audioread(filename):
20 # taken from librosa.util.utils26 # taken from librosa.util.utils
@@ -25,20 +31,43 @@ def read_file_audioread(filename): · 4 unmodified lines
25 fmt = '<i{:d}'.format(n_bytes)31 fmt = '<i{:d}'.format(n_bytes)
26 # Rescale and format the data buffer32 # Rescale and format the data buffer
27 out = scale * np.frombuffer(buf, fmt).astype(dtype)33 out = scale * np.frombuffer(buf, fmt).astype(dtype)
28 out = out.reshape(2, -1)
29 return out34 return out
30 35
31 with audioread.audio_open(filename) as f:36 with audioread.audio_open(filename) as f:
32 total_frames = 037 total_frames = 0
33 for buf in f:38 for buf in f:
34 samples = convert_buffer_to_float(buf)39 samples = convert_buffer_to_float(buf)
40 samples = samples.reshape(f.channels, -1)
35 total_frames += samples.shape[1]41 total_frames += samples.shape[1]
36 return total_frames, f.samplerate42 return total_frames, f.samplerate
37 43
38def load_file_librosa(filename):44def load_file_librosa(filename):
39 y, sr = librosa.load(filename, sr = None)45 y, sr = librosa.load(filename, sr = None)
46 #print y.mean(), y.shape
47 return len(y), sr
48
49def load_file_scipy(filename):
50 sr, y = scipy.io.wavfile.read(filename)
51 y = y.astype('float32') / 32767
52 #print y.mean(), y.shape
40 return len(y), sr53 return len(y), sr
41 54
55def 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
60def 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
65def 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
42def read_file_aubio(filename):71def read_file_aubio(filename):
43 f = aubio.source(filename, hop_size = 1024)72 f = aubio.source(filename, hop_size = 1024)
44 total_frames = 073 total_frames = 0
@@ -58,6 +87,7 @@ def load_file_aubio(filename): · 13 unmodified lines
58 total_frames += read87 total_frames += read
59 if read < f.hop_size: break88 if read < f.hop_size: break
60 assert len(y) == total_frames89 assert len(y) == total_frames
90 #print y.mean(), y.shape
61 return total_frames, f.samplerate91 return total_frames, f.samplerate
62 92
63def test_speed(function, filename):93def test_speed(function, filename):
@@ -81,6 +111,16 @@ if __name__ == '__main__': · 17 unmodified lines
81 sys.exit(1)111 sys.exit(1)
82 filename = sys.argv[1]112 filename = sys.argv[1]
83 113
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
85 for f in functions:125 for f in functions:
86 test_speed(f, filename)126 test_speed(f, filename)
python/demos/demo_sink_create_woodblock.py+1−1
@@ -3,7 +3,7 @@ · 2 unmodified lines
3import sys3import sys
4from math import pi, e4from math import pi, e
5from aubio import sink5from aubio import sink
6from numpy import arange, resize, sin, exp, zeros6from numpy import arange, sin, exp, zeros
7 7
8if len(sys.argv) < 2:8if len(sys.argv) < 2:
9 print 'usage: %s <outputfile> [samplerate]' % sys.argv[0]9 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
39 39
40if len(beats) > 1:40if len(beats) > 1:
41 # do plotting41 # do plotting
42 from numpy import array, arange, mean, median, diff42 from numpy import mean, median, diff
43 import matplotlib.pyplot as plt43 import matplotlib.pyplot as plt
44 bpms = 60./ diff(beats)44 bpms = 60./ diff(beats)
45 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'
python/demos/demo_tss.py+1−0
@@ -44,3 +44,4 @@ if __name__ == '__main__': · 43 unmodified lines
44 get_spectrogram(sys.argv[2])44 get_spectrogram(sys.argv[2])
45 subplot(313)45 subplot(313)
46 get_spectrogram(sys.argv[3])46 get_spectrogram(sys.argv[3])
47 show()
python/demos/demo_waveform_plot.py+1−1
@@ -1,7 +1,7 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3import sys3import sys
4from aubio import pvoc, source4from aubio import source
5from numpy import zeros, hstack5from numpy import zeros, hstack
6 6
7def get_waveform_plot(filename, samplerate = 0, block_size = 4096, ax = None, downsample = 2**4):7def 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