]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/synth/synth.factor
factor: trim using lists
[factor.git] / extra / synth / synth.factor
index be1e5943afc7dbf7f025cf06ffb1de5c2d37b25d..acf668f3fe054bcf3f6b16f0b70acc855f8dff21 100644 (file)
@@ -1,13 +1,14 @@
 ! Copyright (C) 2008 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel locals math math.constants math.functions memoize openal synth.buffers sequences sequences.modified sequences.repeating ;
+USING: accessors kernel math math.constants math.functions
+sequences sequences.modified sequences.repeating ;
 IN: synth
 
 MEMO: single-sine-wave ( samples/wave -- seq )
-    pi 2 * over / [ * sin ] curry map ;
+    [ <iota> ] [ pi 2 * swap / [ * sin ] curry ] bi map ;
 
 : (sine-wave) ( samples/wave n-samples -- seq )
-    [ single-sine-wave ] dip <repeating> ;
+    [ single-sine-wave ] dip <cycles> ;
 
 : sine-wave ( sample-freq freq seconds -- seq )
     pick * >integer [ /i ] dip (sine-wave) ;
@@ -16,7 +17,7 @@ MEMO: single-sine-wave ( samples/wave -- seq )
     [ sample-freq>> -rot sine-wave ] keep swap >>data ;
 
 : >silent-buffer ( seconds buffer -- buffer )
-    tuck sample-freq>> * >integer 0 <repetition> >>data ;
+    [ sample-freq>> * >integer 0 <repetition> ] [ data<< ] [ ] tri ;
 
 TUPLE: harmonic n amplitude ;
 C: <harmonic> harmonic
@@ -32,5 +33,4 @@ C: <note> note
     harmonic amplitude>> <scaled> ;
 
 : >note ( harmonics note buffer -- buffer )
-    dup -roll [ note-harmonic-data ] 2curry map <summed> >>data ;
-
+    [ [ note-harmonic-data ] 2curry map <summed> ] [ data<< ] [ ] tri ;