Should I start Music in Room_load of Room_Afterfadein?

Started by bx83, Tue 15/05/2018 13:18:19

Previous topic - Next topic

bx83

Should I start music in Load or Afterfadein?
Is there a manual page with a list of things that are better off in each function?

It comes from the yet-again dreaded 'how do I transition between two music tracks of the same lengths' question.

BEACH is the beach, the first room, enters after the player starts the game.
CAVE is a cave to the left of the BEACH.

Both music tracks aBeachTheme and aBeachTheme_cave are the same length; they're the same *song* - aBeachTheme_cave have a low volume and 'muted' sound (beccause it's, you know, in a cave).
Both tracks are .OGG format
The Types->Music has a MaxChannels of 1 (so it will always smoothly transition as a new room is entered, and that areas music is played).

BEACH:
Code: ags

function room_FirstLoad()
{
    SetGameOption(OPT_CROSSFADEMUSIC, 1);
    music_chan=aBeachTheme.Play(eAudioPriorityNormal, eRepeat);
    sounds_chan=aOcean_crash.Play(eAudioPriorityNormal, eRepeat);
}

function room_AfterFadeIn()
{
	if (cJulius.PreviousRoom == CAVE) {		//cave
		aWater_dripping.Stop();
		cJulius.Walk(265, 500, eNoBlock, eWalkableAreas);
	}
	

	if (cJulius.PreviousRoom==CAVE || cJulius.PreviousRoom==FARM) {
		beachThemePos=music_chan.Position;
		music_chan=aBeachTheme.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
	}
}


CAVE:
Code: ags

function room_Load()
{
	if (cJulius.PreviousRoom == 2) {
		beachThemePos=music_chan.Position;
		music_chan=aBeachTheme_cave.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
	} 
}


HOWEVER - the CAVE and BEACH background music intermiddently stops, upon entering the room. It doesn't crossfade to nothing; just stops. This can happen the 6th or 7th time I enter, or the 2nd. Random.
What's odd is, when the music *is* working again, it will transition back to it at a different position to where I left off. So, it almost as if the beachThemePos is updating with each successive entry; but when it tried to play the music, a random bug hits, and the playing doesn't go.

Bonus question: which runs first, the Room_Load function, or the Room_FirstLoad function?

Crimson Wizard

#1
Sorry, I do not have time to answer the main question right now, but I can comment on this -

Quote from: bx83 on Tue 15/05/2018 13:18:19
Bonus question: which runs first, the Room_Load function, or the Room_FirstLoad function?

"First time enters room" event creates "Room_FirstLoad" function name by default, but that's a misleading name (and to think of it, should be fixed), because in reality it is "Room first time After Fade-in".
The order of their running is following:

* "Enters room before fade-in" (Room_Load)
* room transition effect
* "First time enters room" (Room_FirstLoad) <--- only if the room is entered for the first time
* "Enters room after fade-in" (Room_AfterFadeIn)

Manual page: http://www.adventuregamestudio.co.uk/manual/ags83.htm#topic78

morganw

I think you are referencing a different channel sometimes, because you are storing the channel pointer in room_FirstLoad(), and then using it a later when the music may be on another channel. Setting max channels to 1 doesn't guarantee you are using the same channel again and again, just that (any) one channel will be available to use.

Crimson Wizard

#3
Quote from: morganw on Tue 15/05/2018 14:01:04Setting max channels to 1 doesn't guarantee you are using the same channel again and again, just that (any) one channel will be available to use.

I think it does, Snarky did testing before which showed that. It appeared that "max channels" property is also acting as "reserved channels".

Also I've been checking the engine code now, and when AGS looks for a free channel for clip of type X, it always skips channels reserved for the particular types, so that might be true.

morganw

I don't think you can stay on the same channel if cross-fading, since you are playing two streams at once.

Crimson Wizard

#5
Quote from: morganw on Tue 15/05/2018 14:09:37
I don't think you can stay on the same channel if cross-fading, since you are playing two streams at once.

There is a special channel for crossfading, it is separate from other channels. Iirc when crossfading starts, the second track is placed on a special channel, and when crossfade ends, it is moved to the normal channel previously occupied by the first track.
Probably this is also why only one crossfading may happen at once using built-in AGS functions.

