Dawn@4
|
1 function [F0, err_msg] = func_OtherPitch(wavfile, handles)
|
Dawn@4
|
2 % [F0, err] = func_SnackPitch(wavfile, windowsize, frameshift, maxF0, minF0)
|
Dawn@4
|
3 % Input: wavfile - input wav file
|
Dawn@4
|
4 % Output: F0
|
Dawn@4
|
5 % err_msg - message of error
|
Dawn@4
|
6 % Notes: Function attempts to call an external command to produce an F0
|
Dawn@4
|
7 % output file which is read back as a vector. F0 output file format should
|
Dawn@4
|
8 % be a column of F0 values for each frame
|
Dawn@4
|
9 %
|
Dawn@4
|
10 % Warning: experimental function
|
Dawn@4
|
11 %
|
Dawn@4
|
12 % Author: Yen-Liang Shue, Speech Processing and Auditory Perception Laboratory, UCLA
|
Dawn@4
|
13 % Copyright UCLA SPAPL 2009
|
Dawn@4
|
14
|
Dawn@4
|
15 % get settings and commands
|
Dawn@4
|
16 VSData = guidata(handles.VSHandle);
|
Dawn@4
|
17 outfile = [wavfile(1:end-3) 'f0'];
|
Dawn@4
|
18
|
Dawn@4
|
19 C = textscan(VSData.vars.F0OtherCommand, '%s', 'delimiter', ' ');
|
Dawn@4
|
20 C = C{1};
|
Dawn@4
|
21
|
Dawn@4
|
22 command = [];
|
Dawn@4
|
23 F0 = NaN;
|
Dawn@4
|
24 err_msg = [];
|
Dawn@4
|
25
|
Dawn@4
|
26 for k=1:length(C)
|
Dawn@4
|
27 if (strcmp(C{k}, '$wavfile'))
|
Dawn@4
|
28 command = [command wavfile ' '];
|
Dawn@4
|
29 elseif (strcmp(C{k}, '$outfile'))
|
Dawn@4
|
30 command = [command outfile ' '];
|
Dawn@4
|
31 else
|
Dawn@4
|
32 command = [command C{k} ' '];
|
Dawn@4
|
33 end
|
Dawn@4
|
34 end
|
Dawn@4
|
35
|
Dawn@4
|
36 % attempt to run command
|
Dawn@4
|
37 [status, results] = system(command);
|
Dawn@4
|
38
|
Dawn@4
|
39 % error occured, exit
|
Dawn@4
|
40 if (status ~= 0)
|
Dawn@4
|
41 err_msg = 'Unable to execute command.';
|
Dawn@4
|
42
|
Dawn@4
|
43 % try to clean up files
|
Dawn@4
|
44 if (exist(outfile, 'file') ~= 0)
|
Dawn@4
|
45 delete(outfile);
|
Dawn@4
|
46 end
|
Dawn@4
|
47
|
Dawn@4
|
48 return;
|
Dawn@4
|
49 end
|
Dawn@4
|
50
|
Dawn@4
|
51 % now check if outfile exists
|
Dawn@4
|
52 if (exist(outfile, 'file') == 0)
|
Dawn@4
|
53 err_msg = 'Unable to find F0 file.';
|
Dawn@4
|
54 return;
|
Dawn@4
|
55 end
|
Dawn@4
|
56
|
Dawn@4
|
57 % if file exists, read in the vectors
|
Dawn@4
|
58 fid = fopen(outfile, 'rt');
|
Dawn@4
|
59 if (fid == -1)
|
Dawn@4
|
60 err_msg = 'Unable to open F0 file.';
|
Dawn@4
|
61 return;
|
Dawn@4
|
62 end
|
Dawn@4
|
63
|
Dawn@4
|
64 C = textscan(fid, '%f');
|
Dawn@4
|
65 fclose(fid);
|
Dawn@4
|
66 F0 = C{1};
|
Dawn@4
|
67
|
Dawn@4
|
68
|
Dawn@4
|
69 % clean up
|
Dawn@4
|
70 delete(outfile);
|
Dawn@4
|
71
|