Mercurial > hg > may
view framer.yeti @ 57:08b2b9fce25c
Remove the complex constants; they're not very useful and pollute the namespace
author | Chris Cannam |
---|---|
date | Wed, 09 Jan 2013 21:35:37 +0000 |
parents | 8c10155c99a7 |
children | 2423c40db780 |
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 = frames parameters (af.open filename), windowedFramesOfFile parameters filename = windowedFrames parameters (af.open filename), frequencyDomainFramesOfFile parameters filename = frequencyDomainFrames parameters (af.open filename), }