Adjust Background music volume
by Hugo Munoz · in iTorque 2D · 07/01/2010 (1:15 pm) · 7 replies
Hey guys, Im trying to dynamically adjust the background music volume of my game.
To play BGM I'm using the following code:
function playBackgroundMusic()
{
$musicStreamFile = "~/data/audio/background/" @ $CurrentLevel @ ".mp3";
echo ($musicStreamFile);
%loop = true;
startiPhoneAudioStream($musicStreamFile,%loop);
}
But turns that I need to adjust the volume of the music when one of the characters is speaking, so is there any way to control the volume of an iPhoneAudioStream via script ?
Thanks
Hugo.
To play BGM I'm using the following code:
function playBackgroundMusic()
{
$musicStreamFile = "~/data/audio/background/" @ $CurrentLevel @ ".mp3";
echo ($musicStreamFile);
%loop = true;
startiPhoneAudioStream($musicStreamFile,%loop);
}
But turns that I need to adjust the volume of the music when one of the characters is speaking, so is there any way to control the volume of an iPhoneAudioStream via script ?
Thanks
Hugo.
About the author
#2
05/26/2011 (4:40 pm)
This is the function I believe I need to expose to script: SoundEngine_SetBackgroundMusicVolume. Hoping I am headed down the right trail. :)
#3
05/26/2011 (5:45 pm)
I think in order to change the volume in script, you need to call alxSetChannelVolume( %channel_ID , %volume ).
#4
05/26/2011 (5:47 pm)
Oh, I didn't thoroughly read the post -- I don't know how to change the volume on streams, if it's different.
#5
$pref::Audio::sfxVolume = 0.8;
$pref::Audio::musicVolume = 0.8;
05/26/2011 (5:52 pm)
Looking through the code, it doesn't look like these are used at all:$pref::Audio::sfxVolume = 0.8;
$pref::Audio::musicVolume = 0.8;
#6
Don't want to post it as the solution yet though since I haven't implemented the rest of our audio and am concerned this change may effect other audio. Will post once I test and get my head around this.
Kind of surprised this hasn't come up before... am I missing something or how do most iTorque devs tackle change the volume for their background music?
05/26/2011 (7:47 pm)
The 'SoundEngine_SetBackgroundMusicVolume' function is working for me so far. Made a console function to access it.Don't want to post it as the solution yet though since I haven't implemented the rest of our audio and am concerned this change may effect other audio. Will post once I test and get my head around this.
Kind of surprised this hasn't come up before... am I missing something or how do most iTorque devs tackle change the volume for their background music?
#7
If you can post your 'SoundEngine_SetBackgroundMusicVolume' console function, even if it isn't perfect I'm sure that many people would be extremely grateful.
10/23/2011 (8:55 am)
Hi Mark,If you can post your 'SoundEngine_SetBackgroundMusicVolume' console function, even if it isn't perfect I'm sure that many people would be extremely grateful.
Torque Owner Mark Grossnickle
I also tried adjusting defaultPrefs:
I also tried to change the master volume in defaultPrefs. None of these constants seemed to affect 'startiPhoneAudioStream' volume.
Going to be digging into this some more, but hoping someone can guide me a bit. Cheers!