1 | function y = pvoc(x, r, n)
|
---|
2 | % y = pvoc(x, r, n) Time-scale a signal to r times faster with phase vocoder
|
---|
3 | % x is an input sound. n is the FFT size, defaults to 1024.
|
---|
4 | % Calculate the 25%-overlapped STFT, squeeze it by a factor of r,
|
---|
5 | % inverse spegram.
|
---|
6 | % 2000-12-05, 2002-02-13 dpwe@ee.columbia.edu. Uses pvsample, stft, istft
|
---|
7 | % $Header: /home/empire6/dpwe/public_html/resources/matlab/pvoc/RCS/pvoc.m,v 1.3 2011/02/08 21:08:39 dpwe Exp $
|
---|
8 |
|
---|
9 | if nargin < 3
|
---|
10 | n = 1024;
|
---|
11 | end
|
---|
12 |
|
---|
13 | % With hann windowing on both input and output,
|
---|
14 | % we need 25% window overlap for smooth reconstruction
|
---|
15 | hop = n/4;
|
---|
16 | % Effect of hanns at both ends is a cumulated cos^2 window (for
|
---|
17 | % r = 1 anyway); need to scale magnitudes by 2/3 for
|
---|
18 | % identity input/output
|
---|
19 | %scf = 2/3;
|
---|
20 | % 2011-02-07: this factor is now included in istft.m
|
---|
21 | scf = 1.0;
|
---|
22 |
|
---|
23 | % Calculate the basic STFT, magnitude scaled
|
---|
24 | X = scf * stft(x', n, n, hop);
|
---|
25 |
|
---|
26 | % Calculate the new timebase samples
|
---|
27 | [rows, cols] = size(X);
|
---|
28 | t = 0:r:(cols-2);
|
---|
29 | % Have to stay two cols off end because (a) counting from zero, and
|
---|
30 | % (b) need col n AND col n+1 to interpolate
|
---|
31 |
|
---|
32 | % Generate the new spectrogram
|
---|
33 | X2 = pvsample(X, t, hop);
|
---|
34 |
|
---|
35 | % Invert to a waveform
|
---|
36 | y = istft(X2, n, n, hop)';
|
---|