Page 1 of 1

Sound API

PostPosted: Fri Mar 10, 2017 10:10
by burli
I think about a new sound API that is a little bit more common and flexibel than the current one

I propose a key/value table with a table of sounds as value and some functions.

The table could look like this

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
registered_sounds = {
    {"wood_sounds",
        {
          footstep = <SimpleSoundSpec>,
          dig = <SimpleSoundSpec>,
          dug = <SimpleSoundSpec>,
          place = <SimpleSoundSpec>,
          place_failed = <SimpleSoundSpec>,
        }
     },
    {"gravel_sounds",
        {
          footstep = <SimpleSoundSpec>,
          dig = <SimpleSoundSpec>,
          dug = <SimpleSoundSpec>,
          place = <SimpleSoundSpec>,
          place_failed = <SimpleSoundSpec>,
        }
     },
    {"stone_sounds",
        {
          footstep = <SimpleSoundSpec>,
          dig = <SimpleSoundSpec>,
          dug = <SimpleSoundSpec>,
          place = <SimpleSoundSpec>,
          place_failed = <SimpleSoundSpec>,
        }
     }
}


Sounds will be added with sounds.register(name, def), it can be overwritten with sounds.overwrite(name, def) and probably a sound.is_registered(name) function to check if a sound is already registered. I think a delete function is not necessary because once a sound is registered it is used somewhere and deleting a registered sound only causes errors.

using a sound could look like this

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_node("dirt:dirt", {
   description = S("Dirt"),
   tiles = {"default_dirt.png"},
   groups = {crumbly = 3, soil = 1},
   sounds = sounds.get("dirt_sounds"),
})


What kinds of sounds are in MTG?

- Damage sounds are hard coded, so they are out
- Node sounds like footsteps and dig/dug
- Tool sounds (break)
- Any more?

What kind of other sounds could be in a Minetest game?
- Mob sounds
- Environment sounds
- GUI effects (e.g. play sound when change wield item)
- Player sounds (panting, hunger)

All this could be handled by this API. Mods are able to overwrite sounds, use already existing sounds and so on

What do you think?

Re: Sound API

PostPosted: Fri Mar 10, 2017 13:23
by burli
This is how it currently looks like

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local dirtsounds = {
      footstep = {name = "default_dirt_footstep", gain = 0.4},
      dug = {name = "default_dirt_footstep", gain = 1.0},
      place = {name = "default_place_node", gain = 1.0},
   }

sounds.register("dirt_sounds", dirtsounds)
sounds.clone("dirt_sounds", "dirt_with_grass_sounds", {
      footstep = {name = "default_grass_footstep", gain = 0.25},
   })

minetest.register_node("dirt:dirt", {
   description = S("Dirt"),
   tiles = {"default_dirt.png"},
   groups = {crumbly = 3, soil = 1},
   sounds = sounds.get("dirt_sounds"),
})

minetest.register_node("dirt:dirt_with_grass", {
   description = S("Dirt with Grass"),
   tiles = {"default_grass.png", "default_dirt.png",
      {name = "default_dirt.png^default_grass_side.png",
         tileable_vertical = false}},
   groups = {crumbly = 3, soil = 1, spreading_dirt_type = 1},
   drop = 'dirt:dirt',
   sounds = sounds.get("dirt_with_grass_sounds"),
})


I add the sounds.clone function. This function makes a clone and can replace specific sounds. I think, the overwrite function is relatively useless

Re: Sound API

PostPosted: Sat Mar 11, 2017 06:44
by Wuzzy
- Tool sounds (break)

If I'm not mistaken, the tool breaking sound has a hardcoded default as well, but I'm not sure.

In general, I think the idea of generalizing the sounds system is a very good idea and much needed. I hate to depend on default or any particular subgame just to get a single sound for my node.

Sounds are definitely something which can be abtracted away from the subgame, and there are many recurring node sounds like dirt, snow, sand, etc.

I think a full-blown API is probably overkill but I like the direction.

Ideally, such a sound mod would become THE central mod for the most basic core sounds. For exotic sounds, mod could still depend or supply their own.

Or even better, such a mod could be integrated into subgames directly. But Minetest Game would have to follow suit as well, and this is going to be very hard. The biggest problem in Minetest Game is the default mod. Sounds in Minetest Game should obviously be abtracted away as well. The sounds should be moved from default into that “standard sound mod” instead.

These are just my random thoughts.

Re: Sound API

PostPosted: Sat Mar 11, 2017 08:27
by burli
I look into a few mods and one of the most used dependencies are the sounds

MTG should add this or a similar mod and mark the sounds functions as deprecated