Diff of /blockproc/blockana.m [797cbb] .. [b6ad1a]  Maximize  Restore

Switch to unified view

a/blockproc/blockana.m b/blockproc/blockana.m
...
...
15
%   `F.blokalg`. Assuming |blockana| is called in the loop only once, *fola*
15
%   `F.blokalg`. Assuming |blockana| is called in the loop only once, *fola*
16
%   can be omitted and the overlaps are handled in the background
16
%   can be omitted and the overlaps are handled in the background
17
%   automatically.    
17
%   automatically.    
18
%
18
%
19
%   See also: block, blocksyn, blockplay
19
%   See also: block, blocksyn, blockplay
20
%
21
%   References: dogrhove12 ltfatnote026
20
    
22
    
21
    if nargin<2
23
    if nargin<2
22
        error('%s: Too few input parameters.',upper(mfilename));
24
        error('%s: Too few input parameters.',upper(mfilename));
23
    end;
25
    end;
24
    
26
    
...
...
35
    % Next block index start (from a global point of view, starting with zero)
37
    % Next block index start (from a global point of view, starting with zero)
36
    nextSb = block_interface('getPos');
38
    nextSb = block_interface('getPos');
37
    % Block index start (from a global point of view, starting with zero)
39
    % Block index start (from a global point of view, starting with zero)
38
    Sb = nextSb-Lb;
40
    Sb = nextSb-Lb;
39
    
41
    
40
    if strcmp(F.blokalg,'sliced')
42
    do_sliced = strcmp(F.blokalg,'sliced');
41
        % General processing
42
        % Equal block length assumtion
43
        % Append the previous block
44
        fext = [loadOverlap(Lb,size(f,2),fola);f];
45
        % Save the current block
46
        if nargout>1
47
           fola = storeOverlap(fext,Lb);
48
        else
49
           storeOverlap(fext,Lb);
50
        end
51
        % Multiply by the slicing window (all channels)
52
        fwin = bsxfun(@times,F.sliwin,fext);
53
        fwin = [fwin; zeros(F.L-size(fwin,1),size(fwin,2))];
54
        % Apply transform
55
        c = F.frana(fwin);
56
    elseif strcmp(F.blokalg,'segola')
43
    do_segola = strcmp(F.blokalg,'segola');
57
      if ~isfield(F,'winLen') 
58
         error('%s: Frame does not have FIR windows.',upper(mfilename));
59
      end
60
      Lw = F.winLen;
61
      
44
    
62
      switch(F.type)
63
         case 'fwt'
64
           J = F.J;
65
           w = F.g;
66
           m = numel(w.h{1}.h);
67
           a = w.a(1);
68
           if Lb<a^J
69
               error('%s: Minimum block length is %i.',upper(mfilename),a^J);
70
           end
71
           rred = (a^J-1)/(a-1)*(m-a);
72
           Sbolen = rred + mod(Sb,a^J);
73
           nextSbolen = rred + mod(nextSb,a^J);
74
           
75
           % Extend from the left side
76
           fext = [loadOverlap(Sbolen,size(f,2),fola);f];
77
           % Save the overlap for the next block
78
           if nargout>1
79
              fola = storeOverlap(fext,nextSbolen);
80
           else
81
              storeOverlap(fext,nextSbolen);
82
           end
83
           
84
           c = block_fwt(fext,w,J);
85
         % Uniform window lengths  
86
         case {'dgtreal','dgt'}
87
%            if Lb<F.a
88
%                error('%s: Minimum block length is %i.',upper(mfilename),F.a);
89
%            end 
90
           a = F.a; 
91
           Lwl = floor(Lw/2);
92
93
           % Overlap length 
94
           Sbolen = ceil((Lw-1)/a)*a + mod(Sb,a);
95
           % Next block overlap length
96
           nextSbolen = ceil((Lw-1)/a)*a + mod(nextSb,a);
97
           Lext = Sbolen + Lb - nextSbolen + Lwl;
98
           startc = ceil(Lwl/a)+1;
99
           endc = ceil((Lext)/a);
100
           
101
           
102
           % Extend from the left side
103
           fext = [loadOverlap(Sbolen,size(f,2),fola);f];
104
           % Save the overlap for the next block
105
           if nargout>1
106
              fola = storeOverlap(fext,nextSbolen);
107
           else
108
              storeOverlap(fext,nextSbolen);
109
           end
110
111
           % Pad with zeros to comply with the frame requirements
112
           fext = [fext; zeros(F.L-size(fext,1),size(fext,2))];
113
           c = F.frana(fext(1:F.L,:));
114
           % Pick just valid coefficients
115
           cc = F.coef2native(c,size(c));
116
           cc = cc(:,startc:endc,:);
117
           c = F.native2coef(cc);
