]> gitweb.factorcode.org Git - factor.git/blob - extra/synth/example/example.factor
factor: trim using lists
[factor.git] / extra / synth / example / example.factor
1 ! Copyright (C) 2008 Alex Chapman
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays kernel make openal openal.alut sequences
4 synth synth.buffers ;
5 IN: 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 ;