]> gitweb.factorcode.org Git - factor.git/blob - extra/audio/engine/test/test.factor
Merge branch 'master' of github.com:erg/factor
[factor.git] / extra / audio / engine / test / test.factor
1 ! (c)2009 Joe Groff bsd license
2 USING: accessors timers audio audio.engine audio.loader calendar
3 destructors io kernel locals math math.functions math.ranges specialized-arrays
4 sequences random math.vectors ;
5 FROM: alien.c-types => short ;
6 SPECIALIZED-ARRAY: short
7 IN: audio.engine.test
8
9 TUPLE: noise-generator ;
10
11 M: noise-generator generator-audio-format
12     drop 1 16 8000 ;
13 M: noise-generator generate-audio
14     drop
15     4096 [ -4096 4096 [a,b] random ] short-array{ } replicate-as
16     8192 ;
17 M: noise-generator dispose
18     drop ;
19
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
23     0 :> i!
24     f 4 <audio-engine> :> engine
25     engine start-audio*
26
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
31
32     [
33         i 1 + i!
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
37
38         i 50 mod zero? [
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
41         ] when
42
43         engine update-audio
44     ] 20 milliseconds every :> timer
45     "Press Enter to stop the test." print
46     readln drop
47     timer stop-timer
48     engine dispose ;
49
50 MAIN: audio-engine-test