]> gitweb.factorcode.org Git - factor.git/blob - extra/openal/example/example.factor
factor: Make source files/resources 644 instead of 755.
[factor.git] / extra / openal / example / example.factor
1 ! Copyright (C) 2007 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: calendar kernel openal openal.alut sequences threads ;
4 IN: openal.example
5
6 : play-hello ( -- )
7     init-openal
8     1 gen-sources
9     first dup AL_BUFFER  alutCreateBufferHelloWorld set-source-param
10     source-play
11     1000 milliseconds sleep ;
12
13 : play-waveform ( waveshape freq phase duration -- )
14     init-openal
15     [
16         [ 1 gen-sources first dup AL_BUFFER ] 4dip
17         alutCreateBufferWaveform
18         set-source-param
19         source-play
20     ] [ seconds sleep ] bi ;
21
22 : play-sine ( freq duration -- )
23   [ ALUT_WAVEFORM_SINE ] 2dip [ 0 ] dip play-waveform ;
24
25 : (play-file) ( source -- )
26     100 milliseconds sleep
27     dup source-playing? [ (play-file) ] [ drop ] if ;
28
29 : play-file ( filename -- )
30     init-openal
31     create-buffer-from-file
32     1 gen-sources
33     first dup [ AL_BUFFER rot set-source-param ] dip
34     dup source-play
35     check-error
36     (play-file) ;
37
38 : play-wav ( filename -- )
39     init-openal
40     create-buffer-from-wav
41     1 gen-sources
42     first dup [ AL_BUFFER rot set-source-param ] dip
43     dup source-play
44     check-error
45     (play-file) ;