Paste: Sine wave crashes
        
	
	
	
		| Author: | muzzleflash | 
|---|
		| Mode: | factor | 
|---|
		| Date: | Sun, 26 Jul 2009 17:53:53 | 
|---|
	
	Plain Text |
	
	GENERIC: next-value ( generator -- value )
TUPLE: sine-generator amplitude current delta ;
: <sine-generator> ( amplitude freq -- sine-generator ) 2 pi * swap / [ pi ] dip sine-generator boa ;
M: sine-generator next-value 
    [ current>> sin ]
    [ amplitude>> ]
    [ dup
        [ current>> ] [ delta>> ] bi + 
        dup 2 pi * >= [ 2 pi * - ] when
    >>current drop ] tri * ;
: sine-data ( samples sample-rate amplitude freq -- byte-array )
    pick swap /
    <sine-generator>
    [ drop 0 <array> ] dip
    [ next-value nip ] curry map ;
	
		
		
			| Author: | blei | 
|---|
			| Mode: | factor | 
|---|
			| Date: | Sun, 26 Jul 2009 19:47:31 | 
|---|
		
		Plain Text |
		
		: sine-data ( samples sample-rate amplitude freq -- byte-array )
    pick swap /
    <sine-generator>
    [ drop iota ] dip
    [ next-value nip ] curry float-array map-as ;
	
		
		
			| Author: | blei | 
|---|
			| Mode: | factor | 
|---|
			| Date: | Sun, 26 Jul 2009 19:51:26 | 
|---|
		
		Plain Text |
		
		: sine-data ( samples sample-rate amplitude freq -- byte-array )
    pick swap /
    <sine-generator>
    [ drop iota ] dip
    [ next-value nip ] curry float-array{ } map-as ;
	
	
		New Annotation