Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Mikael on June 06, 2008, 01:30:55 PM

Title: Problems with volume setting
Post by: Mikael on June 06, 2008, 01:30:55 PM
This is driving me crazy. I don't remember having any problems whatsover with this thing before, but now I simply can't get it to work. I'm probably just missing the obvious.

When I initialize the playing of a sound file, and immedeately want to set the volume to let's say 40, I put it down like this:

Game.SetMusicChannelVolume(1, 40);
Game.PlayMusicChannel(1, "sounds\soundfile.ogg", true);

What happens is that the sound file starts playing at 100 regardless of how I try to change the code. Changing it to 40 using the first line in whatever piece of code after the sound file has started to play always works for me though.

Whjat am I doing wrong?

Thanks in advance,

Mikael
Title: Re: Problems with volume setting
Post by: manarius on June 06, 2008, 01:55:58 PM
i dont use the soundchannel right now (our project is currently at milestone 1 of 6) :)
i think you can handle this by doing this:
Game.SetMusicVolume = 0;
Game.PlayMusic("filename");
Game.SetMusicVolume = 40;

so just setting the MusicVolume to 0 before you start playing the music.
dont know if there is a higher sophisticated way to do that.

hope i could be of help.
greetings
Title: Re: Problems with volume setting
Post by: metamorphium on June 06, 2008, 02:16:33 PM
Mikael, you must switch those lines. From my experience volume can be set after the channel plays.
Title: Re: Problems with volume setting
Post by: Mikael on June 06, 2008, 03:19:35 PM
Thanks the both of you. But unfortunately, none of the methods work. The sound starts playing at 100 no matter what. Metamorphium, it indeed seems like the volume can be set only after the channel plays (as opposed to the Game.PlaySound command, where I set the volume in the first line all constantly, with no problem), but it doesn't even seem to be possible to set it in the the same block of code. I even used the sleep command between my two lines of code just to see what happens, but the sound still keeps playing on 100.

In my game, you will approach a river, and the sound volume from the river must increase as you are getting closer. As it seems now, the only thing you can do with this command is to decrease the volume? (And then increase it after that).

Of course, I can make separate sound files in different volumes and switch between them, but I really hope that there is a more convenient solution.

Thanks,

Mikael
Title: Re: Problems with volume setting
Post by: Mnemonic on June 06, 2008, 03:22:54 PM
Is there any reason for not using PlaySound for this purpose?
Title: Re: Problems with volume setting
Post by: metamorphium on June 06, 2008, 03:43:42 PM
There's  something fishy with your code. I use this always and it works for me well. Can't it be there's some code which interferes with your Game.PlayMusicChannel?

As I really heavily rely on music channels, I never run into problems like this.
Title: Re: Problems with volume setting
Post by: Mikael on June 06, 2008, 06:25:13 PM
I donät think using PlaySound is possible, since I use that all over the scene for other sounds, like lifting and dropping things, etc. As I understand it PlaySound only relies on one channel.

Or is there some way I can use PlaySound over several channels? That would be terrific.

Meta, I don't understand where the fishiness could possible lie.

Thanks,

Mikael
Title: Re: Problems with volume setting
Post by: metamorphium on June 06, 2008, 07:32:54 PM
You can of course play as many sounds as you like. Simply create entity (or use some in the scene editor) and call
entity.PlaySound();

or make a global entity:

global sound = Game.CreateEntity();

and

sound.PlaySound() allows you to have the sound playing even while changing scenes.
Title: Re: Problems with volume setting
Post by: Mikael on June 07, 2008, 06:07:53 PM
So that's how it's done. Thanks.

Mikael
Title: Re: Problems with volume setting
Post by: metamorphium on June 08, 2008, 10:14:32 AM
I don't want to push it but ...

http://res.dead-code.org/doku.php/wmebook:ch10