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