comparison functions/funcsMobilab/read_data_develop.m @ 0:2fadb31a9d55 tip

Import code by Vuegen et al
author Dan Stowell <dan.stowell@elec.qmul.ac.uk>
date Fri, 11 Oct 2013 12:02:43 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:2fadb31a9d55
1 function [segments,samples,labels] = read_data_develop(directoryAudio,directoryAnnotation,new_fs)
2 %%
3 % Mobilab 2012-2013
4 %
5 % Input arguments:
6 % - directoryAudi:
7 % Contains the path to the folder where the data is located
8 % - directoryAnnotation:
9 % Contains the path to the folders where the annotations are located
10 % - new_fs:
11 % Resample the .wav files to this sample frequency. If left
12 % blank, no resampling occur
13 % Output arguments
14 % - segments is a cell structure:
15 % Columns: # number of development examples
16 % Rows: # numer of annotators
17 % Each cell contains the segmented files from corresponding
18 % development file and annotator
19 % - samples is a cell structure:
20 % Same structure as segments. Each cell contains the start and
21 % stop time of the event.
22 % - labels is a cell structure:
23 % Same structure as segments. Each cell contains the labels of
24 % the corresponding events
25 %% Defaults
26 down=1; if nargin < 3; down=0; end
27 %% Annotation
28 addpath(directoryAudio);
29 files=find_format(directoryAudio, '.wav');
30 names=files.names;
31 nrScripts = length(names);
32
33 % Preallocation for speed
34 segments=cell(1,nrScripts);
35 samples=cell(1,nrScripts);
36 labels=cell(1,nrScripts);
37
38 for(scriptNr=1:nrScripts)
39
40 [x_temp fs] = wavread(names{1,scriptNr});
41 if(down==1)
42 x_temp = resample(x_temp,new_fs,fs);
43 fs=new_fs;
44 end,
45
46
47 addpath(directoryAnnotation);
48 files2=find_format(directoryAnnotation, 'txt');
49 annotation=textread(files2.names{1,i}, '%s' ,'delimiter', '\t');
50 startStop=zeros(length(annotation)/3,2);
51 id=cell(length(annotation)/3,1);
52 u=1;
53 for(v=1:3:length(annotation))
54 startStop(u,1)=str2num(annotation{v,1});
55 startStop(u,2)=str2num(annotation{v+1,1});
56 x{u,2}=fs;
57 x{u,1}=x_temp(ceil(startStop(u,1)*x{u,2})+1:ceil(startStop(u,2)*x{u,2}));
58 id{u,1}=annotation{v+2,1};
59 u=u+1;
60 end,
61 segments{k,i}=x;
62 samples{k,i}=startStop;
63 labels{k,i}=id;
64 rmpath(directoryAnnotation{k,1});
65 clear x;
66 end,
67 end
68
69
70
71
72
73
74
75
76
77
78
79
80