1 ! Copyright (C) 2008 Alex Chapman
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel locals math math.constants math.functions memoize openal synth.buffers sequences sequences.modified sequences.repeating ;
6 MEMO: single-sine-wave ( samples/wave -- seq )
7 pi 2 * over / [ * sin ] curry map ;
9 : (sine-wave) ( samples/wave n-samples -- seq )
10 [ single-sine-wave ] dip <repeating> ;
12 : sine-wave ( sample-freq freq seconds -- seq )
13 pick * >integer [ /i ] dip (sine-wave) ;
15 : >sine-wave-buffer ( freq seconds buffer -- buffer )
16 [ sample-freq>> -rot sine-wave ] keep swap >>data ;
18 : >silent-buffer ( seconds buffer -- buffer )
19 tuck sample-freq>> * >integer 0 <repetition> >>data ;
21 TUPLE: harmonic n amplitude ;
22 C: <harmonic> harmonic
27 : harmonic-freq ( note harmonic -- freq )
30 :: note-harmonic-data ( harmonic note buffer -- data )
31 buffer sample-freq>> note harmonic harmonic-freq note secs>> sine-wave
32 harmonic amplitude>> <scaled> ;
34 : >note ( harmonics note buffer -- buffer )
35 dup -roll [ note-harmonic-data ] 2curry map <summed> >>data ;