python/demos: remove unused import and variables
authorPaul Brossier <piem@piem.org>
Tue, 10 May 2016 19:53:01 +0000 (21:53 +0200)
committerPaul Brossier <piem@piem.org>
Tue, 10 May 2016 19:53:01 +0000 (21:53 +0200)
14 files changed:
python/demos/demo_filterbank.py
python/demos/demo_filterbank_slaney.py
python/demos/demo_keyboard.py
python/demos/demo_mel-energy.py
python/demos/demo_mfcc.py
python/demos/demo_onset_plot.py
python/demos/demo_pitch.py
python/demos/demo_pitch_sinusoid.py
python/demos/demo_pysoundcard_record.py
python/demos/demo_reading_speed.py [changed mode: 0644->0755]
python/demos/demo_sink_create_woodblock.py
python/demos/demo_tempo_plot.py
python/demos/demo_tss.py
python/demos/demo_waveform_plot.py

index 1620a03..69dc383 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 
 from aubio import filterbank, fvec
 #! /usr/bin/env python
 
 from aubio import filterbank, fvec
-from pylab import loglog, show, subplot, xlim, ylim, xlabel, ylabel, title
+from pylab import loglog, show, xlim, ylim, xlabel, ylabel, title
 from numpy import vstack, arange
 
 win_s = 2048
 from numpy import vstack, arange
 
 win_s = 2048
index 636dc80..0a42505 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 
 from aubio import filterbank
 #! /usr/bin/env python
 
 from aubio import filterbank
-from numpy import array, arange, vstack
+from numpy import arange, vstack
 
 win_s = 8192
 samplerate = 16000
 
 win_s = 8192
 samplerate = 16000
index 527d03b..63786b9 100755 (executable)
@@ -25,7 +25,6 @@ def get_keyboard_edges(firstnote = 21, lastnote = 108):
     return xb, xw, 2/3. *scaleb, 1/2. * scalew
 
 def create_keyboard_patches(firstnote, lastnote, ax = None):
     return xb, xw, 2/3. *scaleb, 1/2. * scalew
 
 def create_keyboard_patches(firstnote, lastnote, ax = None):
-    import numpy as np
     import matplotlib.pyplot as plt
     from matplotlib.path import Path
     import matplotlib.patches as mpatches
     import matplotlib.pyplot as plt
     from matplotlib.path import Path
     import matplotlib.patches as mpatches
index ac09863..d433058 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 
 import sys
 #! /usr/bin/env python
 
 import sys
-from aubio import fvec, source, pvoc, filterbank
+from aubio import source, pvoc, filterbank
 from numpy import vstack, zeros
 
 win_s = 512                 # fft size
 from numpy import vstack, zeros
 
 win_s = 512                 # fft size
index 2242f0c..d69ccef 100755 (executable)
@@ -2,7 +2,7 @@
 
 import sys
 from aubio import source, pvoc, mfcc
 
 import sys
 from aubio import source, pvoc, mfcc
-from numpy import array, vstack, zeros
+from numpy import vstack, zeros
 
 win_s = 512                 # fft size
 hop_s = win_s / 4           # hop size
 
 win_s = 512                 # fft size
 hop_s = win_s / 4           # hop size
index a928655..5d59cb6 100755 (executable)
@@ -2,7 +2,7 @@
 
 import sys
 from aubio import onset, source
 
 import sys
 from aubio import onset, source
-from numpy import array, hstack, zeros
+from numpy import hstack, zeros
 
 win_s = 512                 # fft size
 hop_s = win_s / 2           # hop size
 
 win_s = 512                 # fft size
 hop_s = win_s / 2           # hop size
index 9126a55..094eee7 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 
 import sys
 #! /usr/bin/env python
 
 import sys
-from aubio import source, pitch, freqtomidi
+from aubio import source, pitch
 
 if len(sys.argv) < 2:
     print "Usage: %s <filename> [samplerate]" % sys.argv[0]
 
 if len(sys.argv) < 2:
     print "Usage: %s <filename> [samplerate]" % sys.argv[0]
