From 144c61533cdd2293aaf1b3b7cfeec8b7ca0df04f Mon Sep 17 00:00:00 2001 From: cheapie Date: Thu, 23 Dec 2021 20:46:24 -0600 Subject: Add support for fading and cutting noteblock sounds Also add a 1kHz sine wave sample, intended for use with this --- nbsounds.lua | 1 + noteblock.lua | 13 ++++++++++++- sounds/digistuff_sine.ogg | Bin 0 -> 7262 bytes 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 sounds/digistuff_sine.ogg diff --git a/nbsounds.lua b/nbsounds.lua index f9ccb2c..6e6a947 100644 --- a/nbsounds.lua +++ b/nbsounds.lua @@ -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 = { diff --git a/noteblock.lua b/noteblock.lua index 58bb747..ef14224 100644 --- a/noteblock.lua +++ b/noteblock.lua @@ -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 }, diff --git a/sounds/digistuff_sine.ogg b/sounds/digistuff_sine.ogg new file mode 100644 index 0000000..ed11711 Binary files /dev/null and b/sounds/digistuff_sine.ogg differ -- cgit v1.2.3