annotate signals/@signal/length.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 % length - length of finite signal
|
samer@1
|
2 function n=length(sig,varargin)
|
samer@1
|
3 opts=prefs('chunk',1024,'init',2,'grow',2,'max',1e12,varargin{:});
|
samer@1
|
4
|
samer@1
|
5 s=construct(sig);
|
samer@1
|
6 try % to make sure we dispose of s once opened
|
samer@1
|
7 chunk=uint64(opts.chunk);
|
samer@1
|
8 n=uint64(0); CHUNK=1:chunk;
|
samer@1
|
9 r=s.reader(opts.chunk);
|
samer@1
|
10 dummy=[];
|
samer@1
|
11 rem=0;
|
samer@1
|
12 while rem==0
|
samer@1
|
13 [dummy,rem]=r();
|
samer@1
|
14 n=n+chunk;
|
samer@1
|
15 if n>opts.max, error('maximum length exceeded'); end
|
samer@1
|
16 end
|
samer@1
|
17 n=n-uint64(rem); % remove rem samples from end
|
samer@1
|
18 catch ex
|
samer@1
|
19 s.dispose();
|
samer@1
|
20 rethrow(ex);
|
samer@1
|
21 end
|
samer@1
|
22 s.dispose();
|
samer@1
|
23 n=double(n);
|
samer@1
|
24 end
|