beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
199 stars 98 forks source link

Add some way to recognize valid sound files (incl. streamable) #1610

Open sprunk opened 1 month ago

sprunk commented 1 month ago

Add Engine.supportedSoundStreamFormats table. Would currently look like { mp3 = true, ogg = true }.

The use case is so that music widgets can automatically support new formats if they get added, right now it has to be done manually like https://github.com/ZeroK-RTS/Zero-K/commit/f0f205998c832e3198bcc6f3809aa022e8bd81af .

p2004a commented 1 month ago

Note: ogg is container, not a format. It can contain different formats inside, like vorbis or opus

sprunk commented 1 month ago

Hm, right. And the same format can have different extensions (jpg vs jpeg) or even any arbitrary extension including none at all (since that's just a convention). So I guess I would have to parse the file to be sure.

In that case perhaps some function to parse a potential sound file for metadata?

Spring.GetSoundFileMetadata(path) -> nil if not a recoil-recognized sound, or {
   .isStreamable    = bool, -- e.g. wav is accepted for single in-world sounds, but not streams
   .durationSeconds = number,
   .format          = "ogg vorbis", -- idk how useful if isStreamable etc exists but probably won't hurt? idk, optional
   .mono            = bool (or .channels = number), -- idk how useful in practice but probably won't hurt? idk, optional
   ... optionally other entries as applicable, possibly in the future
}