annotate Code/Descriptors/Matlab/MPEG7/FromWeb/VoiceSauce/func_StraightPitch.m @ 4:92ca03a8fa99 tip

Update to ICASSP 2013 benchmark
author Dawn Black
date Wed, 13 Feb 2013 11:02:39 +0000
parents
children
rev   line source
Dawn@4 1 function [F0, V] = func_StraightPitch(y, Fs, variables, textgridfile)
Dawn@4 2 % [F0, V] = func_StraightPitch(y, Fs, variables, textgridfile)
Dawn@4 3 % Input: y, Fs - from wavread
Dawn@4 4 % variables - settings
Dawn@4 5 % textgridfile - this is optional
Dawn@4 6 % Output: F0, V - F0 and voicing vectors
Dawn@4 7 % Notes: This function calls the Straight functions. Using textgrid
Dawn@4 8 % segmentation helps to speed up the processing.
Dawn@4 9 %
Dawn@4 10 % Author: Yen-Liang Shue, Speech Processing and Auditory Perception Laboratory, UCLA
Dawn@4 11 % Copyright UCLA SPAPL 2009
Dawn@4 12
Dawn@4 13 maxF0 = variables.maxstrF0;
Dawn@4 14 minF0 = variables.minstrF0;
Dawn@4 15 maxdur = variables.maxstrdur;
Dawn@4 16
Dawn@4 17 prmF0in.DisplayPlots = 0;
Dawn@4 18 prmF0in.ThresholdForVUV = 0.1;
Dawn@4 19 prmF0in.ThresholdForSilence = 1;
Dawn@4 20 prmF0in.F0searchLowerBound = minF0;
Dawn@4 21 prmF0in.F0searchUpperBound = maxF0;
Dawn@4 22 %prmF0in.VUVthresholdofAC1 = 0.9000;
Dawn@4 23
Dawn@4 24 warning off
Dawn@4 25
Dawn@4 26 % break up the file if it is too big (i.e. > 15sec)
Dawn@4 27 if (nargin == 3) % do the whole file, no textgrid data available
Dawn@4 28 L = floor(length(y)/Fs * 1000) - 1;
Dawn@4 29 F0 = zeros(L, 1);
Dawn@4 30
Dawn@4 31 if (length(y) / Fs > maxdur)
Dawn@4 32 % find suitable places to chop
Dawn@4 33 cnt = 1;
Dawn@4 34 startx = 1;
Dawn@4 35 endx = startx + floor(maxdur*Fs);
Dawn@4 36 isgood = 1;
Dawn@4 37
Dawn@4 38 while(startx < length(y))
Dawn@4 39 if (startx == 1)
Dawn@4 40 yseg = y(startx : endx); % extra millisecond
Dawn@4 41 else
Dawn@4 42 yseg = y(startx - floor(F0 / 1000) - 10 : endx); % extra millisecond
Dawn@4 43 end
Dawn@4 44 %fprintf('Processing segment %d to %d\n', startx, endx);
Dawn@4 45
Dawn@4 46 try
Dawn@4 47 [F0seg, V, auxouts, prmF0out] = MulticueF0v14(yseg,Fs,prmF0in);
Dawn@4 48 catch
Dawn@4 49 isgood = 0;
Dawn@4 50 break;
Dawn@4 51 end
Dawn@4 52
Dawn@4 53 F0(cnt:cnt+length(F0seg)-1) = F0seg;
Dawn@4 54 cnt = cnt + length(F0seg);
Dawn@4 55 startx = endx + 1;
Dawn@4 56
Dawn@4 57 remainder = length(y) - endx - 1;
Dawn@4 58 if (remainder > maxdur*Fs)
Dawn@4 59 endx = startx + floor(maxdur*Fs);
Dawn@4 60 else
Dawn@4 61 endx = length(y);
Dawn@4 62 end
Dawn@4 63 end
Dawn@4 64
Dawn@4 65 if (~isgood) % multicue failed
Dawn@4 66 fprintf('Multicue failed: switching to exstraightsource\n');
Dawn@4 67 F0 = exstraightsource(y,Fs,prmF0in);
Dawn@4 68 F0 = F0(1:L)';
Dawn@4 69 V = ones(size(F0seg));
Dawn@4 70 end
Dawn@4 71
Dawn@4 72 else
Dawn@4 73 try
Dawn@4 74 [F0, V, auxouts, prmF0out] = MulticueF0v14(y,Fs,prmF0in);
Dawn@4 75 catch
Dawn@4 76 fprintf('Multicue failed: switching to exstraightsource\n');
Dawn@4 77 F0 = exstraightsource(y,Fs, prmF0in);
Dawn@4 78 F0 = F0(1:L)';
Dawn@4 79 V = ones(size(F0));
Dawn@4 80 end
Dawn@4 81 end
Dawn@4 82 else % use textgrid data
Dawn@4 83 % get the labels to ignore from the settings
Dawn@4 84 tbuffer = variables.tbuffer;
Dawn@4 85 ignorelabels = textscan(variables.TextgridIgnoreList, '%s', 'delimiter', ',');
Dawn@4 86 ignorelabels = ignorelabels{1};
Dawn@4 87
Dawn@4 88 [labels, start, stop] = func_readTextgrid(textgridfile);
Dawn@4 89
Dawn@4 90 labels_tmp = [];
Dawn@4 91 start_tmp = [];
Dawn@4 92 stop_tmp = [];
Dawn@4 93
Dawn@4 94 for k=1:length(variables.TextgridTierNumber)
Dawn@4 95 inx = variables.TextgridTierNumber(k);
Dawn@4 96 if (inx <= length(labels))
Dawn@4 97 labels_tmp = [labels_tmp; labels{inx}];
Dawn@4 98 start_tmp = [start_tmp; start{inx}];
Dawn@4 99 stop_tmp = [stop_tmp; stop{inx}];
Dawn@4 100 end
Dawn@4 101 end
Dawn@4 102
Dawn@4 103 labels = labels_tmp;
Dawn@4 104 start = start_tmp * 1000; % milliseconds
Dawn@4 105 stop = stop_tmp * 1000; % milliseconds
Dawn@4 106
Dawn@4 107 L = floor(length(y) / Fs * 1000) - 1;
Dawn@4 108
Dawn@4 109 F0 = zeros(L, 1) * NaN;
Dawn@4 110 V = zeros(L, 1) * NaN;
Dawn@4 111
Dawn@4 112 for k=1:length(start)
Dawn@4 113
Dawn@4 114 switch(labels{k})
Dawn@4 115 case ignorelabels
Dawn@4 116 continue; % skip anything that is within the ignore list
Dawn@4 117 end
Dawn@4 118
Dawn@4 119 tstart = start(k) - tbuffer;
Dawn@4 120 tstop = stop(k) + tbuffer;
Dawn@4 121
Dawn@4 122 sstart = floor(tstart / 1000 * Fs);
Dawn@4 123 sstop = ceil(tstop / 1000 * Fs);
Dawn@4 124
Dawn@4 125 sstart(sstart <= 0) = 1;
Dawn@4 126 sstop(sstop > length(y)) = length(y);
Dawn@4 127
Dawn@4 128 yseg = y(sstart:sstop);
Dawn@4 129
Dawn@4 130 try
Dawn@4 131 [F0seg, Vseg, auxouts, prmF0out] = MulticueF0v14(yseg,Fs,prmF0in);
Dawn@4 132 catch
Dawn@4 133 fprintf('Multicue failed: switching to exstraightsource\n');
Dawn@4 134 F0seg = exstraightsource(yseg,Fs,prmF0in);
Dawn@4 135 F0seg = F0seg(2:end-1)';
Dawn@4 136 Vseg = ones(size(F0seg));
Dawn@4 137 end
Dawn@4 138
Dawn@4 139 tstart = floor(tstart);
Dawn@4 140 tstart(tstart <= 0) = 1;
Dawn@4 141 F0(tstart:tstart+length(F0seg)-1) = F0seg;
Dawn@4 142 V(tstart:tstart+length(Vseg)-1) = Vseg;
Dawn@4 143
Dawn@4 144 if (length(F0) > L)
Dawn@4 145 F0 = F0(1:L);
Dawn@4 146 end
Dawn@4 147
Dawn@4 148 end
Dawn@4 149
Dawn@4 150 end
Dawn@4 151
Dawn@4 152 % sometimes Straight outputs 0s for F0
Dawn@4 153 F0(F0 == 0) = NaN;