]> gitweb.factorcode.org Git - factor.git/blob - extra/synth/example/example.factor
Merge branch 'master' into experimental
[factor.git] / extra / synth / example / example.factor
1 USING: accessors arrays kernel namespaces openal sequences synth synth.buffers ;
2 IN: synth.example
3
4 : play-sine-wave ( freq seconds sample-freq -- )
5     init-openal
6     <16bit-mono-buffer> >sine-wave-buffer send-buffer id>>
7     1 gen-sources first
8     [ AL_BUFFER rot set-source-param ] [ source-play ] bi
9     check-error ;
10
11 : test-instrument1 ( -- harmonics )
12     [
13         1 0.5 <harmonic> ,
14         2 0.125 <harmonic> ,
15         3 0.0625 <harmonic> ,
16         4 0.03125 <harmonic> ,
17     ] { } make ;
18
19 : test-instrument2 ( -- harmonics )
20     [
21         1 0.25 <harmonic> ,
22         2 0.25 <harmonic> ,
23         3 0.25 <harmonic> ,
24         4 0.25 <harmonic> ,
25     ] { } make ;
26
27 : sine-instrument ( -- harmonics )
28     1 1 <harmonic> 1array ;
29
30 : test-note-buffer ( note -- )
31     init-openal
32     test-instrument2 swap cd-sample-freq <16bit-mono-buffer>
33     >note send-buffer id>>
34     1 gen-sources first [ swap queue-buffer ] [ source-play ] bi
35     check-error ;