Paste: contrib
Author: | typemore |
Mode: | factor |
Date: | Thu, 23 Sep 2010 08:32:02 |
Plain Text |
USING: accessors timers audio audio.engine audio.loader calendar
destructors io kernel locals math math.functions math.ranges specialized-arrays
sequences random math.vectors fry ;
FROM: alien.c-types => short ;
SPECIALIZED-ARRAY: short
IN: music
TUPLE: noise-generator
{ offset initial: 0 }
{ hertz initial: 440 }
{ rate initial: 8000 }
;
M: noise-generator generator-audio-format
drop 1 16 8000 ;
M:: noise-generator generate-audio ( generator -- c-ptr size )
generator rate>> iota
3.1415926 generator rate>> generator hertz>> / / 2 * '[ _ * sin 4096 * ] short-array{ } map-as
generator generator rate>> generator hertz>> mod >>offset drop
8000 ;
M: noise-generator dispose
drop ;
:: audio-test ( -- )
0 :> i!
f 4 <audio-engine> :> engine
engine start-audio*
engine T{ audio-source f { 0.0 0.0 0.0 } 1.0 { 0.0 0.0 0.0 } f }
noise-generator new
0 >>offset
880 >>hertz
8000 >>rate
2
play-streaming-audio-clip :> noise-clip
[
noise-clip source>>
drop
engine update-audio
] 20 milliseconds every :> timer
"Press Enter to stop the test." print
readln drop
timer stop-timer
engine dispose ;
MAIN: audio-test
New Annotation