Adventure Game Studio | Forums

AGS Support => Beginners' Technical Questions => Topic started by: bx83 on Sun 04/03/2018 00:59:59

Title: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks
Post by: bx83 on Sun 04/03/2018 00:59:59
Been playing with sound (again...) and this time, it's completely stuffed.
Everything was working.

BEACH room:

function room_FirstLoad()
{
    SetGameOption(OPT_CROSSFADEMUSIC, 2);
}

function room_Load()
{
...
    SOUNDS=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityNormal, eRepeat);
    MUSIC=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
...
}

function room_RepExec()
{
...
    beachThemePos=MUSIC.Position+1100;
    oceanThemePos=SOUNDS.Position;
...
}


CAVE room (to the left of BEACH room)

function room_Load()
{
...
    if (cJulius.PreviousRoom == BEACH) {
        MUSIC=a1_beachTheme_5_0_CAVE.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
    }

    if (SOUNDS.PlayingClip!=aWater_dripping) {
        SOUNDS=aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
    }
}

function room_RepExec()
{
beachThemePos=MUSIC.Position+1100;
...
}


...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?
Title: Re: Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks ???
Post by: bx83 on Sun 04/03/2018 06:50:50
Another interesting thing:

When I do this, music and sound player:

function room_FirstLoad() {
...
SOUNDS=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityNormal, eRepeat);
//Display("ocean channel %d",SOUNDS.ID);
MUSIC=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
//Display("beach channel %d",MUSIC.ID);


...and this, it doesn't play:

function room_FirstLoad() {
...
SOUNDS=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityNormal, eRepeat);
Display("ocean channel %d",SOUNDS.ID);
MUSIC=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
Display("beach channel %d",MUSIC.ID);


WTF guys.
Title: Re: Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks ???
Post by: bx83 on Sun 04/03/2018 07:10:51
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.
Title: Re: Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks ???
Post by: Snarky on Sun 04/03/2018 09:08:44
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.
Title: Re: Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks ???
Post by: bx83 on Sun 04/03/2018 09:39:50
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.
Title: Re: Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks ???
Post by: bx83 on Sun 04/03/2018 09:44:39
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.
Title: Re: Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks ???
Post by: bx83 on Sun 04/03/2018 10:09:32
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 :/
Title: Re: Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks ???
Post by: bx83 on Sun 04/03/2018 10:17:53
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 :)
Title: Re: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks
Post by: Crimson Wizard on Sun 04/03/2018 14:05:07
Quote from: bx83 on Sun 04/03/2018 10:17:53
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.
Title: Re: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks
Post by: morganw on Sun 04/03/2018 21:58:28
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).
Title: Re: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks
Post by: bx83 on Sun 04/03/2018 22:28:52
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..?
Title: Re: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks
Post by: Crimson Wizard on Sun 04/03/2018 22:42:31
Quote from: bx83 on Sun 04/03/2018 22:28:52
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.
Title: Re: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks
Post by: Gurok on Sun 04/03/2018 23:18:52
Quote from: Crimson Wizard on Sun 04/03/2018 22:42:31
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 :)
Title: Re: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks
Post by: bx83 on Mon 05/03/2018 02:19:43
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:


Room 'beach':
function room_Load () {
     songchan=aSong.PlayFrom(songPos, etc etc);
}

function room_RepExec () {
    songPos=songchan.Position;
}


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


function room_RepExec () {
    songPos=songchan.Position+1100;
}


to get them more in-sync.

Should I do this before I change room?


function leave_left
{
    songchan=songMuted.PlayFrom(songPos, ...);
    cChar.Changeroom(2,100,100);
}


???
Title: Re: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks
Post by: Crimson Wizard on Mon 05/03/2018 02:24:03
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 (ags) Select

function room_Load () {
     int songPos = 0;
     if (songchan != null) // if something is playing in the song channel, then take its position
         songPos = songchan.Position+1100;
     songchan=aSong.PlayFrom(songPos, etc etc);
}


Do I miss anything here?
Title: Re: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks
Post by: bx83 on Mon 05/03/2018 02:31:13
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.
Title: Re: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks
Post by: Crimson Wizard on Mon 05/03/2018 02:36:35
Quote from: bx83 on Mon 05/03/2018 02:31:13
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...
Title: Re: SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks
Post by: bx83 on Mon 05/03/2018 02:58:18
Lesson learned ;P
The code now works without gaps or catchup, flawlessly, done :D