www.pudn.com > LPCToolbox.rar > PKSFIG_CLICK.M


% [range,key] = getframes(snd, pks, oldrange) 
% 
%  Given the formant locations (F1,F2,F3) and bandwidths for 
%  a sequence of analysis frames, GETFRAMES allows the user to 
%  interactively select a range of frames.  
% 
%  uses global variables Ap & Cs (see SETPARAMS) 
% 
%   snd: the speech sound (a vector) 
% 
%   pks: Nx3x2 matrix (N = # of analysis frames in the sound) 
%        pks(i,:,1) are the formant peak locations (F1 F2 F3) for frame i 
%        pks(i,:,2) are the corresponding bandwidths (bw1 bw2 bw3) 
%        (see ANALYZESND for more details). 
% 
%   oldrange: vector giving the numbers of the frames selected 
%      previously (these are usually found by reading the existing .DAT 
%      file for the sound). This vector can be empty. 
% 
%   range  : 1xN vector, giving the numbers of the selected frames 
% 
%   key: most recent key/button pressed by the user 
% 
 
function pksfig_click 
global Ap Cs PFCvars Handle 
 
% this is a windowbtnup callback on Handle.pksfig 
 
%--- check if this is for a left mouse click 
 
clicktype = get(Handle.pksfig, 'SelectionType'); 
 
if strcmp(clicktype, 'normal') == 0, 
  % either 'extend' (middle btn) or 'alt' (right btn) 
  menuactions('nextsnd'); 
  return; 
end 
 
%--- get the click location & init globals is necessary 
 
if isempty(PFCvars) | (PFCvars.numclicks == 0), 
 PFCvars.lines = []; 
 PFCvars.numclicks = 0; 
 PFCvars.oldx = -1; 
end 
 
curaxis = get(Handle.pksfig, 'CurrentAxes'); 
point = get(curaxis, 'CurrentPoint'); 
point = round(point(1,1:2)); % x,y values 
curx = point(1); 
 
% make sure curx (in msec) lines up with a frame boundary 
pts_per_ms = Cs.Fs/1000;  
msec_per_frame = Ap.context_width / pts_per_ms; 
frameidx = round(curx*pts_per_ms/Ap.context_width) + 1;  
frameidx = max(frameidx, 1);          % lower bound 
frameidx = min(frameidx, Cs.nframes); % upper bound 
curx =  (frameidx-1)* msec_per_frame; 
if curx == PFCvars.oldx, 
  return; % ignore this click/keypress 
end 
 
firstline = (rem(PFCvars.numclicks,2) == 0); 
 
%----- 
pts_in_anaframe = Ap.analysis_width; 
pts_in_ctxframe = Ap.context_width; 
 
ax=get(Handle.wavaxis, 'Ylim'); 
smin = ax(1); smax = ax(2); 
 
ax=get(Handle.pksaxis, 'Ylim'); 
fmin = ax(1); fmax = ax(2); 
ax=get(Handle.pksaxis, 'Xlim'); 
frmin = ax(1); frmax = ax(2); 
%----- 
 
if (firstline) 
  Cs.framerange = []; 
 
  % delete the previous vertical lines if any 
  delete(PFCvars.lines);  
  PFCvars.lines = []; 
  PFCvars.oldx = curx; 
 
  axes(Handle.wavaxis); 
  PFCvars.lines(end+1) = plot([curx curx], [smin smax], 'w'); 
  axes(Handle.pksaxis); 
  PFCvars.lines(end+1) = plot([curx curx], [fmin fmax], 'w'); 
 
  set(Handle.pksfigtxt, 'string', ...   
      'Left-click to define other end of the region'); 
 
else % secondline 
 
 axes(Handle.wavaxis); 
 PFCvars.lines(end+1) = plot([curx curx], [smin smax], 'w'); 
 axes(Handle.pksaxis); 
 PFCvars.lines(end+1) = plot([curx curx], [fmin fmax], 'w'); 
 
 set(Handle.pksfigtxt, 'string', ...   
     'Right-click to confirm, or Left-click to redefine the region'); 
 
 l = min(PFCvars.oldx, curx); 
 r = max(PFCvars.oldx, curx); 
 
 % convert l & r from msec to frame indices 
 
 lframe = round((l*pts_per_ms)/Ap.context_width) + 1; 
 rframe = round((r*pts_per_ms)/Ap.context_width) + 1; 
  
 Cs.framerange = lframe:rframe; 
 xframes = Cs.pks(Cs.framerange, 1:3, 1); 
 means = floor(mean(xframes)); 
 
 axes(Handle.pksaxis); 
 h = plot([frmin frmax], [means(1) means(1)], ... 
          [frmin frmax], [means(2) means(2)], ... 
          [frmin frmax], [means(3) means(3)] ); 
 
 h = [h ;  
      text(frmax+1, means(1), int2str(means(1))) ;    
      text(frmax+1, means(2), int2str(means(2))) ;   
      text(frmax+1, means(3), int2str(means(3))) ]; 
 
 PFCvars.lines = [PFCvars.lines h(:)']; 
 PFCvars.oldx = -1; 
end 
 
PFCvars.numclicks = PFCvars.numclicks + 1;