Beginnings of an iMuse type audio system

Started by Phemar, Sat 20/04/2013 13:47:43

Previous topic - Next topic

Phemar

So I got interested in designing an iMuse type dynamic music system for a project. So far I've got the timing correct but there's just a few things I'm worried about.

Here's my code so far (still early testing):

Global Header:
Code: ags
struct iMuse {
  AudioChannel *room;
  import static function Jump (int dest);
};

iMuse room1;


Global Script:
Code: ags
static function iMuse::Jump (int dest) {
  if (room1.room == null) {       //audio is null, so don't continue
    Display("Audio is null");
    return;
  }
  else {
    while (((dest + 170) - room1.room.PositionMs) > 0) Wait(1); //wait until audio reaches it's switch point (plus 170 for timing)
    room1.room.Stop ();
    room1.room = a2.Play ();          //play new sound
  }
}

function game_start() {          //  Play the first sound
  room1.room = a1.Play(eOnce);
}


Room Script:
Code: AGS
function oObject_AnyClick() {
  iMuse.Jump (5000);
}


There's two audio files, each 5 seconds (5000 ms) long. When the game begins, a1 is played, and when the character interacts with an object, the script waits till a1 has reached 5000ms (plus 170, I found that's the delay AGS needs to time things up correctly), then stops a1 and plays a2.

Now, the first problem I have is that this script is blocking - I just don't know how to use it without the Wait(1); command. I tried Timers, but they never time out correctly.

The second problem is that in iMuse.Jump, I've specified that a2 is the next audio file it needs to play. However, I wish the audio file to be specified within one of the arguments to iMuse.Jump. I'm not entirely sure how to do that.

Thirdly, the other problem I have is that a1 needs to played from the global script otherwise iMuse.Jump returns "Audio is Null." I currently have a1 being played in game_start, however I would like to play it from a room script.

Any help? Is what I'm attempting to do even possible? This is just the beginning test. Once I get the kinks sorted out I can create multiple bookmarks on audio files (at the end of phrases etc) so that they can switch anywhere at those bookmarks, and hopefully non-blocking as well.

Thanks for any help!

RickJ

Phemar,

The while loop isn't going to accomplish what you want.  You will need to use repeatedly_execute to poll the progress of a1 each game cycle instead of using while and wait.  The result is that one iteration of your loop is executed each game cycle.

It looks like your is within a context of a module already ... if so you and add repeatedly execute handler to the module.  Hope this helps.


SMF spam blocked by CleanTalk