Index: python/demos/demo_beats_and_tempo.py
===================================================================
--- python/demos/demo_beats_and_tempo.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
+++ python/demos/demo_beats_and_tempo.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
@@ -0,0 +1,39 @@
+#! /usr/bin/env python
+
+import sys
+from aubio import tempo, source
+
+win_s = 512                 # fft size
+hop_s = win_s / 2           # hop size
+samplerate = 44100
+
+if len(sys.argv) < 2:
+    print "Usage: %s <filename>" % sys.argv[0]
+    sys.exit(1)
+
+filename = sys.argv[1]
+beats = []
+
+s = source(filename, samplerate, hop_s)
+t = tempo("default", win_s, hop_s)
+
+block_read = 0
+while True:
+    samples, read = s()
+    isbeat = t(samples)
+    if isbeat:
+        thisbeat = (block_read * hop_s + isbeat[0]) / samplerate
+        print "%.4f" % thisbeat
+        beats.append (thisbeat)
+    block_read += 1
+    if read < hop_s: break
+
+periods = [60./(b - a) for a,b in zip(beats[:-1],beats[1:])]
+
+from numpy import mean, median
+print 'mean period:', mean(periods), 'bpm'
+print 'median period:', median(periods), 'bpm'
+
+from pylab import plot, show
+plot(beats[1:], periods)
+show()
Index: python/demos/demo_onset_sinusoid.py
===================================================================
--- python/demos/demo_onset_sinusoid.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
+++ python/demos/demo_onset_sinusoid.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
@@ -0,0 +1,84 @@
+#! /usr/bin/env python
+
+from numpy import random, sin, arange, ones, zeros
+from math import pi
+from aubio import fvec, onset
+
+def build_sinusoid(length, freqs, samplerate):
+  return sin( 2. * pi * arange(length) * freqs / samplerate)
+
+def run_onset(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(o(f))
+  return cands
+
+methods = ['default',
+           'energy',
+           'complex',
+           'phase',
+           'specdiff',
+           'kl',
+           'mkl',
+           'specflux',
+           'centroid',
+           'spread',
+           'skewness',
+           'kurtosis',
+           'slope',
+           'decrease',
+           'rolloff',
+          ]
+
+cands = {}
+buf_size = 2048
+hop_size = 512
+samplerate = 44100
+sin_length = (samplerate * 10) % 512 * 512
+freqs = zeros(sin_length)
+
+partition = sin_length / 8
+pointer = 0
+
+pointer += partition
+freqs[pointer: pointer + partition] = 440
+
+pointer += partition
+pointer += partition
+freqs[ pointer : pointer + partition ] = 740
+
+pointer += partition
+freqs[ pointer : pointer + partition ] = 1480
+
+pointer += partition
+pointer += partition
+freqs[ pointer : pointer + partition ] = 400 + 5 * random.random(sin_length/8)
+
+a = build_sinusoid(sin_length, freqs, samplerate)
+
+for method in methods:
+  o = onset(method, buf_size, hop_size, samplerate)
+  cands[method] = run_onset(o, a)
+
+print "done computing"
+
+if 1:
+  from pylab import plot, show, xlabel, ylabel, legend, ylim, subplot
+  subplot (211)
+  legend(methods+['ground truth'], 'upper right')
+  xlabel('time (s)')
+  ylabel('amplitude')
+  ramp = arange(0, sin_length).astype('float') / samplerate
+  plot(ramp, a, ':')
+  subplot (212)
+  ramp = arange(0, sin_length / hop_size).astype('float') * hop_size / samplerate
+  for method in methods:
+    plot(ramp, cands[method],'.-')
+    legend(methods, 'upper right')
+    xlabel('time (s)')
+  ylabel('spectral descriptor value')
+  show()
+
Index: python/demos/demo_pitch_sinusoid.py
===================================================================
--- python/demos/demo_pitch_sinusoid.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
+++ python/demos/demo_pitch_sinusoid.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
@@ -0,0 +1,68 @@
+#! /usr/bin/env python
+
+from numpy import random, sin, arange, ones, zeros
+from math import pi
+from aubio import fvec, pitch
+
+def build_sinusoid(length, freqs, samplerate):
+  return sin( 2. * pi * arange(length) * freqs / samplerate)
+
+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))
+  return cands
+
+methods = ['default', 'schmitt', 'fcomb', 'mcomb', 'yin', 'yinfft']
+
+cands = {}
+buf_size = 2048
+hop_size = 512
+samplerate = 44100
+sin_length = (samplerate * 10) % 512 * 512
+freqs = zeros(sin_length)
+
+partition = sin_length / 8
+pointer = 0
+
+pointer += partition
+freqs[pointer: pointer + partition] = 440
+
+pointer += partition
+pointer += partition
+freqs[ pointer : pointer + partition ] = 740
+
+pointer += partition
+freqs[ pointer : pointer + partition ] = 1480
+
+pointer += partition
+pointer += partition
+freqs[ pointer : pointer + partition ] = 400 + 5 * random.random(sin_length/8)
+
+a = build_sinusoid(sin_length, freqs, samplerate)
+
+for method in methods:
+  p = pitch(method, buf_size, hop_size, samplerate)
+  cands[method] = run_pitch(p, a)
+
+print "done computing"
+
+if 1:
+  from pylab import plot, show, xlabel, ylabel, legend, ylim
+  ramp = arange(0, sin_length / hop_size).astype('float') * hop_size / samplerate
+  for method in methods:
+    plot(ramp, cands[method],'.-')
+
+  # plot ground truth
+  ramp = arange(0, sin_length).astype('float') / samplerate
+  plot(ramp, freqs, ':')
+
+  legend(methods+['ground truth'], 'upper right')
+  xlabel('time (s)')
+  ylabel('frequency (Hz)')
+  ylim([0,2000])
+  show()
+
Index: python/demos/demo_simple_robot_voice.py
===================================================================
--- python/demos/demo_simple_robot_voice.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
+++ python/demos/demo_simple_robot_voice.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
@@ -0,0 +1,29 @@
+#! /usr/bin/env python
+
+import sys
+from aubio import source, sink, pvoc
+
+if __name__ == '__main__':
+  if len(sys.argv) < 2:
+    print 'usage: %s <inputfile> <outputfile>' % sys.argv[0]
+    sys.exit(1)
+  samplerate = 44100
+  f = source(sys.argv[1], samplerate, 256)
+  g = sink(sys.argv[2], samplerate)
+  total_frames, read = 0, 256
+
+  win_s = 512                 # fft size
+  hop_s = win_s / 2           # hop size
+  pv = pvoc(win_s, hop_s)                            # phase vocoder
+
+  while read:
+    samples, read = f()
+    spectrum = pv(samples)            # compute spectrum
+    spectrum.phas[:] = 0.             # zero phase
+    new_samples = pv.rdo(spectrum)    # compute modified samples
+    g(new_samples, read)              # write to output
+    total_frames += read
+
+  print "wrote", total_frames, "from", f.uri, "to", g.uri
+
+  
Index: python/demos/demo_sink.py
===================================================================
--- python/demos/demo_sink.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
+++ python/demos/demo_sink.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
@@ -0,0 +1,17 @@
+#! /usr/bin/env python
+
+import sys
+from aubio import source, sink
+
+if __name__ == '__main__':
+  if len(sys.argv) < 3:
+    print 'usage: %s <inputfile> <outputfile>' % sys.argv[0]
+    sys.exit(1)
+  f = source(sys.argv[1], 8000, 256)
+  g = sink(sys.argv[2], 8000)
+  total_frames, read = 0, 256
+  while read:
+    vec, read = f()
+    g(vec, read)
+    total_frames += read
+  print "read", total_frames / float(f.samplerate), "seconds from", f.uri
Index: python/demos/demo_source.py
===================================================================
--- python/demos/demo_source.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
+++ python/demos/demo_source.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
@@ -0,0 +1,15 @@
+#! /usr/bin/env python
+
+import sys
+from aubio import source
+
+if __name__ == '__main__':
+  if len(sys.argv) < 2:
+    print 'usage: %s <inputfile>' % sys.argv[0]
+    sys.exit(1)
+  f = source(sys.argv[1], 8000, 256)
+  total_frames, read = 0, 256
+  while read:
+    vec, read = f()
+    total_frames += read
+  print "read", total_frames / float(f.samplerate), "seconds from", f.uri
Index: python/demos/demo_spectrogram.py
===================================================================
--- python/demos/demo_spectrogram.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
+++ python/demos/demo_spectrogram.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
@@ -0,0 +1,63 @@
+#! /usr/bin/env python
+
+import sys
+from aubio import pvoc, source
+from numpy import array, arange, zeros, shape, log10, vstack
+from pylab import imshow, show, cm, axis, ylabel, xlabel, xticks, yticks
+
+def get_spectrogram(filename):
+  samplerate = 44100
+  win_s = 512                                        # fft window size
+  hop_s = win_s / 2                                  # hop size
+  fft_s = win_s / 2 + 1                              # spectrum bins
+
+  a = source(filename, samplerate, hop_s)            # source file
+  pv = pvoc(win_s, hop_s)                            # phase vocoder
+  specgram = zeros([0, fft_s], dtype='float32')      # numpy array to store spectrogram
+
+  # analysis
+  while True:
+    samples, read = a()                              # read file
+    specgram = vstack((specgram,pv(samples).norm))   # store new norm vector
+    if read < a.hop_size: break
+
+  # plotting
+  imshow(log10(specgram.T + .001), origin = 'bottom', aspect = 'auto', cmap=cm.gray_r)
+  axis([0, len(specgram), 0, len(specgram[0])])
+  # 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.)
+  n_xticks = 10
+  n_yticks = 10
+
+  def get_rounded_ticks( top_pos, step, n_ticks ):
+      top_label = top_pos * step
+      # get the first label
+      ticks_first_label = top_pos * step / n_ticks
+      # round to the closest .1
+      ticks_first_label = round ( ticks_first_label * 10. ) / 10.
+      # compute all labels from the first rounded one
+      ticks_labels = [ ticks_first_label * n for n in range(n_ticks) ] + [ top_label ]
+      # get the corresponding positions
+      ticks_positions = [ ticks_labels[n] / step for n in range(n_ticks) ] + [ top_pos ]
+      # convert to string
+      ticks_labels = [  "%.1f" % x for x in ticks_labels ]
+      # return position, label tuple to use with x/yticks
+      return ticks_positions, ticks_labels
+
+  # apply to the axis
+  xticks( *get_rounded_ticks ( len(specgram), time_step, n_xticks ) )
+  yticks( *get_rounded_ticks ( len(specgram[0]), (samplerate / 2. / 1000.) / len(specgram[0]), n_yticks ) )
+  ylabel('Frequency (kHz)')
+  xlabel('Time (s)')
+
+if __name__ == '__main__':
+  if len(sys.argv) < 2:
+    print "Usage: %s <filename>" % sys.argv[0]
+  else:
+    for soundfile in sys.argv[1:]:
+      get_spectrogram(soundfile)
+      # display graph
+      show()
Index: python/demos/demo_tss.py
===================================================================
--- python/demos/demo_tss.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
+++ python/demos/demo_tss.py	(revision 26adcfb10b34d9673d5c6bbec5d97c925982bf53)
@@ -0,0 +1,47 @@
+#! /usr/bin/env python
+
+import sys
+from aubio import source, sink, pvoc, tss
+
+if __name__ == '__main__':
+  if len(sys.argv) < 2:
+    print 'usage: %s <inputfile> <outputfile_transient> <outputfile_steady>' % sys.argv[0]
+    sys.exit(1)
+
+  samplerate = 44100
+  win_s = 512                 # fft size
+  hop_s = win_s / 2           # block size
+  threshold = 0.26
+
+  f = source(sys.argv[1], samplerate, hop_s)
+  g = sink(sys.argv[2], samplerate)
+  h = sink(sys.argv[3], samplerate)
+
+  pv = pvoc(win_s, hop_s)     # phase vocoder
+  pw = pvoc(win_s, hop_s)     # another phase vocoder
+  t = tss(win_s, hop_s)       # transient steady state separation
+
+  t.set_threshold(threshold)
+
+  read = hop_s
+
+  while read:
+    samples, read = f()               # read file
+    spec = pv(samples)                # compute spectrum
+    trans_spec, stead_spec = t(spec)  # transient steady-state separation
+    transients = pv.rdo(trans_spec)   # overlap-add synthesis of transients
+    steadstate = pw.rdo(stead_spec)   # overlap-add synthesis of steady states
+    g(transients, read)               # write transients to output
+    h(steadstate, read)               # write steady states to output
+
+  del f, g, h                         # finish writing the files now
+
+  from demo_spectrogram import get_spectrogram
+  from pylab import subplot, show
+  subplot(311)
+  get_spectrogram(sys.argv[1])
+  subplot(312)
+  get_spectrogram(sys.argv[2])
+  subplot(313)
+  get_spectrogram(sys.argv[3])
+  show()
