Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Gurok on Wed 05/11/2014 12:35:19

Title: [SOLVED] Stopping an existing sound channel prevents another from playing
Post by: Gurok on Wed 05/11/2014 12:35:19
I have something like this in a room in my current project:


if(aChannelPhoneRing != null && aChannelPhoneRing.IsPlaying)
{
aChannelPhoneRing.Stop(); // Stop the phone ring sound from playing
oPhone.StopAnimating();
oPhone.Graphic = 831;
}
cShelly.Say("Hello?");
cAubrey.Say("Hello.");
Quest.Mark(qBaggage, 1);


And in another module, I have this code for Quest.Mark:


function Mark(static Quest, QuestType quest, int value)
{
if(!Quest.HasPoint(quest, value))
{
Quest.SetPoint(quest, value);
Title.Announce(quest);
aPlotPoint.Play(); // Play the awarded one point sound
}

return;
}


For some reason, calling .Stop on the sound aChannelPhoneRing seems to prevent aPlotPoint from being played.

If I put the code to stop aChannelPhoneRing after the call to my Quest.Mark function, everything works as expected.
If I put Quest.Mark in the same room, it also works as expected.
I think perhaps AGS is reserving the same audio channel for aPlotPoint as aChannelPhoneRing, and perhaps the .Stop command is queued to happen at the end of the script. I don't know enough about AGS' sound system to say.

Does anybody have any ideas? A nice workaround?
Title: Re: Stopping an existing sound channel prevents another from playing
Post by: monkey0506 on Thu 06/11/2014 09:05:37
I'm not sure, but I do know that all the instances of AudioChannel are actually static, even if nothing is playing. It could be reusing the same channel and then since it's technically the same object your other code is stopping the wrong AudioClip.

Couple of things to try:

* Set the aChannelPhoneRing AudioChannel* to null when you're done using it (e.g., after calling Stop).
* Check that the PlayingClip is the one you're expecting.

You could also try changing the audio types and priorities, but that's probably overkill for what you need.
Title: Re: Stopping an existing sound channel prevents another from playing
Post by: Gurok on Thu 06/11/2014 10:15:30
Thanks, Monkey!

I tried setting my AudioChannel *aChannelPhoneRing to null, but it did nothing.

Your other suggestion was very helpful. I haven't solved the problem, but this message does get logged:

if(aChannelPhoneRing != null && aChannelPhoneRing.IsPlaying)
{
aChannelPhoneRing.Stop();
oPhone.StopAnimating();
oPhone.Graphic = 831;
}
cShelly.Say("Hello?");
cAubrey.Say("Hello.");
Quest.Mark(qBaggage, 1);
if(aChannelPhoneRing.PlayingClip == aPlotPoint)
Log("Oh oh!");
Title: Re: Stopping an existing sound channel prevents another from playing
Post by: monkey0506 on Thu 06/11/2014 13:52:39
Where is this code at in the room script? I was thinking maybe this was in rep_ex, but now that I'm looking again I realize that probably wouldn't make sense. But to clarify, the AudioChannel.PlayingClip is being updated for the channel your pointer is pointing to, yet you don't hear any sound if the channel is stopped before playing that sound?

Strange. I'd investigate the other properties, particularly Volume, IsPlaying, and PositionMs. :-\
Title: Re: Stopping an existing sound channel prevents another from playing
Post by: Crimson Wizard on Thu 06/11/2014 18:37:14
I tried to reproduce this, but it worked well for me.

Test script:
Spoiler

room1.asc:
Code (ags) Select

AudioChannel *aChannelPhoneRing;
function room_AfterFadeIn()
{
    aChannelPhoneRing = aPhoneRing.Play(eAudioPriorityNormal, eRepeat);
}

function hHotspot1_AnyClick()
{
    if(aChannelPhoneRing != null && aChannelPhoneRing.IsPlaying)
    {
        aChannelPhoneRing.Stop(); // Stop the phone ring sound from playing
    }
    player.Say("Hello?");
    player.Say("Hello.");
    Quest.Mark(qBaggage, 1);
}


OtherScript.asc:
Code (ags) Select

void Mark(static Quest, QuestType quest, int value)
{
    aPlotPoint.Play();
}

[close]

Do I do something wrong?


By the way, do you have voice speech playing in your game?
Title: Re: Stopping an existing sound channel prevents another from playing
Post by: Gurok on Thu 06/11/2014 21:53:02
Oh, this was my bug. Not AGS' fault.

I found the error. It was in my room_RepExec. See the commented out line:
function room_RepExec()
{
bool playing;

if(!gTransition.Visible)
{
if(Game.DoOnceOnly(String.Property("rDormRoomtVacant.RepExec1")))
PlayIntroduction1(Character.GetFavourite());
else
if(!Camera.IsPanning() && Game.DoOnceOnly(String.Property("rDormRoomVacant.RepExec2")))
PlayIntroduction2(Character.GetFavourite());
if(aChannelPhoneRing)
playing = aChannelPhoneRing.IsPlaying;
else
playing = false;
if(Flag.Get(fDormPhoneRinging) && !Quest.HasPoint(qBaggage, 1))
{
phoneRing++;
if(phoneRing == 1)
aChannelPhoneRing = aPhoneRing.PlayAtObject(oPhone, eOnce);
if(phoneRing == 200)
phoneRing = 0;
if(oPhone.Animating != playing)
{
if(playing)
{
oPhone.SetView(PHONERINGING);
oPhone.Animate(0, 0, eRepeat, eNoBlock);
}
else
{
oPhone.StopAnimating();
oPhone.Graphic = 831;
}
}
}
else
if(playing)
{
//aChannelPhoneRing.Stop();
oPhone.StopAnimating();
oPhone.Graphic = 831;
}
}

return;
}


Of course, that whole final section is unnecessary if I'm stopping the sound/animation elsewhere. What a trap these shared audio channel pointers are! :P

Oh, and monkey_05_06, my code was just in a simple interaction:
function oPhone_Interact()
{
if(Flag.Get(fDormPhoneRinging) && !Quest.HasPoint(qBaggage, 1))
{
if(Try.Reached())
{
if(aChannelPhoneRing != null && aChannelPhoneRing.IsPlaying)
{
aChannelPhoneRing.Stop();
oPhone.StopAnimating();
oPhone.Graphic = 831;
}
cShelly.Say("Hello?");
cAubrey.Say("Hello.");
Quest.Mark(qBaggage, 1);
}
else
Try.ReachObject(oPhone, eModeInteract, eDirectionUpLeft);
}

return;
}


Hope this clears everything up. Sorry to bother people :(

Thanks, CW. Your attempt at reproducing it helped to show it couldn't possibly be an AGS issue.