Home > asr > wave2pitch4pmp.m

wave2pitch4pmp

PURPOSE ^

wave2pitch4pmp: Generate a pitch file from a given wave file

SYNOPSIS ^

function [pitch, status, result]=wave2pitch4pmp(waveFile, plotOpt)

DESCRIPTION ^

 wave2pitch4pmp: Generate a pitch file from a given wave file
    Usage: [status, result]=wave2mlfPitch(waveFile, text, languate, mlfFile, pitchFile, plotOpt)
        waveFile: input wave file
        pitchFile: output pitch file

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [pitch, status, result]=wave2pitch4pmp(waveFile, plotOpt)
0002 % wave2pitch4pmp: Generate a pitch file from a given wave file
0003 %    Usage: [status, result]=wave2mlfPitch(waveFile, text, languate, mlfFile, pitchFile, plotOpt)
0004 %        waveFile: input wave file
0005 %        pitchFile: output pitch file
0006 
0007 %    Roger Jang, 20050812
0008 
0009 if nargin<1, selfdemo; return; end
0010 if nargin<2, plotOpt=0; end
0011 
0012 % Resampling is down within C already
0013 %tempWaveFile=[tempname, '.wav'];
0014 %wave2wave(waveFile, tempWaveFile, 16000, 16);    % Convert to 16KHz, 16Bits
0015 
0016 [parentDir, junk, junk, junk]=fileparts(which(mfilename));
0017 exeDir=[parentDir, '\exe'];
0018 %currDir=pwd;
0019 %cd(exeDir);
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 %cd(currDir);
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 %    volume=frame2volume(buffer2(y, frameSize, overlap));
0047 %    pitchedIndex2=find(volume>max(volume)/10);
0048 %    pitchedIndex=pitchedIndex2;        % Based on volume only
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 % ====== selfdemo
0065 function selfdemo
0066 tic
0067 waveFile='¤@©w.wav';
0068 waveFile='¤£¬O.wav';
0069 pitch=feval(mfilename, waveFile, 1);
0070 toc

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