daniele@182
|
1 %% Buffer Test
|
daniele@182
|
2 % Test script for the function audio->buffer which takes an audio object as
|
daniele@182
|
3 % an input and buffers it into frames. The test assesses wether all the
|
daniele@182
|
4 % possible buffer methods are invertible.
|
daniele@182
|
5 %%
|
daniele@182
|
6
|
daniele@182
|
7 N = 500; % number of audio samples
|
daniele@182
|
8 TOL = 200; % tolerance (in decibels)
|
daniele@182
|
9 verb = true; % verbose
|
daniele@182
|
10
|
daniele@182
|
11 obj = audio(randn(N,1)); % audio object
|
daniele@182
|
12 % wLengts: one window, two windows, maximum number of windows
|
daniele@182
|
13 temp = factor(N);
|
daniele@182
|
14 wLengths = [N; fix(N/2); fix(N/temp(end))];
|
daniele@182
|
15 % overlaps: zero, half window, max
|
daniele@182
|
16 overlapNames = {'zero','half-window','maximum'};
|
daniele@182
|
17 overlaps = {@(n)0, @(n)n/2, @(n)n-1};
|
daniele@182
|
18 % windows: valid windows
|
daniele@182
|
19 windows = {@hanning,@hamming,@triang,@rectwin};
|
daniele@182
|
20 % methods: valid methods
|
daniele@182
|
21 methods = {'standard'};
|
daniele@182
|
22
|
daniele@182
|
23
|
daniele@182
|
24 nLen = length(wLengths);
|
daniele@182
|
25 nOver = length(overlaps);
|
daniele@182
|
26 nWin = length(windows);
|
daniele@182
|
27 nMet = length(methods);
|
daniele@182
|
28 count = 1;
|
daniele@182
|
29 for iLen=1:nLen
|
daniele@182
|
30 for iOver=1:nOver
|
daniele@182
|
31 for iWin=1:nWin
|
daniele@182
|
32 for iMet=1:nMet
|
daniele@182
|
33 if verb
|
daniele@182
|
34 printf('\n buffer test %d/%d - %d window length, %s overlap, %s window and %s method ... ',...
|
daniele@182
|
35 count,nMet*nWin*nOver*nLen,wLengths(iLen),overlapNames{iOver},func2str(windows{iWin}),methods{iMet});
|
daniele@182
|
36 end
|
daniele@182
|
37 obj = buffer(obj,wLengths(iLen),overlaps{iOver}(wLengths(iLen)),windows{iWin},methods{iMet});
|
daniele@182
|
38 s_rec = obj.unbuffer;
|
daniele@182
|
39 if snr(obj.s,s_rec) > TOL
|
daniele@182
|
40 if verb, printf('Passed'); end
|
daniele@182
|
41 else
|
daniele@182
|
42 error('Test failed!');
|
daniele@182
|
43 end
|
daniele@182
|
44 count = count+1;
|
daniele@182
|
45 end
|
daniele@182
|
46 end
|
daniele@182
|
47 end
|
daniele@182
|
48 end
|