Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[7c7a96]: demos / demo_blockproc_pitchshift.m Maximize Restore History

Download this file

demo_blockproc_pitchshift.m    79 lines (61 with data), 1.9 kB

 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function demo_blockproc_pitchshift(source,varargin)
%DEMO_BLOCKPROC_PITCHSHIFT Pitch shift by Gabor coefficient bands shift
% Usage: demo_blockproc_pitchshift('gspi.wav')
%
% For additional help call |demo_blockproc_pitchshift| without arguments.
%
% This script demonstrates a real-time Gabor coefficient manipulation.
% Frequency bands are shifted up or down according to the slider
% position.
%
if demo_blockproc_header(mfilename,nargin)
return;
end
M = 1000;
fobj = blockfigure();
% Basic Control pannel (Java object)
parg = {
{'GdB','Gain',-20,20,0,21},...
{'Shi','Shift',-200,200,0,401}
};
p = blockpanel(parg);
bufLen = 1024;
% Setup blocktream
fs=block(source,varargin{:},'loadind',p,'L',bufLen);
% Window length in ms
winLenms = 20;
[F,Fdual] = framepair('dgtreal',{'hann',floor(fs*winLenms/1e3)},'dual',128,M);
[Fa,Fs] = blockframepairaccel(F,Fdual, bufLen,'segola');
flag = 1;
%Loop until end of the stream (flag) and until panel is opened
while flag && p.flag
gain = blockpanelget(p,'GdB');
gain = 10.^(gain/20);
shift = fix(blockpanelget(p,'Shi'));
% Read block of data
[f,flag] = blockread();
% Apply gain
f=f*gain;
% Obtain DGT coefficients
c = blockana(Fa, f);
% Do the actual coefficient shift
cc = Fa.coef2native(c,size(c));
if(strcmpi(source,'playrec'))
% Hum removal (aka low-pass filter)
cc(1:2,:,:) = 0;
end
if shift<0
cc = [cc(-shift+1:end,:,:); zeros(-shift,size(cc,2),size(cc,3))];
else
cc = [zeros(shift,size(cc,2),size(cc,3)); cc(1:end-shift,:,:)];
end
c = Fa.native2coef(cc);
% Plot the transposed coefficients
blockplot(fobj,Fa,c(:,1));
% Reconstruct from the modified coefficients
fhat = blocksyn(Fs, c, size(f,1));
% Enqueue to be played
blockplay(fhat);
end
% Clear and close all
blockdone(p,fobj);