PS. BTW, what is interesting, from the looks of the code I linked above, OPT_CROSSFADEMUSIC will work properly only if the music clip has built-in type "Music", and its channel is strictly id = 2.

morganw

I think to keep the the script pointer pointing at what you asked to be played (so you can set its volume etc), it would have to move what is playing to the crossfade channel, and then starting playing what is faded in on the (hopefully) original channel. So perhaps this channel is always id 2?

Crimson Wizard

#7
Quote from: morganw on Tue 15/05/2018 14:48:35
I think to keep the the script pointer pointing at what you asked to be played (as so you can set its volume etc), it would have to move what is playing to the crossfade channel, and then starting playing what is faded in on the (hopefully) original channel. So perhaps this channel is always id 2?

EDIT: Alright, all the following is not relevant to AudioChannels and AudioClips, I was looking into the old audio system instead.


From the code it looks like it does opposite: it keeps old music in its channel, and puts new music on crossfade channel.
https://github.com/adventuregamestudio/ags/blob/master/Engine/media/audio/audio.cpp#L1004
Then, when the old music is done fading out, it moves the new playing clip from crossfade channel to music channel.
https://github.com/adventuregamestudio/ags/blob/master/Engine/media/audio/audio.cpp#L939



But then, if it is so, this means that you cannot rely on AudioChannel returned in script at all when you have OPT_CROSSFADEMUSIC option set, because it may be either music channel (if no music is playing currently), or Crossfade channel (if some music was playing and crossfade started).

By "cannot rely" I mean that you cannot store it as "music_chan" and use it in the future. You may still use it to set volume etc though, but only immediately. Because if that was crossfade channel, then the clip will be soon removed from it.

morganw

bx83, could you try defining a global audio channel and use that across both rooms? That should rule out pointing to the wrong channel as the problem.

Crimson Wizard

#9
Quote from: Crimson Wizard on Tue 15/05/2018 15:02:42
Quote from: morganw on Tue 15/05/2018 14:48:35
I think to keep the the script pointer pointing at what you asked to be played (as so you can set its volume etc), it would have to move what is playing to the crossfade channel, and then starting playing what is faded in on the (hopefully) original channel. So perhaps this channel is always id 2?

From the code it looks like it does opposite: it keeps old music in its channel, and puts new music on crossfade channel.


No, I was wrong. Did not understand the code properly perhaps, or maybe there is more than the code I saw.
It actually does what you said: always returns channel 2 from AudioClip.Play, and that channel has requested music in PlayingClip.

EDIT: Oh, the code I found previously was related to old audio system. The new audio system is doing this instead:
https://github.com/adventuregamestudio/ags/blob/master/Engine/media/audio/audio.cpp#L91

My test script:
Spoiler

Code: ags

AudioChannel *mus_chan;
bool a;

function room_AfterFadeIn()
{
	SetGameOption(OPT_CROSSFADEMUSIC, 1);
}

function on_key_press(eKeyCode key)
{
	if (key == eKeySpace)
	{
		if (a)
			mus_chan = aMusic1.Play();
		else
			mus_chan = aMusic2.Play();
		
		int order;
		if (a)
			order = 1;
		else
			order = 2;
			
		int playid;
		if (mus_chan.PlayingClip == aMusic1)
			playid = 1;
		else
			playid = 2;
			
		player.SayBackground(String.Format("Ordered music = %d[mus_chan.ID = %d[music on chan = %d",
			order, 
			mus_chan.ID, 
			playid
			));
		a = !a;
	}
}

[close]

This is very good, otherwise it would be impossible to work with.

bx83

Quote from: morganw on Tue 15/05/2018 17:14:48
bx83, could you try defining a global audio channel and use that across both rooms? That should rule out pointing to the wrong channel as the problem.

It already is:



bx83

I've now altered my code to just get rid off FirstLoad for simplicities sake.
I think I've discovered the error, but I don't know how to fix it.

When I run this code, all runs fine, no intermitent stops -- though, there are intermittent volume changes for music and sound. I haven't touched .Volume for any of these variables.
Sometimes, CAVE resets the music/sound volume for BEACH; but I can't see why CAVE is more 'stable'.

