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