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

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 #20 on: 16 May 2018, 11:31 »
Great, thanks for the info/clarification, CW!

Agreed completely about using test games or prototypes. It's also one of Ben304's recommendations on the BCT podcast.

As for this case, I would recommend as a general approach: use built-in crossfading for music only. For sounds, write a module that does it manually. You probably don't even need to crossfade, just fade out one clip, stop it, then play and fade in the next. I even seem to remember recommending this to you a long time ago, bx83.

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 #21 on: 16 May 2018, 11:49 »
Something that I just realized, I am not sure if the previous crossfade of one type actually fades-in correctly if replaced by the new one of another type. This needs to be tested also.

For sounds, write a module that does it manually. You probably don't even need to crossfade, just fade out one clip, stop it, then play and fade in the next. I even seem to remember recommending this to you a long time ago, bx83.
True, that would be much simplier. Also if they fade in/out in a short time, players likely won't notice a difference.
« Last Edit: 16 May 2018, 11:52 by Crimson Wizard »

selmiak

  • ǝsıɔɹǝxǝ ʞɔǝu puɐ uıɐɹq
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with web design
    •  
    • selmiak worked on a game that was nominated for an AGS Award!
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #22 on: 16 May 2018, 11:59 »
"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)

this is interesting and should be noted somewhere. I always figured Room_Load commands and loading things into memory happens while the screen is black when fading out. But then, there are different screen transition effects, even one effect for warping screens together without any moment of complete blackness throughout the transition.

would it be more precise to say it like this? :
* "cChar enters next room before even fading out the current room" (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)

or more like
* "Engine loads room commands of the next room into memory before even fading out the current room" (Room_Load)
* room transition effect while cChar Sprite enters next room

the cChar doesn't suddenly disappear while fading out, does it?

where in that chain would a new music track (no sfx) start playing?

Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #23 on: 16 May 2018, 12:33 »
The next thing I'm looking at (next month) are the templates and a test game, so I'll try and start with audio tests (since that was also the bit of the ScummVM port which I was looking at). I'm not sure if the behaviour that is confirmed is just for music tracks, but if max channels actually reserved each channel, what happens when it is greater than 1? Are we saying that music is special case, or that using the built-in crossfade for any type of audio is going to keep the channel pointer valid?

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 #24 on: 16 May 2018, 12:47 »
Something that I just realized, I am not sure if the previous crossfade of one type actually fades-in correctly if replaced by the new one of another type. This needs to be tested also.

You mean if you have two different AudioTypes (both set to crossfade) with MaxChannels set to 0, and you're already playing clips of (let's say) AudioType1 on all the available channels, and then you ask to play a clip of AudioType2 with higher priority? I'm not even sure crossfading the clips is the desired behavior in this case. I'm inclined to think only clips of the same AudioType should be crossfaded with each other. And what if one AudioType is set to crossfade but the other not?

using the built-in crossfade for any type of audio is going to keep the channel pointer valid?

Surely this.

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 #25 on: 16 May 2018, 12:52 »
Something that I just realized, I am not sure if the previous crossfade of one type actually fades-in correctly if replaced by the new one of another type. This needs to be tested also.

You mean if you have two different AudioTypes (both set to crossfade) with MaxChannels set to 0, and you're already playing clips of (let's say) AudioType1 on all the available channels, and then you ask to play a clip of AudioType2 with higher priority?

No, I mean if there is already crossfade of two clips of type 1 in progress, and you begin crossfading other two clips of type 2.
Assuming MaxChannels for each type is 1, for simplicity.

Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #26 on: 16 May 2018, 13:13 »
using the built-in crossfade for any type of audio is going to keep the channel pointer valid?
Surely this.
Will have to test by trying to play a lower priority clip, because I don't think we should rule out getting null as the return.

bx83

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #27 on: 17 May 2018, 07:51 »
Thanks guys, it's all coming together... slowly.

Looks like I won't bother with AudioChannel pointers now unless for things like 'beachThemePos=music_chan.Position' and the crossfading I was talking about.

Also, the time it takes to crossfade multiple channels (ie. a sound and some music, and another sounds) can be controlled with just Wait(30), or some general Waiting. I've recently converted my rooms transition to 'instant', and tried to setup a walk of edge of screen to just-in-front-of-border, so every room transition feels more natural, and also, *takes some time that would normally be Blocking*. This seems to work well :)
Hopefully this approach works better consistently.

However, I'm still having problems with volume.
If I set music_chan.Volume=100, all is well; no phantom reduction and restoration of volume level. Upgraded to 3.4.1-p2, still has this problem. Anyway, a stop-gap for the moment.

But I *also* (I've just noticed) I'm having trouble with footstep sounds. They're only at 100% volume when I (sometimes) first enter a room (or, is this entering the area around the 'edge' of the room?...).
After this, they transiton to 0% volume or 8-10% volume, or whatever. One room it's totally silent, next room it's just audible, etc.

I've tried increasing the number of sound channels to 3 and 4, in case the footsteps audio takes up a channel; and also checked the footstep audio is correctly linked to the footsteps in question: but no dice, it's volume is still random.
Anyway: I thought of just setting the footstep volume to 100%, to act as stop-gap for that as well.

Which brings me finally to my question: HOW do you set the audiochannel volumes for footsteps? Are they on their own 'secret' channel (like crossfading)? Do they take up an additional channel, meaning I should increase my MaxChannels to, I don't know, 5?
Is it even possible to set a pointer to footsteps - after setting the footsteps with this kind of code:

Code: Adventure Game Studio
  1. function ChangeFootsteps_normal (int view) {
  2.   ViewFrame *frame = Game.GetViewFrame(1, 0, 1);
  3.   frame.LinkedAudio = aFootstep_normal_a;
  4.   frame = Game.GetViewFrame(view, 1, 1);
  5.   frame.LinkedAudio = aFootstep_normal_a;
  6.   frame = Game.GetViewFrame(view, 2, 1);
  7.   frame.LinkedAudio = aFootstep_normal_a;
  8.   frame = Game.GetViewFrame(view, 3, 1);
  9. ...

Experience would tell me no, since the audiochannel pointer is always null, or doesn't seem to join to the footsteps.

:undecided:

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 #28 on: 17 May 2018, 08:56 »
There's a Character.ScaleVolume setting, which if set to true will adjust the volume of the character depending on its scaling. (Or at least it's supposed to; it's been broken in some versions in the past.) Maybe try to disable that.

There's otherwise no very convenient way to control the volume of footsteps or other audio linked to an animation frame. If you do a forum search, you'll see that the usual recommendation is to create a new audio type, set the type of the clips to that, and use Game.SetAudioTypeVolume().

I'm also curious why you're limiting the Sound channels at all. By setting MaxChannels to 0 it'll use as many as needed for Sound (out of the ones left over once the ones reserved for Speech, Music, etc. are accounted for).

Also, the time it takes to crossfade multiple channels (ie. a sound and some music, and another sounds) can be controlled with just Wait(30), or some general Waiting. I've recently converted my rooms transition to 'instant', and tried to setup a walk of edge of screen to just-in-front-of-border, so every room transition feels more natural, and also, *takes some time that would normally be Blocking*. This seems to work well :)
Hopefully this approach works better consistently.

This doesn't sound like you've taken our advice. :-\ I can't be sure without seeing your code since the description is a bit unclear.

However, I'm still having problems with volume.
If I set music_chan.Volume=100, all is well; no phantom reduction and restoration of volume level. Upgraded to 3.4.1-p2, still has this problem. Anyway, a stop-gap for the moment.

There's a mistake somewhere in your code, and going by the snippet you had in your last post, I'm guessing it has to do with overwriting the music_chan pointer, so that when you're trying to adjust the volume of other clips later on you're actually messing with the music volume.

Forcing the volume to 100 may fix this particular bug, but as long as the mistake is still there it could pop up again in other ways. It might even be what is causing the trouble with the footsteps.

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 #29 on: 17 May 2018, 09:29 »
However, I'm still having problems with volume.
If I set music_chan.Volume=100, all is well; no phantom reduction and restoration of volume level. Upgraded to 3.4.1-p2, still has this problem. Anyway, a stop-gap for the moment.

I've read the whole thread again, but for some reason still could not grasp what exactly happens with the volume in your game.

However, only yesterday Chicky has found following bug and posted it on Discord channel:

Quote
Seems with OPT_CROSSFADEMUSIC set to 1 AGS automatically resets volume and crossfades from 0 to 100, ignoring all volume commands until the crossfade has finished

Maybe it is related? Haven't tested this myself.
« Last Edit: 17 May 2018, 09:56 by Crimson Wizard »

bx83

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #30 on: 17 May 2018, 12:44 »
Okay, all code:
room 2 is BEACH, to the right of CAVE
room 7 is CAVE
room 3 is FARMER, to the right of BEACH
room 4 is CROSSROADS, to the right of FARMER
room 32 is MOUNTAIN TOP, to the top of FARMER

so:
           _32_
7  |  2  |  3   |  4

I turned off the ScaleVolume=true; no difference, the sound of footsteps in inaudable in room 7, 2 and 3, but audible in room 32 and 4.

In room 3, FARMER
What I meant by the 'blocking pause' was the walking in from the edge of the screen initially in a room transition. If I place the Walk() code after track 1 (sound) crossfades:
Code: Adventure Game Studio
  1. sounds_chan=aOcean_crash_cave.PlayFrom(oceanThemePos, eAudioPriorityLow, eRepeat);

but before track 2 (music) crossfades:
Code: Adventure Game Studio
  1. aAfternoonSounds.Play(eAudioPriorityNormal, eRepeat);

...this should work for giving an appropriate pause while crossfading 2 tracks at once; and will hopefuly have me removing the Wait(5) and Wait(30) commands.


Please IGNORE all comments, commented out snippets, 'cheats' etc, the whole thing is in flux. I've also removed all functions that have nothing to do with music, or were not touched by me while testing.
The room transition is now Instant (left a few SetNextScreenTransition(eTransitionInstant) in case i switch it back).
beachTheme is set as volume is 50 set in editor, beachTheme_Cave is set to 40. I also had to set their volumes manually in code or they had volume randomness or cut out intermitendly on room transition.

Also, might be easier to delete anything you don't see as significant.

aBeachTheme, aBeachTheme_cave, a4_mountainCave_92bpm, aSilence (1 second of ansolute silence, to fade out on), and aAfternoonSounds are Music.
aShake_matches, aOcean_crash (for room 2), aOcean_crash_cave (for room 7 and 4) are Sounds.

===========

ROOM 2 - BEACH (this is where the game starts)
Code: Adventure Game Studio
  1. function room_Load()
  2. {
  3.         ChangeFootsteps_normal();
  4.   //cJulius.ScaleVolume=true;
  5.        
  6.         if (GameStarted) {
  7.                 beachThemePos=music_chan.Position;
  8.                 oceanThemePos=sounds_chan.Position;
  9.                 music_chan=aBeachTheme.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  10.                 sounds_chan=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityNormal, eRepeat);
  11.  
  12.         } else {
  13.           //SetGameOption(OPT_CROSSFADEMUSIC, 1);
  14.                 Game.SetAudioTypeSpeechVolumeDrop(eAudioTypeMusic, 30);
  15.                 Game.SetAudioTypeSpeechVolumeDrop(eAudioTypeSound, 40);
  16.        
  17.                 BeenToBeach=true;
  18.                
  19.                 if (FutureTime) {                                                    //LATER IN THE GAME, YOU RETURN TO THE BEACH IN AN UNSPECIFIED LATER TIME, TO SILENCE AND A DIFFERENT BACKGROUND
  20.                         aSilence.Play(eAudioPriorityNormal, eOnce);
  21.                 } else {
  22.                         music_chan=aSilence.Play(eAudioPriorityLow, eOnce);
  23.                         music_chan=aBeachTheme.Play(eAudioPriorityNormal, eRepeat);
  24.                         beachThemePos=music_chan.Position;
  25.                 }
  26.                
  27.                 sounds_chan=aOcean_crash.Play(eAudioPriorityNormal, eRepeat);
  28.                 oceanThemePos=sounds_chan.Position;
  29.                                
  30.                 cJulius.x=436;
  31.                 cJulius.y=537;
  32.                
  33.                 GameStarted=true;
  34.         }
  35.  
  36.         QuicksandConquered=true;        //CHEAT                    //IN THE BEACH ROOM, YOU MUST WALK ACROSS QUICKSAND, WHICH IS IMPOSSIBLE WITHOUT SOLVING A PUZZLE; BUT IT WAS TOO HARD SOLVING THIS PUZZLE OVER AND OVER WHEN TESTING, SO I REMOVED IT
  37. }
  38.  
  39. function room_AfterFadeIn()
  40. {
  41.         if (cJulius.PreviousRoom == 3) {                //farmer
  42.                 aAfternoonSounds.Stop();
  43.                 sounds_chan=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityLow, eRepeat);
  44.         }
  45.  
  46.         if (cJulius.PreviousRoom == 7) {                //cave
  47.                 aWater_dripping.Stop();
  48.                 cJulius.Walk(265, 500, eNoBlock, eWalkableAreas);
  49.         }
  50.        
  51.         music_chan.Volume=50;
  52. }
  53.  
  54.  
  55.  
  56. function room_LeaveRight()
  57. {
  58.   if (cJulius.y<=470) {
  59.                
  60.     SetNextScreenTransition(eTransitionInstant);
  61.     SetGameOption(OPT_CROSSFADEMUSIC, 1);
  62.                
  63.     cJulius.ChangeRoom(3, 90, 600, eDirectionDownRight);     //Farmer
  64.   } else {
  65.     cJulius.ChangeRoom(23, 164, 472, eDirectionRight);   //pixelated forest
  66.   }
  67. }
  68.  
  69.  
  70. function room_LeaveLeft()
  71. {
  72.         if (cJulius.y >= 240 && cJulius.y <= 520) {
  73.                 cJulius.Walk(0, cJulius.y, eBlock, eWalkableAreas);
  74.                 SetNextScreenTransition(eTransitionInstant);
  75.                 cJulius.ChangeRoom(7, 900, 385);       //Cave
  76.         }
  77. }
  78.    
  79. function room_LeaveBottom()
  80. {
  81.   cJulius.ChangeRoom(23, 120, 437);   //pixel forest
  82. }


=====================


ROOM 7 - CAVE
Code: Adventure Game Studio
  1. function room_LeaveRight()
  2. {
  3.   if (cJulius.y<=405){
  4.                 cJulius.Walk(1054, cJulius.y, eBlock, eAnywhere);
  5.                 SetNextScreenTransition(eTransitionInstant);
  6.                 cJulius.ChangeRoom(2, 2, 500, eDirectionRight); //beach
  7.   }
  8. }
  9.  
  10. function room_FirstLoad()
  11. {
  12.   BeenToCave=true;
  13. }
  14.  
  15. function room_Load()
  16. {
  17.         //braun fixes car
  18.         cBraun.LockView(67);
  19.         cBraun.Animate(0, 1, eRepeat, eNoBlock);
  20.  
  21.         if (FutureTime) {
  22.                 music_chan.Stop();
  23.         } else {
  24.                         beachThemePos=music_chan.Position;
  25.                         music_chan=aBeachTheme_cave.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  26.         }
  27.        
  28.         sounds_chan=aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
  29. }
  30.  
  31. function room_AfterFadeIn()
  32. {
  33.         music_chan.Volume=40;
  34. }

=====================

ROOM 3 - FARM (room 47 is 'farmer detail' - ignore)
Code: Adventure Game Studio
  1. function room_LeaveLeft()
  2. {
  3.   cJulius.ChangeRoom(2, 910, 330, eDirectionLeft);       //Beach
  4. }
  5.  
  6. function room_LeaveRight()
  7. {
  8.   cJulius.ChangeRoom(4, 90, 560, eDirectionRight);         //Crossroads
  9. }
  10.  
  11. function room_LeaveTop()
  12. {
  13.         cJulius.Walk(654, 452, eBlock, eWalkableAreas);
  14.         cJulius.ChangeRoom(32, 196, 384, eDirectionRight);       //Mountaintop
  15. }
  16.  
  17. function room_Load()
  18. {
  19.         ChangeFootsteps_normal();
  20.        
  21.         //oceanThemePos=sounds_chan.Position;
  22.        
  23.        
  24.         //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);
  25.         //Wait(30);
  26.         sounds_chan=aOcean_crash_cave.PlayFrom(oceanThemePos, eAudioPriorityLow, eRepeat);
  27.         //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);
  28.         Wait(5);
  29.         aAfternoonSounds.Play(eAudioPriorityNormal, eRepeat);
  30.         //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);
  31.         Wait(30);
  32.         //REPLACE THIS WITH WALKING OFFSCREEN PART
  33. }
  34.  
  35.  
  36. function room_AfterFadeIn()
  37. {
  38.         if (cJulius.PreviousRoom==2) {  //beach
  39.                 aOcean_crash.Stop();
  40.         }
  41.        
  42.         if(cJulius.PreviousRoom==32) {  //mountain cave
  43.                 cJulius.Walk(426, 539, eBlock, eWalkableAreas);
  44.         }
  45.        
  46.         music_chan.Volume=100;
  47. }

============================

ROOM 4 - CROSSROADS
Code: Adventure Game Studio
  1. function room_LeaveLeft()
  2. {
  3.         if (!smallone) {
  4.     if (cJulius.y >= 370) {
  5.       cJulius.ChangeRoom(3, 900, 600, eDirectionLeft);       //Farmer
  6.     } else {
  7.       cJulius.ChangeRoom(12, 935, 310, eDirectionDown);   //W village
  8.     }
  9.         }
  10. }
  11.  
  12. function room_Load()
  13. {
  14.         aOcean_crash.Stop();
  15.         aOcean_crash_cave.Stop();
  16.        
  17.         music_chan=aCrossroads.Play(eAudioPriorityNormal, eRepeat);
  18.  
  19.         if (HasMace && dTrainer.GetOptionState(7)==eOptionOffForever) {         //north village
  20.                 cTrainer.Transparency=100;      //disappear
  21.         }
  22. }
  23.  
  24. function room_AfterFadeIn()
  25. {
  26.         if (cJulius.PreviousRoom==8) {          //south village
  27.                 cJulius.Walk(470, 628, eBlock, eAnywhere);      //walk up from south edge
  28.         }
  29.  
  30.  
  31. }


==============

ROOM 32 - MOUNTAINTOP
Code: Adventure Game Studio
  1.  
  2. function room_Load()
  3. {
  4.   ChangeFootsteps_snow();
  5.        
  6.     aOcean_crash_cave.Stop();
  7.     aAfternoonSounds.Stop();
  8. }
  9.  
  10. function room_AfterFadeIn()
  11. {
  12.     if (music_chan!=null) {
  13.         if (music_chan.PlayingClip!=a4_mountainCave_92bpm) {
  14.             music_chan = a4_mountainCave_92bpm.Play(eAudioPriorityNormal, eRepeat);  
  15.         }
  16.     } else {
  17.         music_chan = a4_mountainCave_92bpm.Play(eAudioPriorityNormal, eRepeat);  
  18.     }
  19. }
  20.  
  21. function room_RepExec()
  22. {
  23.   if (GetWalkableAreaAt(cJulius.x, cJulius.y)==1) {
  24.     ChangeFootsteps_snow();
  25.   } else if (GetWalkableAreaAt(cJulius.x, cJulius.y)==2) {
  26.     ChangeFootsteps_concrete();
  27.   }
  28. }
  29.  
  30.  
  31. function room_LeaveLeft()
  32. {
  33.   cJulius.ChangeRoom(3, 654, 452, eDirectionDown);  //farmer
  34. }


That's it, abridged. Hopefully you can pick up a massive error to do with setting volumes etc.

There are quite a number of non-natural transitions in the code; the only natural transition are anywhere you see:
Code: Adventure Game Studio
  1. SetNextScreenTransition(eTransitionInstant);

This has Julius wakling off a eg. a left edge, room transitons instantly, and then in the next he walks in from the eg. right edge, before finally stopping and returning control to the user.
« Last Edit: 17 May 2018, 12:47 by bx83 »

bx83

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #31 on: 17 May 2018, 12:57 »
Here's a video of the above:
link here

You might want to listen on 100%+ volume, the footsteps are just audible in room 4 (crossroads).

bx83

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #32 on: 19 May 2018, 06:45 »
Anyone...?
Anyway, I do understand AudioChannel and crossfade more. Pitty about footstep sounds but it will be fixed later I suppose.
Thankyou :)

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 #33 on: 19 May 2018, 07:20 »
The obvious difference between these rooms is that in 2,7 and 3 you're playing background sounds on sound_chan, while you're not doing so in rooms 4 and 32.

So if you still have the Sounds set to use only 1 channel, then it straightforwardly won't work, for obvious reasons.

Your game logic is also a bit of a mess. I think things would be a lot cleaner if you distinguished game-wide, permanent settings, like OPT_CROSSFADEMUSIC (which, as we've learned, shouldn't be used in the first place) and the screen transition style, from temporary state. Don't set these repeatedly whenever you change rooms, but once at game start.