The default volume for both music and sounds was set to 100% inherited for both; just to make sure, I then changed it to 100% for both non-inherited. No difference.
They have 95 (music) and 99 (sounds) ReductionWhileSpeechPlaying

My code:

BEACH:
Code: ags

function room_Load()
{
	if (GameStarted) {
		beachThemePos=music_chan.Position;
		oceanThemePos=sounds_chan.Position;
		music_chan=aBeachTheme.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
		sounds_chan=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityNormal, eRepeat);
	} else {
            SetGameOption(OPT_CROSSFADEMUSIC, 1);
	    if (FutureTime) {
		music_chan.Stop();
	    } else {
	        music_chan=aBeachTheme.Play(eAudioPriorityNormal, eRepeat);
	        beachThemePos=music_chan.Position;
	    }
		
            sounds_chan=aOcean_crash.Play(eAudioPriorityNormal, eRepeat);
	    oceanThemePos=sounds_chan.Position;
		
	    cJulius.x=436;
	    cJulius.y=537;
	    GameStarted=true;
	}
}

function room_FirstLoad()
{
}

function room_AfterFadeIn()
{
	if (cJulius.PreviousRoom == CAVE) {		//cave
		aWater_dripping.Stop();
		cJulius.Walk(265, 500, eNoBlock, eWalkableAreas);
	}
}


CAVE:
Code: ags

function room_Load()
{	
	if (FutureTime) {
	    music_chan.Stop();
	} else {
	    beachThemePos=music_chan.Position;
	    music_chan=aBeachTheme_cave.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
	}
	
	sounds_chan=aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
}

function room_AfterFadeIn()
{
}


I ran a test to see which audiochannel ID and Volume were being used, by placing this immmediately in AfterFadein after each time music_chan or sounds_chan was invoked:
Display("music channel ID %d, sounds channel ID %d, volumes are %d and %d respectively",music_chan.ID, sounds_chan.ID,  music_chan.Volume, sounds_chan.Volume);

Sounds volume I decided to ignore, as there's a MaxChannel of 5 for sounds, so each test of sounds_chan.Volume got a different clip each time (I think? Anyway the channel bobbed around from 1 to 5 each room tresnition).

They were reporting channel ID 1 for music every time; and a volume of 6, for music.
This is a very low %, an didn't change; but the actual sound colming out of the speaker ranged from ~5 to 100 each transition.

Nothing was done to volume by me.
I changed the music_chan.Volume to 100 each room transition; this seemed to fix it.

Pointer variable corrupt/changing position in memory and reading garbage? Why only this room, though?
Or have I missed something? (feels like something huge.... :/)

This is a mess, but I don't know how or why. Once again, I'm happy to pay like US$1,000 to anyone who can debug the sound/music system. The above code is simplified, and leave out a lot of walking, animation commands, and etc. that's too complex to include here.

I mean, I don't want to beg, but this one simple 'OceanThemePos' has really screwed things up for me. I've tried like 50 different versions of the code, then always, *something* goes wrong at random times.
If you want me to include all code, unaltered, *and* a video, I will; or send you the code for the game as PM (CrimsonWizard and Snarky - or anyone else I could trust).

Truly, I'm at my wits end.

bx83

Is there a way to reference channels in the style of Audiochannel* channel[1] or channel[5] or what have you?

I don't think I understand (stil!) the AudioChannel system.
For example, if your Type:Music has MaxChannels of 1, and Crossfade is set to MediumFade, can I just type:

aAfternoonSounds.Play(eAudioPriorityNormal, eRepeat);

or must it be:

music_chan=aAfternoonSounds.Play(eAudioPriorityNormal, eRepeat);

???

And if I want to find an AudioClip that's being player, ie.

if (sounds_chan.PlayingClip!=aOcean_crash_cave) {
    sounds_chan = aOcean_crash_cave.Play;
}

I should do the above to stop it playing twice, or three times, or 15 times etc?

