|
From: Martin R. <ru...@us...> - 2004-08-12 23:15:48
|
Update of /cvsroot/foo/foo/elkfoo/examples/kernel In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28193/examples/kernel Added Files: Makefile.am biquad.foo fof.foo manual_mix.foo sine.foo Log Message: added examples from fhg repository --- NEW FILE: sine.foo --- ;; sine~ example (define (fm~ carrier ratio index) (define mod (mul~ carrier ratio)) (sine~ (add~ carrier (mul~ (sine~ mod) (mul~ mod index))))) (syn 1 3 (output~ 1 (fm~ (~ 440) (~ 5) (expon~ 50 10 3)))) (play) --- NEW FILE: biquad.foo --- ;; biquad.foo ;; 2004-07-28 rumori@banff :-) ;; convenience wrapper for c2p2zf~ ;; calculate the biquad freq values (define (biquad~ input gain pole-freq pole-reson zero-freq zero-reson) (define (calc-freq freq reson) (* 2 reson (cos (* 2 pi freq (/ 1 (foo-default-srate)))))) (c2p2zf~ input ; input signal gain ; for now 1 by 1 (calc-freq pole-freq pole-reson) ; freq (- pole-reson) ; reson 1 ; "output gain", don't know the reason why this is here (- (calc-freq zero-freq zero-reson)) zero-reson)) --- NEW FILE: Makefile.am --- # foo/elkfoo/examples/kernel/Makefile.am # 2004 rumori # $Id: Makefile.am,v 1.1 2004/08/12 23:15:38 rumori Exp $ NULL = noinst_DATA = \ biquad.foo \ fof.foo \ manual_mix.foo \ sine.foo \ $(NULL) --- NEW FILE: fof.foo --- ;; fof~ example (define (fof-bank~ f0 parameter-list t a d) (define (helper x) (apply fof~ (list f0 (~ (car x)) (~ (cadr x)) (~ (dB->lin (caddr x))) t a d))) (apply add~ (map helper parameter-list))) (define p '((609 78 0) (1000 88 -7) (2450 123 -9) (2700 128 -9))) (syn 1 3 (output~ 1 (fof-bank~ (~ 88) p (~ 0.001) (~ 0.012) (~ 0.001)))) (play) --- NEW FILE: manual_mix.foo --- ;; foo manual mixsnd example ;; define 2 different sweeps (left + right) (define (make-sweep1) (output~ 1 (sine~ (expon~ 20 20000 3)))) (define (make-sweep2) (output~ 2 (mul~ (sine~ (expon~ 20000 20 3)) (bln~ (~ 500))))) ;; let's hear them separately (syn 2 3 (make-sweep1)) (play) (syn 2 3 (make-sweep2)) (play) ;; now the "orthodox" way: create context, soundfile, task, run task etc. (define context1 (make-context 2)) (with-context context1 make-sweep1) (create-soundfile "/tmp/rumori/foo1.aiff" 'short 2 48000 'aiff) (define task1 (make-task 0 0 "/tmp/rumori/foo1.aiff" context1)) (run-task task1 3) (play "/tmp/rumori/foo1.aiff") ;; 2nd quick (begin (define context2 (make-context 2)) (with-context context2 make-sweep2) (create-soundfile "/tmp/rumori/foo2.aiff" 'short 2 48000 'aiff) (run-task (make-task 0 0 "/tmp/rumori/foo2.aiff" context2) 3) (play "/tmp/rumori/foo2.aiff")) ;; archive (serialize) first context for potential later use (with-output-to-file "/tmp/rumori/sweep1.context" (lambda () (write-context context1))) ;; let's render both contexts together into one file (create-soundfile "/tmp/rumori/foomix.aiff" 'incremental 2 48000 'aiff) (run-task (make-task 0 0 "/tmp/rumori/foomix.aiff" (copy-context context1)) 3) (run-task (make-task 0 0 "/tmp/rumori/foomix.aiff" (copy-context context2)) 3) (play "/tmp/rumori/foomix.aiff/mixfloat.imx") ;; and now let's subtract the second one ;; read mixinfo (define mixinfo (call-with-input-file "/tmp/rumori/foomix.aiff/mix0001t" read)) mixinfo ;; read original context (define subtract-context (call-with-input-file "/tmp/rumori/foomix.aiff/mix0001c" read-context)) ;; render the context into a temporary file (define ref (cadr (list-ref mixinfo 2))) (define off (cadr (list-ref mixinfo 3))) (define dur (/ (cadr (list-ref mixinfo 4)) (cadr (list-ref mixinfo 5)))) (create-soundfile "/tmp/rumori/subtract.aiff" 'float (context-channels subtract-context) (cadr (list-ref mixinfo 5)) 'aiff) (run-task (make-task ref off "/tmp/rumori/subtract.aiff" subtract-context) dur) ;; sounds like the original second sweep (play "/tmp/rumori/subtract.aiff") ;; read the file channel by channel, multiply data by -1 (define (subtract-file) (define subsnd (open-snd "/tmp/rumori/subtract.aiff")) (output~ 1 (mul~ (~ -1) (read-snd~ (snd-extract subsnd 1)))) (output~ 2 (mul~ (~ -1) (read-snd~ (snd-extract subsnd 2))))) ;; mix inversed sound data into mixfile (run-task (make-task ref off "/tmp/rumori/foomix.aiff" (context 2 (subtract-file))) dur) ;; done! (play "/tmp/rumori/foomix.aiff/mixfloat.imx") |