annotate signals/@signal/gathern.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 % gathern - Collect exactly n samples from a signal
|
samer@1
|
2 %
|
samer@1
|
3 % gathern :: N:natural, signal(C,R), options -> [[C,N]], natural.
|
samer@1
|
4 function [x,rem]=gathern(m,sig,varargin)
|
samer@1
|
5 opts=prefs('chunk',256,varargin{:});
|
samer@1
|
6
|
samer@1
|
7 s=construct(sig);
|
samer@1
|
8 try % to make sure we dispose of s once opened
|
samer@1
|
9 chunk=uint32(opts.chunk);
|
samer@1
|
10 n=uint32(0); CHUNK=1:chunk;
|
samer@1
|
11 x=zeros(channels(sig),m);
|
samer@1
|
12 r=s.reader(opts.chunk);
|
samer@1
|
13 rem=0;
|
samer@1
|
14 while rem==0 && n+chunk<=m
|
samer@1
|
15 [x(:,n+CHUNK),rem]=r();
|
samer@1
|
16 n=n+chunk;
|
samer@1
|
17 end
|
samer@1
|
18 if n<m && rem==0 % need more and not run out
|
samer@1
|
19 [y,rem]=r();
|
samer@1
|
20 x(:,n+1:m)=y(:,1:m-n);
|
samer@1
|
21 rem=(m-n)-(chunk-rem);
|
samer@1
|
22 end
|
samer@1
|
23 catch ex
|
samer@1
|
24 s.dispose();
|
samer@1
|
25 rethrow(ex);
|
samer@1
|
26 end
|
samer@1
|
27 s.dispose();
|
samer@1
|
28 end
|
samer@1
|
29
|
samer@1
|
30
|
samer@1
|
31
|