From e11640ebce01e39b4a900c5c29acd401cda4f77f Mon Sep 17 00:00:00 2001 From: John Glover Date: Thu, 23 Aug 2012 18:28:47 +0100 Subject: [examples] Move examples to top level. Update examples so file paths can be specified on the command line. --- examples/plotpartials.py | 19 +++++++++++++++++++ examples/plotpeaks.py | 22 ++++++++++++++++++++++ examples/residual.py | 17 +++++++++++++++++ examples/resynth.py | 21 +++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 examples/plotpartials.py create mode 100644 examples/plotpeaks.py create mode 100644 examples/residual.py create mode 100644 examples/resynth.py (limited to 'examples') diff --git a/examples/plotpartials.py b/examples/plotpartials.py new file mode 100644 index 0000000..65017b0 --- /dev/null +++ b/examples/plotpartials.py @@ -0,0 +1,19 @@ +import sys +import matplotlib.pyplot as plt +import simpl + +usage = 'Usage: python {0} '.format(__file__) +if len(sys.argv) != 2: + print usage + sys.exit(1) + +audio = simpl.read_wav(sys.argv[1])[0] + +pd = simpl.LorisPeakDetection() +pd.max_peaks = 30 +peaks = pd.find_peaks(audio) +pt = simpl.MQPartialTracking() +pt.max_partials = 30 +partials = pt.find_partials(peaks) +simpl.plot_partials(partials, show_peaks=False) +plt.show() diff --git a/examples/plotpeaks.py b/examples/plotpeaks.py new file mode 100644 index 0000000..ef2a1a4 --- /dev/null +++ b/examples/plotpeaks.py @@ -0,0 +1,22 @@ +import sys +import simpl +import matplotlib.pyplot as plt + +usage = 'Usage: python {0} '.format(__file__) +if len(sys.argv) != 2: + print usage + sys.exit(1) + +audio = simpl.read_wav(sys.argv[1])[0] + +# take just a few frames +audio = audio[len(audio) / 2:(len(audio) / 2) + 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) +plt.show() diff --git a/examples/residual.py b/examples/residual.py new file mode 100644 index 0000000..cd41dd4 --- /dev/null +++ b/examples/residual.py @@ -0,0 +1,17 @@ +import sys +import numpy as np +import scipy.io.wavfile as wav +import simpl + +usage = 'Usage: python {0} '.format(__file__) +if len(sys.argv) != 3: + print usage + sys.exit(1) + +audio = simpl.read_wav(sys.argv[1])[0] +output_file = sys.argv[2] + +r = simpl.SMSResidual() +audio_out = r.synth(audio) +audio_out = np.asarray(audio_out * 32768, np.int16) +wav.write(output_file, 44100, audio_out) diff --git a/examples/resynth.py b/examples/resynth.py new file mode 100644 index 0000000..99d6e39 --- /dev/null +++ b/examples/resynth.py @@ -0,0 +1,21 @@ +import sys +import numpy as np +import scipy.io.wavfile as wav +import simpl + +usage = 'Usage: python {0} '.format(__file__) +if len(sys.argv) != 3: + print usage + sys.exit(1) + +audio = simpl.read_wav(sys.argv[1])[0] +output_file = sys.argv[2] + +pd = simpl.LorisPeakDetection() +peaks = pd.find_peaks(audio) +pt = simpl.SMSPartialTracking() +partials = pt.find_partials(peaks) +synth = simpl.LorisSynthesis() +audio_out = synth.synth(partials) +audio_out = np.asarray(audio_out * 32768, np.int16) +wav.write(output_file, 44100, audio_out) -- cgit v1.2.3