Author Topic: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks  (Read 425 times)

bx83

  • Get 'Er Doooooone
Been playing with sound (again...) and this time, it's completely stuffed.
Everything was working.

BEACH room:
Code: Adventure Game Studio
  1. function room_FirstLoad()
  2. {
  3.     SetGameOption(OPT_CROSSFADEMUSIC, 2);
  4. }
  5.  
  6. function room_Load()
  7. {
  8. ...
  9.     SOUNDS=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityNormal, eRepeat);
  10.     MUSIC=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  11. ...
  12. }
  13.  
  14. function room_RepExec()
  15. {
  16. ...
  17.     beachThemePos=MUSIC.Position+1100;
  18.     oceanThemePos=SOUNDS.Position;
  19. ...
  20. }

CAVE room (to the left of BEACH room)
Code: Adventure Game Studio
  1. function room_Load()
  2. {
  3. ...
  4.     if (cJulius.PreviousRoom == BEACH) {
  5.         MUSIC=a1_beachTheme_5_0_CAVE.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  6.     }
  7.        
  8.     if (SOUNDS.PlayingClip!=aWater_dripping) {
  9.         SOUNDS=aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
  10.     }
  11. }
  12.  
  13. function room_RepExec()
  14. {
  15. beachThemePos=MUSIC.Position+1100;
  16. ...
  17. }
  18.  

...but assignments to MUSIC channel just... don't come on - at this time, or anytime after that.

What happens:
The music stops (doesn't fade out to silence) forever.

What's supposed to happen:
The track from the previous room fades out, and this new one fades in on assignment (eg. MUSIC=aMusic.Play)

What's going on?
-Is it due to order of functions? (I thought it was: FirstLoad -> Load -> AfterFadein)?
-Is it due to me not deleting the AudioCache directory and starting again?
-Is it due to a bug or should I reload the editor?
« Last Edit: 04 Mar 2018, 10:18 by bx83 »

bx83

  • Get 'Er Doooooone
Another interesting thing:

When I do this, music and sound player:
Code: Adventure Game Studio
  1. function room_FirstLoad() {
  2. ...
  3. SOUNDS=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityNormal, eRepeat);
  4. //Display("ocean channel %d",SOUNDS.ID);
  5. MUSIC=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  6. //Display("beach channel %d",MUSIC.ID);

...and this, it doesn't play:
Code: Adventure Game Studio
  1. function room_FirstLoad() {
  2. ...
  3. SOUNDS=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityNormal, eRepeat);
  4. Display("ocean channel %d",SOUNDS.ID);
  5. MUSIC=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  6. Display("beach channel %d",MUSIC.ID);

WTF guys.

bx83

  • Get 'Er Doooooone
I replaced SOUNDS and MUSIC with sounds_chan and music_chan, thinking that the capital letters might have thrown them off.
They didn't; all previous errors are the same, and happening the same way.

Also tried deleting everything AudioCache; and comparing to an earlier version where sound worked. Made it extactly the same; no dice.

I know this is an obvious one (or a bug, in which I case I have no idea what I'll do), but I can't see it.

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Well, the first thing I'd try would be to change the MaxChannels to some other value to check if that's actually the problem.

bx83

  • Get 'Er Doooooone
Changed it to 2 - same deal.
Copied and pasted room 2 (beach) and room 7 (cave) from the working archived one - same problem.
Very very odd.

bx83

  • Get 'Er Doooooone
I also tried getting rid of all sounds, and finding out if music would play on sounds_chan (with MaxChannels=1) would play then - nope, total silence.

bx83

  • Get 'Er Doooooone
AHA!

The beachThemePos, which is being updated on music_chan's position, is NOT being updated in the latest version; it's always 0, no matter what.
However, the code is exactly the same.
The problem then is in the Audio section on the right hand menu, as this is the only thing I've changed in the last week; or, god knows :/

bx83

  • Get 'Er Doooooone
SOLVED.

It was because I was switching between OGG's and WAV's; or, I had both running in channels. Case closed, all works well :)

If anyone didn't know this (and I'm sure most of you did, but whatevs) - it's risky running songs of a different file type... ever :)

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!
It was because I was switching between OGG's and WAV's; or, I had both running in channels. Case closed, all works well :)

If anyone didn't know this (and I'm sure most of you did, but whatevs) - it's risky running songs of a different file type... ever :)

bx83, according to the manual, in AGS WAV sounds have different meaning of Position value:

Quote
MIDI - the beat number
MOD/XM/S3M - the pattern number
WAV/VOC - the sample number (eg. in a 22050 Hz sound, 22050 = 1 second)
OGG/MP3 - milliseconds offset

