shithub: aubio

Download patch

ref: 4120fbc9a4fe29d1d7c2e25be6212014dd790086
parent: 416ddd1268856448ec2b79b189b8c0f9d6347974
author: Paul Brossier <piem@piem.org>
date: Sun May 15 23:16:00 EDT 2016

python/demos: python3 and double precision compatibility

--- a/python/demos/demo_bpm_extract.py
+++ b/python/demos/demo_bpm_extract.py
@@ -45,8 +45,14 @@
             break
 
     # Convert to periods and to bpm 
-    bpms = 60./diff(beats)
-    b = median(bpms)
+    if len(beats) > 1:
+        if len(beats) < 4:
+            print("few beats found in {:s}".format(path))
+        bpms = 60./diff(beats)
+        b = median(bpms)
+    else:
+        b = 0
+        print("not enough beats found in {:s}".format(path))
     return b
 
 if __name__ == '__main__':
@@ -53,4 +59,4 @@
     import sys
     for f in sys.argv[1:]:
         bpm = get_file_bpm(f)
-        print "%6s" % ("%.2f" % bpm), f
+        print("{:6s} {:s}".format("{:2f}".format(bpm), f))
--- a/python/demos/demo_filterbank.py
+++ b/python/demos/demo_filterbank.py
@@ -19,7 +19,7 @@
 
 f.set_coeffs(coeffs)
 
