comparison Code/ProcessDatabase.m @ 0:ea0c737c6323

first commit
author Dawn Black <dawn.black@eecs.qmul.ac.uk>
date Thu, 26 Jul 2012 14:46:25 +0100
parents
children a3d62264030c
comparison
equal deleted inserted replaced
-1:000000000000 0:ea0c737c6323
1 function [] = ProcessDatabase( databaseName, functionName, sampleStartNum, OVERWRITE )
2 % run from D:\Dropbox\BUPTResearch2011\EmotionDetectionCode\Code
3 machineName = getenv('COMPUTERNAME');
4
5 switch machineName
6 case 'LAPTOP'
7 % for Dawn's laptop
8 root = 'D:\Dropbox\'
9 case 'SLATE1'
10 % for Dawn's Slate
11 root = 'E:\Dropbox\'
12 case 'DAWNBLACK-PC'
13 % for Dawn's work PC
14 root = 'C:\Users\dawn\Dropbox\'
15 end
16
17 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code'])
18 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\Matlab\MPEG7'])
19 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\Matlab\Common'])
20 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\Matlab\MPEG7\FromWeb'])
21 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\PRAAT'])
22 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Collation'])
23 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\General'])
24
25 switch databaseName
26 case 'ChineseOpera'
27 cd([root 'BUPTResearch2011/Data/Opera/TestDatabase'])
28 startEmotion = 4;
29 case 'MandarinSpeech'
30 cd([root 'BUPTResearch2011/Data/Database/EditedRecording'])
31 startEmotion = 3;
32 case 'SpeechTestFiles'
33 cd([root 'BUPTResearch2011\Data\SpeechTestFiles\MyAnnotatedFiles'])
34 startEmotion = 3;
35 end
36
37 fileStructure = dir;
38
39 % how many samples do we have?
40 noOfSamples = size( fileStructure );
41 firstfileOpen = 1;
42
43 if( sampleStartNum < 3 )
44 sampleStartNum = 3;
45 end
46
47 for sampleNum = sampleStartNum : noOfSamples(1)
48 sampleDirName = fileStructure(sampleNum).name
49 if( fileStructure(sampleNum).isdir == 1 ) % only directories
50 cd( sampleDirName );
51 % how many emotions for that sample?
52 validEmotionList = dir;
53 noOfEmotions = size( validEmotionList );
54
55 for emotionNum = startEmotion : noOfEmotions(1)
56 emotionName = validEmotionList(emotionNum).name;
57 cd( emotionName );
58 % how many samples for that emotion?
59 sampleNames = dir;
60 noOfSamples = size( sampleNames );
61
62 for sampleNumber = 3 : noOfSamples(1)
63 if( sampleNames(sampleNumber).isdir == 0 ) % skip directories
64 currentSampleName = sampleNames(sampleNumber).name
65 % get the file type
66 extName = currentSampleName(length( currentSampleName ) - 3: end);
67 % is it a .wav file?
68 if strcmp( extName, '.wav' )
69 newDirName = currentSampleName( 1 : length( currentSampleName ) - 4 );
70 % if none exists, make a new directory for all the results of
71 % our calculations.
72 mkdir( [ newDirName '_metrics'] );
73 cd ( [ newDirName '_metrics'] );
74
75 % call your function here
76 switch functionName
77 % functions that start with 'get' simply read
78 % from existing text files
79 % functions that start with 'detect' check if
80 % the results file already exists, if they do
81 % not (or the OVERWRITE flag is true) then the
82 % results are calculated afresh.
83
84 % case 'getsampleDependantThresholds'
85 % statsFileName = '../../../../FeatureSets/singingsampleDependantThresholds.txt';
86 % statsFileID = fopen( statsFileName, 'a' );
87 % % is this the first sample in this emotion for
88 % % this sample?
89 % if( sampleNumber == 3 )
90 % if ( firstfileOpen == 0 )
91 % if(strfind( oldDirName , 'fem') > 0 )
92 % sampleName = oldDirName( 6 : end );
93 % meanET = mean( energyThreshold );
94 % meanSCT = mean( spectralCentroidThreshold );
95 % fprintf( statsFileID, '%s \t %f \t %f \n', sampleName, meanET, meanSCT );
96 % elseif(strfind( oldDirName , 'male') > 0 )
97 % sampleName = oldDirName( 6 : end );
98 % meanET = mean( energyThreshold );
99 % meanSCT = mean( spectralCentroidThreshold );
100 % fprintf( statsFileID, '%s \t %f \t %f \n', sampleName, meanET, meanSCT );
101 % end
102 % end
103 %
104 % spectralCentroidThreshold = [];
105 % energyThreshold = [];
106 % firstfileOpen = 0;
107 % end
108 %
109 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
110 % [st , et] = getsampleDependantThresholds( newDirName, x, fs, statsFileID, frameLength, noOfFrames );
111 % spectralCentroidThreshold = [spectralCentroidThreshold st];
112 % energyThreshold = [energyThreshold et];
113 % oldDirName = newDirName;
114 %
115 % fclose( statsFileID );
116 % case 'getPitchStatistics'
117 % statsHeaderFileName = '../../../../FeatureSets/singingHeaderPitchStats.txt';
118 % statsHeaderFileID = fopen( statsHeaderFileName, 'w' );
119 % if( firstfileOpen == 1 )
120 % fprintf( statsHeaderFileID, 'name \t unvoiced to voiced frame ratio \t mean voiced pitch \t median voiced pitch \t stdev voiced pitch \t variance voiced pitch \t min voiced pitch \t max voiced pitch \t range voiced pitch \t mean voiced pitch grad \t median voiced pitch grad \t stdev pitch grad \t variance voiced pitch grad \t min voiced pitch grad \t max voiced pitch grad \t range voiced pitch grad \n');
121 % firstfileOpen = 0;
122 % end
123 % fclose(statsHeaderFileID);
124 %
125 % statsFileName = '../../../../FeatureSets/singingPitchStats.txt';
126 % statsFileID = fopen( statsFileName, 'a' );
127 %
128 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
129 % getPitchStatistics( newDirName, x, fs, statsFileID, frameLength, noOfFrames );
130 % fclose( statsFileID );
131 %
132 %
133 %
134 %
135 %
136 % %%%%%%%%%%%%%%% careful %%%%%%%%%%%%%%%
137 % case 'getHNRStatistics'
138 % statsHeaderFileName = '../../../../FeatureSets/singingHeaderHNRStats.txt';
139 % statsHeaderFileID = fopen( statsHeaderFileName, 'w' );
140 % if( firstfileOpen == 1 )
141 % fprintf( statsHeaderFileID, 'name \t \t \t \t \t \n');
142 % firstfileOpen = 0;
143 % end
144 % fclose(statsHeaderFileID);
145 %
146 % statsFileName = '../../../../FeatureSets/singingHNRStats.txt';
147 % statsFileID = fopen( statsFileName, 'a' );
148 %
149 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
150 % getHNRStatistics( newDirName, x, fs, statsFileID, frameLength, noOfFrames );
151 % fclose( statsFileID );
152 %
153 %
154 %
155 %
156 % case 'getEnergyStatistics'
157 % statsFileName = '../../../../FeatureSets/singingEnergyStats.txt';
158 % statsFileID = fopen( statsFileName, 'a' );
159 % if( firstfileOpen == 1 )
160 % fprintf( statsFileID, 'name \t mean energy \t mean voiced energy \t mean unvoiced energy \n');
161 % firstfileOpen = 0;
162 % end
163 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
164 % getEnergyStatistics( newDirName, x, fs, statsFileID, frameLength, noOfFrames );
165 % fclose( statsFileID );
166 %
167 %
168 % % %%%%% for energy-related features %%%%%
169 % % case 'getOtherEnergyStatistics'
170 % % statsFileName = '../../../../FeatureSets/singingOtherEnergyStats.txt';
171 % % statsFileID = fopen( statsFileName, 'a' );
172 % % if( firstfileOpen == 1 )
173 % % fprintf( statsFileID, 'name \t derivation of non silent energy \t derivation of voiced energy \t derivation of unvoiced energy \n');
174 % % firstfileOpen = 0;
175 % % end
176 % % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
177 % % getOtherEnergyStatistics( newDirName, x, fs, statsFileID, frameLength, noOfFrames );
178 % % fclose( statsFileID );
179 %
180 %
181 %
182 % case 'getBasicDescriptors'
183 % % includes audio waveform and audio power
184 % statsFileName = '../../../../FeatureSets/singingbasicDescriptors.txt';
185 % statsFileID = fopen( statsFileName, 'a' );
186 % if( firstfileOpen == 1 )
187 % fprintf( statsFileID, 'name \t meanAWF \t STDAWF \t minAWF \t maxAWF \t rangeAWF \t meanAP \t STDAP \t minAP \t maxAP \t rangeAP \t meanHR \t STDHR \t minHR \t maxHR \t rangeHR \n');
188 % firstfileOpen = 0;
189 % end
190 %
191 % getBasicDescriptors( newDirName, statsFileID );
192 % fclose( statsFileID );
193 % case 'getBasicSpectralDescriptors'
194 % % includes audio spectrum envelope, audio spectrum
195 % % centroid, audio spectrum spread, audio spectrum flatness
196 % statsFileName = '../../../../FeatureSets/singingbasicSpectralDescriptors.txt';
197 % statsFileID = fopen( statsFileName, 'a' );
198 % % Add a header column
199 % if( firstfileOpen == 1 )
200 % fprintf( statsFileID, ' name \t meanASE \t STDASE \t minASE \t maxASE \t rangeASE \t meanASC \t STDASC \t minASC \t maxASC \t rangeASC \t meanASS \t STDASS \t minASS \t maxASS \t rangeASS \t meanASF \t STDASF \t minASF \t maxASF \t rangeASF \n');
201 % % fprintf( statsFileID, ' name \t meanAWE \t STDAWE \t minAWE \t maxAWE \t rangeAWE \t meanAP \t STDAP \t minAP \t maxAP \t rangeAP \n');
202 % firstfileOpen = 0;
203 % end
204 %
205 % getBasicSpectralDescriptors1( newDirName, statsFileID );
206 % fclose( statsFileID );
207 % disp('NOT FINISHED');
208 % case 'getTemporalTimbralDescriptors'
209 %
210 % % includes log attack time and temporal
211 % % centroid
212 % statsFileName = '../../../../FeatureSets/singingtemporalTimbralDescriptors.txt';
213 % statsFileID = fopen( statsFileName, 'a' );
214 % % Add a header column
215 % if( firstfileOpen == 1)
216 % fprintf( statsFileID, ' name \t temporal centriod \t log attack time \n');
217 % firstfileOpen = 0;
218 % end
219 %
220 % getTemporalTimbralDescriptors( newDirName, statsFileID );
221 % fclose( statsFileID );
222 % case 'getSpectralTimbralDescriptors'
223 % % collate the Harmonic Spectral Centroid,
224 % % Harmonmic Spectral Deviation, Harmonic
225 % % Spectral Spread, Harmonic Spectral Variation
226 % % and Spectral Centroid
227 %
228 % statsFileName = '../../../../FeatureSets/singingspectralTimbralDescriptors.txt';
229 % statsFileID = fopen( statsFileName, 'a' );
230 % % Add a header column
231 % if( firstfileOpen == 1)
232 % fprintf( statsFileID, ' name \t HSC \t HSD \t HSS \t HSV \t SC \n');
233 % firstfileOpen = 0;
234 % end
235 %
236 % getSpectralTimbralDescriptors( newDirName, statsFileID );
237 % fclose( statsFileID );
238 % case 'getMFCCs'
239 % if( firstfileOpen )
240 % statsFileName = '../../../../FeatureSets/singingMFCCDescriptorsHeader.txt';
241 % statsFileID = fopen( statsFileName, 'w' );
242 %
243 % % Add a header file
244 % % putMFCCHeader( statsFileID );
245 % fclose( statsFileID );
246 % end
247 %
248 % statsFileName = '../../../../FeatureSets/singingMFCCDescriptors.txt';
249 % statsFileID = fopen( statsFileName, 'a' );
250 %
251 % getMFCCStatistics( newDirName, statsFileID );
252 % fclose( statsFileID );
253 %
254 % %lin
255 case 'getPRAAT'
256 % collate all Shimmer values
257 statsFileName = '../../../../../../../TestResults/singingPRAATStats.txt';
258 statsFileID = fopen( statsFileName, 'w' );
259 % Add a header row
260 if( firstfileOpen == 1 )
261 fprintf( statsFileID, 'Metrics calculated using the PRAAT software. \n' );
262 fprintf( statsFileID, ' name \t JITTER: ddp \t local \t ppq5 \t rap \t SHIMMER: local \t dda \t apq3 \t apq5 \t apq11 \t FORMANTS: number of formants \t positions \t bandwidths \n');
263 firstfileOpen = 0;
264 end
265
266 get_PRAAT( newDirName, statsFileID );
267 fclose( statsFileID );
268
269 % case 'getJitter'
270 % % collate Jitter
271 % statsFileName = '../../../../FeatureSets/singingJitterStats.txt';
272 % statsFileID = fopen( statsFileName, 'a' );
273 %
274 % getJitter( newDirName, statsFileID );
275 % fclose( statsFileID );
276 %
277 %
278 %
279 % %%%%% get all the pitch and energy related features
280
281
282 % case 'getFeaturesOfDuration'
283 % % collate number, mean and ratio duration of
284 % % unvoiced and voiced sounds, median and
285 % % standard deviation number of voiced sounds
286 % statsFileName = '../../../../FeatureSets/singingDurationStats.txt';
287 % statsFileID = fopen( statsFileName, 'a' );
288 % getFeaturesOfDuration( newDirName, statsFileID );
289 % fclose( statsFileID );
290 %
291 % case 'getFeaturesOfRelativePitch'
292 % % collate relative pitch maximum, minimum and
293 % % the position of those pitches
294 % statsFileName = '../../../../FeatureSets/singingRelativePitchStats.txt';
295 % statsFileID = fopen( statsFileName, 'a' );
296 % getFeaturesOfRelativePitch( newDirName, statsFileID );
297 % fclose( statsFileID );
298 %
299 % case 'getFeaturesOfRelativeEnergyGradient'
300 % % collate the value and position of relative
301 % % maximum of energy gradient
302 % statsFileName = '../../../../FeatureSets/singingRelativeEnergyGradientStats.txt';
303 % statsFileID = fopen( statsFileName, 'a' );
304 % getFeaturesOfRelativeEnergyGradient( newDirName, statsFileID );
305 % fclose( statsFileID );
306 %
307 %
308 %
309 case 'calculatePitch'
310 detect_pitch( currentSampleName, OVERWRITE );
311
312 case 'calculateSilence'
313 detect_silence( currentSampleName, OVERWRITE );
314
315 case 'calculateVUV'
316 % find the voiced and unvoiced frames using
317 % the harmonic ratio and pitch information
318 detect_VoicedUnvoiced( currentSampleName, OVERWRITE );
319
320 % case 'calculateAudioWaveform'
321 %
322 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
323 % AW_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
324 %
325 % case 'calculateAudioSpectrumEnvelope'
326 %
327 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
328 % ASE_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
329 %
330 % case 'calculateAudioSpectrumCentriodAndSpread'
331 %
332 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
333 % ASC_ASS_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
334 %
335 % case 'calculateAudioSpectrumBasisAndProjection'
336 %
337 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
338 % ASB_ASP_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
339 %
340 case 'calculateAudioPower'
341
342 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
343 detect_AudioPower( currentSampleName, x, fs, frameLength, noOfFrames );
344 %
345 % case 'calculateLogAttackTIme'
346 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
347 % LAT_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
348 %
349 % case 'calculateTemporalCentroid'
350 %
351 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
352 % TC_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
353 %
354 % case 'calculateHarmonicRatio'
355 %
356 % % can't find this function yet
357 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
358 % HR_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
359 %
360 case 'calculateHarmonicNoiseRatio'
361 detect_HNR( currentSampleName, OVERWRITE );
362 %
363 % case 'calculateSpectralTimbralDescriptors'
364 %
365 % % these are best calculated together.
366 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
367 % spectralTimbralDescriptors( currentSampleName, x, fs, frameLength, noOfFrames );
368
369 case 'calculateAudioSpectrumFlatness'
370
371 [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
372 AudioSpectralFlatness_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
373
374 % case 'calculateMFCCs'
375 %
376 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
377 % MFCC_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
378 %
379 % case 'calculatesampleDependantThresholds'
380 %
381 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
382 % sampleDependantThresholds( currentSampleName, x, fs, frameLength, noOfFrames );
383 %
384 %
385 % %%%%% pitch related features %%%%%
386 % case 'calculatesampleVoicedSoundDuration'
387 %
388 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
389 % getVoicedSoundDuration( currentSampleName, x, fs, noOfFrames, frameLength );
390 %
391 % case 'calculatesampleRelativePitch'
392 %
393 % singingpitchStatsFileName = 'singingpitchStats.txt';
394 % singingpitchStatsFileID = fopen( singingpitchStatsFileName, 'r' );
395 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
396 % getRelativePitch( singingpitchStatsFileID, currentSampleName, x, fs, noOfFrames, frameLength, 7 );
397 % fclose(singingpitchStatsFileID);
398 %
399 % case 'calculatesampleRelativePitchFeatures'
400 %
401 % singingpitchStatsFileName1 = '../../../../FeatureSets/singingpitchStats.txt';
402 % singingpitchStatsFileID1 = fopen( singingpitchStatsFileName1, 'r' );
403 % singingpitchStatsFileName2 = 'singingpitchStats.txt';
404 % singingpitchStatsFileID2 = fopen( singingpitchStatsFileName2, 'r' );
405 % [averageValues1 averageValues2 averageValues3] = getRelativePitchFeatures( singingpitchStatsFileID1, 7 );
406 % getEachRelativePitchFeature( singingpitchStatsFileID2, currentSampleName, 7, averageValues1, averageValues2, averageValues3 );
407 % fclose(singingpitchStatsFileID1);
408 % fclose(singingpitchStatsFileID2);
409 %
410 % case 'calculatesamplePitchPosition'
411 %
412 % singingpitchStatsFileName = 'singingpitchStats.txt';
413 % singingpitchStatsFileID = fopen( singingpitchStatsFileName, 'r' );
414 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
415 % getPitchPosition( singingpitchStatsFileID, currentSampleName, x, fs, noOfFrames, frameLength, 7 );
416 % fclose(singingpitchStatsFileID);
417 %
418 %
419 %
420 % %%%%% energy related features %%%%%
421 % case 'calculatesampleRelativeEnergyByMeanAll'
422 %
423 % singingenergyStatsFileName = '../../../../FeatureSets/singingenergyStats.txt';
424 % singingenergyhStatsFileID = fopen( singingenergyStatsFileName, 'r' );
425 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
426 % getRelativeEnergyByMeanAll( singingenergyhStatsFileID, currentSampleName, x, fs, noOfFrames, frameLength, 3 );
427 % fclose(singingenergyhStatsFileID);
428 %
429 % case 'calculatesampleRelativeEnergyByMeanVoiced'
430 %
431 % singingenergyStatsFileName = '../../../../FeatureSets/singingenergyStats.txt';
432 % singingenergyhStatsFileID = fopen( singingenergyStatsFileName, 'r' );
433 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
434 % getRelativeEnergy( singingenergyhStatsFileID, currentSampleName, x, fs, noOfFrames, frameLength, 3 );
435 % fclose(singingenergyhStatsFileID);
436 %
437 % case 'calculatesampleRelativeEnergyGradientByMeanAll'
438 %
439 % statsFileName = '../../../../FeatureSets/singingenergyStats.txt';
440 % statsFileID = fopen( statsFileName, 'r' );
441 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
442 % getRelativeEnergyGradient( statsFileID, newDirName, x, fs, noOfFrames, frameLength, 3 );
443 % fclose( statsFileID );
444 %
445 % case 'calculatesampleRelativeEnergyGradientFeaturesByMeanAll'
446 %
447 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
448 % getRelativeEnergyGradientFeatures( currentSampleName, x, fs, noOfFrames, frameLength );
449 %
450
451 end
452
453 cd ../
454 end
455 end
456
457 end
458 cd ../
459
460 end
461 cd ../
462 end
463
464 end
465
466 cd ../
467