Mercurial > hg > dcase2013_ed_vuegenetal
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/functions/funcsMobilab/read_data_develop.m Fri Oct 11 12:02:43 2013 +0100 @@ -0,0 +1,80 @@ +function [segments,samples,labels] = read_data_develop(directoryAudio,directoryAnnotation,new_fs) +%% +% Mobilab 2012-2013 +% +% Input arguments: +% - directoryAudi: +% Contains the path to the folder where the data is located +% - directoryAnnotation: +% Contains the path to the folders where the annotations are located +% - new_fs: +% Resample the .wav files to this sample frequency. If left +% blank, no resampling occur +% Output arguments +% - segments is a cell structure: +% Columns: # number of development examples +% Rows: # numer of annotators +% Each cell contains the segmented files from corresponding +% development file and annotator +% - samples is a cell structure: +% Same structure as segments. Each cell contains the start and +% stop time of the event. +% - labels is a cell structure: +% Same structure as segments. Each cell contains the labels of +% the corresponding events +%% Defaults +down=1; if nargin < 3; down=0; end +%% Annotation +addpath(directoryAudio); +files=find_format(directoryAudio, '.wav'); +names=files.names; +nrScripts = length(names); + +% Preallocation for speed +segments=cell(1,nrScripts); +samples=cell(1,nrScripts); +labels=cell(1,nrScripts); + +for(scriptNr=1:nrScripts) + + [x_temp fs] = wavread(names{1,scriptNr}); + if(down==1) + x_temp = resample(x_temp,new_fs,fs); + fs=new_fs; + end, + + + addpath(directoryAnnotation); + files2=find_format(directoryAnnotation, 'txt'); + annotation=textread(files2.names{1,i}, '%s' ,'delimiter', '\t'); + startStop=zeros(length(annotation)/3,2); + id=cell(length(annotation)/3,1); + u=1; + for(v=1:3:length(annotation)) + startStop(u,1)=str2num(annotation{v,1}); + startStop(u,2)=str2num(annotation{v+1,1}); + x{u,2}=fs; + x{u,1}=x_temp(ceil(startStop(u,1)*x{u,2})+1:ceil(startStop(u,2)*x{u,2})); + id{u,1}=annotation{v+2,1}; + u=u+1; + end, + segments{k,i}=x; + samples{k,i}=startStop; + labels{k,i}=id; + rmpath(directoryAnnotation{k,1}); + clear x; + end, +end + + + + + + + + + + + + +