0001 function [pitch, status, result]=wave2pitch4pmp(waveFile, plotOpt)
0002
0003
0004
0005
0006
0007
0008
0009 if nargin<1, selfdemo; return; end
0010 if nargin<2, plotOpt=0; end
0011
0012
0013
0014
0015
0016 [parentDir, junk, junk, junk]=fileparts(which(mfilename));
0017 exeDir=[parentDir, '\exe'];
0018
0019
0020 executable=[exeDir, '\pt4pmp.exe'];
0021 if ~exist(executable)
0022 msg=sprintf('Cannot find %s!\n', executable);
0023 error(msg);
0024 end
0025 pitchFile='pitch.txt'; if exist(pitchFile)==2, delete(pitchFile); end
0026 volumeFile='volume.txt'; if exist(volumeFile)==2, delete(volumeFile); end
0027 cmd={executable, waveFile};
0028 cmd=join(cmd, ' ');
0029 disp(cmd);
0030 [status, result]=dos(cmd);
0031 if exist(pitchFile)~=2
0032 msg=sprintf('Cannot find %s!\n', pitchFile);
0033 error(msg);
0034 end
0035
0036 pitch=asciiRead(pitchFile);
0037 volume=asciiRead(volumeFile);
0038
0039 if plotOpt
0040 [y, fs, nbits]=wavRead(waveFile);
0041 waveObj.signal=y*2^nbits/2; waveObj.fs=fs; waveObj.nbits=nbits;
0042 frameSize=512; overlap=192; fs=16000;
0043 pitchObj.frameRate=fs/(frameSize-overlap);
0044 pitchObj.signal=asciiRead(pitchFile)+3;
0045
0046
0047
0048
0049
0050 subplot(3,1,1);
0051 plot((1:length(y))/fs, y); axis([-inf inf -1 1]); ylabel('Waveform');
0052 subplot(3,1,2);
0053 plot(volume, '.-'); set(gca, 'xlim', [-inf inf]); ylabel('Volume');
0054 volTh1=asciiRead('volTh1.txt'); line([1, length(volume)], volTh1*[1 1], 'color', 'r');
0055 volTh2=asciiRead('volTh2.txt'); line([1, length(volume)], volTh2*[1 1], 'color', 'm');
0056 subplot(3,1,3);
0057 tempPitch=pitch; tempPitch(tempPitch==0)=[]; meanPitch=(min(tempPitch)+max(tempPitch))/2;
0058 tempPitch=pitch; tempPitch(tempPitch==0)=nan;
0059 plot(tempPitch, '.-'); axis([-inf inf meanPitch-6 meanPitch+6]); ylabel('Pitch');
0060
0061 buttonH=wavePitchPlayButton(waveObj, pitchObj);
0062 end
0063
0064
0065 function selfdemo
0066 tic
0067 waveFile='¤@©w.wav';
0068 waveFile='¤£¬O.wav';
0069 pitch=feval(mfilename, waveFile, 1);
0070 toc