1 ! Copyright (C) 2009 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors timers audio.engine audio.loader calendar
4 destructors io kernel math math.functions ranges specialized-arrays
5 sequences random math.vectors ;
6 SPECIALIZED-ARRAY: alien.c-types:short
9 TUPLE: noise-generator ;
11 M: noise-generator generator-audio-format
13 M: noise-generator generate-audio
15 4096 [ -4096 4096 [a..b] random ] short-array{ } replicate-as
17 M: noise-generator dispose
20 :: audio-engine-test ( -- )
21 "vocab:audio/engine/test/loop.aiff" read-audio :> loop-sound
22 "vocab:audio/engine/test/once.wav" read-audio :> once-sound
24 f 4 <audio-engine> :> engine
27 engine T{ audio-source f { 1.0 0.0 0.0 } 1.0 { 0.0 0.0 0.0 } f } loop-sound t
28 play-static-audio-clip :> loop-clip
29 engine T{ audio-source f { -1.0 0.0 0.0 } 1.0 { 0.0 0.0 0.0 } f } noise-generator new 2
30 play-streaming-audio-clip :> noise-clip
34 i 0.05 * [ sin ] [ cos ] bi :> ( s c )
35 loop-clip source>> { c 0.0 s } >>position drop
36 noise-clip source>> { c 0.0 s } -2.0 v*n >>position drop
39 engine T{ audio-source f { 0.0 0.0 0.0 } 1.0 { 0.0 0.0 0.0 } f } once-sound f
40 play-static-audio-clip drop
44 ] 20 milliseconds every :> timer
45 "Press Enter to stop the test." print
50 MAIN: audio-engine-test