(That's terrible API, of course, but this is what we have. That might also be the reason to switch all your music to MP3/OGG)

I never tried crossfading different music types, so idk if that technicaly works in AGS, but even assuming it might work, you have to alter from "samples number" to "milliseconds" by dividing/multiplying the variable.

For example, if your wav is 44100 Hz, then playing it from 1 second (1000 ms) would require you passing 44100 instead.
« Last Edit: 04 Mar 2018, 14:18 by Crimson Wizard »

It is probably also worth noting, these sample positions do not account for stereo (so don't multiply by two, to account for samples on the left and right channels).

bx83

  • Get 'Er Doooooone
Extremedly useful advice.

Does anyone know if there's a way to arbitraily time in seconds/milleconds during runtime?
If I wanted to measure the amount of time between room_Load's and room_AfterFadeIn? There's no way of getting a loop or arbitrary timer, but somehow..?

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!
Does anyone know if there's a way to arbitraily time in seconds/milleconds during runtime?
If I wanted to measure the amount of time between room_Load's and room_AfterFadeIn? There's no way of getting a loop or arbitrary timer, but somehow..?

Why do you need that? Cannot you just take position of previous music right when you are about to start a new one? Or is it for something else?

In theory, you could use DateTime functions, but unfortunately AGS restricts it to 1-second precision, so won't be of much use here.
« Last Edit: 04 Mar 2018, 22:49 by Crimson Wizard »

Gurok

  • Rottwheelers
  • When life hands you lemons, combine them with the mop
    • I can help with AGS tutoring
    •  
    • Best Innovation Award Winner 2016, for improving and extending the AGS scripting language
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • Gurok worked on a game that was nominated for an AGS Award!
      Gurok worked on a game that won an AGS Award!
In theory, you could use DateTime functions, but unfortunately AGS restricts it to 1-second precision, so won't be of much use here.

I like to think CJ was forward-thinking here, given the recent Spectre and Meltdown scares :)

bx83

  • Get 'Er Doooooone
I'm using it because there's always a bit of lag between the songs.

I use fadeout/fadein for room transitions.

I have 2 tracks, completely identical in length and content, but one is 'muted' (like being played on a radio). Track 1 for 'beach', muted track 2 for 'cave'.
I switch between the tracks, but at the same time, so hopefullly it's floorless.

I do music-switching in room_Load; perhaps I should change the track, *then* go to the new room? Just a thought; it currently looks like:

Code: Adventure Game Studio
  1. Room 'beach':
  2. function room_Load () {
  3.      songchan=aSong.PlayFrom(songPos, etc etc);
  4. }
  5.  
  6. function room_RepExec () {
  7.     songPos=songchan.Position;
  8. }

...same in room 'cave'; atm I've been using:

Code: Adventure Game Studio
  1. function room_RepExec () {
  2.     songPos=songchan.Position+1100;
  3. }

to get them more in-sync.

Should I do this before I change room?

Code: Adventure Game Studio
  1. function leave_left
  2. {
  3.     songchan=songMuted.PlayFrom(songPos, ...);
  4.     cChar.Changeroom(2,100,100);
  5. }

???
« Last Edit: 05 Mar 2018, 02:22 by 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!
But that still does not answer my question: why cannot you just take position of previous music right when you are about to start a new one? Why constantly updating the value in rep_exec at all?

Code: Adventure Game Studio
  1. function room_Load () {
  2.      int songPos = 0;
  3.      if (songchan != null) // if something is playing in the song channel, then take its position
  4.          songPos = songchan.Position+1100;
  5.      songchan=aSong.PlayFrom(songPos, etc etc);
  6. }
  7.  

Do I miss anything here?
« Last Edit: 05 Mar 2018, 02:27 by Crimson Wizard »

bx83

  • Get 'Er Doooooone
Because I want to keep the songPos updating, so it's in sync with the song; guess I didn't have to :/
Sorry, I find this music business so confusing.

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!
Because I want to keep the songPos updating, so it's in sync with the song; guess I didn't have to :/
Sorry, I find this music business so confusing.

Well, this is not directly related to music, but rather to using game objects.
If you already have a song in the channel variable, then you do not need extra variable to copy its position all the time. You just use the channel variable to access its Position field when you need it, and it will tell you its actual current value.

This is same like with character, for example. If you want to know its X coordinate at particular moment, you do not have to copy it to another variable in repExec, you just take cChar.x right in the moment you need it.
Hopefully I make sense...
« Last Edit: 05 Mar 2018, 02:40 by Crimson Wizard »

bx83

  • Get 'Er Doooooone
Lesson learned ;P
The code now works without gaps or catchup, flawlessly, done :D
« Last Edit: 05 Mar 2018, 05:29 by bx83 »