SOLVED Setting Audio->Type->Music->MaxChannels to 1 just stops new music tracks

Started by bx83, Sun 04/03/2018 00:59:59

Previous topic - Next topic

bx83

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

BEACH room:
Code: ags

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)
Code: ags

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?

bx83

Another interesting thing:

When I do this, music and sound player:
Code: ags

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:
Code: ags

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.

bx83

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

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

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

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

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

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

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.

morganw

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

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

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.

Gurok

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 :)
[img]http://7d4iqnx.gif;rWRLUuw.gi

bx83

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: ags

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:

Code: ags

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


to get them more in-sync.

Should I do this before I change room?

Code: ags

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


???

Crimson Wizard

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

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?

bx83

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

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

bx83

Lesson learned ;P
The code now works without gaps or catchup, flawlessly, done :D

SMF spam blocked by CleanTalk