diff options
author | John Glover <glover.john@gmail.com> | 2010-10-18 17:32:05 +0100 |
---|---|---|
committer | John Glover <glover.john@gmail.com> | 2010-10-18 17:32:05 +0100 |
commit | 30755b92afeae5a5a32860b4f4297180f6d3398d (patch) | |
tree | c9332a65adc6a27016678fccee6ce979d87fed07 /examples | |
parent | 58a7c36c5a219d8306f276db157097ac30782079 (diff) | |
download | simpl-30755b92afeae5a5a32860b4f4297180f6d3398d.tar.gz simpl-30755b92afeae5a5a32860b4f4297180f6d3398d.tar.bz2 simpl-30755b92afeae5a5a32860b4f4297180f6d3398d.zip |
Moved project over to Git
Diffstat (limited to 'examples')
-rw-r--r-- | examples/plotpartials.py | 38 | ||||
-rw-r--r-- | examples/plotpeaks.py | 35 | ||||
-rw-r--r-- | examples/timestretch.py | 45 |
3 files changed, 118 insertions, 0 deletions
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 |