samer@0: % abufsig - Arrow which produces multiple buffered frames from a signal samer@0: % samer@0: % abufsig :: samer@0: % signal(C,R), samer@0: % N:natural ~'block size', samer@0: % M:natural ~'hop size', samer@0: % L:natural ~'buffer width' samer@0: % -> arrow({},{[[N*C,L]]}). samer@0: % samer@0: % abufsig :: samer@0: % signal(C,R), samer@0: % N:natural ~'block size', samer@0: % M:natural ~'hop size' samer@0: % -> arrow({},{[[N*C,1]]]}). samer@0: % samer@0: % abufsig :: samer@0: % signal(C,R), samer@0: % N:natural ~'block size', samer@0: % -> arrow({},{[[C*N,1]]]}). samer@0: % samer@0: % If hop size is omitted, it defaults to the block size. samer@0: % If buffer width is omitted, it defaults to 1. samer@0: samer@0: function o=abufsig(source,block,hop,width) samer@0: if nargin<4, width=1; end samer@0: if nargin<3, hop=block; end samer@0: samer@0: ch=channels(source); samer@0: if (mod(block,ch)>0 || mod(hop,ch)) samer@0: error('Block size and hop must be a multiple of channel count'); samer@0: end samer@0: samer@0: if width==1, samer@0: o=asignal(source,block/ch,hop/ch)*arr(@flt); samer@0: else samer@0: olap = block-hop; samer@0: span = (hop*(width-1)+block); samer@0: jump = (hop*width); samer@0: o=asignal(source,span/ch,jump/ch)*arr(@buf); samer@0: end samer@0: samer@0: function y=flt(x), y=x(:); end samer@0: function y=buf(x), y=buffer(x(:),block,olap,'nodelay'); end samer@0: end samer@0: