Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: skuttleman on Fri 26/08/2011 03:59:51

Title: Bug in New Audio System
Post by: skuttleman on Fri 26/08/2011 03:59:51
Has anyone else experienced the following problem with the audio system:

The volume of one or more audio channels or one or more audio types has to be set to 0, but System.Volume is NOT set to 0. Then if you get to a skippable cutscene and SKIP it, the volume of any channel or audio type that is set to 0, will jump to the value of System.Volume.

Has anyone else run into this?
Title: Re: Bug in New Audio System
Post by: arj0n on Fri 26/08/2011 09:28:41
Same  (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=44218.0)thing described in this post?
Title: Re: Bug in New Audio System
Post by: skuttleman on Fri 26/08/2011 14:21:22
Nope. Not the same. The audio is completely unaffected unless, the volume of the channel in question is set to 0. If the volume of the channel is set to 1 or any other value from 1 to 100, it stays right where it should.
Title: Re: Bug in New Audio System
Post by: Haggis on Sun 03/06/2012 18:06:37
Not sure if a solution to this has been found yet but I too am experiencing this issue.

I have a music volume slider in my 'settings' GUI - if I adjust this to 0 then the music is essentially muted.
When I enter a cutscene the music volume remains muted throughout, however when the cutscene ends the music volume is suddenly set back to (I assume) the System volume. The Music volume slider will still be set to 0 and if I adjust the slider afterwards the music volume will resolve back to the slider setting. This only affects music audio types and only when the volume is set to 0 (muted).

At present I get round the issue by running the following immediately after an endCutscene event (sMusic being the music volume slider value) - which in effect sets the volume back to the slider value:
Code (AGS) Select
Game.SetAudioTypeVolume(eAudioTypeMusic, sMusic.Value*10, eVolExistingAndFuture);

I did have this in the global 'repeat all the time' but it meant that track cross fades stopped working as the fade effect was overruled.
Title: Re: Bug in New Audio System
Post by: Billbis on Thu 26/09/2013 09:58:46
I hope it's ok if I revive this old topic.
I experimented the same issue : If music / effects / ambient Volume is set to 0, at the end of a cutscene (whether or not you skip it), volume will be reset to some default original value.
I am not a C/C++ coder, but I had a look at the source code. In global_game.cpp (https://github.com/adventuregamestudio/ags/blob/fe442768372fa35af9265f4912a970232045762d/Engine/ac/global_game.cpp) line 484 and next ones :
Code (C++) Select
int EndCutscene () {
    if (play.in_cutscene == 0)
        quit("!EndCutscene: not in a cutscene");

    int retval = play.fast_forward;
    play.in_cutscene = 0;
    // Stop it fast-forwarding
    stop_fast_forwarding();

    // make sure that the screen redraws
    invalidate_screen();

    // Return whether the player skipped it
    return retval;
}

stop_fast_forwarding is call at the end of cutscenes. It is define in game.cpp (https://github.com/adventuregamestudio/ags/blob/709b63c3317b5f5b4ce50d20b8d5fe017988b795/Engine/ac/game.cpp) line 2612 and next ones :
Code (C++) Select
void stop_fast_forwarding() {
    // when the skipping of a cutscene comes to an end, update things
    play.fast_forward = 0;
    setpal();
    if (play.end_cutscene_music >= 0)
        newmusic(play.end_cutscene_music);

    // Restore actual volume of sounds
    for (int aa = 0; aa < MAX_SOUND_CHANNELS; aa++)
    {
        if ((channels[aa] != NULL) && (!channels[aa]->done) &&
            (channels[aa]->volAsPercentage == 0) &&
            (channels[aa]->originalVolAsPercentage > 0))
        {
            channels[aa]->volAsPercentage = channels[aa]->originalVolAsPercentage;
            channels[aa]->set_volume((channels[aa]->volAsPercentage * 255) / 100);
        }
    }

    update_music_volume();
}

I have the (possibly wrong) intuition that :
Code (C++) Select
(channels[aa]->originalVolAsPercentage > 0))
should be :
Code (C++) Select
(channels[aa]->originalVolAsPercentage >= 0))

Can someone more expert have a look at this?
Thank you.

EDIT: I forget to say that this bug is present in current stable release: AGS 3.2.1. I should have test the latest beta maybe it is already fixed? :sealed:
Title: Re: Bug in New Audio System
Post by: Crimson Wizard on Thu 26/09/2013 18:47:14
I confirm, still present in 3.3.0 beta.
Thanks for bumping this, Billbis, I wasn't aware of this.


EDIT:
What I experience, and what I see from the code too, is that if any clip's volume will be by any means exactly 0 at the time of  EndCutscene() call, then its volume will be reset to what it was when the clip started playing.
If it started playing with volume 0, it will stay so. If it started with volume 50, it will return to 50.

To clarify:
Code (ags) Select

Game.SetAudioTypeVolume(eAudioTypeMusic, 0, eVolExistingAndFuture);
AudioChannel *c = aMusic1.Play();
Display("%d", c.Volume); // will display '0'
StartCutscene(eSkipESCOnly);
Display("%d", c.Volume); // will display '0'
EndCutscene();
Display("%d", c.Volume); // will display '0'

All is correct.

But
Code (ags) Select

AudioChannel *c = aMusic1.Play();
Display("%d", c.Volume); // will display '100'
Game.SetAudioTypeVolume(eAudioTypeMusic, 0, eVolExistingAndFuture);
Display("%d", c.Volume); // will display '0'
StartCutscene(eSkipESCOnly);
Display("%d", c.Volume); // will display '0'
EndCutscene();
Display("%d", c.Volume); // will display '100' !!

Error!



Also
Code (ags) Select

AudioChannel *c = aMusic1.Play();
Display("%d", c.Volume); // will display '100'
StartCutscene(eSkipESCOnly);
c.Volume = 0;
Display("%d", c.Volume); // will display '0'
c.Volume = 50;
Display("%d", c.Volume); // will display '50'
EndCutscene();
Display("%d", c.Volume); // will display '50'

All is correct.

But
Code (ags) Select

AudioChannel *c = aMusic1.Play();
Display("%d", c.Volume); // will display '100'
StartCutscene(eSkipESCOnly);
c.Volume = 50;
Display("%d", c.Volume); // will display '50'
c.Volume = 0;
Display("%d", c.Volume); // will display '0'
EndCutscene();
Display("%d", c.Volume); // will display '100' !!

Error!
Title: Re: Bug in New Audio System
Post by: Crimson Wizard on Thu 26/09/2013 21:18:50
Ok, I think I fixed this one.


But, - while we are at it, - the cutscenes might produce more audio related issues.

For example, if you start a clip inside a cutscene, and player is skipping cutscene, then the clip starts silent, but saves the "correct" volume to be restored after cutscene.
Thing is that if you use AudioChannel.Volume property, the return value will be different, depending on whether cutscene is being skipped or not.
Now, imagine you want to set volume to the multiple of default:

Code (ags) Select

AudioChannel *c = aMusic1.Play();
c.Volume = c.Volume / 2;


If cutscene is playing normally, you get a music playing at half volume. But if cutscene is being skipped, you get c.Volume = 0 / 2 = 0, and the music is not played even when cutscene is over...

Question is, should this be considered a bug, or a cutscene specific behavior, that game developer must take into consideration?
Title: Re: Bug in New Audio System
Post by: Billbis on Thu 26/09/2013 21:59:26
Quote from: Crimson WizardOk, I think I fixed this one.
Many thanks ! ;-D
Quote from: Crimson WizardQuestion is, should this be considered a bug, or a cutscene specific behavior, that game developer must take into consideration?
I have no idea... ???
Title: Re: Bug in New Audio System
Post by: Crimson Wizard on Thu 26/09/2013 22:51:49
Ok, I guess since I am fixing how "saved volume" works during cutscene, I think I can return saved volume on getting Volume property instead. This should solve this issue for good.
Title: Re: Bug in New Audio System
Post by: selmiak on Sat 28/09/2013 18:13:43
will this be fixed in ags3.3? I ran into the same problem and would appreciate this fix :)
Title: Re: Bug in New Audio System
Post by: Crimson Wizard on Sat 28/09/2013 18:56:35
Quote from: selmiak on Sat 28/09/2013 18:13:43
will this be fixed in ags3.3? I ran into the same problem and would appreciate this fix :)
Yes (already fixed in repository).
Title: Re: Bug in New Audio System
Post by: selmiak on Sat 28/09/2013 19:18:15
nice :D
Now I'll wait for a stable release.