Created
October 2, 2012 02:02
-
-
Save ttm/3815747 to your computer and use it in GitHub Desktop.
Vibrato in PCM audio (fixed!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf8 -*- | |
#FIXED!!! | |
import numpy as n, pylab as p, scikits.audiolab as a | |
fa=44100 # sample rate | |
Dv=2048 # length of the table | |
fv=6. # vibrato frequency | |
nu=.2 # depth in semitones | |
f=440. # freq of the sound itself | |
x=n.linspace(0,2*n.pi,Dv,endpoint=False) | |
tabv=n.sin(x) # sin table | |
ii=n.arange(fa * 2) # 2 seconds | |
gv=n.array(ii*fv*float(Dv)/fa, n.int) # indexes of the vibrato pattern | |
tv=tabv[gv%Dv]*nu # instant semitones deviation for each PCM sample | |
fi=f*( 2.**( tv/12. ) ) # instant freq in Hz of the sound | |
dD=fi*(Dv/float(fa)) | |
gi=n.cumsum(dD,0,n.int)%Dv | |
ti=tabv[gi] | |
a.wavwrite(ti,"vibrato.wav",fa) | |
ff=n.ones(ii.shape[0])*f | |
gi=n.array( ii * (Dv/float(fa)) * ff , n.int ) % Dv | |
t=tabv[ gi ] | |
a.wavwrite(t,"original.wav",fa) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment