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