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)
Adding Ogg Vorbis controls to Lua?
Moderator: Moderators
- hughperkins
- AI Developer
- Posts: 836
- Joined: 17 Oct 2006, 04:14
Re: Adding Ogg Vorbis controls to Lua?

http://spring.clan-sy.com/wiki/Lua_UnsyncedCtrl
Re: Adding Ogg Vorbis controls to Lua?
but playsoundstream doesn't work from sd7?
Re: Adding Ogg Vorbis controls to Lua?
You have to unpack the soundfile first, via Spring.ExtractModArchiveFile()
Re: Adding Ogg Vorbis controls to Lua?
that's messy.
anyway, I'm making a public domain music player widget once I finish getting everything installed again
anyway, I'm making a public domain music player widget once I finish getting everything installed again
Re: Adding Ogg Vorbis controls to Lua?
Hey, this is great, exactly what many of us want. Please do it!
Re: Adding Ogg Vorbis controls to Lua?
What are the benefits of using .ogg standard over other formats for music?
Re: Adding Ogg Vorbis controls to Lua?
Spring only supports ogg and wav, and ogg is much smaller.MR.D wrote:What are the benefits of using .ogg standard over other formats for music?
- hughperkins
- AI Developer
- Posts: 836
- Joined: 17 Oct 2006, 04:14
Re: Adding Ogg Vorbis controls to Lua?
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.
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

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.
- hughperkins
- AI Developer
- Posts: 836
- Joined: 17 Oct 2006, 04:14
Re: Adding Ogg Vorbis controls to Lua?
Ok interestingArgh wrote:It's been done, working, and is implemented in P.U.R.E....
http://spring.clan-sy.com/wiki/Lua_UnsyncedCtrl

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?
Re: Adding Ogg Vorbis controls to Lua?
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...Do you have examples of using it?