Audio channels

Started by ddavey1983, Sat 13/03/2021 16:11:40

Previous topic - Next topic

ddavey1983

Hello

I'm experiencing an issue with my sound effects (Using AGS 3.5). I seem unable to play sounds simultaneously. If one sound effect is playing and another starts before it's finished it cuts the first one short. This didn't happen in my previous games and checking the code, I haven't coded anything any different this time.

I haven't (and didn't last time) use priorities for sounds. I just used a.sound.play() and it just...worked. Now it doesn't.

This is the code that works in my last game. The music plays and the camera click sound effect plays over the top:

Code: ags

function room_AfterFadeIn()
{
StartCutscene (eSkipAnyKey);
aAtmospheremusic.Play ();
Wait (30);
oa.Visible=true;
Wait (100);
ob.Visible=true;
aCamera.Play ();
ob.Visible=false;
Wait (100);
od.Visible=true;
aCamera.Play ();
oc.Visible=false;
Wait (900);
aAtmospheremusic.Stop ();
EndCutscene ();
player.ChangeRoom (6, -30, 215);


This is the code that doesn't work. The first camera click turns the music off:

Code: ags

StartCutscene (eSkipAnyKey);
aAtmospheremusic.Play();
Wait (30);
oa.Visible=true;
aCamera.Play();
Wait (100);
ob.Visible=true;
aCamera.Play ();
oa.Visible=false;
Wait (100);
oc.Visible=true;
aCamera.Play ();
ob.Visible=false;
Wait (900);
aAtmospheremusic.Stop ();
EndCutscene ();
player.ChangeRoom (6, -30, 215);



Anyone have any ideas? Is it a setting in General settings I'v forgotten I had to change in the first game?

Thanks

arj0n

#1
Although your title says Audio Channels, you're using AudioClips without AudioChannels.

So, in stead of using AudioClips I would create 2 AudioChannels so you can separate the music from the sfx and create fading in/out.

in global script:
Code: ags

AudioChannel *music;
AudioChannel *sfx;


then to play (and stop) music:
Code: ags

music = aAtmospheremusic.Play(eAudioPriorityNormal, eOnce);

  &
Code: ags

aAtmospheremusic.Stop ();


and play sfx:
Code: ags

sfx = aCamera.Play(eAudioPriorityNormal, eOnce);

Crimson Wizard

#2
ddavey1983 the first thing to check is that you have enough channels reserved (Max Channels) in corresponding Audio Types (look it up in the project tree). AGS can play as much clips simulatneously as channels reserved for that type.
Optionally you may remove any reservation, then it will use any channels left after reserving for other types.


arj0n, the code you posted does not change anything in practice, except you store the returned channel pointer in the variable, but you are not using it for anything either.
Also, Stop() function does not return anything so "music = aAtmospheremusic.Stop();" should not compile.

There's some serious misconception I meet on these forums not for the first time, that adding AudioChannel* variable into expression lets you control where sounds are playing, but it does not. This is both syntactically meaningless, and logically untrue.
Having AudioChannel* variable in your code does not create any channels, the audio channels in AGS are precreated and fixed in number (there are total 8 of them in current version).

ddavey1983

Thankyou both for replying.

Crimson Wizard It was the Max Channels variables that were the issue. In my previous game I had (as a total fluke) uploaded one clip into ambient sound and one into sound. Therefore they played fine simulaneously even with max channels set to 1 for each audio type. As I didn't have too many simultaneous sounds, the issue didn;t arise anywhere else.

This time, they were both in sound so it didn't work. I've adusted the max channels and now it works.

Thanks!

arj0n

Quote from: Crimson Wizard on Sat 13/03/2021 17:12:50

arj0n, the code you posted does not change anything in practice, except you store the returned channel pointer in the variable, but you are not using it for anything either.
Also, Stop() function does not return anything so "music = aAtmospheremusic.Stop();" should not compile.
You're correct, I accidentally removed the .Play part and added the channel name in the stop while posting.
I should have re-read it before posting. Fixed.

SMF spam blocked by CleanTalk