There's no other way to check if an actual audioclip, referenced by it's name, is playing or not -- is this because you need the audiochannel pointer to find a specific audioclip; or it just grab's the clip's name from a list of playing tracks, and then returns a pointer to you?

I'm really very confused about thier functioning :/
For example, in the code above, would things work the same or better if I just made it:
aAfternoonSounds.Play(eAudioPriorityNormal, eRepeat);
rather than:
music_chan=aAfternoonSounds.Play(eAudioPriorityNormal, eRepeat);

???

Snarky

The obvious suspicion is that it has to do with the VolumeReductionWhileSpeechPlaying. Try changing that to 0 to see if the problem goes away. I do remember I had to fix something about this bit of code in the cut-down project builds you sent me for the SpeechBubble development, but I don't remember exactly what I did, and it might have to do with some resources you removed (I don't think it even compiled when I got it).

Snarky

Quote from: bx83 on Wed 16/05/2018 07:01:31
Is there a way to reference channels in the style of Audiochannel* channel[1] or channel[5] or what have you?

Yes. System.AudioChannels[i]

QuoteI don't think I understand (stil!) the AudioChannel system.

The way I like to think of it, the AudioChannels are like 8 record players. Each can play one record (AudioClip) at a time. You can ask to have some number of the record players (AudioChannels) assigned to a particular type of record (AudioType), and in that case, it reserves that many of them permanently (meaning those particular record players are only used for that type of record, and records of that type are always played on one of those particular players). When you play a record, it tells you which player it picked to play it, in case you want to adjust the volume, stop it, or whatnot.

QuoteFor example, if your Type:Music has MaxChannels of 1, and Crossfade is set to MediumFade, can I just type:

aAfternoonSounds.Play(eAudioPriorityNormal, eRepeat);

or must it be:

music_chan=aAfternoonSounds.Play(eAudioPriorityNormal, eRepeat);

???

You don't ever HAVE to store the audio channel pointer, and apart from that the two commands do exactly the same thing. It's only worth doing in case you want to either (1) check whether the clip actually started playing (if it fails for some reason, the channel it returns will be null), or (2) do something with the channel while the clip is playing (like adjust the volume).

If you're playing a music clip and you only have one music channel, the AudioChannel pointer should always be the same (contrary to what morganw says), so if you set it once you don't really ever need to do it again. (Though there are some edge-cases that I think could potentially cause problems, like restoring a save game with different audio settings in winsetup.)

QuoteAnd if I want to find an AudioClip that's being player, ie.

if (sounds_chan.PlayingClip!=aOcean_crash_cave) {
    sounds_chan = aOcean_crash_cave.Play;
}

I should do the above to stop it playing twice, or three times, or 15 times etc?

Huh? Have you got sounds set to only 1 channel? Otherwise the code above doesn't make much sense. Why would the clip play more than once in the first place?

QuoteThere's no other way to check if an actual audioclip, referenced by it's name, is playing or not -- is this because you need the audiochannel pointer to find a specific audioclip; or it just grab's the clip's name from a list of playing tracks, and then returns a pointer to you?

I'm really very confused about thier functioning :/

There's no built-in function to do it, but it's easy enough to loop through and check each AudioChannel.

QuoteFor example, in the code above, would things work the same or better if I just made it:
aAfternoonSounds.Play(eAudioPriorityNormal, eRepeat);
rather than:
music_chan=aAfternoonSounds.Play(eAudioPriorityNormal, eRepeat);

Work better in what way? It all depends on what you want to do and the rest of the code around it.

bx83

Quote from: Snarky on Wed 16/05/2018 07:32:07
QuoteAnd if I want to find an AudioClip that's being player, ie.

if (sounds_chan.PlayingClip!=aOcean_crash_cave) {
    sounds_chan = aOcean_crash_cave.Play;
}

I should do the above to stop it playing twice, or three times, or 15 times etc?

Huh? Have you got sounds set to only 1 channel? Otherwise the code above doesn't make much sense. Why would the clip play more than once in the first place?

If I have 5 sound channels, then channel 1, 2, 3, etc can be taken up by aOcean_crash_cave. Or is the audioclip unique?

Okay well I need to do one of the following:
a) make maxaudiochannels 1 for both music and sounds; or
b) have a function which finds and then stops an audioclip for a given name

