| 
									
										
										
										
											2008-05-19 22:01:14 -04:00
										 |  |  | ! Copyright (C) 2008 Alex Chapman | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2010-02-17 01:31:21 -05:00
										 |  |  | USING: accessors arrays kernel namespaces make openal openal.alut sequences | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:40 -04:00
										 |  |  | synth synth.buffers ;
 | 
					
						
							| 
									
										
										
										
											2008-05-19 10:58:45 -04:00
										 |  |  | IN: synth.example | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : play-sine-wave ( freq seconds sample-freq -- )
 | 
					
						
							|  |  |  |     init-openal | 
					
						
							|  |  |  |     <16bit-mono-buffer> >sine-wave-buffer send-buffer id>> | 
					
						
							|  |  |  |     1 gen-sources first
 | 
					
						
							|  |  |  |     [ AL_BUFFER rot set-source-param ] [ source-play ] bi
 | 
					
						
							|  |  |  |     check-error ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : test-instrument1 ( -- harmonics )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         1 0.5 <harmonic> , | 
					
						
							|  |  |  |         2 0.125 <harmonic> , | 
					
						
							|  |  |  |         3 0.0625 <harmonic> , | 
					
						
							|  |  |  |         4 0.03125 <harmonic> , | 
					
						
							|  |  |  |     ] { } make ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : test-instrument2 ( -- harmonics )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         1 0.25 <harmonic> , | 
					
						
							|  |  |  |         2 0.25 <harmonic> , | 
					
						
							|  |  |  |         3 0.25 <harmonic> , | 
					
						
							|  |  |  |         4 0.25 <harmonic> , | 
					
						
							|  |  |  |     ] { } make ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : sine-instrument ( -- harmonics )
 | 
					
						
							|  |  |  |     1 1 <harmonic> 1array ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : test-note-buffer ( note -- )
 | 
					
						
							|  |  |  |     init-openal | 
					
						
							|  |  |  |     test-instrument2 swap cd-sample-freq <16bit-mono-buffer> | 
					
						
							|  |  |  |     >note send-buffer id>> | 
					
						
							|  |  |  |     1 gen-sources first [ swap queue-buffer ] [ source-play ] bi
 | 
					
						
							|  |  |  |     check-error ;
 |