public
Last active

Vibrato in PCM audio (fixed!)

  • Download Gist
vibrato.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#-*- coding: utf8 -*-
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
 
gi=n.array( ii * fi * (Dv/float(fa) ) , n.int ) % Dv # indexes of the sound itself in the LUT
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.