But I'm really warn out now, so I think I'll go off and kill myself :P

The mists of Audiochannel are beginning to clear, but it's still quite confusing. I mean, why the hell isn't it easy to just say: 'you know that audio clip you were just playing? well crossfade it into this one.'
or 'you know those sound effect clips you were just playing? well just cross-fade them nothing, and then start up these new ones.'
AND, at the default volume, etc.

I'll try the VolumeReductionWhileSpeechPlaying to 0 and see if that changes anything.

I've run into yet more problems crossfading to sounds and music clips for no known reason. They just immediately jump into the new track (and .Stop() the old one); or sometimes not! And they just never play.
Plus, this changes depending on whether I do a Display() of the audiochannel ID, volume etc; or not. So it seems to take some time to do the transition.... but not for the other rooms.

ps: is AudioClip.Stop() just a way of stopping and AudioClip cold, or does it crossfade to nothing? Not that this seems to have any relationship to what actually happens, but I was just wondering the correct version.

I'm not trying to be obnoxious, I'm really not, but this is getting self destroying. I mean I will literally pay you money to debug these rooms for me.

Snarky

Quote from: bx83 on Wed 16/05/2018 08:46:01
If I have 5 sound channels, then channel 1, 2, 3, etc can be taken up by aOcean_crash_cave. Or is the audioclip unique?

Well, it is unique, but it can be playing on multiple channels at the same time. Just like "a particular sprite" is unique, but can be assigned to different objects or character loops and displayed simultaneously.

My question was more about why it would be playing on multiple channels simultaneously in the first place. I guess if there's a long "tail" to the sound I can see having two waves playing simultaneously, but with a regularly repeating sound like a wave I would expect you to have pretty tight control over it (you wouldn't be randomly triggering wave sounds at lots of different points in the code, I hope).

QuoteOkay well I need to do one of the following:
a) make maxaudiochannels 1 for both music and sounds; or

Do you want to be able to play multiple sounds at the same time? (For example in order to crossfade them?) If yes, don't do this.

Quoteb) have a function which finds and then stops an audioclip for a given name

AudioClip.Stop(). But why do you need this?

QuoteBut I'm really warn out now, so I think I'll go off and kill myself :P

If you don't rush things, but just take the time to figure things step by step (for example with a test game), things are much easier. Trying to get something buggy to work as quickly as possible by just hacking away randomly without quite understanding what's going on is always frustrating. (That's what I had to do for the Awards client towards the end, since I had fatal bugs popping up at the last minute before a hard deadline, and it was intensely stressful and unpleasant.)

QuoteThe mists of Audiochannel are beginning to clear, but it's still quite confusing. I mean, why the hell isn't it easy to just say: 'you know that audio clip you were just playing? well crossfade it into this one.'
or 'you know those sound effect clips you were just playing? well just cross-fade them nothing, and then start up these new ones.'
AND, at the default volume, etc.

Referring to "that audio clip you were just playing" is exactly what the AudioChannel pointer you get from AudioClip.Play() is for. Most common operations you might want to do are not actually particularly difficult, but the way it works is not well explained in the manual, so it can be confusing.

Cross-fading is not that simple an operation in the first place, and cross-fading multiple tracks simultaneously can very easily fail in various ways (particularly because you run out of channels to do the mixing), so it's never going to be trivial to do.

QuoteI've run into yet more problems crossfading to sounds and music clips for no known reason.

"crossfading to sounds and music clips"? These are two entirely different things, though. With music you're using OPT_CROSSFADEMUSIC to do built-in crossfading (using the hidden crossfade channel Crimson Wizard explained). For sounds you have to do the crossfading manually using separate channels.

QuoteThey just immediately jump into the new track (and .Stop() the old one); or sometimes not! And they just never play.
Plus, this changes depending on whether I do a Display() of the audiochannel ID, volume etc; or not. So it seems to take some time to do the transition.... but not for the other rooms.

Can't comment without seeing your code.

Quoteps: is AudioClip.Stop() just a way of stopping and AudioClip cold, or does it crossfade to nothing? Not that this seems to have any relationship to what actually happens, but I was just wondering the correct version.

It just stops it. (Perhaps for a music track with OPT_CROSSFADEMUSIC on it fades it out, but I'm not betting on it.)

bx83

Quote from: Snarky on Wed 16/05/2018 09:20:46
Quote from: bx83 on Wed 16/05/2018 08:46:01
If I have 5 sound channels, then channel 1, 2, 3, etc can be taken up by aOcean_crash_cave. Or is the audioclip unique?

Well, it is unique, but it can be playing on multiple channels at the same time. Just like "a particular sprite" is unique, but can be assigned to different objects or character loops and displayed simultaneously.

My question was more about why it would be playing on multiple channels simultaneously in the first place. I guess if there's a long "tail" to the sound I can see having two waves playing simultaneously, but with a regularly repeating sound like a wave I would expect you to have pretty tight control over it (you wouldn't be randomly triggering wave sounds at lots of different points in the code, I hope).

Wave as in ocean wave or sound wave?
Consider:
I have 4 Sound channels (MaxChannels=4). Each time I enter a room, we play an ocean waves sound.
If I don't have the
Code: ags
ff (music_chan.PlayingClip!=aOcean) { aOcean.Play() );

then it will start to fill up the available audio channels with this clip each time I enter the room.

QuoteOkay well I need to do one of the following:
a) make maxaudiochannels 1 for both music and sounds; or

