annotate signals/@signal/gather.m @ 61:eff6bddf82e3
tip
Finally implemented perceptual brightness thing.
author |
samer |
date |
Sun, 11 Oct 2015 10:20:42 +0100 |
parents |
289445d368a7 |
children |
|
rev |
line source |
samer@1
|
1 % gather - collect all samples from a finite signal
|
samer@1
|
2 % gather :: signal(C,R), options -> [[C,N]].
|
samer@1
|
3 function x=gather(sig,varargin)
|
samer@1
|
4 opts=prefs('chunk',256,'init',512,'grow',2,'max',1e9,varargin{:});
|
samer@1
|
5
|
samer@1
|
6 s=construct(sig);
|
samer@1
|
7 try % to make sure we dispose of s once opened
|
samer@1
|
8 chunk=uint32(opts.chunk);
|
samer@1
|
9 n=uint32(0); CHUNK=1:chunk;
|
samer@1
|
10 cap=opts.init; % initial capacity of buffer
|
samer@1
|
11 x=zeros(channels(sig),cap); % buffer
|
samer@1
|
12 r=s.reader(opts.chunk);
|
samer@1
|
13 rem=0;
|
samer@1
|
14 s.start();
|
samer@1
|
15 while rem==0
|
samer@1
|
16 if n+chunk>cap % need more room
|
samer@1
|
17 if n>opts.max, error('maximum capacity exceeded'); end
|
samer@1
|
18 cap=opts.grow*cap;
|
samer@1
|
19 x=repmat(x,1,opts.grow);
|
samer@1
|
20 end
|
samer@1
|
21 [x(:,n+CHUNK),rem]=r();
|
samer@1
|
22 n=n+chunk;
|
samer@1
|
23 end
|
samer@1
|
24 n=n-rem; % remove rem samples from end
|
samer@1
|
25 catch ex
|
samer@1
|
26 s.dispose();
|
samer@1
|
27 rethrow(ex);
|
samer@1
|
28 end
|
samer@1
|
29 s.stop();
|
samer@1
|
30 s.dispose();
|
samer@1
|
31 x=x(:,1:n); % grab only valid samples
|
samer@1
|
32 end
|
samer@1
|
33
|