Getting true music position in ms and questions

Started by eri0o, Tue 19/12/2017 23:15:23

Previous topic - Next topic

eri0o

I noticed the music position in ms is not updated every frame. Is this intentional?

I came up with the following code to fix this, where actualACMusMs has the true music position:

Code: ags

AudioChannel *acMusic;

//fix to report correct music position, game in 60fps
int frame;
int acMusPreviousMs;
bool startedRepeat;
int frameWhenRepeatingStarted;
int actualACMusMs;

void playMusic(AudioClip * musicClip){ 
  acMusic = musicClip.Play(eAudioPriorityHigh, eRepeat);
}


void repeatedly_execute_always(){
  if(IsGamePaused()==1 || acMusic==null){
    return;  
  }

  frame++;
  
  if(acMusic.PositionMs==acMusPreviousMs){
    if(!startedRepeat){
      frameWhenRepeatingStarted=frame-1;
    }
    startedRepeat=true;
    actualACMusMs = acMusPreviousMs+(frame-frameWhenRepeatingStarted)*16;
  } else {
    startedRepeat=false;
    actualACMusMs= acMusic.PositionMs;
  }
  
  acMusPreviousMs = acMusic.PositionMs;
}


I did this because I am experimenting with some music in my game that is active, like, I switch music depending on changes on the environment, and needed to correctly position the music when switching.

Also, imagine a graph:

(music 1)--->>(music 2)<< loop music 2 forever

How would you detect music 1 has ended and you need to proceed to music 2? Also if I have crossfade activated, how should I force crossfade to not happen then?

eri0o

Whoa! PlayQueued is a nice command! Thanks! :D

Crimson Wizard

To be fair, PlayQueued queue sound only if there is 1 channel reserved for that audio type, otherwise it will start immediately. IDK what's your current setup is, depending on it this function may be useful or not.

I've got an impression that it was not intentionally designed for the described scenario, but rather for scenario where sound must play either immediately or after previous (presumably short) sound has finished.

Snarky

Quote from: eri0o on Tue 19/12/2017 23:15:23
if I have crossfade activated, how should I force crossfade to not happen then?

Code: ags
SetGameOption(OPT_CROSSFADEMUSIC, 0);

eri0o

Nice one! Thanks Snarky!

Hey Crimson Wizard! Yeah, I am constantly going back and forward with using two channels and custom crossfade and a single channel with in engine crossfade. Also I think I may have a small hitch in my loop, I am not sure if it's from the music file or the engine yet... :/

SMF spam blocked by CleanTalk