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