Skip to content

Commit 54de66b

Browse files
authored
Add pitch variations for most noteblock sounds (#535)
1 parent 6890624 commit 54de66b

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

mesecons_noteblock/README.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Credits of sound files:
2+
3+
Note: Most sounds have not been used verbatim, but tweaked a little to be more suitable for the noteblock mod.
4+
5+
* mesecons_noteblock_litecrash.ogg
6+
* License: CC BY 3.0
7+
* by freesound.org user ani_music
8+
* Source: https://freesound.org/people/ani_music/sounds/219612/
9+
10+
Everything else:
11+
Created by Mesecons authors, licensed CC BY 3.0.
12+
13+
--------------------
14+
License links:
15+
* CC BY 3.0: http://creativecommons.org/licenses/by/3.0/

mesecons_noteblock/doc/noteblock/description.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<tr><td>Chest or Locked Chest</td><td>Snare</td></tr>
77
<tr><td>Any tree</td><td>Crash</td></tr>
88
<tr><td>Any wooden planks</td><td>Lite Crash</td></tr>
9-
<tr><td>Coal Block</td><td>Explosion sound</td></tr>
10-
<tr><td>Lava Source</td><td>Fire sound</td></tr>
9+
<tr><td>Coal Block</td><td>Explosion sound (fixed pitch)</td></tr>
10+
<tr><td>Lava Source</td><td>Fire sound (fixed pitch)</td></tr>
1111
<tr><td>Steel Block</td><td>Piano (high pitch, one octave higher than normal)</td></tr>
1212
<tr><td>Any other block</td><td>Piano (low pitch)</td></tr>
1313
</table>

mesecons_noteblock/init.lua

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ minetest.register_node("mesecons_noteblock:noteblock", {
2020
mesecon.noteblock_play(pos, node.param2)
2121
end
2222
}},
23+
place_param2 = 11, -- initialize at C note
2324
on_blast = mesecon.on_blastnode,
2425
})
2526

@@ -45,7 +46,7 @@ local soundnames = {
4546
"mesecons_noteblock_a",
4647
"mesecons_noteblock_asharp",
4748
"mesecons_noteblock_b",
48-
"mesecons_noteblock_c"
49+
"mesecons_noteblock_c" -- << noteblock is initialized here
4950
}
5051

5152
local node_sounds = {}
@@ -74,6 +75,9 @@ mesecon.noteblock_play = function(pos, param2)
7475
pos.y = pos.y-1
7576
local nodeunder = minetest.get_node(pos).name
7677
local soundname = node_sounds[nodeunder]
78+
local use_pitch = true
79+
local pitch
80+
-- Special sounds
7781
if not soundname then
7882
for k,v in pairs(node_sounds_group) do
7983
local g = minetest.get_item_group(nodeunder, k)
@@ -83,6 +87,7 @@ mesecon.noteblock_play = function(pos, param2)
8387
end
8488
end
8589
end
90+
-- Piano
8691
if not soundname then
8792
soundname = soundnames[param2]
8893
if not soundname then
@@ -92,13 +97,24 @@ mesecon.noteblock_play = function(pos, param2)
9297
if nodeunder == steelblock_nodename then
9398
soundname = soundname.. 2
9499
end
100+
use_pitch = false
101+
end
102+
-- Disable pitch for fire and explode because they'd sound too odd
103+
if soundname == "fire_fire" or soundname == "tnt_explode" then
104+
use_pitch = false
105+
end
106+
if use_pitch then
107+
-- Calculate pitch
108+
-- Adding 1 to param2 because param2=11 is *lowest* pitch sound
109+
local val = (param2+1)%12
110+
pitch = 2^((val-6)/12)
95111
end
96112
pos.y = pos.y+1
97113
if soundname == "fire_fire" then
98114
-- Smoothly fade out fire sound
99115
local handle = minetest.sound_play(soundname, {pos = pos, loop = true})
100116
minetest.after(3.0, minetest.sound_fade, handle, -1.5, 0.0)
101117
else
102-
minetest.sound_play(soundname, {pos = pos}, true)
118+
minetest.sound_play(soundname, {pos = pos, pitch = pitch}, true)
103119
end
104120
end
-2.76 KB
Binary file not shown.

0 commit comments

Comments
 (0)