Add support for fading and cutting noteblock sounds

Also add a 1kHz sine wave sample, intended for use with this
This commit is contained in:
cheapie 2021-12-23 20:46:24 -06:00
parent 47a32ff26e
commit 144c61533c
3 changed files with 13 additions and 1 deletions

@ -33,6 +33,7 @@ local valid_sounds = {
digistuff_piezo_long = "digistuff_piezo_long_single",
digistuff_piston_extend = "digistuff_piston_extend",
digistuff_piston_retract = "digistuff_piston_retract",
sine = "digistuff_sine",
}
local mod_sounds = {

@ -73,7 +73,18 @@ minetest.register_node("digistuff:noteblock", {
if type(msg.pitch) == "number" then
pitch = math.max(0.05,math.min(10,msg.pitch))
end
if sound then minetest.sound_play({name = sound,gain = volume,},{pos = pos,pitch = pitch,},true) end
if sound then
if type(msg.cut) == "number" and msg.cut >= 0 then
msg.cut = math.min(msg.cut,10)
local handle = minetest.sound_play({name = sound,gain = volume,},{pos = pos,pitch = pitch,},false)
minetest.after(msg.cut,minetest.sound_stop,handle)
elseif type(msg.fadestep) == "number" and type(msg.fadegain) == "number" and msg.fadegain >= 0 and type(msg.fadestart) == "number" and msg.fadestart >= 0 then
local handle = minetest.sound_play({name = sound,gain = volume,},{pos = pos,pitch = pitch,},false)
minetest.after(msg.fadestart,minetest.sound_fade,handle,msg.fadestep,msg.fadegain)
else
minetest.sound_play({name = sound,gain = volume,},{pos = pos,pitch = pitch,},true)
end
end
end
end
},

BIN
sounds/digistuff_sine.ogg Normal file

Binary file not shown.