Dawn@4: function [F0, V] = func_StraightPitch(y, Fs, variables, textgridfile) Dawn@4: % [F0, V] = func_StraightPitch(y, Fs, variables, textgridfile) Dawn@4: % Input: y, Fs - from wavread Dawn@4: % variables - settings Dawn@4: % textgridfile - this is optional Dawn@4: % Output: F0, V - F0 and voicing vectors Dawn@4: % Notes: This function calls the Straight functions. Using textgrid Dawn@4: % segmentation helps to speed up the processing. Dawn@4: % Dawn@4: % Author: Yen-Liang Shue, Speech Processing and Auditory Perception Laboratory, UCLA Dawn@4: % Copyright UCLA SPAPL 2009 Dawn@4: Dawn@4: maxF0 = variables.maxstrF0; Dawn@4: minF0 = variables.minstrF0; Dawn@4: maxdur = variables.maxstrdur; Dawn@4: Dawn@4: prmF0in.DisplayPlots = 0; Dawn@4: prmF0in.ThresholdForVUV = 0.1; Dawn@4: prmF0in.ThresholdForSilence = 1; Dawn@4: prmF0in.F0searchLowerBound = minF0; Dawn@4: prmF0in.F0searchUpperBound = maxF0; Dawn@4: %prmF0in.VUVthresholdofAC1 = 0.9000; Dawn@4: Dawn@4: warning off Dawn@4: Dawn@4: % break up the file if it is too big (i.e. > 15sec) Dawn@4: if (nargin == 3) % do the whole file, no textgrid data available Dawn@4: L = floor(length(y)/Fs * 1000) - 1; Dawn@4: F0 = zeros(L, 1); Dawn@4: Dawn@4: if (length(y) / Fs > maxdur) Dawn@4: % find suitable places to chop Dawn@4: cnt = 1; Dawn@4: startx = 1; Dawn@4: endx = startx + floor(maxdur*Fs); Dawn@4: isgood = 1; Dawn@4: Dawn@4: while(startx < length(y)) Dawn@4: if (startx == 1) Dawn@4: yseg = y(startx : endx); % extra millisecond Dawn@4: else Dawn@4: yseg = y(startx - floor(F0 / 1000) - 10 : endx); % extra millisecond Dawn@4: end Dawn@4: %fprintf('Processing segment %d to %d\n', startx, endx); Dawn@4: Dawn@4: try Dawn@4: [F0seg, V, auxouts, prmF0out] = MulticueF0v14(yseg,Fs,prmF0in); Dawn@4: catch Dawn@4: isgood = 0; Dawn@4: break; Dawn@4: end Dawn@4: Dawn@4: F0(cnt:cnt+length(F0seg)-1) = F0seg; Dawn@4: cnt = cnt + length(F0seg); Dawn@4: startx = endx + 1; Dawn@4: Dawn@4: remainder = length(y) - endx - 1; Dawn@4: if (remainder > maxdur*Fs) Dawn@4: endx = startx + floor(maxdur*Fs); Dawn@4: else Dawn@4: endx = length(y); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: if (~isgood) % multicue failed Dawn@4: fprintf('Multicue failed: switching to exstraightsource\n'); Dawn@4: F0 = exstraightsource(y,Fs,prmF0in); Dawn@4: F0 = F0(1:L)'; Dawn@4: V = ones(size(F0seg)); Dawn@4: end Dawn@4: Dawn@4: else Dawn@4: try Dawn@4: [F0, V, auxouts, prmF0out] = MulticueF0v14(y,Fs,prmF0in); Dawn@4: catch Dawn@4: fprintf('Multicue failed: switching to exstraightsource\n'); Dawn@4: F0 = exstraightsource(y,Fs, prmF0in); Dawn@4: F0 = F0(1:L)'; Dawn@4: V = ones(size(F0)); Dawn@4: end Dawn@4: end Dawn@4: else % use textgrid data Dawn@4: % get the labels to ignore from the settings Dawn@4: tbuffer = variables.tbuffer; Dawn@4: ignorelabels = textscan(variables.TextgridIgnoreList, '%s', 'delimiter', ','); Dawn@4: ignorelabels = ignorelabels{1}; Dawn@4: Dawn@4: [labels, start, stop] = func_readTextgrid(textgridfile); Dawn@4: Dawn@4: labels_tmp = []; Dawn@4: start_tmp = []; Dawn@4: stop_tmp = []; Dawn@4: Dawn@4: for k=1:length(variables.TextgridTierNumber) Dawn@4: inx = variables.TextgridTierNumber(k); Dawn@4: if (inx <= length(labels)) Dawn@4: labels_tmp = [labels_tmp; labels{inx}]; Dawn@4: start_tmp = [start_tmp; start{inx}]; Dawn@4: stop_tmp = [stop_tmp; stop{inx}]; Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: labels = labels_tmp; Dawn@4: start = start_tmp * 1000; % milliseconds Dawn@4: stop = stop_tmp * 1000; % milliseconds Dawn@4: Dawn@4: L = floor(length(y) / Fs * 1000) - 1; Dawn@4: Dawn@4: F0 = zeros(L, 1) * NaN; Dawn@4: V = zeros(L, 1) * NaN; Dawn@4: Dawn@4: for k=1:length(start) Dawn@4: Dawn@4: switch(labels{k}) Dawn@4: case ignorelabels Dawn@4: continue; % skip anything that is within the ignore list Dawn@4: end Dawn@4: Dawn@4: tstart = start(k) - tbuffer; Dawn@4: tstop = stop(k) + tbuffer; Dawn@4: Dawn@4: sstart = floor(tstart / 1000 * Fs); Dawn@4: sstop = ceil(tstop / 1000 * Fs); Dawn@4: Dawn@4: sstart(sstart <= 0) = 1; Dawn@4: sstop(sstop > length(y)) = length(y); Dawn@4: Dawn@4: yseg = y(sstart:sstop); Dawn@4: Dawn@4: try Dawn@4: [F0seg, Vseg, auxouts, prmF0out] = MulticueF0v14(yseg,Fs,prmF0in); Dawn@4: catch Dawn@4: fprintf('Multicue failed: switching to exstraightsource\n'); Dawn@4: F0seg = exstraightsource(yseg,Fs,prmF0in); Dawn@4: F0seg = F0seg(2:end-1)'; Dawn@4: Vseg = ones(size(F0seg)); Dawn@4: end Dawn@4: Dawn@4: tstart = floor(tstart); Dawn@4: tstart(tstart <= 0) = 1; Dawn@4: F0(tstart:tstart+length(F0seg)-1) = F0seg; Dawn@4: V(tstart:tstart+length(Vseg)-1) = Vseg; Dawn@4: Dawn@4: if (length(F0) > L) Dawn@4: F0 = F0(1:L); Dawn@4: end Dawn@4: Dawn@4: end Dawn@4: Dawn@4: end Dawn@4: Dawn@4: % sometimes Straight outputs 0s for F0 Dawn@4: F0(F0 == 0) = NaN;