Dawn@4
|
1 function [HNR] = detect_MFCC( sampleWavFileName, OVERWRITE )
|
Dawn@4
|
2
|
Dawn@4
|
3 sampleFileName = sampleWavFileName( 1 : length( sampleWavFileName ) - 4 );
|
Dawn@4
|
4 [x, fs, frameLength, noOfFrames] = openFile( sampleWavFileName );
|
Dawn@4
|
5
|
Dawn@4
|
6 %---------------- GET THE SILENT FRAME VALUES -------------------
|
Dawn@4
|
7
|
Dawn@4
|
8 % only wish to consider pitch values from voiced frames.
|
Dawn@4
|
9 % silent and unvoiced frames will produce pitch values that
|
Dawn@4
|
10 % are random and therefore will bias our results
|
Dawn@4
|
11
|
Dawn@4
|
12 segmentFrames = detect_Silence( sampleWavFileName, 0 );
|
Dawn@4
|
13 [ silentFrames ] = getSilentDataArray( segmentFrames, noOfFrames );
|
Dawn@4
|
14
|
Dawn@4
|
15 % open original calculation
|
Dawn@4
|
16 fileName = [ sampleFileName '_MFCC.txt'];
|
Dawn@4
|
17 fileID = fopen( fileName );
|
Dawn@4
|
18
|
Dawn@4
|
19 if(( fileID <= 0 ) || ( OVERWRITE )) %does the file exist?
|
Dawn@4
|
20 % no
|
Dawn@4
|
21 disp('WARNING: MISSING MFCC FILE');
|
Dawn@4
|
22 %calculate it
|
Dawn@4
|
23 mfcc = calculate_MFCC( x, fs, frameLength, noOfFrames );
|
Dawn@4
|
24
|
Dawn@4
|
25 fileID = fopen( fileName, 'w');
|
Dawn@4
|
26 for i = 1 : (noOfFrames-1)
|
Dawn@4
|
27 if( silentFrames(i) == 1 )
|
Dawn@4
|
28 % frame is not silent
|
Dawn@4
|
29 fprintf(fileID, '%d %s \n' , i, num2str( mfcc(:,i)' ));
|
Dawn@4
|
30 else
|
Dawn@4
|
31 % set to zero
|
Dawn@4
|
32 mfcc(:,i) = 0;
|
Dawn@4
|
33 end
|
Dawn@4
|
34 end
|
Dawn@4
|
35 fclose( fileID );
|
Dawn@4
|
36 fileID = fopen( fileName );
|
Dawn@4
|
37 end
|
Dawn@4
|
38
|
Dawn@4
|
39
|
Dawn@4
|
40 mfcc = fscanf( fileID, '%f', inf );
|
Dawn@4
|
41 mfcc = buffer(mfcc,14); % 13 MFCC values and one frame number
|
Dawn@4
|
42 mfcc = mfcc(2:14,:)';
|
Dawn@4
|
43
|
Dawn@4
|
44 fclose(fileID);
|