Adding Ogg Vorbis controls to Lua?

Adding Ogg Vorbis controls to Lua?

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Adding Ogg Vorbis controls to Lua?

Post by hughperkins »

Yes, this is an MTR topic. I'm thinking of actually implementing it though. One of the things I really miss about TA, the original version, is the awesome context-sensitive music. Kindof thinking it could be cool to add this to Spring?

The most generic way to do this could be to expose a couple of simple methods to Lua that allows one to play .ogg Ogg Vorbis files from within the current mod. We could have a new "music" subdirectory within the .sd7 files.

Whilst the development sounds pretty simple, I'd quite like to bounce the idea around first, just to check:

* any issues with adding an additional library to Spring? (I think we're already using OpenAL? So we'd just need to add the Ogg Vorbis SDK dlls, ie ogg.dll, vorbis.dll, vorbisfile.dll and vorbisenc.dll)
* is Lua the appropriate place to control the music? Does Lua have access to information such as "Is there a battle going on right now?"
* would people use it? (I guess I should put this particular question more in the "Lua Scripts" part of the forums?)

Given my track record of writing something in a few hours / couple of days, and then no-one ever uses it :-D , I think it's probably worth bouncing the idea around for a few weeks / months, and then spending the 3 or 4 hours to actually implement it.

Implementation details, provisional:
* music is entirely separate from Spring, except to the extent that Lua scripts can control it
* we use Ogg Vorbis files, because they don't need license fees, it's an open standard, it's cross-platform
* the .ogg files are stored in standard mod files, in a subdirectory "music"
* we expose the following methods to Lua:
- playMusic( musicFileName )
- stopMusic()
- getCurrentMusicFileName() (returns null if nothing being played, or it just finished playing)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Adding Ogg Vorbis controls to Lua?

Post by Argh »

:roll: It's been done, working, and is implemented in P.U.R.E....

http://spring.clan-sy.com/wiki/Lua_UnsyncedCtrl
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Adding Ogg Vorbis controls to Lua?

Post by aegis »

but playsoundstream doesn't work from sd7?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Adding Ogg Vorbis controls to Lua?

Post by Argh »

You have to unpack the soundfile first, via Spring.ExtractModArchiveFile()
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Adding Ogg Vorbis controls to Lua?

Post by aegis »

that's messy.
anyway, I'm making a public domain music player widget once I finish getting everything installed again
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Re: Adding Ogg Vorbis controls to Lua?

Post by REVENGE »

Hey, this is great, exactly what many of us want. Please do it!
User avatar
MR.D
Posts: 1527
Joined: 06 Aug 2005, 13:15

Re: Adding Ogg Vorbis controls to Lua?

Post by MR.D »

What are the benefits of using .ogg standard over other formats for music?
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

Re: Adding Ogg Vorbis controls to Lua?

Post by Hoi »

MR.D wrote:What are the benefits of using .ogg standard over other formats for music?
Spring only supports ogg and wav, and ogg is much smaller.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Re: Adding Ogg Vorbis controls to Lua?

Post by hughperkins »

mp3 has some sort of patent/license burden
ogg is technically similar in performance to mp3, but without the patent/license burden.

I'm not going to argue over whether mp3 or ogg are technically better. I'm sure there are arguments for both, but broadly they're in the same ball-park.

Oh, there's also things like various wmv type formats, which are Microsoft-specific. I think they give good performance, but who wants to include Microsoft stuff in Opensource software :-) not to mention we probably wouldnt even be allowed to, without paying lots of license fees and stuff.

Edit: note that would could be nice would be to make the formats/codecs/etc pluggable, but that increases the amount of work involved quite a lot. Easier, at least in the short-term, to pick one format, and get modders to convert their music files into that format.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Re: Adding Ogg Vorbis controls to Lua?

Post by hughperkins »

Argh wrote::roll: It's been done, working, and is implemented in P.U.R.E....

http://spring.clan-sy.com/wiki/Lua_UnsyncedCtrl
Ok interesting :-)

So, that implies that we're already linking to the appropriate ogg vorbis dlls? It also implies agreement that Lua is the place to put the music control logic?

Do you have examples of using it? What would it take to make a lua script that detects whether there is a battle going on, and chooses music appropriately?

I'm not quite sure exactly how the TA music works. I guess the options are:
- any of one's own units are attacking
- any of one's own units are taking damage
- either of these

I guess if I can make a mod that depends on one of the existing TA mods, and just adds context-sensitive music, then I can provide that to the mod creator, and perhaps they'll integrate it into their mod?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Adding Ogg Vorbis controls to Lua?

Post by Argh »

Do you have examples of using it?
Yes. Go get P.U.R.E., look for Theme.lua in the Widgets folder. It's totally easy, caveman code. I have a randomizer for the playlist, and that's all- improving it would be ridiculously easy for anybody with basic Lua skills...
Post Reply

Return to “Engine”