comparison examples/sound/sampled/specfilter.scm @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 ;;; Example of some more complicated spectral processing.
2 ;;; We read two audio inputs: one from the sound card and one
3 ;;; from a file. Then we filter one by the spectrum of the
4 ;;; other.
5
6 (load "functions.scm")
7 (load "models.scm")
8 (load "lineout.scm")
9 (load "audio.scm")
10 (load "synthesis.scm")
11 (load "filelist.scm")
12
13 (define size 512) ; size of STFT frames
14 (define hop 128) ; hops size
15 (define fmt (mono 22050))
16 (tasks)
17
18 ;; X is an object or unit which manages the FT of live input.
19 ;; Y is an object or unit which manages the FT of the file input.
20 ;; f is the normalised magnitude spectrum of the file input.
21 ;; z is the magnitude spectrum of the live input
22 (define X (ft-vec (norm (linein (linesrc (default-mixer) fmt) size hop))))
23 (define Y (node "filter" (ft-vec (norm (linein (filesource) size hop)))))
24 (define f (diffscale (ft-mag Y) cauchy-spec))
25 (define z (ft-mag X))
26 ; (define f (VVector. "filter" (.size z)))
27
28 ; at this point, the task list has a lot of stuff in it: everything
29 ; required to generate f and z when the main loop is run.
30
31 (put "lineout.scale" 1.0e-5) ; get a lot of clipping if this is too large
32 (.setWindow X (Constant. 1.0)) ; override Hanning window in STFT default
33
34 ; this adds a task to multiply z (in place) by f
35 (addtasks (task (Mathx.mul (.array z) (.array f))))
36
37 ; invert FT wih new magnitudes from z
38 ; then overlap-and-add output to audio output
39 (overlap-and-add (linesnk (mixer-n 2) fmt)
40 (rescaled-ift Y z hop))
41
42 (expose)
43
44 ; at this point the task list is ready and the whole
45 ; is started by calling (start) or pressing the start button
46 ; on the Regulator GUI.:w
47
48