-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpitch_shift.m
31 lines (26 loc) · 962 Bytes
/
pitch_shift.m
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
29
30
function [yOut] = pitch_shift(yIn,NH)
% PITCH_SHIFT Shift pitch of sound yIn by 'NH' half-steps
% Each interval will be approximated by multiplying by
% 2^(1/12) per half-step, as on a real fretted instrument
% requires: pvoc_files to be in working directory
shfactor = 2^(NH*1/12);
tsaudio = pvoc(yIn,1/shfactor);
[N1,D1] = rat(1/shfactor); % approximate 1/shfactor to a rational number
yOut = resample(tsaudio,N1,D1);
% pitch shift may shorten file length: zero pad end of vector.
if(length(yOut) < length(yIn))
yOut = padarray(yOut,[length(yIn)-length(yOut),0],'post');
end
end
%{
Pitch shifting code provided by D.P.W. Ellis of Columbia University
This phase vocoder is an open-source implementation of the algorithm
by Flanagan & Golden/Dolson
@misc{Ellis02-pvoc
author = {D. P. W. Ellis},
year = {2002},
title = {A Phase Vocoder in {M}atlab},
note = {Web resource},
url = {http://www.ee.columbia.edu/~dpwe/resources/matlab/pvoc/},
}
%}