sgstream/sound.lua.example

39 lines
819 B
Plaintext
Raw Permalink Normal View History

2024-05-27 13:06:41 +03:00
local sg = require "soundgen"
sg=(function(sg)
local obj = setmetatable({},sg)
obj.__index = obj
obj.proto = obj
-- custom methods here
return obj
end)(sg)
-- throw a bunch of random things together
local snd = sg:sine():freq(250)
:pm(sg:sine():freq(250/6):fade(0,0.3):amp(1/250),-1,1)
snd=snd:amp(0.8):freq(2):add(
sg:sine():freq(250)
:pm(sg:sine():freq(250),0,1/250):amp(0.3))
snd=snd:freq(1)
:pm(snd:phase(0):fade(0.3,0.0),0,0.001)
:freq(0.5)
-- fade in, fade out, reverb
snd=snd
:fade(0.01,0)
:fade(0,0.3)
:amp(0.5)
:reverb(4,1/250*30,0.4)
-- compose
local ssnd = sg.add(
snd:freq(1):phase(0),
snd:freq(0.99):phase(-0.5),
snd:freq(1.01):phase(-1),
snd:freq(1):phase(-1.4),
snd:freq(1.1):phase(-1.8)
):clamp(0,2.1,true):loop():amp(1)
return
ssnd, -- sound
1/250*6 -- oscillogram lookaround