-times = vstack([arange(win_s / 2 + 1) * samplerate / win_s] * n_filters)
+times = vstack([arange(win_s // 2 + 1) * samplerate / win_s] * n_filters)
 title('Bank of filters built using a simple list of boundaries\nThe middle band has been amplified by 2.')
 loglog(times.T, f.get_coeffs().T, '.-')
 xlim([50, samplerate/2])
--- a/python/demos/demo_filterbank_slaney.py
+++ b/python/demos/demo_filterbank_slaney.py
@@ -11,7 +11,7 @@
 
 from pylab import loglog, title, show, xlim, ylim, xlabel, ylabel
 xlim([0,samplerate / 2])
-times = vstack([arange(win_s / 2 + 1) * samplerate / win_s] * 40)
+times = vstack([arange(win_s // 2 + 1) * samplerate / win_s] * 40)
 loglog(times.T, f.get_coeffs().T, '.-')
 title('Mel frequency bands coefficients')
 xlim([100, 7500])
--- a/python/demos/demo_filterbank_triangle_bands.py
+++ b/python/demos/demo_filterbank_triangle_bands.py
@@ -16,7 +16,7 @@
 
 subplot(211)
 title('Examples of filterbank built with set_triangle_bands and set_coeffs')
-times = vstack([arange(win_s / 2 + 1) * samplerate / win_s] * n_filters)
+times = vstack([arange(win_s // 2 + 1) * samplerate / win_s] * n_filters)
 loglog(times.T, f.get_coeffs().T, '.-')
 xlim([50, samplerate/2])
 ylim([1.0e-6, 2.0e-2])
@@ -37,7 +37,7 @@
 f.set_coeffs(coeffs)
 
 subplot(212)
-times = vstack([arange(win_s / 2 + 1) * samplerate / win_s] * n_filters)
+times = vstack([arange(win_s // 2 + 1) * samplerate / win_s] * n_filters)
 loglog(times.T, f.get_coeffs().T, '.-')
 xlim([50, samplerate/2])
 ylim([1.0e-6, 2.0e-2])
--- a/python/demos/demo_mel-energy.py
+++ b/python/demos/demo_mel-energy.py
@@ -5,10 +5,10 @@
 from numpy import vstack, zeros
 
 win_s = 512                 # fft size
-hop_s = win_s / 4           # hop size
+hop_s = win_s // 4          # hop size
 
 if len(sys.argv) < 2:
-    print "Usage: %s <filename> [samplerate]" % sys.argv[0]
+    print("Usage: %s <filename> [samplerate]" % sys.argv[0])
     sys.exit(1)
 
 filename = sys.argv[1]
@@ -34,14 +34,14 @@
     samples, read = s()
     fftgrain = pv(samples)
     new_energies = f(fftgrain)
-    print '%f' % (total_frames / float(samplerate) ),
-    print ' '.join(['%f' % b for b in new_energies])
+    timestr = '%f' % (total_frames / float(samplerate) )
+    print('{:s} {:s}'.format(timestr, ' '.join(['%f' % b for b in new_energies])))
     energies = vstack( [energies, new_energies] )
     total_frames += read
     if read < hop_s: break
 
 if 1:
-    print "done computing, now plotting"
+    print("done computing, now plotting")
     import matplotlib.pyplot as plt
     from demo_waveform_plot import get_waveform_plot
     from demo_waveform_plot import set_xlabels_sample2time
--- a/python/demos/demo_mfcc.py
+++ b/python/demos/demo_mfcc.py
@@ -5,13 +5,13 @@
 from numpy import vstack, zeros
 
 win_s = 512                 # fft size
-hop_s = win_s / 4           # hop size
+hop_s = win_s // 4          # hop size
 n_filters = 40              # must be 40 for mfcc
 n_coeffs = 13
 samplerate = 44100
 
 if len(sys.argv) < 2:
-    print "Usage: %s <source_filename>" % sys.argv[0]
+    print("Usage: %s <source_filename>" % sys.argv[0])
     sys.exit(1)
 
 source_filename = sys.argv[1]
--- a/python/demos/demo_onset.py
+++ b/python/demos/demo_onset.py
@@ -4,10 +4,10 @@
 from aubio import source, onset
 
 win_s = 512                 # fft size
-hop_s = win_s / 2           # hop size
+hop_s = win_s // 2          # hop size
 
 if len(sys.argv) < 2:
-    print "Usage: %s <filename> [samplerate]" % sys.argv[0]
+    print("Usage: %s <filename> [samplerate]" % sys.argv[0])
     sys.exit(1)
 
 filename = sys.argv[1]
@@ -28,7 +28,7 @@
 while True:
     samples, read = s()
     if o(samples):
-        print "%f" % o.get_last_s()
+        print("%f" % o.get_last_s())
         onsets.append(o.get_last())
     total_frames += read
     if read < hop_s: break
--- a/python/demos/demo_onset_plot.py
+++ b/python/demos/demo_onset_plot.py
@@ -5,10 +5,10 @@
 from numpy import hstack, zeros
 
 win_s = 512                 # fft size
-hop_s = win_s / 2           # hop size
+hop_s = win_s // 2          # hop size
 
 if len(sys.argv) < 2:
-    print "Usage: %s <filename> [samplerate]" % sys.argv[0]
+    print("Usage: %s <filename> [samplerate]" % sys.argv[0])
     sys.exit(1)
 
 filename = sys.argv[1]
@@ -34,10 +34,10 @@
 while True:
     samples, read = s()
     if o(samples):
-        print "%f" % (o.get_last_s())
+        print("%f" % (o.get_last_s()))
         onsets.append(o.get_last())
     # keep some data to plot it later
-    new_maxes = (abs(samples.reshape(hop_s/downsample, downsample))).max(axis=0)
+    new_maxes = (abs(samples.reshape(hop_s//downsample, downsample))).max(axis=0)
     allsamples_max = hstack([allsamples_max, new_maxes])
     desc.append(o.get_descriptor())
     tdesc.append(o.get_thresholded_descriptor())
@@ -61,9 +61,10 @@
     plt1.xaxis.set_visible(False)
     plt1.yaxis.set_visible(False)
     desc_times = [ float(t) * hop_s / samplerate for t in range(len(desc)) ]
-    desc_plot = [d / max(desc) for d in desc]
+    desc_max = max(desc) if max(desc) != 0 else 1.
+    desc_plot = [d / desc_max for d in desc]
     plt2.plot(desc_times, desc_plot, '-g')
-    tdesc_plot = [d / max(desc) for d in tdesc]
+    tdesc_plot = [d / desc_max for d in tdesc]
     for stamp in onsets:
         stamp /= float(samplerate)
         plt2.plot([stamp, stamp], [min(tdesc_plot), max(desc_plot)], '-r')
--- a/python/demos/demo_pitch.py
+++ b/python/demos/demo_pitch.py
@@ -4,17 +4,17 @@
 from aubio import source, pitch
 
 if len(sys.argv) < 2:
-    print "Usage: %s <filename> [samplerate]" % sys.argv[0]
+    print("Usage: %s <filename> [samplerate]" % sys.argv[0])
     sys.exit(1)
 
 filename = sys.argv[1]
 
 downsample = 1
-samplerate = 44100 / downsample
+samplerate = 44100 // downsample
 if len( sys.argv ) > 2: samplerate = int(sys.argv[2])
 
-win_s = 4096 / downsample # fft size
-hop_s = 512  / downsample # hop size
+win_s = 4096 // downsample # fft size
+hop_s = 512  // downsample # hop size
 
 s = source(filename, samplerate, hop_s)
 samplerate = s.samplerate
@@ -36,7 +36,7 @@
     #pitch = int(round(pitch))
     confidence = pitch_o.get_confidence()
     #if confidence < 0.8: pitch = 0.
-    #print "%f %f %f" % (total_frames / float(samplerate), pitch, confidence)
+    print("%f %f %f" % (total_frames / float(samplerate), pitch, confidence))
     pitches += [pitch]
     confidences += [confidence]
     total_frames += read
--- a/python/demos/demo_pitch_sinusoid.py
+++ b/python/demos/demo_pitch_sinusoid.py
@@ -22,7 +22,7 @@
 sin_length = (samplerate * 10) % 512 * 512
 freqs = np.zeros(sin_length)
 
-partition = sin_length / 8
+partition = sin_length // 8
 pointer = 0
 
 pointer += partition
@@ -44,9 +44,10 @@
 for method in methods:
     p = aubio.pitch(method, buf_size, hop_size, samplerate)
     cands[method] = run_pitch(p, a)
-    print cands[method]
+    print(method)
+    print(cands[method])
 
-print "done computing"
+print("done computing")
 
 if 1:
     import matplotlib.pyplot as plt
--- a/python/demos/demo_pysoundcard_record.py
+++ b/python/demos/demo_pysoundcard_record.py
@@ -10,7 +10,6 @@
     duration = 5 # in seconds
     s = Stream(blocksize = hop_size, channels = 1)
     g = sink(sink_path, samplerate = int(s.samplerate))
-    print s.channels
 
     s.start()
     total_frames = 0
@@ -22,7 +21,8 @@
             g(mono_vec, hop_size)
             total_frames += hop_size
     except KeyboardInterrupt:
-        print "stopped after", "%.2f seconds" % (total_frames / s.samplerate)
+        duration = total_frames / float(s.samplerate)
+        print("stopped after %.2f seconds" % duration)
     s.stop()
 
 if __name__ == '__main__':
--- a/python/demos/demo_simple_robot_voice.py
+++ b/python/demos/demo_simple_robot_voice.py
@@ -5,7 +5,7 @@
 
 if __name__ == '__main__':
     if len(sys.argv) < 2:
-        print 'usage: %s <inputfile> <outputfile>' % sys.argv[0]
+        print('usage: %s <inputfile> <outputfile>' % sys.argv[0])
         sys.exit(1)
     samplerate = 44100
     f = source(sys.argv[1], samplerate, 256)
@@ -13,7 +13,7 @@
     total_frames, read = 0, 256
 
     win_s = 512                          # fft size
-    hop_s = win_s / 2                    # hop size
+    hop_s = win_s // 2                   # hop size
     pv = pvoc(win_s, hop_s)              # phase vocoder
 
     while read:
@@ -25,4 +25,5 @@
         g(new_samples, read)             # write to output
         total_frames += read
 
-    print "wrote", total_frames, "from", f.uri, "to", g.uri
+    format_str = "read {:d} samples from {:s}, written to {:s}"
+    print(format_str.format(total_frames, f.uri, g.uri))
--- a/python/demos/demo_simple_spectral_weighting.py
+++ b/python/demos/demo_simple_spectral_weighting.py
@@ -13,7 +13,7 @@
 
 if __name__ == '__main__':
     if len(sys.argv) < 2:
-        print 'usage: %s <inputfile> <outputfile>' % sys.argv[0]
+        print('usage: %s <inputfile> <outputfile>' % sys.argv[0])
         sys.exit(1)
     samplerate = 0 
     if len(sys.argv) > 3: samplerate = int(sys.argv[3])
@@ -22,7 +22,7 @@
     g = sink(sys.argv[2], samplerate)
 
     win_s = 512 # fft size
-    hop_s = win_s / 2 # hop size
+    hop_s = win_s // 2 # hop size
     pv = pvoc(win_s, hop_s) # phase vocoder
 
     # spectral weighting vector
@@ -30,7 +30,7 @@
         .8 * hanningz(80)[40:],
         zeros( 50 ),
         1.3 * hanningz(100),
-        zeros (win_s / 2 + 1 - 40 - 50 - 100),
+        zeros (win_s // 2 + 1 - 40 - 50 - 100),
         ] )
 
     if 0:
@@ -52,4 +52,5 @@
         g(new_samples, read)
         total_frames += read
 
-    print "read", total_frames / float(samplerate), "seconds from", f.uri
+    duration = total_frames / float(samplerate)
+    print("read {:.3f}s from {:s}".format(duration, f.uri))
--- a/python/demos/demo_sink.py
+++ b/python/demos/demo_sink.py
@@ -5,7 +5,7 @@
 
 if __name__ == '__main__':
     if len(sys.argv) < 3:
-        print 'usage: %s <inputfile> <outputfile> [samplerate] [hop_size]' % sys.argv[0]
+        print('usage: %s <inputfile> <outputfile> [samplerate] [hop_size]' % sys.argv[0])
         sys.exit(1)
 
     if len(sys.argv) > 3: samplerate = int(sys.argv[3])
@@ -22,8 +22,10 @@
         vec, read = f()
         g(vec, read)
         total_frames += read
-    print "wrote", "%.2fs" % (total_frames / float(samplerate) ),
-    print "(", total_frames, "frames", "in",
-    print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
-    print "from", f.uri,
-    print "to", g.uri
+    outstr = "wrote %.2fs" % (total_frames / float(samplerate))
+    outstr += " (%d frames in" % total_frames
+    outstr += " %d blocks" % (total_frames // f.hop_size)
+    outstr += " at %dHz)" % f.samplerate
+    outstr += " from " + f.uri
+    outstr += " to " + g.uri
+    print(outstr)
--- a/python/demos/demo_sink_create_woodblock.py
+++ b/python/demos/demo_sink_create_woodblock.py
@@ -2,11 +2,11 @@
 
 import sys
 from math import pi, e
-from aubio import sink
+from aubio import sink, float_type
 from numpy import arange, sin, exp, zeros
 
 if len(sys.argv) < 2:
-    print 'usage: %s <outputfile> [samplerate]' % sys.argv[0]
+    print('usage: %s <outputfile> [samplerate]' % sys.argv[0])
     sys.exit(1)
 
 samplerate = 44100 # samplerate in Hz
@@ -25,9 +25,9 @@
 period = float(samplerate) /  pitch
 # create a sine lookup table
 tablelen = 1000
-sinetable = arange(tablelen + 1, dtype = 'float32')
+sinetable = arange(tablelen + 1, dtype = float_type)
 sinetable = 0.7 * sin(twopi * sinetable/tablelen)
-sinetone = zeros((duration,), dtype = 'float32')
+sinetone = zeros((duration,), dtype = float_type)
 
 # compute sinetone at floating point period
 for i in range(duration):
@@ -39,7 +39,7 @@
     sinetone[i] = a + frac * (b -a)
 
 # apply some envelope
-float_ramp = arange(duration, dtype = 'float32')
+float_ramp = arange(duration, dtype = float_type)
 sinetone *= exp( - e * float_ramp / duration / decay)
 sinetone[:attack] *= exp( e * ( float_ramp[:attack] / attack - 1 ) )
 
--- a/python/demos/demo_sink_multi.py
+++ b/python/demos/demo_sink_multi.py
@@ -5,7 +5,7 @@
 
 if __name__ == '__main__':
     if len(sys.argv) < 3:
-        print 'usage: %s <inputfile> <outputfile> [samplerate] [hop_size]' % sys.argv[0]
+        print('usage: %s <inputfile> <outputfile> [samplerate] [hop_size]' % sys.argv[0])
         sys.exit(1)
 
     if len(sys.argv) > 3: samplerate = int(sys.argv[3])
@@ -22,10 +22,11 @@
         vec, read = f.do_multi()
         g.do_multi(vec, read)
         total_frames += read
-    print "wrote", "%.2fs" % (total_frames / float(samplerate) ),
-    print "(", total_frames, "frames", "in",
-    print total_frames / f.hop_size, "blocks",
-    print "of", f.channels, "channels",
-    print "at", "%dHz" % f.samplerate, ")",
-    print "from", f.uri,
-    print "to", g.uri
+    outstr = "wrote %.2fs" % (total_frames / float(samplerate))
+    outstr += " (%d frames in" % total_frames
+    outstr += " %d blocks" % (total_frames // f.hop_size)
+    outstr += " of %d channels" % f.channels
+    outstr += " at %dHz)" % f.samplerate
+    outstr += " from " + f.uri
+    outstr += " to " + g.uri
+    print(outstr)
--- a/python/demos/demo_slicing.py
+++ b/python/demos/demo_slicing.py
@@ -6,7 +6,7 @@
 
 if __name__ == '__main__':
     if len(sys.argv) < 3:
-        print 'usage: %s <inputfile> <duration>' % sys.argv[0]
+        print('usage: %s <inputfile> <duration>' % sys.argv[0])
         sys.exit(1)
     source_file = sys.argv[1]
     duration = float(sys.argv[2])
@@ -44,7 +44,8 @@
         total_frames_written += read
     total_duration = total_frames_written / float(samplerate)
     slice_n += 1
-    print 'created %(slice_n)s slices from %(source_base_name)s%(source_ext)s' % locals(),
-    print ' (total duration %(total_duration).2fs)' % locals()
+    outstr = 'created %(slice_n)s slices from %(source_base_name)s%(source_ext)s' % locals()
+    outstr += ' (total duration %(total_duration).2fs)' % locals()
+    print(outstr)
     # close source and sink files
     del f, g
--- a/python/demos/demo_source.py
+++ b/python/demos/demo_source.py
@@ -5,7 +5,7 @@
 
 if __name__ == '__main__':
     if len(sys.argv) < 2:
-        print 'usage: %s <inputfile> [samplerate] [hop_size]' % sys.argv[0]
+        print('usage: %s <inputfile> [samplerate] [hop_size]' % sys.argv[0])
         sys.exit(1)
     samplerate = 0
     hop_size = 256
@@ -20,7 +20,9 @@
         vec, read = f()
         total_frames += read
         if read < f.hop_size: break
-    print "read", "%.2fs" % (total_frames / float(samplerate) ),
-    print "(", total_frames, "frames", "in",
-    print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
-    print "from", f.uri
+    outstr = "read %.2fs" % (total_frames / float(samplerate))
+    outstr += " (%d frames in" % total_frames
+    outstr += " %d blocks" % (total_frames // f.hop_size)
+    outstr += " at %dHz)" % f.samplerate
+    outstr += " from " + f.uri
+    print(outstr)
--- a/python/demos/demo_specdesc.py
+++ b/python/demos/demo_specdesc.py
@@ -1,14 +1,14 @@
 #! /usr/bin/env python
 
 import sys
+import numpy as np
 from aubio import fvec, source, pvoc, specdesc
-from numpy import hstack
 
 win_s = 512                 # fft size
-hop_s = win_s / 4           # hop size
+hop_s = win_s // 4          # hop size
 
 if len(sys.argv) < 2:
-    print "Usage: %s <filename> [samplerate]" % sys.argv[0]
+    print("Usage: %s <filename> [samplerate]" % sys.argv[0])
     sys.exit(1)
 
 filename = sys.argv[1]
@@ -30,7 +30,7 @@
 
 for method in methods:
     cands = []
-    all_descs[method] = fvec(0)
+    all_descs[method] = np.array([])
     o[method] = specdesc(method, win_s)
 
 total_frames = 0
@@ -39,17 +39,17 @@
 while True:
     samples, read = s()
     fftgrain = pv(samples)
-    #print "%f" % ( total_frames / float(samplerate) ),
+    #outstr = "%f" % ( total_frames / float(samplerate) )
     for method in methods:
         specdesc_val = o[method](fftgrain)[0]
-        all_descs[method] = hstack ( [all_descs[method], specdesc_val] )
-        #print "%f" % specdesc_val,
-    #print
+        all_descs[method] = np.append(all_descs[method], specdesc_val)
+        #outstr += " %f" % specdesc_val
+    #print(outstr)
     total_frames += read
     if read < hop_s: break
 
 if 1:
-    print "done computing, now plotting"
+    print("done computing, now plotting")
     import matplotlib.pyplot as plt
     from demo_waveform_plot import get_waveform_plot
     from demo_waveform_plot import set_xlabels_sample2time
--- a/python/demos/demo_spectrogram.py
+++ b/python/demos/demo_spectrogram.py
@@ -1,19 +1,19 @@
 #! /usr/bin/env python
 
 import sys, os.path
-from aubio import pvoc, source
+from aubio import pvoc, source, float_type
 from numpy import zeros, log10, vstack
 import matplotlib.pyplot as plt
 
 def get_spectrogram(filename, samplerate = 0):
     win_s = 512                                        # fft window size
-    hop_s = win_s / 2                                  # hop size
-    fft_s = win_s / 2 + 1                              # spectrum bins
+    hop_s = win_s // 2                                 # hop size
+    fft_s = win_s // 2 + 1                             # spectrum bins
 
     a = source(filename, samplerate, hop_s)            # source file
     if samplerate == 0: samplerate = a.samplerate
     pv = pvoc(win_s, hop_s)                            # phase vocoder
-    specgram = zeros([0, fft_s], dtype='float32')      # numpy array to store spectrogram
+    specgram = zeros([0, fft_s], dtype=float_type)     # numpy array to store spectrogram
 
     # analysis
     while True:
@@ -28,8 +28,8 @@
     # show axes in Hz and seconds
     time_step = hop_s / float(samplerate)
     total_time = len(specgram) * time_step
-    print "total time: %0.2fs" % total_time,
-    print ", samplerate: %.2fkHz" % (samplerate / 1000.)
+    outstr = "total time: %0.2fs" % total_time
+    print(outstr + ", samplerate: %.2fkHz" % (samplerate / 1000.))
     n_xticks = 10
     n_yticks = 10
 
@@ -65,12 +65,12 @@
 
 if __name__ == '__main__':
     if len(sys.argv) < 2:
-        print "Usage: %s <filename>" % sys.argv[0]
+        print("Usage: %s <filename>" % sys.argv[0])
     else:
         for soundfile in sys.argv[1:]:
             fig = get_spectrogram(soundfile)
             # display graph
-            fig.show()
+            plt.show()
             #outimage = os.path.basename(soundfile) + '.png'
             #print ("writing: " + outimage)
             #plt.savefig(outimage)
--- a/python/demos/demo_tempo.py
+++ b/python/demos/demo_tempo.py
@@ -4,10 +4,10 @@
 from aubio import tempo, source
 
 win_s = 512                 # fft size
-hop_s = win_s / 2           # hop size
+hop_s = win_s // 2          # hop size
 
 if len(sys.argv) < 2:
-    print "Usage: %s <filename> [samplerate]" % sys.argv[0]
+    print("Usage: %s <filename> [samplerate]" % sys.argv[0])
     sys.exit(1)
 
 filename = sys.argv[1]
@@ -33,7 +33,7 @@
     is_beat = o(samples)
     if is_beat:
         this_beat = int(total_frames - delay + is_beat[0] * hop_s)
-        print "%f" % (this_beat / float(samplerate))
+        print("%f" % (this_beat / float(samplerate)))
         beats.append(this_beat)
     total_frames += read
     if read < hop_s: break
--- a/python/demos/demo_tempo_plot.py
+++ b/python/demos/demo_tempo_plot.py
@@ -4,10 +4,10 @@
 from aubio import tempo, source
 
 win_s = 512                 # fft size
-hop_s = win_s / 2           # hop size
+hop_s = win_s // 2          # hop size
 
 if len(sys.argv) < 2:
-    print "Usage: %s <filename> [samplerate]" % sys.argv[0]
+    print("Usage: %s <filename> [samplerate]" % sys.argv[0])
     sys.exit(1)
 
 filename = sys.argv[1]
@@ -42,8 +42,8 @@
     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'
-    print 'plotting', filename
+    print('mean period: %.2fbpm, median: %.2fbpm' % (mean(bpms), median(bpms)))
+    print('plotting %s' % filename)
     plt1 = plt.axes([0.1, 0.75, 0.8, 0.19])
     plt2 = plt.axes([0.1, 0.1, 0.8, 0.65], sharex = plt1)
     plt.rc('lines',linewidth='.8')
@@ -75,5 +75,5 @@
     plt.show()
 
 else:
-    print 'mean period:', "%.2f" % 0, 'bpm', 'median', "%.2f" % 0, 'bpm',
-    print 'nothing to plot, file too short?'
+    print('mean period: %.2fbpm, median: %.2fbpm' % (0, 0))
+    print('plotting %s' % filename)
--- a/python/demos/demo_tss.py
+++ b/python/demos/demo_tss.py
@@ -5,12 +5,12 @@
 
 if __name__ == '__main__':
     if len(sys.argv) < 2:
-        print 'usage: %s <inputfile> <outputfile_transient> <outputfile_steady>' % sys.argv[0]
+        print('usage: %s <inputfile> <outputfile_transient> <outputfile_steady>' % sys.argv[0])
         sys.exit(1)
 
     samplerate = 44100
-    win_s = 1024      # fft size
-    hop_s = win_s / 4 # block size
+    win_s = 1024       # fft size
+    hop_s = win_s // 4 # block size
     threshold = 0.5
 
     f = source(sys.argv[1], samplerate, hop_s)
--- a/python/demos/demo_waveform_plot.py
+++ b/python/demos/demo_waveform_plot.py
@@ -21,7 +21,7 @@
     while True:
         samples, read = a()
         # keep some data to plot it later
-        new_maxes = (abs(samples.reshape(hop_s/downsample, downsample))).max(axis=0)
+        new_maxes = (abs(samples.reshape(hop_s//downsample, downsample))).max(axis=0)
         allsamples_max = hstack([allsamples_max, new_maxes])
         total_frames += read
         if read < hop_s: break
@@ -48,7 +48,7 @@
 if __name__ == '__main__':
     import matplotlib.pyplot as plt
     if len(sys.argv) < 2:
-        print "Usage: %s <filename>" % sys.argv[0]
+        print("Usage: %s <filename>" % sys.argv[0])
     else:
         for soundfile in sys.argv[1:]:
             get_waveform_plot(soundfile)