function pitch=myPt(au, ptOpt, showPlot); % myPt: Pitch tracking from audio % % Usage: % pitch=myPt(au, ptOpt, showPlot); % au: audio % ptOpt: options for pitch % showPlot: 1 for plotting, 0 for not plotting % pitch: computed pitch % % Example: % waveFile='londonBridgeIsFallingDown.wav'; % au=myAudioRead(waveFile); % ptOpt=myPtOptSet; % ptOpt.useVolThreshold=1; % showPlot=1; % myPt(au, ptOpt, showPlot); % Roger Jang, 20110531, 20130416 if nargin<1, selfdemo; return; end if nargin<2, ptOpt=myPtOptSet; end if nargin<3, showPlot=0; end if ischar(au), au=myAudioRead(au); end % If the give au is a file name y=au.signal; fs=au.fs; nbits=au.nbits; y=y-mean(y); frameSize=round(ptOpt.frameDuration*au.fs/1000); overlap=round(ptOpt.overlapDuration*au.fs/1000); frameMat=enframe(y, frameSize, overlap); frameNum=size(frameMat, 2); pitch=zeros(frameNum, 1); volume=zeros(frameNum, 1); % ====== Compute volume & its threshold (計算音量 & 音量門檻值) volume=frame2volume(frameMat); volMax=max(volume); volMin=min(volume); ptOpt.volTh=volMin+0.1*(volMax-volMin); % ====== Compute pitch 計算音高(會用到音量門檻值) ptOpt.frame2pitchOpt.fs=fs; for i=1:frameNum frame=frameMat(:, i); pitch(i)=frame2pitch(frame, ptOpt.frame2pitchOpt); end pitch0=pitch; if ptOpt.useVolThreshold pitch(volume