118
         case {'filterbank','filterbankreal','ufilterbank','ufilterbankreal'}
119
            
120
         otherwise
121
           error('%s: Unsupported frame.',upper(mfilename));
122
      end
123
    elseif strcmp(F.blokalg,'naive')
45
    if strcmp(F.blokalg,'naive')
46
       % Most general. Should work for anything.
47
       % Produces awful block artifacts when coefficients are altered.
124
       f = [f; zeros(F.L-size(f,1),size(f,2))];
48
       f = [f; zeros(F.L-size(f,1),size(f,2))];
125
       c = F.frana(f);
49
       c = F.frana(f);
50
    elseif do_sliced || do_segola
51
52
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
       %% STEP 1) Determine overlap lengths 
54
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55
       if do_sliced
56
          % Sliced real-time block processing
57
          % Equal block length assumtion
58
          Sbolen = Lb;
59
          nextSbolen = Lb;
60
       else
61
             if ~isfield(F,'winLen') 
62
                error('%s: Frame does not have FIR windows.',upper(mfilename));
63
             end
64
             % Window length
65
             Lw = F.winLen;
66
          switch(F.type)
67
             case 'fwt'
68
                J = F.J;
69
                w = F.g;
70
                m = numel(w.h{1}.h);
71
                a = w.a(1);
72
                if Lb<a^J
73
                   error('%s: Minimum block length is %i.',upper(mfilename),a^J);
74
                end
75
                rred = (a^J-1)/(a-1)*(m-a);
76
                Sbolen = rred + mod(Sb,a^J);
77
                nextSbolen = rred + mod(nextSb,a^J);
78
             case {'dgtreal','dgt'}
79
                a = F.a; 
80
                Sbolen = ceil((Lw-1)/a)*a + mod(Sb,a);
81
                nextSbolen = ceil((Lw-1)/a)*a + mod(nextSb,a);
82
             case {'filterbank','filterbankreal','ufilterbank','ufilterbankreal'}
83
                a = F.lcma;
84
                Sbolen = ceil((Lw-1)/a)*a + mod(Sb,a);
85
                nextSbolen = ceil((Lw-1)/a)*a + mod(nextSb,a);
86
             otherwise
87
                error('%s: Unsupported frame.',upper(mfilename));
88
          end
89
       end
90
       
91
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92
       %% STEP 2) Common overlap handling 
93
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94
       % Append the previous block
95
       fext = [loadOverlap(Sbolen,size(f,2),fola);f];
96
       % Save the current block
97
       if nargout>1
98
          fola = storeOverlap(fext,nextSbolen);
99
       else
100
          storeOverlap(fext,nextSbolen);
101
       end
102
       
103
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104
       %% STEP 3) Do the rest
105
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106
       if do_sliced
107
          % Multiply by the slicing window (all channels)
108
          fwin = bsxfun(@times,F.sliwin,fext);
109
          fwin = [fwin; zeros(F.L-size(fwin,1),size(fwin,2))];
110
          % Apply transform
111
          c = F.frana(fwin);
112
       else
113
          switch(F.type)
114
             case 'fwt'
115
                c = block_fwt(fext,w,J);
116
             case {'dgtreal','dgt'}
117
                Lwl = floor(Lw/2);
118
                Lext = Sbolen + Lb - nextSbolen + Lwl;
119
                startc = ceil(Lwl/a)+1;
120
                endc = ceil((Lext)/a);
121
                % Pad with zeros to comply with the frame requirements
122
                fext = [fext; zeros(F.L-size(fext,1),size(fext,2))];
123
                c = F.frana(fext(1:F.L,:));
124
                % Pick just valid coefficients
125
                cc = F.coef2native(c,size(c));
126
                cc = cc(:,startc:endc,:);
127
                c = F.native2coef(cc);
128
             case {'filterbank','filterbankreal','ufilterbank','ufilterbankreal'}
129
                a = F.a(:,1);
130
                Lwl = floor(Lw/2);
131
                Lext = Sbolen + Lb - nextSbolen + Lwl;
132
                startc = ceil(Lwl./a)+1;
133
                endc = ceil((Lext)./a);
134
                fext = [fext; zeros(F.L-size(fext,1),size(fext,2))];
135
                c = F.frana(fext(1:F.L,:));
136
                cc = F.coef2native(c,size(c));
137
                cc = cellfun(@(cEl,sEl,eEl) cEl(sEl:eEl,:),cc,num2cell(startc),num2cell(endc),'UniformOutput',0);
138
                c = F.native2coef(cc);
139
          end
140
       end
126
    else
141
    else
127
       error('%s: Frame was not created with blockaccel.',upper(mfilename));
142
       error('%s: Frame was not created with blockaccel.',upper(mfilename));
128
    end
143
    end
129
144
130
end % BLOCKANA
145
end % BLOCKANA

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks