Author Topic: Should I start Music in Room_load of Room_Afterfadein?  (Read 1912 times)

bx83

  • Get 'Er Doooooone
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: Adventure Game Studio
  1. function room_FirstLoad()
  2. {
  3.     SetGameOption(OPT_CROSSFADEMUSIC, 1);
  4.     music_chan=aBeachTheme.Play(eAudioPriorityNormal, eRepeat);
  5.     sounds_chan=aOcean_crash.Play(eAudioPriorityNormal, eRepeat);
  6. }
  7.  
  8. function room_AfterFadeIn()
  9. {
  10.         if (cJulius.PreviousRoom == CAVE) {             //cave
  11.                 aWater_dripping.Stop();
  12.                 cJulius.Walk(265, 500, eNoBlock, eWalkableAreas);
  13.         }
  14.        
  15.  
  16.         if (cJulius.PreviousRoom==CAVE || cJulius.PreviousRoom==FARM) {
  17.                 beachThemePos=music_chan.Position;
  18.                 music_chan=aBeachTheme.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  19.         }
  20. }

CAVE:
Code: Adventure Game Studio
  1. function room_Load()
  2. {
  3.         if (cJulius.PreviousRoom == 2) {
  4.                 beachThemePos=music_chan.Position;
  5.                 music_chan=aBeachTheme_cave.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  6.         }
  7. }

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

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #1 on: 15 May 2018, 13:56 »
Sorry, I do not have time to answer the main question right now, but I can comment on this -

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
« Last Edit: 15 May 2018, 17:21 by Crimson Wizard »

Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #2 on: 15 May 2018, 14:01 »
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

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #3 on: 15 May 2018, 14:08 »
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.

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.
« Last Edit: 15 May 2018, 14:10 by Crimson Wizard »

Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #4 on: 15 May 2018, 14:09 »
I don't think you can stay on the same channel if cross-fading, since you are playing two streams at once.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #5 on: 15 May 2018, 14:11 »
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.
« Last Edit: 15 May 2018, 14:18 by Crimson Wizard »

Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #6 on: 15 May 2018, 14:48 »
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?
« Last Edit: 15 May 2018, 16:15 by morganw »

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #7 on: 15 May 2018, 15:02 »
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.
« Last Edit: 15 May 2018, 20:04 by Crimson Wizard »

Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #8 on: 15 May 2018, 17:14 »
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

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #9 on: 15 May 2018, 19:52 »
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:
Add spoiler tag for Hidden:
Code: Adventure Game Studio
  1. AudioChannel *mus_chan;
  2. bool a;
  3.  
  4. function room_AfterFadeIn()
  5. {
  6.         SetGameOption(OPT_CROSSFADEMUSIC, 1);
  7. }
  8.  
  9. function on_key_press(eKeyCode key)
  10. {
  11.         if (key == eKeySpace)
  12.         {
  13.                 if (a)
  14.                         mus_chan = aMusic1.Play();
  15.                 else
  16.                         mus_chan = aMusic2.Play();
  17.                
  18.                 int order;
  19.                 if (a)
  20.                         order = 1;
  21.                 else
  22.                         order = 2;
  23.                        
  24.                 int playid;
  25.                 if (mus_chan.PlayingClip == aMusic1)
  26.                         playid = 1;
  27.                 else
  28.                         playid = 2;
  29.                        
  30.                 player.SayBackground(String.Format("Ordered music = %d[mus_chan.ID = %d[music on chan = %d",
  31.                         order,
  32.                         mus_chan.ID,
  33.                         playid
  34.                         ));
  35.                 a = !a;
  36.         }
  37. }
  38.  

This is very good, otherwise it would be impossible to work with.
« Last Edit: 15 May 2018, 20:05 by Crimson Wizard »

bx83

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #10 on: 16 May 2018, 03:43 »
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

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #11 on: 16 May 2018, 05:43 »
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: Adventure Game Studio
  1. function room_Load()
  2. {
  3.         if (GameStarted) {
  4.                 beachThemePos=music_chan.Position;
  5.                 oceanThemePos=sounds_chan.Position;
  6.                 music_chan=aBeachTheme.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  7.                 sounds_chan=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityNormal, eRepeat);
  8.         } else {
  9.             SetGameOption(OPT_CROSSFADEMUSIC, 1);
  10.             if (FutureTime) {
  11.                 music_chan.Stop();
  12.             } else {
  13.                 music_chan=aBeachTheme.Play(eAudioPriorityNormal, eRepeat);
  14.                 beachThemePos=music_chan.Position;
  15.             }
  16.                
  17.             sounds_chan=aOcean_crash.Play(eAudioPriorityNormal, eRepeat);
  18.             oceanThemePos=sounds_chan.Position;
  19.                
  20.             cJulius.x=436;
  21.             cJulius.y=537;
  22.             GameStarted=true;
  23.         }
  24. }
  25.  
  26. function room_FirstLoad()
  27. {
  28. }
  29.  
  30. function room_AfterFadeIn()
  31. {
  32.         if (cJulius.PreviousRoom == CAVE) {             //cave
  33.                 aWater_dripping.Stop();
  34.                 cJulius.Walk(265, 500, eNoBlock, eWalkableAreas);
  35.         }
  36. }
  37.  

CAVE:
Code: Adventure Game Studio
  1. function room_Load()
  2. {      
  3.         if (FutureTime) {
  4.             music_chan.Stop();
  5.         } else {
  6.             beachThemePos=music_chan.Position;
  7.             music_chan=aBeachTheme_cave.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  8.         }
  9.        
  10.         sounds_chan=aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
  11. }
  12.  
  13. function room_AfterFadeIn()
  14. {
  15. }

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

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #12 on: 16 May 2018, 07:01 »
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

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #13 on: 16 May 2018, 07:03 »
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

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #14 on: 16 May 2018, 07:32 »
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]

Quote
I 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.

Quote
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);

???

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.)

Quote
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?

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?

Quote
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 :/

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

Quote
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);

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

bx83

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #15 on: 16 May 2018, 08:46 »
Quote
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?

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

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #16 on: 16 May 2018, 09:20 »
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).

Quote
Okay 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
b) have a function which finds and then stops an audioclip for a given name

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

Quote
But 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.)

Quote
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.

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.

Quote
I'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.

Quote
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.

Can't comment without seeing your code.

Quote
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.

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

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #17 on: 16 May 2018, 09:57 »
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: Adventure Game Studio
  1. 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.

Quote
Okay 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.

Quote
b) 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
Quote
But 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 :/


Quote
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.

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
Quote
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.

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
Quote
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.

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

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #18 on: 16 May 2018, 10:57 »
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.

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: Adventure Game Studio
  1. 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
Quote
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.

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.

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).
« Last Edit: 16 May 2018, 10:59 by Snarky »

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #19 on: 16 May 2018, 11:04 »
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)
« Last Edit: 16 May 2018, 11:48 by Crimson Wizard »