index 6407e58..1194df2 100755 (executable)
@@ -1,6 +1,6 @@
 #! /usr/bin/env python
 
 #! /usr/bin/env python
 
-from numpy import random, sin, arange, ones, zeros
+from numpy import random, sin, arange, zeros
 from math import pi
 from aubio import fvec, pitch
 
 from math import pi
 from aubio import fvec, pitch
 
@@ -10,7 +10,6 @@ def build_sinusoid(length, freqs, samplerate):
 def run_pitch(p, input_vec):
   f = fvec (p.hop_size)
   cands = []
 def run_pitch(p, input_vec):
   f = fvec (p.hop_size)
   cands = []
-  count = 0
   for vec_slice in input_vec.reshape((-1, p.hop_size)):
     f[:] = vec_slice
     cands.append(p(f))
   for vec_slice in input_vec.reshape((-1, p.hop_size)):
     f[:] = vec_slice
     cands.append(p(f))
index e3816d2..2b5c706 100755 (executable)
@@ -21,9 +21,8 @@ def record_sink(sink_path):
             mono_vec = vec.sum(-1) / float(s.channels[0])
             g(mono_vec, hop_size)
             total_frames += hop_size
             mono_vec = vec.sum(-1) / float(s.channels[0])
             g(mono_vec, hop_size)
             total_frames += hop_size
-    except KeyboardInterrupt, e:
+    except KeyboardInterrupt:
         print "stopped after", "%.2f seconds" % (total_frames / s.samplerate)
         print "stopped after", "%.2f seconds" % (total_frames / s.samplerate)
-        pass
     s.stop()
 
 if __name__ == '__main__':
     s.stop()
 
 if __name__ == '__main__':
old mode 100644 (file)
new mode 100755 (executable)
index e6fdb78..1158cec
@@ -5,16 +5,22 @@
 
 Compare the speed of several methods for reading and loading a sound file.
 
 
 Compare the speed of several methods for reading and loading a sound file.
 
-This file depends on audioread and librosa:
-    https://github.com/beetbox/audioread
-    https://github.com/bmcfee/librosa
+This file depends on the following packages:
+
+    - audioread     https://github.com/beetbox/audioread
+    - librosa       https://github.com/bmcfee/librosa
+    - pydub         https://github.com/jiaaro/pydub
 
 """
 
 import numpy as np
 import aubio
 
 """
 
 import numpy as np
 import aubio
+"""
 import audioread
 import librosa
 import audioread
 import librosa
+import scipy.io.wavfile
+from pydub import AudioSegment
+"""
 
 def read_file_audioread(filename):
     # taken from librosa.util.utils
 
 def read_file_audioread(filename):
     # taken from librosa.util.utils
@@ -25,20 +31,43 @@ def read_file_audioread(filename):
         fmt = '<i{:d}'.format(n_bytes)
         # Rescale and format the data buffer
         out = scale * np.frombuffer(buf, fmt).astype(dtype)
         fmt = '<i{:d}'.format(n_bytes)
         # Rescale and format the data buffer
         out = scale * np.frombuffer(buf, fmt).astype(dtype)
-        out = out.reshape(2, -1)
         return out
 
     with audioread.audio_open(filename) as f:
         total_frames = 0
         for buf in f:
             samples = convert_buffer_to_float(buf)
         return out
 
     with audioread.audio_open(filename) as f:
         total_frames = 0
         for buf in f:
             samples = convert_buffer_to_float(buf)
+            samples = samples.reshape(f.channels, -1)
             total_frames += samples.shape[1]
         return total_frames, f.samplerate
 
 def load_file_librosa(filename):
     y, sr = librosa.load(filename, sr = None)
             total_frames += samples.shape[1]
         return total_frames, f.samplerate
 
 def load_file_librosa(filename):
     y, sr = librosa.load(filename, sr = None)
+    #print y.mean(), y.shape
+    return len(y), sr
+
+def load_file_scipy(filename):
+    sr, y = scipy.io.wavfile.read(filename)
+    y = y.astype('float32') / 32767
+    #print y.mean(), y.shape
     return len(y), sr
 
     return len(y), sr
 