Do you want to be able to play multiple sounds at the same time? (For example in order to crossfade them?) If yes, don't do this.[/quote]

But how will not setting it to 1 allow me to crossfade? That's the opposite.

Quoteb) have a function which finds and then stops an audioclip for a given name

AudioClip.Stop(). But why do you need this?[/quote}

Sorry, meant to say 'crossfade to nothing' not 'stops'.
Quote
QuoteBut I'm really warn out now, so I think I'll go off and kill myself :P

If you don't rush things, but just take the time to figure things step by step (for example with a test game), things are much easier. Trying to get something buggy to work as quickly as possible by just hacking away randomly without quite understanding what's going on is always frustrating. (That's what I had to do for the Awards client towards the end, since I had fatal bugs popping up at the last minute before a hard deadline, and it was intensely stressful and unpleasant.)

Yeah, well I know what you mean :/


QuoteCross-fading is not that simple an operation in the first place, and cross-fading multiple tracks simultaneously can very easily fail in various ways (particularly because you run out of channels to do the mixing), so it's never going to be trivial to do.

Yeah but could it be trivial for just one music track and one sound track?
I get the feeling I'll need to build a function which loops through all the audio channels, crossfades ones I want closed to nothing, and the others to crossfade to new tracks with a Wait(10) pause (using Wait has helped me to solve a few problems recently.)

Quote"crossfading to sounds and music clips"? These are two entirely different things, though. With music you're using OPT_CROSSFADEMUSIC to do built-in crossfading (using the hidden crossfade channel Crimson Wizard explained). For sounds you have to do the crossfading manually using separate channels.

Is the hidden crossfade channel in addition to the MaxChannels we've set up? Or is it just one channel, used for each sound crossfading.
Are they crossfaded simultaneously? One at a time?....

Quote
QuoteThey just immediately jump into the new track (and .Stop() the old one); or sometimes not! And they just never play.
Plus, this changes depending on whether I do a Display() of the audiochannel ID, volume etc; or not. So it seems to take some time to do the transition.... but not for the other rooms.

Can't comment without seeing your code.

I can send you a link to the main project? It will be about 1GB but it will explain everything and allow you to see quickly what's wrong. It really only affects the first 3 rooms, which use the crossfading music/sounds run by the position of each (ie. beachThemePos) in an audiochannel (ie. music_chan).

Quote
Quoteps: is AudioClip.Stop() just a way of stopping and AudioClip cold, or does it crossfade to nothing? Not that this seems to have any relationship to what actually happens, but I was just wondering the correct version.

It just stops it. (Perhaps for a music track with OPT_CROSSFADEMUSIC on it fades it out, but I'm not betting on it.)

Well what about crossfading sound effects?
Sounds and Music both have a 'crossfade tracks' option in the editor, but I can only set it for music (OPT_CROSSFADEMUSIC).

Snarky

Just so we're using the correct terminology: to "crossfade" is to fade out one track while fading in a different track: their volumes "cross". "Crossfade to nothing" is not a term, it's just called fading out.

Quote from: bx83 on Wed 16/05/2018 09:57:29
Wave as in ocean wave or sound wave?
Consider:
I have 4 Sound channels (MaxChannels=4). Each time I enter a room, we play an ocean waves sound.
If I don't have the
Code: ags
ff (music_chan.PlayingClip!=aOcean) { aOcean.Play() );

then it will start to fill up the available audio channels with this clip each time I enter the room.

What sound type is aOcean? If it's Music, then it won't be a problem because you only have one Music channel and this is what it will play. If it's Sound, then why are you looking at what's playing on music_chan? (Unless music_chan is one of the channels devoted to Sound clips, which would be really bad variable naming.) And if you have 4 sound channels, you can't just check whether it's playing on one particular channel, unless you specifically know that aOcean is playing on that particular channel and no other.

In summary, there's something very wrong with your logic here.

Quote
QuoteDo you want to be able to play multiple sounds at the same time? (For example in order to crossfade them?) If yes, don't do this.

But how will not setting it to 1 allow me to crossfade? That's the opposite.

It won't. That's why I said "If yes, don't do this".

Sorry, I misread. By not setting it to 1 you will have additional channels. You can use these channels to crossfade manually. In order to crossfade sounds, I believe this is the only way to do it.

Quote from: bx83 on Wed 16/05/2018 09:57:29
Quote from: Snarky on Wed 16/05/2018 09:20:46
It just stops it. (Perhaps for a music track with OPT_CROSSFADEMUSIC on it fades it out, but I'm not betting on it.)

Well what about crossfading sound effects?
Sounds and Music both have a 'crossfade tracks' option in the editor, but I can only set it for music (OPT_CROSSFADEMUSIC).

It's not documented, so figuring out how those two things interact would require either inspecting the engine code, or some systematic testing.

One possibility (and I'm JUST SPECULATING here) is that OPT_CROSSFADEMUSIC (which predates the new audio system) actually applies to all audio types that have have "crossfade tracks" set to true. However, there is still only one (hidden) channel for the built-in crossfading, so it will only be able to crossfade one clip at a time. If you try to use these settings to crossfade multiple clips simultaneously (both music and an audio clip, or two audio clips), things will go wrong. That could certainly explain some of the things you're experiencing (clips not playing, or clips stopping immediately rather than fading out).

Crimson Wizard

#19
Quote from: bx83 on Wed 16/05/2018 09:57:29
Well what about crossfading sound effects?
Sounds and Music both have a 'crossfade tracks' option in the editor, but I can only set it for music (OPT_CROSSFADEMUSIC).

Alright, this needs clarification.

There are two audio systems in the AGS, as Snarky already mentioned, and OPT_CROSSFADEMUSIC is from old system, but "Crossfade tracks" is from new system.
OPT_CROSSFADEMUSIC works only for music, but "Crossfade tracks" is for everything.
So, you don't need to set OPT_CROSSFADEMUSIC at all, instead set "Crossfade tracks" in every Audio Type that you want to crossfade.

However, there is only ONE built-in crossfade channel, which means that only one crossfade will be performed at a time.
If there was already some crossfade done at the moment when you begin new one, the previous crossfade will cancel, and the fading-out clip will stop immediately (however the previous fading-in clip will continue to gain volume normally)EDIT: hmm, just realized I am not so sure about this, needs to be checked out.
If this is not good for you, then you'd probably need to design your own crossfading system in script, using at least 2 channels per type you want to be able to crossfade.


Anyway, seeing all the trouble you are going through, my strongest advice is to actually make a small test game and write a script module that controls crossfading, and that you could later use in your game. Maybe even don't use two rooms, and make tracks switch by key press.
Designing and testing such script in actual big game usually brings additional complications, because there are more factors, you need to constantly get into right rooms to test it, and so on.
(It will also be much easier to share your game/code with others, since test game is smaller)

SMF spam blocked by CleanTalk