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