Mercurial > hg > smallbox
comparison util/classes/@audio/buffer.m @ 182:f8bc99a5470c danieleb
Added test for audio buffer function
author | Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk> |
---|---|
date | Mon, 09 Jan 2012 12:58:00 +0000 |
parents | 1495bdfa13e9 |
children | 2f5ce7c8792a f1e601cc916d |
comparison
equal
deleted
inserted
replaced
181:0dc98f1c60bb | 182:f8bc99a5470c |
---|---|
1 %% Buffer function | |
2 % Buffers the samples of the audio object into the columns of the matrix S | |
3 % based on the input parameters | |
4 %% | |
1 function obj = buffer(obj,wLength,overlap,window,method) | 5 function obj = buffer(obj,wLength,overlap,window,method) |
2 | 6 |
3 %% Check inputs & Defaults | 7 %% Check inputs & Defaults |
4 error(nargchk(2, 5, nargin, 'struct')); | 8 error(nargchk(2, 5, nargin, 'struct')); |
5 | 9 if rem(length(obj.s),wLength) |
10 error('The wLength must be an integer divisor of the signal length!'); | |
11 end | |
6 if ~exist('overlap','var') || isempty(overlap), overlap = 0; end | 12 if ~exist('overlap','var') || isempty(overlap), overlap = 0; end |
7 if ~exist('method','var') || isempty(method), method = 'standard'; end | 13 if ~exist('method','var') || isempty(method), method = 'standard'; end |
8 | 14 |
9 %% Buffer audio | 15 %% Buffer audio |
10 switch lower(method) | 16 switch lower(method) |
13 validWindows = {'hanning','hamming','triang','rectwin'}; | 19 validWindows = {'hanning','hamming','triang','rectwin'}; |
14 if ~sum(strcmpi(validWindows,func2str(window))); | 20 if ~sum(strcmpi(validWindows,func2str(window))); |
15 error('The window chosen is not valid because it cannot be inverted!'); | 21 error('The window chosen is not valid because it cannot be inverted!'); |
16 end | 22 end |
17 obj.S = diag(window(wLength))*buffer(obj.s,wLength,overlap,'nodelay'); | 23 obj.S = diag(window(wLength))*buffer(obj.s,wLength,overlap,'nodelay'); |
18 case 'lot' | 24 % case 'lot' |
19 if ~exist('window','var') || isempty(window), window = 'sin2'; end | 25 % if ~exist('window','var') || isempty(window), window = 'sin2'; end |
20 s_lot = lot(obj.s,wLength,'id',overlap,window); | 26 % s_lot = lot(obj.s,wLength,'id',overlap,window); |
21 obj.S = buffer(s_lot,wLength); | 27 % obj.S = buffer(s_lot,wLength); |
22 otherwise | 28 otherwise |
23 error('Please specify a valid buffer method'); | 29 error('Please specify a valid buffer method'); |
24 end | 30 end |
25 | 31 |
26 obj.bufferOperator = struct('wLength',wLength,'overlap',... | 32 obj.bufferOperator = struct('wLength',wLength,'overlap',... |