Closed paramat closed 7 years ago
Please don't remove the sounds! Fix sound code instead Problem with flames is this, light some wood on fire with flint and steel, fly away, you will notice that fire sound attenuates quickly with distance to some quite level, but you can still hear for 500 blocks and beyond, even 1000...
Surely it would be possible to reduce the audible radius and decrease the number of nodes triggering sound loops.
A new api for ambient noise emitted by masses of nodes would be desirable. It could be extended to leaf masses emitting birdsong, grass emitting cricket chirrups and wolf-howls from pine trunks, even the whirring of machinery.
My Ambience lite has a faster way of checking for flame and playing sound: https://www.github.com/tenplus1/ambience
I think tenplus1's mod has potential and the method should be considered for fire sounds and maybe flowing water sounds too.
Or just include the damn thing, we need ambience, I doubt someone will code it.
Nope it is excessive with all the wildlife sounds, so a mod thing.
I'm looking into using tenplus1's code for fire sounds.
I'd postpone this until we get an idea where client-side modding API goes. That is the right place for ambient sounds IMHO, and will make it much easier to do.
True, but until that arrives we need better working and more lightweight fire sounds, the current implementation is really bad, and heavy.
Greatly simplified tenplus1's ambience mod for use with fire sounds. Code: https://gist.github.com/paramat/b9b664fdacfd3847db2051a919552f68 You can test this code by placing 'permanent_flame' nodes as these do not trigger current fire sound code. Maybe i'll now make a PR for easier testing.
Updated that code again. Now the flame count from the previous cycle is stored. If a player walks into range of flames an alternative version of the sound is played that smoothly fades in. If a player walks out of range of flames an alternative version of the sound is played that smoothly fades out. This avoids any instant start or stop of fire sounds.
https://github.com/paramat/parambience Here it is as a mod for testing, easily tested by placing 'permanent flame' nodes around. The time cycle is 4s to reduce the occurence of node searches, the cycle can be reduced in the parameters, the search radius can also be adjusted. There are now 3 alternative fire samples used to avoid a repetitive ambience, all have been re-edited from the original freesound download.
Fade is nice, but it works kinda weird, you approach it - sound kicks in much later and does not depend on distance. It feels very awkward. 4sec cycle is very slow, good results start from 1 sec and faster.
Start fire / dig fire - wait 4 seconds to hear sounds is ridiculous.
Yeah, the cycle could be made shorter, it'a case of balancing it against weight of 'find nodes in area' searches, tenplus1's mod uses 2s. The radius could perhaps be 6. The non-positional sounds are a little weird, but i don't yet know an acceptable way to have positional. The current sound code must go though, so the choice is imperfection or silence,
I'll try something with positional, it won't be perfect though.
https://github.com/paramat/parambience @Fixer-007 Now positional, uses the first flame position in list, which is southern and western, so in a large collection of flames the sound will come from a corner. Since the sounds are now positional, each player in range of flames adds a sound in the environment, a little weird but hopefully not a big problem. Worth it for positional sounds. I changed the cycle to 3s, it may have to be 2s but that's short enough, 1s or shorter is too often to trigger these large node searches around every player all the time. We have to balance the feature against load.
I tried choosing a random flame position per cycle, that made the position shift every cycle which seemed to be worse, however that is an option. You can test that wiith this line at line 49:
pos = fpos[math.random(#fpos)],
Since the sounds are now positional, each player in range of flames adds a sound in the environment
o_0 o_0 o_0
@paramat - that's why I linked sound played to an actual player to stop multiple sounds playing... to_player = player_name,
Well i just thought of having positional sounds played to only one player, if that's possible, i thought it wasn't from the documentation, i'll try it. I'll also use the position from the centre of the list of node positions, this will tend to be the node closest to the player.
Updated mod, seems to work.
Profiler results after few minutes of testing with 200 sound sources, avg us time is pretty low for default:
Values below show absolute/relative times spend per server step by the instrumented function.
A total of 18161 samples were taken
instrumentation | min µs | max µs | avg µs | min % | max % | avg %
-------------------------------------------------------- | --------- | --------- | --------- | ----- | ----- | ------
flowers: | 0 | 206 | 0 | 0.0 | 85.8 | 0.0
- ABM 'Flower spread' ............................... | 2 | 206 | 53 | 2.2 | 85.8 | 34.9
creative: | 0 | 1 | 0 | 0.0 | 5.0 | 0.0
- on_placenode[1] ................................... | 1 | 1 | 1 | 0.1 | 5.0 | 3.6
fire: | 0 | 250 | 0 | 0.0 | 93.5 | 0.1
- ABM 'Extinguish flame' ............................ | 174 | 174 | 174 | 93.5 | 93.5 | 93.5
- ABM 'Ignite flame' ................................ | 42 | 250 | 82 | 21.8 | 89.9 | 64.1
- ABM 'Remove flammable nodes' ...................... | 51 | 131 | 83 | 29.3 | 84.0 | 68.3
nyancat: | 0 | 111 | 0 | 0.0 | 87.4 | 0.1
- on_generated[1] ................................... | 1 | 111 | 18 | 4.5 | 87.4 | 35.1
xpanes: | 0 | 81 | 0 | 0.0 | 84.4 | 0.5
- on_placenode[1] ................................... | 7 | 81 | 15 | 1.2 | 84.4 | 43.2
parambience: | 0 | 918 | 2 | 0.0 | 98.5 | 4.7
- globalstep[1] ..................................... | 1 | 918 | 3 | 0.0 | 98.5 | 7.9
default: | 4 | 2166 | 17 | 1.5 | 100.0 | 94.6
- globalstep[1] ..................................... | 4 | 2166 | 16 | 1.5 | 100.0 | 94.0
- ABM 'Grass spread' ................................ | 1 | 49 | 12 | 1.6 | 79.0 | 30.4
- ABM 'Leaf decay' .................................. | 6 | 113 | 20 | 2.7 | 81.3 | 38.6
- ABM 'Grass covered' ............................... | 2 | 100 | 19 | 1.7 | 78.5 | 44.5
-------------------------------------------------------- | --------- | --------- | --------- | ----- | ----- | ------
total: | 4 | 2167 | 19 | 100.0 | 100.0 | 100.0
Mod profiler result for 0.025 sec simulating 1 sec cycle time for 40 players (it sounded weird btw)...
Values below show absolute/relative times spend per server step by the instrumented function.
A total of 2162 samples were taken
instrumentation | min µs | max µs | avg µs | min % | max % | avg %
-------------------------------------------------------- | --------- | --------- | --------- | ----- | ----- | ------
fire: | 0 | 53 | 0 | 0.0 | 19.2 | 0.0
- ABM 'Ignite flame' ................................ | 42 | 53 | 48 | 8.3 | 19.2 | 13.7
flowers: | 0 | 6 | 0 | 0.0 | 3.8 | 0.0
- ABM 'Flower spread' ............................... | 3 | 6 | 4 | 2.6 | 3.8 | 3.2
parambience: | 0 | 2565 | 131 | 0.0 | 99.4 | 63.9
- globalstep[1] ..................................... | 1 | 2565 | 150 | 0.1 | 99.4 | 73.5
default: | 5 | 1208 | 18 | 0.6 | 100.0 | 36.1
- globalstep[1] ..................................... | 5 | 1208 | 18 | 0.6 | 100.0 | 35.8
- ABM 'Grass spread' ................................ | 2 | 58 | 11 | 1.1 | 38.7 | 11.9
- ABM 'Leaf decay' .................................. | 17 | 32 | 26 | 18.8 | 23.9 | 21.4
- ABM 'Grass covered' ............................... | 5 | 95 | 22 | 2.1 | 77.2 | 25.3
-------------------------------------------------------- | --------- | --------- | --------- | ----- | ----- | ------
total: | 5 | 2588 | 149 | 100.0 | 100.0 | 100.0
avg is higher but not in dangerous zone for that much players.
searching middle point for sound often gives some odd results, place some sounds underground, and few above your head, you will notice how rapidly its volume and probably position can change if you move just 1 block away or under it. I think it is not the best method, another example when I have lots of scattered fire around - but it is very quite when you go away from the flame - sound goes down but just before end volume bumps up again a lot and dies down
Good points. Non-positional may be better.
The problem with shortening the cycle is that the sound samples then get shorter, 1s samples are not going to sound as good. I feel 2-3s is about right.
Updated the mod. Since the node search is being done it is little extra load to search for water sounds also. 'Make sounds non-positional again. Add water sounds (CC BY-NC so temporary)' I might submit this as an ambience mod for MTGame.
See #1385
The problem with shortening the cycle is that the sound samples then get shorter
hm, why can't it keep playing the sound out of cycle varying volume as needed? Could this be a problem in future?
Just FYI: Don't trust the documentation, it is misleading. Sounds can be looped regardless of their association with an object. Moreover, sounds are not "attached" to an object internally.
When minetest.sound_play( ) is invoked with an object, it does not maintain any reference to the object. It is only used for positioning purposes at the time of invocatioin. Regardless of whether the object is moved or removed afterward, the looped sound will continue to play from that same position until stopped (hence the bug with fire sounds).
If you really want to attach a sound to an object, you'd need to create and maintain a state table.
From lua_api.txt: 'loop = true, -- only sounds connected to objects can be looped' I don't see objects used. Fire sounds are reported to be heard 1000s of nodes away.
Rejoining the game makes flames go silent. The fire sound code is hacky and probably heavy, playing looped sounds every 6 nodes. Certainly we need a new sound API and engine code for uses such as flames and running water.