Separate Volume Controls

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6682
Joined: Wed Feb 28, 2007 7:54 am

Re: Separate Volume Controls

Post by another_commander »

So, in the next nightly we should be able to control music volume, loop status, position etc in real time. Due to the way sound and music are set up internally, it is not entirely straightforward in the current implementation and it is possible that a better way to handle this exists, I just couldn't see it. Having said that, it's not difficult either, thankfully.

In order to enable this kind of control, I have exposed to Javascript the sound source object of the music currently playing. So, once we have access to that object, we can work with it like we do with any other sound source. The new function that does it is part of the Sound JS class and is called musicSoundSource. More specifically, if I want to adjust on the fly, say, the volume of the music currently playing, what I would do is something like this:

Code: Select all

myMusicSoundSource = Sound.musicSoundSource();
myMusicSoundSource.volume = 0.4;
If the music file is a 44KHz mono ogg, we can also do stuff like

Code: Select all

myMusicSoundSource.position = [-1,0,0]; // throw the currently playing music to the left channel
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Separate Volume Controls

Post by Svengali »

Muchas gracias, a_c! 8)
Post Reply