[Oxyd] [1.1.5] Some sounds played with LuaPlayer.play_sound{position=nil} are affected by zoom, but not all.

This subforum contains all the issues which we already resolved.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

[Oxyd] [1.1.5] Some sounds played with LuaPlayer.play_sound{position=nil} are affected by zoom, but not all.

Post by eradicator »

What?

When using play_sound() without a position then the sound should play "everywhere" according to the documentation, but this is only true for some sounds. Also I can't see any rule which sounds are affected and which are not.

Expected behavior

Sounds played without position should always be unaffected by zoom.

Explanation

For my screenshot mod i'm trying to play some sounds upon certain player interactions, which happens at possibly very high zoom-out. So i need a reliable way to play sounds in a zoom independant way. At first i thought only modded "sound" prototypes are affected, but during writing of this post i noticed that some build-in sounds are also affected. I also tried the prototype modifier "audible_distance_modifier" but setting it to either 0 / 1 / 10 did not affect the result.

Reproduction

Use the command or the demo mod (best on a new map where there are no other distracting noises). The script will slowly zoom out while playing sounds. You will notice that the inventory related sounds are always the same volume, but the build sound and the modded sound fade out until they're inaudible.


zz-bugtest-template_0.0.1.zip
(31.81 KiB) Downloaded 115 times

Code: Select all

/c
local zoom,k = {4,2,1,1/2,1/4,1/8,1/16}
local nx = function() repeat k = next(zoom,k) until k return zoom[k] end

script.on_nth_tick(30, function(e)
  local p = game.players[1]
  if e.tick % 60 == 30 then
    p.zoom = nx()
  else
    --[[unaffected by zoom]]
    p.play_sound{path = 'utility/inventory_click',  volume_modifier = 1}
    p.play_sound{path = 'utility/inventory_move',  volume_modifier = 1}
    --[[affected by zoom]]
    p.play_sound{path = 'utility/build_large', volume_modifier = 1}
    end
  end)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Oxyd
Former Staff
Former Staff
Posts: 1428
Joined: Thu May 07, 2015 8:42 am
Contact:

Re: [Oxyd] [1.1.5] Some sounds played with LuaPlayer.play_sound{position=nil} are affected by zoom, but not all.

Post by Oxyd »

What's happening here is that each sound has a type associated with it. inventory_click and inventory_move are gui-effect sounds, build_large is a game-effect. The type determines which mixer the sound is played through. A player can set the volume of each mixer individually in the sound volume settings, which is why the sound types exist.

Game-effect sounds are also affected by zoom level, as you've just discovered, to give the effect of the virtual camera (together with the pretend microphone) pulling away from the world up into the higher levels of Nauvis atmosphere.

So, from this point of view, it's not a bug – it's working as intended. But, there's also the slight inconvenience that the sound type is not a part of the prototype, so as a modder you don't really have a say in it.

So I added an additional optional parameter to the play_sound functions in the Lua API. That means you will be able to do this to force the build_effect sound to be played through the gui-effect mixer:

Code: Select all

p.play_sound{path = 'utility/build_large', volume_modifier = 1, override_sound_type = 'gui-effect'}
Which means it will also be affected by the GUI effects slider in sound settings, as it should be for your use-case.

So not a bug, but also fixed in 1.1.7.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [Oxyd] [1.1.5] Some sounds played with LuaPlayer.play_sound{position=nil} are affected by zoom, but not all.

Post by eradicator »

Oxyd wrote: Wed Dec 16, 2020 6:09 pm But, there's also the slight inconvenience that the sound type is not a part of the prototype, so as a modder you don't really have a say in it.
So as suspected there was some internal hardcoded magic involved.
Oxyd wrote: Wed Dec 16, 2020 6:09 pm So I added an additional optional parameter to the play_sound functions in the Lua API.

So not a bug, but also fixed in 1.1.7.
Perfect solution. Especially nice because it allows using the same sound in different contexts. Thank you very much for fixing it anyway and even writing a lengthy explanation :)!
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Post Reply

Return to “Resolved Problems and Bugs”