Also, what purpose is there to lines like
Code: Adventure Game Studio
  1.                         music_chan=aSilence.Play(eAudioPriorityLow, eOnce);
  2.                         music_chan=aBeachTheme.Play(eAudioPriorityNormal, eRepeat);
  3.                         beachThemePos=music_chan.Position;
in Room_Load? (1) You're first telling it to play one clip and then immediately telling it to play another, presumably of the same type. Why? Is this some hack to disable crossfading by interrupting it? If some of CW's concerns turn out to be correct, this could potentially lead to erratic volume changes, so... maybe don't? (2) Shouldn't oceanThemePos always be 0 since you're just starting to play it on the line above? (3) By the time you use it, it will be completely outdated anyway.

bx83

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #34 on: 19 May 2018, 10:33 »
I completely agree.
All of this is left over in code from revisions of revisions based on an imperfect knowledge of the sound system and partially done re-writing of various room's code.
I'll clean these up before putting more code here.

BTW are you planning on ever making more than one crossfade channel?

Also - if a programmer has to change the OPT_CROSSFADEMUSIC from 1 to 0 and then back again -  how should they do it if OPT_CROSSFADEMUSIC is not to be used anymore? How do you control *this* option (the one in the Editor, the 'Crossfade Tracks', as opposed to OPT_CROSSFADEMUSIC)? Like Game.SetAudioTypeCrossfade?
The reason I ask is this presents a pickle in my one piece of simultaneous dialogue in the whole game:

Code: Adventure Game Studio
  1.         SetGameOption(OPT_CROSSFADEMUSIC, 0);           //set crossfade to 'no crossfade' for sounds_chan (because the dialogue sound is set as a 'Music' or dialogue ("&123 This is a line") piece, and we want it played cleanly, not to crossfade in or out)
  2.  
  3.         game.bgspeech_stay_on_display = 1;
  4.         sounds_chan=aCombinedLineLibrary.Play(eAudioPriorityNormal, eOnce);    //<-- this is the combined speech of two players
  5.  
  6.         cJulius.LockView(68);
  7.         cJulius.Animate(0, 4, eOnce, eNoBlock);        //animate 1st player's speech
  8.  
  9.         cNerd.SayAtBubble(550, 270, "&110 We are very sorry to makers of Everyone Loves Raymond. He is not our own creation and wholly the property of 'Where's Lunch', 'Worldwide Pants', and 'HBO Independent Productions'. Thankyou for viewing our slap-stick play.");        //get 2nd player to say his line (???)
  10.  
  11.         aCombinedLineLibrary.Stop();    //stop the combined speech line
  12.  
  13.         cJulius.LockView(1);            //back to normal animation
  14.         cJulius.Animate(8, -7, eOnce, eBlock);    
  15.  
  16.         cJulius.UnlockView();        //unlock view(s)
  17.  
  18.         SetGameOption(OPT_CROSSFADEMUSIC, 1);   //set crossfade back for sounds_chan

(obviously there is random confusing crap in there, but it works)
The above code uses the crossfade option to change it from 'slow' to 'no crossfade', and then back again... and it works! Somehow :/ ...... because according to you and the errors I was getting before, it shouldn't work.

I think was my reason for putting:
Code: Adventure Game Studio
  1. music_chan=aSilence.Play(eAudioPriorityLow, eOnce);
  2. music_chan=aBeachTheme.Play(eAudioPriorityNormal, eRepeat);
...was an attempt to prime the music_chan pointer; removed it, still works, god knows what I was thinking.
« Last Edit: 19 May 2018, 10:35 by bx83 »

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 #35 on: 19 May 2018, 11:27 »
The obvious solution to the speech issue is to not have the audio type of the background speech clips be Music.

... I may regret this, because I think the best solution would be to clean up your code thoroughly, but I think there is a pretty simple workaround/fix.

