Home > asr > waveCmPitchPlot.m

waveCmPitchPlot

PURPOSE ^

waveCmPitchPlot: Plot waveform and pitch simultaneously

SYNOPSIS ^

function waveCmPitchPlot(waveFile, xmlFile, pitchObj1, pitchObj2)

DESCRIPTION ^

 waveCmPitchPlot: Plot waveform and pitch simultaneously
    Usage: waveCmPitchPlot(waveFile, xmlFile, pitchObj1, pitchObj2)
        pitchObj1: pitch object to be drawn
        pitchObj2: pitch object to be drawn

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function waveCmPitchPlot(waveFile, xmlFile, pitchObj1, pitchObj2)
0002 % waveCmPitchPlot: Plot waveform and pitch simultaneously
0003 %    Usage: waveCmPitchPlot(waveFile, xmlFile, pitchObj1, pitchObj2)
0004 %        pitchObj1: pitch object to be drawn
0005 %        pitchObj2: pitch object to be drawn
0006 
0007 % Roger Jang, 20060217
0008 
0009 if nargin<1, selfdemo; return; end
0010 
0011 % ====== 切音圖
0012 clf;
0013 subplot(2,1,1);
0014 waveCmPlot(waveFile, xmlFile);
0015 labelStr=waveFile;
0016 labelStr=strrep(labelStr, '\', '/'); labelStr=strrep(labelStr, '_', '\_');
0017 xlabel(labelStr);
0018 % ====== Plot pitch
0019 pitch=pitchObj1.signal;
0020 [y, fs, nbits]=wavReadInt(waveFile);
0021 y=y(:,1);    % Stereo to mono
0022 frameTime=frame2sampleIndex(1:length(pitch), fs/pitchObj1.frameRate, 0)/fs;
0023 
0024 subplot(2,1,2);
0025 pitch(pitch==0)=nan;
0026 plot(frameTime, pitch, '.-');
0027 if nargin==3
0028     plot(frameTime, pitch, '.-');
0029     legend('Pitch');
0030 elseif nargin==4
0031     pitch2=pitchObj2.signal;
0032     pitch2(pitch2==0)=nan;
0033     frameTime2=frame2sampleIndex(1:length(pitch2), fs/pitchObj2.frameRate, 0)/fs;
0034     plot(frameTime, pitch, '.-', frameTime2, pitch2, 'o-r');
0035     legend('Pitch1', 'Pitch2');
0036 end
0037 ylabel('Pitch'); grid on;
0038 set(gca, 'xlim', [1, length(y)]/fs); set(gca, 'ylim', [-inf inf]);
0039 % ====== Buttons for playback
0040 waveObj.signal=y-mean(y); waveObj.fs=fs; waveObj.nbits=nbits;
0041 if nargin==3
0042     buttonH=wavePitchPlayButton(waveObj, pitchObj1);
0043 elseif nargin==4
0044     buttonH=wavePitchPlayButton(waveObj, pitchObj1, pitchObj2);
0045 end
0046 
0047 % ====== Self demo
0048 function selfdemo
0049 waveFile='囉哩囉唆令人不爽.wav';
0050 xmlFile='囉哩囉唆令人不爽.xml';
0051 pitchFile1='囉哩囉唆令人不爽1.pitch';    % Generated by Roger's program
0052 pitchFile2='囉哩囉唆令人不爽2.pitch';    % Generated by SFS, which records freq instead of pitch
0053 [y, fs, nbits]=wavRead(waveFile);
0054 % Prepare pitchObj1
0055 frameSize=640; overlap=480;
0056 pitchObj1.frameRate=fs/(frameSize-overlap);
0057 pitchObj1.signal=asciiRead(pitchFile1);
0058 % Prepare pitchObj2
0059 frameSize=160; overlap=0;
0060 pitchObj2.frameRate=fs/(frameSize-overlap);
0061 pitchObj2.signal=freq2pitch(asciiRead(pitchFile2));
0062 % Plotting
0063 feval(mfilename, waveFile, xmlFile, pitchObj1, pitchObj2);

Generated on Tue 01-Jun-2010 09:50:19 by m2html © 2003