]> gitweb.factorcode.org Git - factor.git/blob - extra/audio/engine/test/test.factor
da9a24d72eb0313b13896f6718e2fac0c287f880
[factor.git] / extra / audio / engine / test / test.factor
1 ! Copyright (C) 2009 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors timers audio audio.engine audio.loader calendar
4 destructors io kernel locals math math.functions math.ranges specialized-arrays
5 sequences random math.vectors ;
6 FROM: alien.c-types => short ;
7 SPECIALIZED-ARRAY: short
8 IN: audio.engine.test
9
10 TUPLE: noise-generator ;
11
12 M: noise-generator generator-audio-format
13     drop 1 16 8000 ;
14 M: noise-generator generate-audio
15     drop
16     4096 [ -4096 4096 [a..b] random ] short-array{ } replicate-as
17     8192 ;
18 M: noise-generator dispose
19     drop ;
20
21 :: audio-engine-test ( -- )
22     "vocab:audio/engine/test/loop.aiff" read-audio :> loop-sound
23     "vocab:audio/engine/test/once.wav" read-audio :> once-sound
24     0 :> i!
25     f 4 <audio-engine> :> engine
26     engine start-audio*
27
28     engine T{ audio-source f {  1.0 0.0 0.0 } 1.0 { 0.0 0.0 0.0 } f } loop-sound t
29         play-static-audio-clip :> loop-clip
30     engine T{ audio-source f { -1.0 0.0 0.0 } 1.0 { 0.0 0.0 0.0 } f } noise-generator new 2
31         play-streaming-audio-clip :> noise-clip
32
33     [
34         i 1 + i!
35         i 0.05 * [ sin ] [ cos ] bi :> ( s c )
36         loop-clip  source>> { c 0.0 s }          >>position drop
37         noise-clip source>> { c 0.0 s } -2.0 v*n >>position drop
38
39         i 50 mod zero? [
40             engine T{ audio-source f { 0.0 0.0 0.0 } 1.0 { 0.0 0.0 0.0 } f } once-sound f
41             play-static-audio-clip drop
42         ] when
43
44         engine update-audio
45     ] 20 milliseconds every :> timer
46     "Press Enter to stop the test." print
47     readln drop
48     timer stop-timer
49     engine dispose ;
50
51 MAIN: audio-engine-test