As we have learned, AGS has 9 AudioChannels:

-1: Crossfade [reserved]
 0: Speech [reserved]
 1: Game-assigned
 2: Game-assigned
 3: Game-assigned
 4: Game-assigned
 5: Game-assigned
 6: Game-assigned
 7: Game-assigned

The way you have it set up now, if I understand it correctly, it's:

-1: Crossfade [reserved]
 0: Speech [reserved]
 1: Music
 2: Sound
 3: [Unused]
 4: [Unused]
 5: [Unused]
 6: [Unused]
 7: [Unused]

(I don't know for sure that it's precisely channel 1 for Music and Channel 2 for Sound, but it's something like this.)

Instead, I suggest you create a new AudioType, which you can call e.g. BackgroundSound. Set its MaxChannels property to 1 and crossfade to true. Set the MaxChannels property of Sound to 0 (unlimited) and crossfade to false. Change the AudioType of the background sounds to BackgroundSound. Change the AudioType of the background speech clips to Sound.

This way, the AudioChannel assignments should be something like:

-1: Crossfade [reserved]
 0: Speech [reserved]
 1: Music
 2: BackgroundSound
 3: [Free - Can be used for Sound]
 4: [Free - Can be used for Sound]
 5: [Free - Can be used for Sound]
 6: [Free - Can be used for Sound]
 7: [Free - Can be used for Sound]

This way, Music and BackgroundSound can still be crossfaded using the built-in feature (though not at the same time), background speech (as Sound clips) won't crossfade, you'll be able to play up to five Sound effects simultaneously (e.g. footsteps, background speech), and Sounds won't be affected by Music or BackgroundSound at all.

There's probably still some code that needs cleaning up so this will work bug-free, but it should simplify things a lot.
« Last Edit: 19 May 2018, 11:29 by Snarky »

bx83

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #36 on: 19 May 2018, 12:31 »
This further gives me knowledge into Audio. Didn't know I could have 7 extra named types, and separate them into 7 different 'channels'.
I've got half a mind to do this:

-1: crossfades
0: Speech  (crossfade off, maxchan 1)
1: Music (crossfade on, maxchan 1)
2: Sounds_1 (crossfade on, maxchan 1)
3: Sounds_2 (crossfade on, maxchan 1)
4: Extra (crossfade off, maxchan 1)
5: free
6: free
7: free

Each room has music; so just set Music to new track, then it's the nex track, all smooth.
They also have 1 sound; I use Sounds_1, same thing.
It might have 1 extra sound: Sounds_2.
For temporary sounds (door-bell, jangling keys, etc. that just do the sound 'eOnce'), we have Extra
The other's probably won't be used.
I can track and separate all :)

And I can figure out how to drop in blocking pauses like Wait for 2 or 3 sounds, so all of them have a smooth crossfade if needed.

No more 'Music_chan' etc, we have audio types which themselves are 1 track maxchannel pointers to begin with :)
No possibility of having pointer's overwritten; these internal anyway and don't *need* a global variable.

Correct?

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 #37 on: 19 May 2018, 13:56 »
  • You can't set crossfade or MaxChannels for the Speech channel. It's controlled by AGS.
  • The drawback of having two separate Background Sound types is that each clip has to be assigned a specific type, so you won't be able to mix and match between the channels.
  • Why are you so dead set on setting MaxChannels=1 for everything? In this setup, just set the MaxChannels for the "Extra" type to 0, and then if it happens that you need to play multiple sounds at the same time it will just work.

No more 'Music_chan' etc, we have audio types which themselves are 1 track maxchannel pointers to begin with :)

No, they're not. AudioTypes are enums, and the mapping from AudioType to AudioChannel* is not accessible to the game script.

In order to adjust volumes etc. you'll still need AudioChannel pointers.

bx83

  • Get 'Er Doooooone
Re: Should I start Music in Room_load of Room_Afterfadein?
« Reply #38 on: 20 May 2018, 05:56 »
Are there 7 channels in total, or per AudioType?
Will post updated code later, all... seems to work now.

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 #39 on: 20 May 2018, 06:13 »
Are there 7 channels in total, or per AudioType?

:shocked:
Well, let me ask you this: What are AudioChannels, and why are they limited to 7 (or 8, or 9, depending on how you count) in the first place?