From 30755b92afeae5a5a32860b4f4297180f6d3398d Mon Sep 17 00:00:00 2001
From: John Glover <glover.john@gmail.com>
Date: Mon, 18 Oct 2010 17:32:05 +0100
Subject: Moved project over to Git

---
 examples/plotpartials.py | 38 ++++++++++++++++++++++++++++++++++++++
 examples/plotpeaks.py    | 35 +++++++++++++++++++++++++++++++++++
 examples/timestretch.py  | 45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+)
 create mode 100644 examples/plotpartials.py
 create mode 100644 examples/plotpeaks.py
 create mode 100644 examples/timestretch.py

(limited to 'examples')

diff --git a/examples/plotpartials.py b/examples/plotpartials.py
new file mode 100644
index 0000000..64974d5
--- /dev/null
+++ b/examples/plotpartials.py
@@ -0,0 +1,38 @@
+# Copyright (c) 2009 John Glover, National University of Ireland, Maynooth
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of 
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import simpl
+import simpl.plot
+import numpy as np
+from scipy.io.wavfile import read
+
+input_file = '../test/audio/flute.wav'
+audio_in_data = read(input_file)
+audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0  # values between -1 and 1
+sample_rate = audio_in_data[0]
+
+# take just the first few frames
+audio = audio_in[0:4096]
+# Peak detection and partial tracking using SMS
+pd = simpl.SMSPeakDetection()
+pd.max_peaks = 20
+pd.hop_size = 147
+peaks = pd.find_peaks(audio)
+pt = simpl.MQPartialTracking()
+pt.max_partials = 20
+partials = pt.find_partials(peaks)
+simpl.plot.plot_partials(partials)
+simpl.plot.show()
diff --git a/examples/plotpeaks.py b/examples/plotpeaks.py
new file mode 100644
index 0000000..200b803
--- /dev/null
+++ b/examples/plotpeaks.py
@@ -0,0 +1,35 @@
+# Copyright (c) 2009 John Glover, National University of Ireland, Maynooth
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of 
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import simpl
+import simpl.plot
+import numpy as np
+from scipy.io.wavfile import read
+
+input_file = '../test/audio/flute.wav'
+audio_in_data = read(input_file)
+audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0  # values between -1 and 1
+sample_rate = audio_in_data[0]
+
+# take just the first few frames
+audio = audio_in[0:4096]
+# peak detection using the SndObj library
+pd = simpl.SndObjPeakDetection()
+pd.max_peaks = 20
+peaks = pd.find_peaks(audio)
+# plot peaks using matplotlib
+simpl.plot.plot_peaks(peaks)
+simpl.plot.show()
diff --git a/examples/timestretch.py b/examples/timestretch.py
new file mode 100644
index 0000000..874b567
--- /dev/null
+++ b/examples/timestretch.py
@@ -0,0 +1,45 @@
+# Copyright (c) 2009 John Glover, National University of Ireland, Maynooth
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of 
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+from simpl import SndObjPeakDetection, SndObjPartialTracking, SndObjSynthesis
+from simpl.fx import time_stretch
+from scipy.io.wavfile import read, write
+import numpy as np
+import time
+
+input_file = '../test/audio/sinechirpsine.wav'
+output_file = 'scs_2x_sndobj.wav'
+time_stretch_factor = 2
+
+start_time = time.time()
+audio_in_data = read(input_file)
+audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0  # values between -1 and 1
+sample_rate = audio_in_data[0]
+
+print "Time stretching", input_file, "by a factor of", time_stretch_factor
+pd = SndObjPeakDetection()
+pd.max_peaks = 100
+peaks = pd.find_peaks(audio_in)
+pt = SndObjPartialTracking()
+pt.max_partials = 10
+partials = pt.find_partials(peaks)
+partials = time_stretch(partials, time_stretch_factor)
+sndobj_synth = SndObjSynthesis()
+audio_out = sndobj_synth.synth(partials)
+audio_out = np.asarray(audio_out * 32768, np.int16)
+print "Execution time:", time.time() - start_time, "seconds"
+print "Writing output to", output_file
+write(output_file, 44100, audio_out)
\ No newline at end of file
-- 
cgit v1.2.3