annotate Code/Descriptors/Matlab/MPEG7/FromWeb/VoiceSauce/func_SnackFormants.m @ 4:92ca03a8fa99 tip

Update to ICASSP 2013 benchmark
author Dawn Black
date Wed, 13 Feb 2013 11:02:39 +0000
parents
children
rev   line source
Dawn@4 1 function [F1, F2, F3, F4, B1, B2, B3, B4, err] = func_SnackFormants(wavfile, windowlength, frameshift, preemphasis)
Dawn@4 2 % [F1, F2, F3, F4, B1, B2, B3, B4, err] = func_SnackFormants(wavfile, windowlength, frameshift, preemphasis)
Dawn@4 3 % Input: wavfile - input wav file
Dawn@4 4 % windowlength - windowlength in seconds
Dawn@4 5 % frameshift - in seconds
Dawn@4 6 % preemphasis - wonder what this could be?
Dawn@4 7 % Output: Fx, Bx - formant and bandwidth vectors
Dawn@4 8 % err - error flag
Dawn@4 9 % Notes: If on Windows/PC, this function will call up the Snack executable
Dawn@4 10 % in the Windows folder. Otherwise, it will try to call up Snack - this
Dawn@4 11 % require Snack to be installed beforehand.
Dawn@4 12 %
Dawn@4 13 % Author: Yen-Liang Shue, Speech Processing and Auditory Perception Laboratory, UCLA
Dawn@4 14 % Copyright UCLA SPAPL 2009
Dawn@4 15
Dawn@4 16 % settings
Dawn@4 17 iwantfilecleanup = 1; %delete tcl,f0,frm files when done
Dawn@4 18 tclfilename = 'tclforsnackformant.tcl'; %produce tcl file to call snack
Dawn@4 19
Dawn@4 20 % make the wavfile acceptable to tcl in Snack
Dawn@4 21 formantfile = [wavfile(1:end-3) 'frm'];
Dawn@4 22 wavfile = strrep(wavfile, '[', '\[');
Dawn@4 23 wavfile = strrep(wavfile, ']', '\]');
Dawn@4 24 wavfile = ['"' wavfile '"'];
Dawn@4 25 %wavfile = strrep(wavfile, '\', '\\'); % for PC
Dawn@4 26
Dawn@4 27 if (ispc) % pc can run snack.exe
Dawn@4 28 wavfile = strrep(wavfile, '\', '\\');
Dawn@4 29 cmds = sprintf('-windowlength %.3f -framelength %.3f -windowtype Hamming -lpctype 1 -preemphasisfactor %.3f -ds_freq 10000', windowlength, frameshift, preemphasis);
Dawn@4 30 err = system(['Windows\snack.exe formant ' wavfile ' ' cmds]);
Dawn@4 31
Dawn@4 32 else % for macs and possibly others
Dawn@4 33 %cmd = 'tclsh'; % this is for older macs
Dawn@4 34 cmd = 'wish8.4'; % seems to work for OSX Snow Leopard
Dawn@4 35 %cmd = 'wish84'; % for PC
Dawn@4 36
Dawn@4 37 fid = fopen(tclfilename, 'wt');
Dawn@4 38 fprintf(fid, '#!/bin/sh\n');
Dawn@4 39 fprintf(fid, '# the next line restarts with wish \\\n');
Dawn@4 40 fprintf(fid, 'exec wish8.4 "$0" "$@"\n\n');
Dawn@4 41 fprintf(fid, 'package require snack\n\n');
Dawn@4 42 fprintf(fid, 'snack::sound s\n\n');
Dawn@4 43 fprintf(fid, 's read %s\n\n', wavfile);
Dawn@4 44 fprintf(fid, 'set fd [open [file rootname %s].frm w]\n', wavfile);
Dawn@4 45 fprintf(fid, 'puts $fd [join [s formant -windowlength %.3f -framelength %.3f -windowtype 1 -lpctype 1 -preemphasisfactor %.3f -ds_freq 10000] \\n]\n', windowlength, frameshift, preemphasis);
Dawn@4 46 fprintf(fid, 'close $fd\n\n');
Dawn@4 47 fprintf(fid, 'exit');
Dawn@4 48 fclose(fid);
Dawn@4 49
Dawn@4 50 err = system([cmd ' ' tclfilename]);
Dawn@4 51 end
Dawn@4 52
Dawn@4 53 % change back into original file
Dawn@4 54 wavfile = strrep(wavfile, '\[', '[');
Dawn@4 55 wavfile = strrep(wavfile, '\]', ']');
Dawn@4 56
Dawn@4 57 % oops, error, exit now
Dawn@4 58 if (err~=0)
Dawn@4 59 F1 = NaN; F2 = NaN; F3 = NaN; F4 = NaN;
Dawn@4 60 B1 = NaN; B2 = NaN; B3 = NaN; B4 = NaN;
Dawn@4 61 if (iwantfilecleanup)
Dawn@4 62 formantfile = strrep(formantfile, '\\', '\');
Dawn@4 63 if (exist(formantfile, 'file') ~= 0)
Dawn@4 64 delete(formantfile);
Dawn@4 65 end
Dawn@4 66
Dawn@4 67 if (exist(tclfilename, 'file') ~= 0)
Dawn@4 68 delete(tclfilename);
Dawn@4 69 end
Dawn@4 70 end
Dawn@4 71 return;
Dawn@4 72 end
Dawn@4 73
Dawn@4 74 % snack call was successful, read out formant values
Dawn@4 75 [F1,F2,F3,F4,B1,B2,B3,B4] = textread(formantfile, '%f %f %f %f %f %f %f %f');
Dawn@4 76
Dawn@4 77 if (iwantfilecleanup)
Dawn@4 78 formantfile = strrep(formantfile, '\\', '\');
Dawn@4 79 if (exist(formantfile, 'file') ~= 0)
Dawn@4 80 delete(formantfile);
Dawn@4 81 end
Dawn@4 82
Dawn@4 83 if (exist(tclfilename, 'file') ~= 0)
Dawn@4 84 delete(tclfilename);
Dawn@4 85 end
Dawn@4 86 end