wolffd@0
|
1 %sucht die datei (1) "coelebs_aufn1_ch1"unter sourcedir bei datei (2)
|
wolffd@0
|
2 % coelebs_aufn1_ch1_01 im segmentsdir.
|
wolffd@0
|
3 % daraufhin wird die genaue stelle des vorkommens von (2) in (1) gesucht,
|
wolffd@0
|
4 % und in sekunden an den dateinamen angehängt;
|
wolffd@0
|
5
|
wolffd@0
|
6 clear
|
wolffd@0
|
7 global globalvars;
|
wolffd@0
|
8 addpath('..\vogelst\k-band250905')
|
wolffd@0
|
9 sourcedir='F:\Aufnahmen\2006-Juni-3-Remscheid-Daniel';
|
wolffd@0
|
10 %sourcedir='F:\Ample';
|
wolffd@0
|
11 %sourcedir='M:\PrograMathe\matlab\work\hiwi\vogelst\testmaterial\online2';
|
wolffd@0
|
12
|
wolffd@0
|
13 segmentsdir='F:\viele_einzelne_strophen\fringila_coelebs_buchfink\typ1';
|
wolffd@0
|
14
|
wolffd@0
|
15 %segmentsdir='F:\viele_einzelne_strophen\fringila_coelebs_buchfink\tst';
|
wolffd@0
|
16 %segmentsdir='M:\PrograMathe\matlab\work\hiwi\vogelst\testmaterial\online';
|
wolffd@0
|
17
|
wolffd@0
|
18
|
wolffd@0
|
19
|
wolffd@0
|
20 %---------------------------------------------z-------------zugehörige dateien suchen
|
wolffd@0
|
21 allpaths=genpath(sourcedir);
|
wolffd@0
|
22 data_names=dir(strcat(segmentsdir,'\*.wav'));
|
wolffd@0
|
23 psourcedirs = explode(';',allpaths);
|
wolffd@0
|
24 for i = 1:length(data_names)
|
wolffd@0
|
25 ldata_names{i} = data_names(i).name;
|
wolffd@0
|
26 end
|
wolffd@0
|
27
|
wolffd@0
|
28 names_done = [];
|
wolffd@0
|
29 relsource_files = {};
|
wolffd@0
|
30 for i = 1:length(psourcedirs)
|
wolffd@0
|
31 actdir = dir(strcat(psourcedirs{i},'\*.wav'));
|
wolffd@0
|
32 ldata_names = ldata_names(setdiff(1:length(ldata_names),names_done));
|
wolffd@0
|
33 for j = 1:length(ldata_names)
|
wolffd@0
|
34 for k = 1:length(actdir)
|
wolffd@0
|
35 if(strncmp(actdir(k).name,ldata_names{j},length(ldata_names{j})-7))
|
wolffd@0
|
36 names_done = [names_done j];
|
wolffd@0
|
37 relsource_files= cat(1,relsource_files,{[strcat(psourcedirs{i},'\',actdir(k).name)] [strcat(segmentsdir,'\',ldata_names{j})]});
|
wolffd@0
|
38 end
|
wolffd@0
|
39 end
|
wolffd@0
|
40 end
|
wolffd@0
|
41 end
|
wolffd@0
|
42
|
wolffd@0
|
43
|
wolffd@0
|
44
|
wolffd@0
|
45 oldsource='';
|
wolffd@0
|
46 oldsamplesource=0;
|
wolffd@0
|
47 k=1;
|
wolffd@0
|
48 position=zeros(size(relsource_files,1),2);
|
wolffd@0
|
49
|
wolffd@0
|
50 i=1;
|
wolffd@0
|
51 while i <= size(relsource_files,1)
|
wolffd@0
|
52 aktsource =char(relsource_files(i,1));
|
wolffd@0
|
53 aktsamplesource=i;
|
wolffd@0
|
54 %--------------------------------------------------features generieren und overhead
|
wolffd@0
|
55
|
wolffd@0
|
56 if ~strcmp(aktsource,oldsource) || (aktsamplesource~=oldsamplesource) %neue quelldatei
|
wolffd@0
|
57 aktmajstart=1;
|
wolffd@0
|
58 siz=WAVREAD(aktsource,'size');
|
wolffd@0
|
59 siz=siz(1,1);
|
wolffd@0
|
60 aktmajpointer = min(siz,globalvars.maxaudiodatalen);
|
wolffd@0
|
61 [aktdata,sr,nbits]=wavread(aktsource,[aktmajstart aktmajpointer]);
|
wolffd@0
|
62 oldsource=aktsource;
|
wolffd@0
|
63 if length(aktdata(1,:)) > 1
|
wolffd@0
|
64 aktdata = aktdata(:,1);
|
wolffd@0
|
65 end
|
wolffd@0
|
66 windowsz=floor(sr/5);
|
wolffd@0
|
67 fprintf('generating features for fast search \n');
|
wolffd@0
|
68 aktfeat =resample(abs(specgram(aktdata,windowsz,sr,windowsz,floor(windowsz/2))),1,40);
|
wolffd@0
|
69 elseif (aktmajpointer < siz) && (aktsamplesource==oldsamplesource) %alte quelldatei zu lang
|
wolffd@0
|
70 aktmajstart=aktmajstart+floor(globalvars.maxaudiodatalen/2);
|
wolffd@0
|
71 aktmajpointer=min(aktmajpointer+floor(globalvars.maxaudiodatalen/2),siz);
|
wolffd@0
|
72 if (aktmajstart-aktmajpointer) < windowsz
|
wolffd@0
|
73 aktmajstart=max(aktmajstart-windowsz,1);
|
wolffd@0
|
74 end
|
wolffd@0
|
75 [aktdata,sr,nbits]=wavread(aktsource,[aktmajstart aktmajpointer]);
|
wolffd@0
|
76 if length(aktdata(1,:)) > 1
|
wolffd@0
|
77 aktdata = aktdata(:,1);
|
wolffd@0
|
78 end
|
wolffd@0
|
79 fprintf('generating features for fast search \n');
|
wolffd@0
|
80 aktfeat =resample(abs(specgram(aktdata,windowsz,sr,windowsz,floor(windowsz/2))),1,40);
|
wolffd@0
|
81 end
|
wolffd@0
|
82
|
wolffd@0
|
83
|
wolffd@0
|
84 if (aktsamplesource~=oldsamplesource)%neue suchdatei
|
wolffd@0
|
85 [aktsample,sr,nbits]=wavread(char(relsource_files(i,2)));
|
wolffd@0
|
86 oldsamplesource=aktsamplesource;
|
wolffd@0
|
87 if length(aktsample(1,:)) > 1
|
wolffd@0
|
88 aktsample = aktsample(:,1);
|
wolffd@0
|
89 end
|
wolffd@0
|
90
|
wolffd@0
|
91 if(length(aktsample)>=windowsz)
|
wolffd@0
|
92 aktsamplefeat =resample(abs(specgram(aktsample(1:windowsz),windowsz,sr,windowsz,floor(windowsz/2))),1,40);
|
wolffd@0
|
93 for j=1:size(aktfeat,2)
|
wolffd@0
|
94 di(j)=dist(aktfeat(:,j),aktsamplefeat(:,1));
|
wolffd@0
|
95 end
|
wolffd@0
|
96 bdi = di>mean(di);
|
wolffd@0
|
97 else
|
wolffd@0
|
98 fprintf('fast search not possible \n');
|
wolffd@0
|
99 bdi=ones(1,size(aktfeat,2))
|
wolffd@0
|
100 end
|
wolffd@0
|
101 fprintf(strcat('searching for \n', escape(aktsource ),' in \n' ,escape(char(relsource_files(i,2))),'\n' ));
|
wolffd@0
|
102 end
|
wolffd@0
|
103
|
wolffd@0
|
104
|
wolffd@0
|
105 %---------------------- bestandteil lokalisieren (k mismatches), ausreichende minmatches
|
wolffd@0
|
106 minmatches=length(aktsample);
|
wolffd@0
|
107 found=0;
|
wolffd@0
|
108 aktpointer=1;
|
wolffd@0
|
109 aktstart=1;
|
wolffd@0
|
110 len = length(aktdata);
|
wolffd@0
|
111 len2=length(aktsample);
|
wolffd@0
|
112 while ((aktstart+len2)<=len) &&~found
|
wolffd@0
|
113 mismatches=0;
|
wolffd@0
|
114 aktstart=aktstart+1;
|
wolffd@0
|
115 aktpointer=aktstart;
|
wolffd@0
|
116 while (aktpointer <= len)&&(mismatches <k)&&((aktpointer-(aktstart)+1)<=len2)
|
wolffd@0
|
117 if(aktdata(aktpointer) ~= aktsample(aktpointer-(aktstart)+1))
|
wolffd@0
|
118 mismatches = mismatches+1;
|
wolffd@0
|
119 if(~bdi(floor(aktpointer/(windowsz/2))+1))
|
wolffd@0
|
120 aktpointer=aktpointer+(windowsz/2);
|
wolffd@0
|
121 end
|
wolffd@0
|
122 end
|
wolffd@0
|
123 aktpointer=aktpointer+1;
|
wolffd@0
|
124 if (aktpointer-aktstart) >= minmatches
|
wolffd@0
|
125 fprintf('found');
|
wolffd@0
|
126 position(i,:)=[floor((aktmajstart-1+aktstart)/sr) floor((aktmajstart-1+aktpointer)/sr)]
|
wolffd@0
|
127 found=1;
|
wolffd@0
|
128 break
|
wolffd@0
|
129 end
|
wolffd@0
|
130 end
|
wolffd@0
|
131 end
|
wolffd@0
|
132 if(position(i,2)~=0)
|
wolffd@0
|
133
|
wolffd@0
|
134 %---------------------------------------------zugehörige infos in dateien schreiben
|
wolffd@0
|
135 newfilename= strcat(substr(char(relsource_files(i,2)),0,length(relsource_files(i,2))-5),'__',...
|
wolffd@0
|
136 s_to_hhmmss(position(i,1)),'-',s_to_hhmmss(position(i,2)),'.wav');
|
wolffd@0
|
137 movefile(char(relsource_files(i,2)),newfilename);
|
wolffd@0
|
138
|
wolffd@0
|
139 filetoopen=strcat(newfilename,'.txt');
|
wolffd@0
|
140 ftoex=dir(filetoopen);
|
wolffd@0
|
141 if(length(ftoex)==0)
|
wolffd@0
|
142 FID = fopen(filetoopen,'w');
|
wolffd@0
|
143 fprintf(FID,'%s','annotations for ');
|
wolffd@0
|
144 fprintf(FID,'%s',newfilename);
|
wolffd@0
|
145 fprintf(FID,'\n');
|
wolffd@0
|
146 fprintf(FID,'%s','sourcefile available at');
|
wolffd@0
|
147 fprintf(FID,'\n');
|
wolffd@0
|
148 fprintf(FID,'%s',char(relsource_files(i,1)));
|
wolffd@0
|
149 fprintf(FID,'\n');
|
wolffd@0
|
150 fprintf(FID,'%s','time of occurrence in hhmmss format:');
|
wolffd@0
|
151 fprintf(FID,'\n');
|
wolffd@0
|
152 fprintf(FID,'%s',s_to_hhmmss(position(i,1)));
|
wolffd@0
|
153 fprintf(FID,'%s','-');
|
wolffd@0
|
154 fprintf(FID,'%s',s_to_hhmmss(position(i,2)));
|
wolffd@0
|
155 fprintf(FID,'\n');
|
wolffd@0
|
156 fprintf(FID,'%s','in seconds:');
|
wolffd@0
|
157 fprintf(FID,'\n');
|
wolffd@0
|
158 fprintf(FID,'%s',sprintf('%d',position(i,1)));
|
wolffd@0
|
159 fprintf(FID,'\n');
|
wolffd@0
|
160 fprintf(FID,'%s',sprintf('%d',position(i,2)));
|
wolffd@0
|
161 fprintf(FID,'\n');
|
wolffd@0
|
162 fprintf(FID,'%s','comments:');
|
wolffd@0
|
163
|
wolffd@0
|
164 fclose(FID);
|
wolffd@0
|
165 end
|
wolffd@0
|
166
|
wolffd@0
|
167 i=i+1;
|
wolffd@0
|
168 elseif(aktmajpointer==siz)
|
wolffd@0
|
169 i=i+1;
|
wolffd@0
|
170 end
|
wolffd@0
|
171 end
|
wolffd@0
|
172
|
wolffd@0
|
173
|
wolffd@0
|
174
|
wolffd@0
|
175
|
wolffd@0
|
176
|
wolffd@0
|
177
|