Skip to content

Instantly share code, notes, and snippets.

@trentgill
Last active October 8, 2022 18:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trentgill/23d6c8376d371997d7933d959ddba258 to your computer and use it in GitHub Desktop.
Save trentgill/23d6c8376d371997d7933d959ddba258 to your computer and use it in GitHub Desktop.
lil demo of ASL creating simple decaying oscillator tones
--- bouncy
-- tiny demo of ASL's dyn, generating a stream of bass notes from crow
-- little sequins of frequencies
PIT = sequins{ 110
, 110*1.5
, 110*1.25
, 110*1.666
, 110*1.333
}
RYT = sequins{1,0.5,0.33,2}
function init()
-- start output 1 oscillating with an intrinsic decay envelope
output[1]( oscillate( dyn{pitch=PIT()} -- dynamically set frequency
, dyn{lev=5}:mul(0.95) -- level fades from 5 to ~0, :mul(0.95) sets decay rate
, 'linear')) -- triangle wave
-- start a clock with the 'notes' function for plucking notes
clock.run(notes)
end
function notes()
while true do
clock.sleep(RYT()) -- wait for beat to finish
output[1].dyn.pitch = PIT() -- set a new pitch
output[1].dyn.lev = 5 -- reset level to 5V (will decay immediately)
end
end
function stop()
clock.cleanup() -- stop all clocks
output[1].volts = 0 -- disable oscillator
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment