@@ -10,9 +10,9 @@ function check_volume_levels(cmd, fn1, fn2, fn3, do_plot)
1010% do_plot - Plot figure of levels if 1, defaults to 0
1111%
1212% E.g.
13- % check_volume_levels('generate','sine.wav');
14- % check_volume_levels('measure','rec1.wav','rec2.wav','rec3.wav');
15- % check_volume_levels('measure','rec1.wav','rec2.wav','rec3.wav', 1);
13+ % check_volume_levels('generate', 'sine.wav');
14+ % check_volume_levels('measure', 'rec1.wav', 'rec2.wav', 'rec3.wav');
15+ % check_volume_levels('measure', 'rec1.wav', 'rec2.wav', 'rec3.wav', 1);
1616
1717% SPDX-License-Identifier: BSD-3-Clause
1818% Copyright(c) 2016 Intel Corporation. All rights reserved.
@@ -55,13 +55,13 @@ function check_volume_levels(cmd, fn1, fn2, fn3, do_plot)
5555 fs = 48e3 ;
5656 f1 = 701 ;
5757 f2 = 1297 ;
58- a = 10 ^ (-40 / 20 );
58+ a = 10 ^ (-40 / 20 );
5959 t = 60 ;
6060 x1 = multitone(fs , f1 , a , t );
6161 x2 = multitone(fs , f2 , a , t );
6262 x = [x1 ' ; x2 ' ]' ;
6363 sx = size(x );
64- d = (rand(sx(1 ), sx(2 )) - 0.5 )/ 2 ^ 15 ;
64+ d = (rand(sx(1 ), sx(2 )) - 0.5 ) / 2 ^ 15 ;
6565 audiowrite(fn , x + d , fs );
6666 pass = 1 ;
6767end
@@ -90,7 +90,7 @@ function check_volume_levels(cmd, fn1, fn2, fn3, do_plot)
9090 t1.vtol = 0.5 ; % Pass test with max +/- 0.5 dB mismatch
9191
9292 % Check test 1
93- pass1 = level_vs_time_checker(fn1 , t1 , lm , ' 1/ 3' , do_plot );
93+ pass1 = level_vs_time_checker(fn1 , t1 , lm , ' 1 / 3' , do_plot );
9494
9595 % Default gains for test 2
9696 m1 = [vmut vnom vnom vmut ];
@@ -103,7 +103,7 @@ function check_volume_levels(cmd, fn1, fn2, fn3, do_plot)
103103 t2.vtol = t1 .vtol ; % Same as previous
104104
105105 % Check test 2
106- pass2 = level_vs_time_checker(fn2 , t2 , lm , ' 2/ 3' , do_plot );
106+ pass2 = level_vs_time_checker(fn2 , t2 , lm , ' 2 / 3' , do_plot );
107107
108108 % Default gains for test 3
109109 vol_ch1 = [ vmut vmut m2(1 ) vnom ];
@@ -114,7 +114,7 @@ function check_volume_levels(cmd, fn1, fn2, fn3, do_plot)
114114 t3.vtol = t1 .vtol ; % Same as previous
115115
116116 % Check test 3
117- pass3 = level_vs_time_checker(fn3 , t3 , lm , ' 3/ 3' , do_plot );
117+ pass3 = level_vs_time_checker(fn3 , t3 , lm , ' 3 / 3' , do_plot );
118118
119119 if pass1 == 1 && pass2 == 1 && pass3 == 1
120120 pass = 1 ;
@@ -139,7 +139,7 @@ function check_volume_levels(cmd, fn1, fn2, fn3, do_plot)
139139
140140 % Swapped channels?
141141 sine_freqs_orig = lm .sine_freqs ;
142- lm.sine_freqs = sine_freqs_orig(end : - 1 : 1 );
142+ lm.sine_freqs = sine_freqs_orig(end : - 1 : 1 );
143143 lev = level_vs_time(fn , lm );
144144 pass_test = check_levels(lev , tc , lm , 0 );
145145 if pass_test
@@ -150,7 +150,7 @@ function check_volume_levels(cmd, fn1, fn2, fn3, do_plot)
150150 % Swapped controls?
151151 lm.sine_freqs = sine_freqs_orig ;
152152 volumes_orig = tc .volumes ;
153- tc.volumes = volumes_orig(: , end : - 1 : 1 );
153+ tc.volumes = volumes_orig(: , end : - 1 : 1 );
154154 lev = level_vs_time(fn , lm );
155155 pass_test = check_levels(lev , tc , lm , 0 );
156156 if pass_test
@@ -159,7 +159,7 @@ function check_volume_levels(cmd, fn1, fn2, fn3, do_plot)
159159 end
160160
161161 % Swapped controls and swapped channels
162- lm.sine_freqs = sine_freqs_orig(end : - 1 : 1 );
162+ lm.sine_freqs = sine_freqs_orig(end : - 1 : 1 );
163163 lev = level_vs_time(fn , lm );
164164 pass_test = check_levels(lev , tc , lm , 0 );
165165 if pass_test
@@ -175,13 +175,13 @@ function plot_levels(meas, tc, lm)
175175
176176 sv = size(tc .volumes );
177177 hold on ;
178- for j = 1 : sv(2 )
179- for i = 1 : sv(1 )
180- plot([tc .vctimes(i )+ tc .meas(1 ) tc .vctimes(i )+ tc .meas(2 )], ...
181- [tc .volumes(i ,j )+ tc .vtol tc .volumes(i ,j )+ tc .vtol ], ' r--' );
182- if tc .volumes(i ,j ) > - 100
183- plot([tc .vctimes(i )+ tc .meas(1 ) tc .vctimes(i )+ tc .meas(2 )], ...
184- [tc .volumes(i ,j )- tc .vtol tc .volumes(i ,j )- tc .vtol ], ' r--' );
178+ for j = 1 : sv(2 )
179+ for i = 1 : sv(1 )
180+ plot([tc .vctimes(i ) + tc .meas(1 ) tc .vctimes(i ) + tc .meas(2 )], ...
181+ [tc .volumes(i , j ) + tc .vtol tc .volumes(i , j ) + tc .vtol ], ' r--' );
182+ if tc .volumes(i , j ) > - 100
183+ plot([tc .vctimes(i ) + tc .meas(1 ) tc .vctimes(i ) + tc .meas(2 )], ...
184+ [tc .volumes(i , j ) - tc .vtol tc .volumes(i , j ) - tc .vtol ], ' r--' );
185185 end
186186 end
187187 end
@@ -196,25 +196,25 @@ function plot_levels(meas, tc, lm)
196196 dg_tol = 0.1 ;
197197 gains = meas .levels - lm .sine_dbfs ;
198198 sv = size(tc .volumes );
199- for j = 1 : sv(2 )
200- for i = 1 : sv(1 )
199+ for j = 1 : sv(2 )
200+ for i = 1 : sv(1 )
201201 % Initial location to test
202- ts = tc .vctimes(i )+ tc .meas(1 );
203- te = tc .vctimes(i )+ tc .meas(2 );
202+ ts = tc .vctimes(i ) + tc .meas(1 );
203+ te = tc .vctimes(i ) + tc .meas(2 );
204204 idx0 = find(meas .t < te );
205205 idx = find(meas .t(idx0 ) > ts );
206206
207207 % Delay if settled gain is later in the window,
208208 % this adds more robustness to test for controls
209209 % apply delay.
210- dg = diff(gains(idx ,j ));
210+ dg = diff(gains(idx , j ));
211211 if max(abs(dg )) > dg_tol
212212 n_idx = length(idx );
213- dg_rev = dg(end : - 1 : 1 );
213+ dg_rev = dg(end : - 1 : 1 );
214214 idx_add = length(dg ) - find(abs(dg_rev ) > dg_tol , 1 , ' first' ) + 1 ;
215215 idx = idx + idx_add ;
216216 if idx(end ) > size(gains , 1 )
217- idx = idx(1 ): size(gains , 1 );
217+ idx = idx(1 ) : size(gains , 1 );
218218 end
219219 if idx(1 ) > size(gains , 1 ) || length(idx ) < 0.5 * n_idx
220220 fprintf(1 , ' Channel %d controls impact is delayed too much ' , j );
@@ -224,8 +224,8 @@ function plot_levels(meas, tc, lm)
224224 end
225225 end
226226 avg_gain = mean(gains(idx , j ));
227- max_gain = tc .volumes(i ,j ) + tc .vtol ;
228- min_gain = tc .volumes(i ,j ) - tc .vtol ;
227+ max_gain = tc .volumes(i , j ) + tc .vtol ;
228+ min_gain = tc .volumes(i , j ) - tc .vtol ;
229229 if avg_gain > max_gain
230230 if verbose
231231 fprintf(1 , ' Channel %d Failed upper gain limit at ' , j );
@@ -234,7 +234,7 @@ function plot_levels(meas, tc, lm)
234234 end
235235 pass = 0 ;
236236 end
237- if tc .volumes(i ,j ) > - 100
237+ if tc .volumes(i , j ) > - 100
238238 if avg_gain < min_gain
239239 if verbose
240240 fprintf(1 , ' Channel %d failed lower gain limit at ' , j );
@@ -259,24 +259,24 @@ function plot_levels(meas, tc, lm)
259259 ngrid = lm .tgrid * fs ;
260260 nlength = lm .tlength * fs ;
261261 nmax = nlev - round(nlength / ngrid ) + 1 ;
262- ret.t = (0 : (nmax - 1 )) * lm .tgrid ;
262+ ret.t = (0 : (nmax - 1 )) * lm .tgrid ;
263263 ret.levels = zeros(nmax , nch );
264- for i = 1 : nmax
264+ for i = 1 : nmax
265265 i1 = floor((i - 1 ) * ngrid + 1 );
266266 i2 = floor(i1 + nlength - 1 );
267- ret .levels(i , : ) = level_dbfs(x(i1 : i2 , : ));
267+ ret .levels(i , : ) = level_dbfs(x(i1 : i2 , : ));
268268 end
269- ret.levels_lin = 10 .^ (ret .levels / 20 );
269+ ret.levels_lin = 10 .^ (ret .levels / 20 );
270270end
271271
272272function y = bandpass_filter(x , f , fs )
273273 sx = size(x );
274274 y = zeros(sx(1 ), sx(2 ));
275275 c1 = 0.8 ;
276- c2 = 1 / c1 ;
277- for j = 1 : sx(2 )
278- [b , a ] = butter(4 , 2 *[c1 * f(j ) c2 * f(j )]/ fs );
279- y(: ,j ) = filter(b , a , x(: ,j ));
276+ c2 = 1 / c1 ;
277+ for j = 1 : sx(2 )
278+ [b , a ] = butter(4 , 2 *[c1 * f(j ) c2 * f(j )] / fs );
279+ y(: , j ) = filter(b , a , x(: , j ));
280280 end
281281end
282282
0 commit comments