1function [setupStructNew, delayStructNew] = updateSettings(microphone, TheFarEnd, setupStruct, delayStruct); 2 3% other, constants 4setupStruct.hsupport1 = setupStruct.support/2 + 1; 5setupStruct.factor = 2 / setupStruct.oversampling; 6setupStruct.updatel = setupStruct.support/setupStruct.oversampling; 7setupStruct.estLen = round(setupStruct.avtime * setupStruct.samplingfreq/setupStruct.updatel); 8 9% compute some constants 10blockLen = setupStruct.support/setupStruct.oversampling; 11delayStruct.maxDelayb = floor(setupStruct.samplingfreq*delayStruct.maxDelay/setupStruct.updatel); % in blocks 12 13%input 14tlength = min([length(microphone),length(TheFarEnd)]); 15updateno = floor(tlength/setupStruct.updatel); 16setupStruct.tlength = setupStruct.updatel*updateno; 17setupStruct.updateno = updateno - setupStruct.oversampling + 1; 18 19% signal length 20n = floor(min([length(TheFarEnd), length(microphone)])/setupStruct.support)*setupStruct.support; 21setupStruct.nb = n/blockLen - setupStruct.oversampling + 1; % in blocks 22 23setupStruct.win = sqrt([0 ; hanning(setupStruct.support-1)]); 24 25% Construct filterbank in Bark-scale 26 27K = setupStruct.subBandLength; %Something's wrong when K even 28erbs = 21.4*log10(0.00437*setupStruct.samplingfreq/2+1); 29fe = (10.^((0:K)'*erbs/K/21.4)-1)/0.00437; 30setupStruct.centerFreq = fe; 31H = diag(ones(1,K-1))+diag(ones(1,K-2),-1); 32Hinv = inv(H); 33aty = 2*Hinv(end,:)*fe(2:end-1); 34boundary = aty - (setupStruct.samplingfreq/2 + fe(end-1))/2; 35if rem(K,2) 36 x1 = min([fe(2)/2, -boundary]); 37else 38 x1 = max([0, boundary]); 39end 40%x1 41g = fe(2:end-1); 42g(1) = g(1) - x1/2; 43x = 2*Hinv*g; 44x = [x1;x]; 45%figure(42), clf 46xy = zeros((K+1)*4,1); 47yy = zeros((K+1)*4,1); 48xy(1:4) = [fe(1) fe(1) x(1) x(1)]'; 49yy(1:4) = [0 1 1 0]'/x(1); 50for kk=2:K 51 xy((kk-1)*4+(1:4)) = [x(kk-1) x(kk-1) x(kk) x(kk)]'; 52 yy((kk-1)*4+(1:4)) = [0 1 1 0]'/(x(kk)-x(kk-1)); 53end 54xy(end-3:end) = [x(K) x(K) fe(end) fe(end)]'; 55yy(end-3:end) = [0 1 1 0]'/(fe(end)*2-2*x(K)); 56%plot(xy,yy,'LineWidth',2) 57%fill(xy,yy,'y') 58 59x = [0;x]; 60xk = x*setupStruct.hsupport1/setupStruct.samplingfreq*2; 61%setupStruct.erbBoundaries = xk; 62numInBand = zeros(length(xk),1); 63xh = (0:setupStruct.hsupport1-1); 64 65for kk=1:length(xk) 66 if (kk==length(xk)) 67 numInBand(kk) = length(find(xh>=xk(kk))); 68 else 69 numInBand(kk) = length(intersect(find(xh>=xk(kk)),find(xh<xk(kk+1)))); 70 end 71end 72setupStruct.numInBand = numInBand; 73 74setupStructNew = setupStruct; 75 76delayStructNew = struct(... 77 'sxAll2',zeros(setupStructNew.hsupport1,setupStructNew.nb),... 78 'syAll2',zeros(setupStructNew.hsupport1,setupStructNew.nb),... 79 'z200',zeros(5,setupStructNew.hsupport1),... 80 'z500',zeros(5,delayStruct.maxDelayb+1),... 81 'bxspectrum',uint32(zeros(setupStructNew.nb,1)),... 82 'byspectrum',uint32(zeros(setupStructNew.nb,1)),... 83 'bandfirst',delayStruct.bandfirst,'bandlast',delayStruct.bandlast,... 84 'bxhist',uint32(zeros(delayStruct.maxDelayb+1,1)),... 85 'bcount',zeros(1+delayStruct.maxDelayb,setupStructNew.nb),... 86 'fout',zeros(1+delayStruct.maxDelayb,setupStructNew.nb),... 87 'new',zeros(1+delayStruct.maxDelayb,setupStructNew.nb),... 88 'smlength',delayStruct.smlength,... 89 'maxDelay', delayStruct.maxDelay,... 90 'maxDelayb', delayStruct.maxDelayb,... 91 'oneGoodEstimate', 0,... 92 'delayAdjust', 0,... 93 'delayNew',zeros(setupStructNew.nb,1),... 94 'delay',zeros(setupStructNew.nb,1)); 95