+def load_file_scipy_mmap(filename):
+    sr, y = scipy.io.wavfile.read(filename, mmap = True)
+    #print y.mean(), y.shape
+    return len(y), sr
+
+def read_file_pydub(filename):
+    song = AudioSegment.from_file(filename)
+    song.get_array_of_samples()
+    return song.frame_count(), song.frame_rate
+
+def load_file_pydub(filename):
+    song = AudioSegment.from_file(filename)
+    y = np.asarray(song.get_array_of_samples(), dtype = 'float32')
+    y = y.reshape(song.channels, -1) / 32767.
+    return song.frame_count(), song.frame_rate
+
 def read_file_aubio(filename):
     f = aubio.source(filename, hop_size = 1024)
     total_frames = 0
 def read_file_aubio(filename):
     f = aubio.source(filename, hop_size = 1024)
     total_frames = 0
@@ -58,6 +87,7 @@ def load_file_aubio(filename):
         total_frames += read
         if read < f.hop_size: break
     assert len(y) == total_frames
         total_frames += read
         if read < f.hop_size: break
     assert len(y) == total_frames
+    #print y.mean(), y.shape
     return total_frames, f.samplerate
 
 def test_speed(function, filename):
     return total_frames, f.samplerate
 
 def test_speed(function, filename):
@@ -81,6 +111,16 @@ if __name__ == '__main__':
         sys.exit(1)
     filename = sys.argv[1]
 
         sys.exit(1)
     filename = sys.argv[1]
 
-    functions = [read_file_aubio, load_file_aubio, read_file_audioread, load_file_librosa]
+    functions = [
+            read_file_aubio,
+            load_file_aubio,
+            #load_file_scipy,
+            #load_file_scipy_mmap,
+            #read_file_audioread,
+            #load_file_librosa,
+            #read_file_pydub,
+            #load_file_pydub,
+            ]
+
     for f in functions:
         test_speed(f, filename)
     for f in functions:
         test_speed(f, filename)
index 2c06a5f..745daae 100755 (executable)
@@ -3,7 +3,7 @@
 import sys
 from math import pi, e
 from aubio import sink
 import sys
 from math import pi, e
 from aubio import sink
-from numpy import arange, resize, sin, exp, zeros
+from numpy import arange, sin, exp, zeros
 
 if len(sys.argv) < 2:
     print 'usage: %s <outputfile> [samplerate]' % sys.argv[0]
 
 if len(sys.argv) < 2:
     print 'usage: %s <outputfile> [samplerate]' % sys.argv[0]
index de06d00..043e144 100755 (executable)
@@ -39,7 +39,7 @@ while True:
 
 if len(beats) > 1:
     # do plotting
 
 if len(beats) > 1:
     # do plotting
-    from numpy import array, arange, mean, median, diff
+    from numpy import mean, median, diff
     import matplotlib.pyplot as plt
     bpms = 60./ diff(beats)
     print 'mean period:', "%.2f" % mean(bpms), 'bpm', 'median', "%.2f" % median(bpms), 'bpm'
     import matplotlib.pyplot as plt
     bpms = 60./ diff(beats)
     print 'mean period:', "%.2f" % mean(bpms), 'bpm', 'median', "%.2f" % median(bpms), 'bpm'
index b38f474..aa9107e 100755 (executable)
@@ -44,3 +44,4 @@ if __name__ == '__main__':
     get_spectrogram(sys.argv[2])
     subplot(313)
     get_spectrogram(sys.argv[3])
     get_spectrogram(sys.argv[2])
     subplot(313)
     get_spectrogram(sys.argv[3])
+    show()
index 91c6eda..b4bd42a 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 
 import sys
 #! /usr/bin/env python
 
 import sys
-from aubio import pvoc, source
+from aubio import source
 from numpy import zeros, hstack
 
 def get_waveform_plot(filename, samplerate = 0, block_size = 4096, ax = None, downsample = 2**4):
 from numpy import zeros, hstack
 
 def get_waveform_plot(filename, samplerate = 0, block_size = 4096, ax = None, downsample = 2**4):