Mercurial > hg > jslab
diff examples/sound/sampled/specfilter.scm @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/sound/sampled/specfilter.scm Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,48 @@ +;;; Example of some more complicated spectral processing. +;;; We read two audio inputs: one from the sound card and one +;;; from a file. Then we filter one by the spectrum of the +;;; other. + +(load "functions.scm") +(load "models.scm") +(load "lineout.scm") +(load "audio.scm") +(load "synthesis.scm") +(load "filelist.scm") + +(define size 512) ; size of STFT frames +(define hop 128) ; hops size +(define fmt (mono 22050)) +(tasks) + +;; X is an object or unit which manages the FT of live input. +;; Y is an object or unit which manages the FT of the file input. +;; f is the normalised magnitude spectrum of the file input. +;; z is the magnitude spectrum of the live input +(define X (ft-vec (norm (linein (linesrc (default-mixer) fmt) size hop)))) +(define Y (node "filter" (ft-vec (norm (linein (filesource) size hop))))) +(define f (diffscale (ft-mag Y) cauchy-spec)) +(define z (ft-mag X)) +; (define f (VVector. "filter" (.size z))) + +; at this point, the task list has a lot of stuff in it: everything +; required to generate f and z when the main loop is run. + +(put "lineout.scale" 1.0e-5) ; get a lot of clipping if this is too large +(.setWindow X (Constant. 1.0)) ; override Hanning window in STFT default + +; this adds a task to multiply z (in place) by f +(addtasks (task (Mathx.mul (.array z) (.array f)))) + +; invert FT wih new magnitudes from z +; then overlap-and-add output to audio output +(overlap-and-add (linesnk (mixer-n 2) fmt) + (rescaled-ift Y z hop)) + +(expose) + +; at this point the task list is ready and the whole +; is started by calling (start) or pressing the start button +; on the Regulator GUI.:w + +