Getting sound to stop/start
by Richard O · in Torque Game Engine · 04/28/2005 (6:31 am) · 9 replies
Hi all,
im having a few problems with sound in our game. the initial idea was for players to follow sound until they reached the source, which would then trigger that sound off and another one to start up. my problem is, i cant get it to turn off. im using tutorial.base as my testing level and two audio emitters are placed in two different positions using the level editor and the following audio profiles
the following code is what appears in the .mis file when i save the mission
the sounds are named sound1 and sound2. i have a trigger set up between them, so that when the player enters the trigger it will turn sound1 off and turn sound2 on. the trigger code looks like this:
whenever i enter the trigger, the sound doesn't turn off and the other one doesn't start up. i can get the sound to turn off if i use alxStopAll();, but there'll be other sounds going on (music, atmos, etc) and i don't want them to be affected. some times i can get the sound to play by calling the datablock (Testing0 or Testing1) and specifing a pos, but this is a bit hard to control and won't switch off when i call alxStop();. one thing i can get to work is when i enter the trigger zone, i can get the audio emitter to move to the second position.
so, the aim of this rambling, is a plea for aid. am i calling the alxStop() and alxPlay() wrong? how can i get it to work as i need it to? or, failing that, how can i change the audio file playing in the emitter, so i can just have it move position and play a different song. i'd prefer the first version, as there's plans for smaller sub-objectives using audio that need to be turned off when finished.
so, if you can make sense of this, and you know how to help, i'd appreciate it.
thanks
im having a few problems with sound in our game. the initial idea was for players to follow sound until they reached the source, which would then trigger that sound off and another one to start up. my problem is, i cant get it to turn off. im using tutorial.base as my testing level and two audio emitters are placed in two different positions using the level editor and the following audio profiles
datablock AudioProfile(Testing0)
{
filename = "~/data/sound/testing.wav";
description = AudioDefaultLooping3d;
preload = true;
};
datablock AudioProfile(Testing1)
{
filename = "~/data/sound/footfall.wav";
description = AudioDefaultLooping3d;
preload = true;
};the following code is what appears in the .mis file when i save the mission
new AudioEmitter(sound1) {
position = "1.95515 -396.876 155.494";
rotation = "1 0 0 0";
scale = "1 1 1";
profile = "Testing0";
useProfileDescription = "1";
fileName = "0";
type = "2";
volume = "1";
outsideAmbient = "1";
referenceDistance = "1";
maxDistance = "5";
isLooping = "1";
loopCount = "-1";
minLoopGap = "0";
maxLoopGap = "0";
enableVisualFeedback = "1";
is3D = "1";
coneInsideAngle = "360";
coneOutsideAngle = "360";
coneOutsideVolume = "0.25";
coneVector = "0 1 0";
};
//the same thing for sound2, except the profile is "Testing1"the sounds are named sound1 and sound2. i have a trigger set up between them, so that when the player enters the trigger it will turn sound1 off and turn sound2 on. the trigger code looks like this:
$soundArray[0] = sound1;
$soundArray[1] = sound2;
$currPos = 0;
datablock TriggerData( SoundTrigger )
{
// tickPeriodMS is a value is used to control how often the console
// onTriggerTick callback is called while there are any objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
};
function SoundTrigger::onEnterTrigger( %this, %trigger, %obj )
{
echo( "entered the sound trigger");
//alxStopAll();
if($currPos != 1){
alxStop($soundArray[$currPos]);
$currPos += 1;
alxPlay($soundArray[$currPos]);
} else {
alxStop($soundArray[$currPos]);
$currPos = 0;
alxPlay($soundArray[$currPos]);
}
Parent::onEnterTrigger( %this, %trigger, %obj );
}whenever i enter the trigger, the sound doesn't turn off and the other one doesn't start up. i can get the sound to turn off if i use alxStopAll();, but there'll be other sounds going on (music, atmos, etc) and i don't want them to be affected. some times i can get the sound to play by calling the datablock (Testing0 or Testing1) and specifing a pos, but this is a bit hard to control and won't switch off when i call alxStop();. one thing i can get to work is when i enter the trigger zone, i can get the audio emitter to move to the second position.
so, the aim of this rambling, is a plea for aid. am i calling the alxStop() and alxPlay() wrong? how can i get it to work as i need it to? or, failing that, how can i change the audio file playing in the emitter, so i can just have it move position and play a different song. i'd prefer the first version, as there's plans for smaller sub-objectives using audio that need to be turned off when finished.
so, if you can make sense of this, and you know how to help, i'd appreciate it.
thanks
#2
i tried that but it didn't work. in the console it prints out "cannot find audio profile sound1". i can get a sound to play by changing the sound array to
thanks
04/29/2005 (11:08 am)
Hi billy,i tried that but it didn't work. in the console it prints out "cannot find audio profile sound1". i can get a sound to play by changing the sound array to
$soundArray[0] = Testing0;and using this code:
$soundfx = alxPlay($soundArray[$currPos], sound1.getPosition());the stopping code you gave me works fine with that. when i echo out $soundfx i get a number along the lines of -2147483423 or something to that effect. that code doesn't turn the sound1 emitter on, it just starts a new sound in that position that doesn't show up in the mission editor, which kinda makes the whole point of the emitter useless as i can just have placeholders where i want the sounds to show up, though this doesn't give me any control over the distance or angle of the sound. is there a way to start up a sound, then point it to a datablock to get its info from? its a complety roundabout solution and a bit messy tho.
thanks
#3
Another approach would be to change the volume on the emitters.
I havent tried it but its a clue.
Do you place the emitters on the map or do you want to spawn them ?
I try to understand how you want this to work :)
04/30/2005 (3:23 am)
Are you only using 1 trigger for this ?Another approach would be to change the volume on the emitters.
I havent tried it but its a clue.
Do you place the emitters on the map or do you want to spawn them ?
I try to understand how you want this to work :)
#4
04/30/2005 (6:45 am)
Im just using the one trigger at the minute for testing purposes. the idea is for sounds to be placed on the map that would lead the player to an item. the item and emitter would be surrounded by a trigger, so when the player picks up the item, that sound is turned off and the next emitter on the list is turned on to lead the player somewhere else for another item. the emitters need to be placed as i need to have control over the direction, maxdistance, and all that. does that help at all?
#5
04/30/2005 (7:21 am)
I would expect that you need to put the stop functionality into the 'onLeaveTrigger' event.
#6
04/30/2005 (7:53 am)
The problem is accessing the emitters that i place. if i typeecho(alxIsPlaying(sound1));into the console window, it returns 0, even tho im standing beside it and its playing. i thought this might be because it wasn't picking up sound1 as an object but if i type
echo(sound1.getPosition());i get its coords back, so it is being picked up somewhere. im confused :(
#7
I was wondering if you ever figured this problem out? I'm also having trouble triggering audio emitters on/off. Can you please update the thread if you made some progress on the issue.
Many thanks
09/23/2005 (7:42 am)
Hi Richard,I was wondering if you ever figured this problem out? I'm also having trouble triggering audio emitters on/off. Can you please update the thread if you made some progress on the issue.
Many thanks
#8
02/06/2006 (3:45 am)
Having the same problem of starting and stopping the audio emitters through alxplay(), which are defined through datablock and instanced in mission file. Was anyone able to solve this?
#9
11/15/2007 (7:16 am)
I'm having same problem, but am doing the starts and stops in c++? Anyone come up with a solution for this?
Torque 3D Owner Billy L
for playing
and this for stopping