Mercurial > hg > may
view framer.yeti @ 84:c1c99f26d1fc
More toward structured outputs
author | Chris Cannam |
---|---|
date | Sun, 17 Mar 2013 22:29:19 +0000 |
parents | 2423c40db780 |
children |
line wrap: on
line source
module framer; /** * Framer expresses a stream (or a file) as a lazy list of (possibly * overlapping) frames of mono data. */ block = load block; bf = load blockfuncs; af = load audiofile; win = load window; fft = load fft; blockList framesize stream = if stream.finished? then (stream.close (); [] ); else block.resizedTo framesize (stream.readMono framesize) :. \(blockList framesize stream); fi; overlappingBlockList size hop stream valid buffer = ( b = stream.readMono hop; obtained = block.length b; // Retain framesize - hop samples from old buffer, add hop samples // (zero-padded if necessary) just read buffer = block.concat [block.rangeOf buffer hop (size-hop), block.resizedTo hop b]; // Number of "valid" elements (not tail-end zero-padding) left in buffer remaining = valid - (hop - obtained); if remaining <= 0 then stream.close (); []; else buffer :. \(overlappingBlockList size hop stream remaining buffer); fi); frames { framesize, hop } stream = if framesize == hop then blockList framesize stream else overlappingBlockList framesize hop stream framesize (block.zeros framesize); fi; windowedFrames { framesize, hop, window } stream = (win = window framesize; map (bf.multiply win) (frames { framesize, hop } stream)); frequencyDomainFrames { framesize, hop } stream = (f = fft.realForward framesize; map f (windowedFrames { framesize, hop, window = win.hann } stream)); { frames, windowedFrames, frequencyDomainFrames, framesOfFile parameters filename = case af.open filename of Stream s: Frames (frames parameters s); Error e: Error e; esac, windowedFramesOfFile parameters filename = case af.open filename of Stream s: Frames (windowedFrames parameters s); Error e: Error e; esac, frequencyDomainFramesOfFile parameters filename = case af.open filename of Stream s: Frames (frequencyDomainFrames parameters s); Error e: Error e; esac, }