summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-10-03 17:07:43 +0200
committerJohn Glover <j@johnglover.net>2012-10-03 17:07:43 +0200
commit12fe29417d68963b1e36bc37261f7f23beb5fbea (patch)
tree8f8500a31bdce0a59273962f04aca704c61ce8aa /examples
parentaa1a18cf13c5fe1e9d46fdcf562e855e043bbf4e (diff)
downloadsimpl-12fe29417d68963b1e36bc37261f7f23beb5fbea.tar.gz
simpl-12fe29417d68963b1e36bc37261f7f23beb5fbea.tar.bz2
simpl-12fe29417d68963b1e36bc37261f7f23beb5fbea.zip
[examples] Add pitch shifting example.
Diffstat (limited to 'examples')
-rw-r--r--examples/pitchshift.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/pitchshift.py b/examples/pitchshift.py
new file mode 100644
index 0000000..df27c7e
--- /dev/null
+++ b/examples/pitchshift.py
@@ -0,0 +1,39 @@
+import sys
+import math
+import numpy as np
+import scipy.io.wavfile as wav
+import simpl
+
+usage = 'Usage: python {0} '.format(__file__) + \
+ '<input wav file> <pitch shift amount> <output wav file>'
+
+if len(sys.argv) != 4:
+ print usage
+ sys.exit(1)
+
+audio, sampling_rate = simpl.read_wav(sys.argv[1])
+pitch_shift_amount = float(sys.argv[2])
+output_file = sys.argv[3]
+
+pd = simpl.LorisPeakDetection()
+frames = pd.find_peaks(audio)
+pt = simpl.SMSPartialTracking()
+frames = pt.find_partials(frames)
+
+twelfth_root_2 = math.pow(2.0, 1.0 / 12)
+freq_scale = math.pow(twelfth_root_2, pitch_shift_amount)
+
+for frame in frames:
+ partials = frame.partials
+ for p in partials:
+ p.frequency *= freq_scale
+ frame.partials = partials
+
+synth = simpl.SndObjSynthesis()
+harm_synth = synth.synth(frames)
+r = simpl.SMSResidual()
+res_synth = r.synth(audio)
+
+audio_out = harm_synth + res_synth
+audio_out = np.asarray(audio_out * 32768, np.int16)
+wav.write(output_file, sampling_rate, audio_out)