function [callnumber, part, begframe, lenframe, begsam, lensam]=wheremg(begmg, lenmg) % Syntax: [call, part, begframe, lenframe, begsam, lensam]=wheremg(begmg, lenmg); % % function for multigram finding in the original database. % Before 1st call to that function , wheremginit MUST BE EXECUTED filling % some global variables. % % begmg - beginning of multigram in the big chain % lenmg - length of multigram % call - call number, where is this multigram % part - part number (within the call) % begframe - beginning frame of that mg. (within the call). % lenframe - length of that mg. (in frames) % begsam - beginning of that mg. (in samples) % lensam - length of that mg. (in samples) % global vars got from wheremginit: global wmg_liste wmg_call_begins_in_targets wmg_calls wmg_path %%% determine the call. callindex = find( begmg >= wmg_call_begins_in_targets(1:wmg_calls) & ... begmg < wmg_call_begins_in_targets(2:wmg_calls+1) ); if (size(callindex) ~= [1 1] ) disp ('can not find the call corresponding to that multigram'); end begcall = wmg_call_begins_in_targets (callindex); callnumber = wmg_liste(callindex); %%% get the beginning relative to this call begmgincall = begmg - begcall; %%% load the files necessary for call - at first, the IFLIM FILE %--------------------------------------------------------------- nameiflim=[wmg_path int2str(callnumber) '.iflim']; iflim=readparam(nameiflim, [3, inf], 'long'); phibegins=iflim(1,:); phiends=iflim(2,:); phigrav=iflim(3,:); philengths=phiends-phibegins; % then PLIM file %--------------- nameplim=[wmg_path int2str(callnumber) '.plim']; plimfile=fopen(nameplim, 'r'); plim=fscanf(plimfile, '%d', [2 inf]); fclose(plimfile); pbegins=plim(1,:); plengths=plim(2,:); parts=length(plengths); %pbegins %plengths %%% now, put it all together %----------------------------------- % get the no of part and check, if the mg. does not "cross" parts partnumber=max (find (begmgincall >= pbegins)) - 1; % in C indexing if (begmgincall + lenmg > pbegins(partnumber+1) + plengths(partnumber+1) ), error ('this is bad. Multigram goes over the part border.'); end % begmgincall and lenmg can be used directly to index the interpol functions %============================================================================ % IMPORTANT PART: how to choose the beg. and end of a segment ? % Possibilities: % 1) beginning of 1st, end of last interpol function % 2) center of gravity of 1st, center of gravity of last interepol fun % (bad for just uni-grams) % 3) beginning: average of the beginning of 1st fun with the end of previous fun % end: average of the end of last fun with the beginning of next fun. % for 1st function in the beginning of part - beg. of 1st function % for last fun in the end of part - end of last fun. bmm=begmgincall + 1 ; % for Matlab %%% 1) %begframe=phibegins(bmm); %endframe=phiends(bmm + lenmg - 1); %%% 2) %begframe=phigrav(bmm); %endframe=phigrav(bmm + lenmg - 1); %%% 3) partbegin=pbegins(partnumber+1); partlength=plengths(partnumber+1); if begmgincall > partbegin, % not first function in part begframe=round( (phibegins(bmm) + phiends(bmm-1)) / 2); else % 1st function in part begframe=phibegins(bmm); end if begmgincall < partbegin + partlength -1, % not last function in part endframe = round ( (phiends(bmm + lenmg - 1) + phibegins(bmm + lenmg)) / 2); else % it is the last endframe=phiends(bmm + lenmg - 1); end % ----------- lenframe=endframe-begframe+1; % and in samples: begsam=begframe * 80; endsam=endframe * 80 + 159; lensam=endsam-begsam+1; %disp('call, part, begframe, lenframe, begsam, lensam'); %[int2str(callnumber) ' ' int2str(partnumber) ' ' int2str(begframe) ' ' int2str(lenframe) ... % ' ' int2str(begsam) ' ' int2str(lensam)] disp([int2str(callnumber) ' ' int2str(begsam) ' ' int2str(lensam)]);