Page 1 of 1

Adjusting Volume of base items

Posted: Fri Jul 11, 2014 7:49 pm
by Turtle
Hi! How would I go about adjusting the volume for certain entities? Some sounds, like when follower robots die, are just too loud for my taste and it's too much trouble when I change the base files every update. First, it'll throw a CRC error when trying to patch, next I'll forget which lines I changed - just annoying. So I figured I'd make a mod for myself and never worry about it again.

Re: Adjusting Volume of base items

Posted: Fri Jul 11, 2014 8:28 pm
by FreeER
Hm, I know some sounds are specified with a volume as well, my guess would be that if it's not specified it defaults to 1 (or 100%), so if you were to use the data.raw to access where those sounds are defined and add a volume of less than 1 (or whatever the current is for that sound) it might work...

so data.raw accesses are done in the following form:
data.raw["type"]["name"]["property"], if they do not contain a '-' then you can use a '.' instead of the full ["index_key"] syntax (ie: data.raw.type.name.property)..
Hopefully there aren't too many that you find too loud because it'd be a fairly boring process...
A full example (for the fast transport belt, from volume of 0.4 to 0.2) and for the assembling machine mk 2:

Code: Select all

data.raw["transport-belt"]["fast-transport-belt"].working_sound.sound.volume = 0.2

data.raw["assembling-machine"]["assembling-machine-2"].open_sound.volume = 0.65
data.raw["assembling-machine"]["assembling-machine-2"].close_sound.volume = 0.55
data.raw["assembling-machine"]["assembling-machine-2"].working_sound.sound[1].volume = 0.4
data.raw["assembling-machine"]["assembling-machine-2"].working_sound.sound[2].volume = 0.4
data.raw["assembling-machine"]["assembling-machine-2"].working_sound.idle_sound.volume = 0.3
Note how the assembling-machine's working_sound.sound has 2 unnamed tables in it, as they are unnamed they can only be accessed with it's full indexing syntax using a 1 for the first, a 2 for the second, etc. (or a for loop)

Of course you only change the ones that you actually want to change, it may be unnecessary to change all of the sounds.
Also note that working_sound has an apparent_volume property, it's possible that changing that to a lower value would decrease all of the sounds specified within working_sound (but I haven't tested).
Also, you could just as well change the filename(s) so that it points towards "__your-mod-name__/mod-sound-directory/filename.ext" (with the quotes), if you've edited the sound files to be a lower volume. Obviously replace the your-mod-name and such properly, and it's two '_' characters (not just one) on each side of the mod name :)

If there are a lot to change maybe tweaking this would be easier

Code: Select all

function soundFinder(table)
  for name, values in pairs(table) do
    if type(values) == "table" and name:find("sound") then
      if values.filename then
        if values.volume then 
          values.volume = values.volume*0.7
        else
          values.volume = 0.7
        end
      else
        soundFinder(values)
      end
    end
  end
end
so the obvious intent here is that you'd pass a table from data.raw (probably by looping over a type) and it "tries" to find all sound properties and lower it's volume by 30%. It's likely going to miss some since I wrote it very quickly and haven't tested it :) and if there's only a few sounds that are too loud it's definitely overkill to employ such an approach :lol:

Well, I hope you find that at least a bit helpful (btw, you're welcome for the indirect help with adding coal liquefaction's recipe to the production module allow list, anytime!) :P

Re: Adjusting Volume of base items

Posted: Fri Jul 11, 2014 9:08 pm
by Turtle
Thanks! It's only a few sounds so I don't need to do a loop... otherwise I'd just use the master volume hehe. Mainly the explosion sound when follower robots die. But while I'm at it and just for the sake of learning this, the logistics robots working sound points to a function. How would I mod that?

Code: Select all

    type = "logistic-robot",
    name = "logistic-robot",
    ....
    working_sound = flying_robot_sounds(),

Code: Select all

function flying_robot_sounds()
  return
  {
    sound =
    {
      { filename = "__base__/sound/flying-robot-1.ogg", volume = 0.6 },
      { filename = "__base__/sound/flying-robot-2.ogg", volume = 0.6 },
      { filename = "__base__/sound/flying-robot-3.ogg", volume = 0.6 },
      { filename = "__base__/sound/flying-robot-4.ogg", volume = 0.6 },
      { filename = "__base__/sound/flying-robot-5.ogg", volume = 0.6 }
    },
    max_sounds_per_type = 3
  }
end
For anyone that's looking to do something similar:
1. Create a folder inside your mods folder and name it whatever you want, I named mine TurtleMod
2. Create a file named info.json and put in the following:

Code: Select all

{
  "name": "YourMod",
  "version": "0.1",
  "title": "YourMod",
  "author": "YourName",
  "contact": "",
  "homepage": "",
  "description": "My basic changes to base."
}
3. Create a file named data.lua and put in the following:

Code: Select all

data.raw.explosion.explosion.sound[1].volume = 0.5
data.raw.explosion.explosion.sound[2].volume = 0.5
The above mod will decrease the follower robot death sound from 0.8 to 0.5.

Re: Adjusting Volume of base items

Posted: Fri Jul 11, 2014 9:19 pm
by FreeER
Turtle wrote:But while I'm at it and just for the sake of learning this, the logistics robots working sound points to a function. How would I mod that?
It's actually really similar (note, you can't change the function itself because it's not actually placed into data.raw) :)
what will be in data.raw is the return result of the function, so you can pretend that it's like this:

Code: Select all

   working_sound =  {
    sound =
    {
      { filename = "__base__/sound/flying-robot-1.ogg", volume = 0.6 },
      { filename = "__base__/sound/flying-robot-2.ogg", volume = 0.6 },
      { filename = "__base__/sound/flying-robot-3.ogg", volume = 0.6 },
      { filename = "__base__/sound/flying-robot-4.ogg", volume = 0.6 },
      { filename = "__base__/sound/flying-robot-5.ogg", volume = 0.6 }
    },
    max_sounds_per_type = 3
  }
and change those individually. Or you could copy and paste that function into your file and modify it, then instead of modifying each individual sound you simply use data.raw["logistic-robot"]["logistic-robot"].working_sound = flying_robot_sounds() (that will reference the function that you defined/modified).

Re: Adjusting Volume of base items

Posted: Fri Jul 11, 2014 9:52 pm
by Turtle
Oh I see now. I was trying:

Code: Select all

data.raw["logistic-robot"]["logistic-robot"].working_sound.sound.filename[1].volume = 0.1
If I had looked at the assembly machine entity first, I should've seen that. Thanks again!