PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/extra/synth/example/example.factor

http://github.com/abeaumont/factor
Unknown | 38 lines | 33 code | 5 blank | 0 comment | 0 complexity | 5971ca54c8f2be94e0d90c181bcf4a2c MD5 | raw file
 1! Copyright (C) 2008 Alex Chapman
 2! See http://factorcode.org/license.txt for BSD license.
 3USING: accessors arrays kernel namespaces make openal openal.alut sequences
 4synth synth.buffers ;
 5IN: synth.example
 6
 7: play-sine-wave ( freq seconds sample-freq -- )
 8    init-openal
 9    <16bit-mono-buffer> >sine-wave-buffer send-buffer id>>
10    1 gen-sources first
11    [ AL_BUFFER rot set-source-param ] [ source-play ] bi
12    check-error ;
13
14: test-instrument1 ( -- harmonics )
15    [
16        1 0.5 <harmonic> ,
17        2 0.125 <harmonic> ,
18        3 0.0625 <harmonic> ,
19        4 0.03125 <harmonic> ,
20    ] { } make ;
21
22: test-instrument2 ( -- harmonics )
23    [
24        1 0.25 <harmonic> ,
25        2 0.25 <harmonic> ,
26        3 0.25 <harmonic> ,
27        4 0.25 <harmonic> ,
28    ] { } make ;
29
30: sine-instrument ( -- harmonics )
31    1 1 <harmonic> 1array ;
32
33: test-note-buffer ( note -- )
34    init-openal
35    test-instrument2 swap cd-sample-freq <16bit-mono-buffer>
36    >note send-buffer id>>
37    1 gen-sources first [ swap queue-buffer ] [ source-play ] bi
38    check-error ;