Mercurial > hg > aimc
comparison matlab/bmm/carfac/SAI_DesignLayers.m @ 623:b3118c9ed67f
Turn the AGC coeffs inside out: array of structs instead of a struct of little arrays.
In C++ use a vector<AGC_coeffs> for this; each of 4 stages has an entry; many fewer places
need to do indexing by stage, and this removes the temptation to use little eigen arrays
for the 4 stages.
Also latest version of experimental log-lag SAI hacks.
author | dicklyon@google.com |
---|---|
date | Tue, 21 May 2013 04:24:05 +0000 |
parents | fc353426eaad |
children |
comparison
equal
deleted
inserted
replaced
611:0fbaf443ec82 | 623:b3118c9ed67f |
---|---|
15 % distributed under the License is distributed on an "AS IS" BASIS, | 15 % distributed under the License is distributed on an "AS IS" BASIS, |
16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17 % See the License for the specific language governing permissions and | 17 % See the License for the specific language governing permissions and |
18 % limitations under the License. | 18 % limitations under the License. |
19 | 19 |
20 function [layer_array, total_width] = SAI_DesignLayers( ... | 20 function [layer_array, total_width, lag_period_samples] = SAI_DesignLayers( ... |
21 n_layers, width_per_layer) | 21 n_layers, width_per_layer, seglen) |
22 % function [layer_array, total_width] = SAI_DesignLayers( ... | 22 % function [layer_array, total_width] = SAI_DesignLayers( ... |
23 % n_layers, width_per_layer) | 23 % n_layers, width_per_layer) |
24 % | 24 % |
25 % The layer_array is a struct array containing an entry for each layer | 25 % The layer_array is a struct array containing an entry for each layer |
26 % in a layer of power-of-2 decimated pieces of SAI that get composited | 26 % in a layer of power-of-2 decimated pieces of SAI that get composited |
39 % otherwise width + left_overlap + right_overlap. The total width of the | 39 % otherwise width + left_overlap + right_overlap. The total width of the |
40 % final composite SAI is the sum of the widths. | 40 % final composite SAI is the sum of the widths. |
41 % Other fields could be added to hold state, such as history buffers for | 41 % Other fields could be added to hold state, such as history buffers for |
42 % each layer, or those could go in state struct array... | 42 % each layer, or those could go in state struct array... |
43 | 43 |
44 | |
45 % Elevate these to a param struct? | 44 % Elevate these to a param struct? |
46 if nargin < 1 | 45 if nargin < 1 |
47 n_layers = 11 | 46 n_layers = 12; |
48 end | 47 end |
49 if nargin < 2 | 48 if nargin < 2 |
50 width_per_layer = 32; % resolution "half life" in space | 49 width_per_layer = 24; % resolution "half life" in space; half-semitones |
51 end | 50 end |
52 future_lags = 4 * width_per_layer; | 51 future_lags = 0 * width_per_layer; |
53 width_first_layer = future_lags + 1 * width_per_layer; | 52 width_extra_last_layer = 0 * width_per_layer; |
54 width_extra_last_layer = 2 * width_per_layer; | 53 left_overlap = 10; |
55 left_overlap = 15; | 54 right_overlap = 10; |
56 right_overlap = 15; | 55 first_window_width = seglen; % Less would be a problem. |
57 first_window_width = 400; % or maybe use seglen? or 0.020 * fs? | |
58 min_window_width = 1*width_per_layer; % or somewhere on that order | 56 min_window_width = 1*width_per_layer; % or somewhere on that order |
59 window_exponent = 1.4; | 57 window_exponent = 1.4; |
60 alpha_max = 1; | 58 alpha_max = 1; |
59 | |
60 width_first_layer = future_lags + 2 * width_per_layer; | |
61 | 61 |
62 % Start with NAP_samples_per_SAI_sample, declining to 1 from here: | 62 % Start with NAP_samples_per_SAI_sample, declining to 1 from here: |
63 max_samples_per = 2^(n_layers - 1); | 63 max_samples_per = 2^(n_layers - 1); |
64 % Construct the overall lag-warping function: | 64 % Construct the overall lag-warping function: |
65 NAP_samples_per_SAI_sample = [ ... | 65 NAP_samples_per_SAI_sample = [ ... |
66 max_samples_per * ones(1, width_extra_last_layer), ... | 66 max_samples_per * ones(1, width_extra_last_layer), ... |
67 max_samples_per * ... | 67 max_samples_per * ... |
68 2 .^ (-(1:(width_per_layer * (n_layers - 1))) / width_per_layer), ... | 68 2 .^ (-(1:(width_per_layer * (n_layers - 1))) / width_per_layer), ... |
69 ones(1, width_first_layer)]; | 69 ones(1, width_first_layer), ]; % w/o future for now. |
70 | |
71 lag_period_samples = cumsum(NAP_samples_per_SAI_sample(end:-1:1)); | |
72 lag_period_samples = lag_period_samples(end:-1:1); % Put it back in order. | |
73 lag_period_samples = lag_period_samples - lag_period_samples(end - future_lags); | |
70 | 74 |
71 % Each layer needs a lag_warp for a portion of that, divided by | 75 % Each layer needs a lag_warp for a portion of that, divided by |
72 % 2^(layer-1), where the portion includes some overlap into its neighbors | 76 % 2^(layer-1), where the portion includes some overlap into its neighbors |
73 % with higher layer numbers on left, lower on right. | 77 % with higher layer numbers on left, lower on right. |
74 | 78 |
169 % using two window placements overlapped 50%. | 173 % using two window placements overlapped 50%. |
170 n_triggers = 2; | 174 n_triggers = 2; |
171 layer_array(layer).n_window_pos = n_triggers; | 175 layer_array(layer).n_window_pos = n_triggers; |
172 layer_array(layer).buffer_width = layer_array(layer).frame_width + ... | 176 layer_array(layer).buffer_width = layer_array(layer).frame_width + ... |
173 floor((1 + (n_triggers - 1)/2) * layer_array(layer).window_width); | 177 floor((1 + (n_triggers - 1)/2) * layer_array(layer).window_width); |
178 % Make sure it's big enough for next layer to shift in what it wants. | |
179 n_shift = ceil(seglen / (2.0^(layer - 1))); | |
180 if layer_array(layer).buffer_width < 6 + n_shift; | |
181 layer_array(layer).buffer_width = 6 + n_shift; | |
182 end | |
174 end | 183 end |
175 | 184 |
176 return | 185 return |
177 | 186 |