samer@3: % framedata - return abstract data object for buffering signal frames samer@0: % samer@0: % framedata :: samer@3: % ( s:seq [C,T] ~'C-channel signal of length T', samer@0: % N:natural ~'frame size', samer@0: % M:natural ~'hop size', samer@0: % L:natural ~'frames per buffer' | ([] => whole file) samer@0: % options... ) samer@3: % -> seq [N,L]. samer@0: % samer@0: % Options: samer@0: % wrap/0 if 1, then buffer samples as if one continuous circular signal samer@0: % otherwise, don't return buffers that wrap round from end to start samer@0: % random/0: if [], return buffers sequentially, if number or random state samer@0: % vector, return buffers in random order, using value as seed. samer@0: % filter/[] optional filter function to apply to long windows before buffering samer@0: % samer@0: % Note: if the signal is a multichannel signal, ie of size CxT with C>1, samer@0: % the samples for each channel are interleaved. samer@0: samer@3: function a=framedata(signal,frame,hop,width,varargin) samer@0: if nargin<4, width = []; end samer@37: opts=options('wrap',0,'random',[],'dim',2,'filter',@id,varargin{:}); samer@0: if isempty(width), opts.truncate=0; end samer@0: samer@0: [span,jump]=windowparams(size(signal),frame,hop,width,opts); samer@0: if isempty(opts.random), samer@42: wd=window(signal,span,jump,'wrap',opts.wrap,'dim',opts.dim); samer@0: else samer@0: wd=rndwindow(signal,span,opts.dim); samer@0: end samer@0: samer@3: wd=opts.filter(wd); samer@3: if size(wd,1)>1, wd=map(@flatten,wd); end samer@3: olap=frame-hop; samer@3: if hop