Author Topic: Complicated audio question  (Read 725 times)


  • Rottwheelers
  • Posts: 1,165
    • I can help with story design
Complicated audio question
« on: 07 Apr 2012, 01:20 »
I tried to figure out a more descriptive title for this thread, but it kept being too long to be functional. Apologies for the vagueness.

Two questions:

1. I'm in the process of trying to design my game, and am wondering how difficult it would be to utilize audio that is:

  • Pulled from a random pool of OGG files,
  • Played at random times, provided no other sounds are playing,
  • Played only in certain rooms,
  • And with a pool that can grow or contract according to player action (using boolean variables).

I believe from looking through the manual that I could figure out how to do most of these individually, but might perhaps run into trouble trying to write a stack of code that meets all of the above qualifications. I don't need the code yet, as I'm still just figuring out the design document. All I need to know now is, is this feasible, and how difficult would it be to pull off?

If it proves too difficult, now is the time to figure out alternatives. I'm trying to save myself some headache in advance. I've left the above purposefully generic. If you need further clarification on how I intend to use this in-game, see below:

Spoiler: ShowHide

My game is set aboard what is essentially a docked ship. The PC can roam the ship and the port where it's docked. I'm looking to implement an onboard announcement system (thus the limit to only certain rooms, those on the ship), that would provide ambiance, hints (e.g. "A reminder to all personnel that _required_item_ can be found in the bursar's office." -- I'd want to remove these once that task was completed), and feedback for player actions ("Would all crewmembers please refrain from setting passengers on fire?" -- I'd want to add these according to player actions: e.g. if (SetPassengerOnFire == true)).

The random, continual nature of the announcements would, as I said, add to the ambiance, but would also allow me to seamlessly introduce specific announcements at specific times without the break in immersion that a sudden playing of audio might cause.

I still don't feel as though I'm explaining this very well. Let me know if you kind folk need clarification.

2. Could I save some file space in the compiled game by reducing the bitrate of OGG files that purposefully sound lo-fi, and will mixed bitrates cause any problems in AGS?

I feel as though based on past experience, I should thank Khris in advance, but anyone who has thoughts or advice, feel free to respond.


  • Posts: 14
Re: Complicated audio question
« Reply #1 on: 07 Apr 2012, 11:15 »
Actually not impossibly hard to do. You will need to work with loads of variables, as you already found out yourself, you will need to add checks against tehse variables in your code to see if some announcement has become invalid, i.e. your passengeronfire=true.
Also you'd need to check against the current room of the player if you wanna use that information to direct playback as well. I would not put too much work into the logic to "only play when no other sound is playing". Just give it a channel with low piority and you should be fine. If you hear character footsteps while the announcement is playing i'd think it only adds to the realism. In the end the work depends a bit on how many announcements and variables you use, but with like 20 of them i still think you could be done in an hour or 2, most work will just be writing down all if....then conditions for all variables.

Mixed bitrates are no problem for AGS and while i already learned from khris that the image size does not affect game size i believe that the ogg files do matter.

Calin Leafshade

  • Posts: 3,514
  • Long live King Cat!
    • I can help with making music
    • I can help with voice acting
    • Calin Leafshade worked on a game that won an AGS Award!
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
Re: Complicated audio question
« Reply #2 on: 07 Apr 2012, 13:16 »
ok, if I'm understanding correctly you want something like this:

*code done without AGS, may be syntax errors.
Code: Adventure Game Studio
  2. AudioClip *pool[100]; // The number of audio clips but i dont think AGS provides that number to you but any number > is fine.
  3. int clipCount = 0;
  5. bool ContainsClip(*AudioClip clip)
  6. {
  7.   int i;
  8.   while (i < clipCount)
  9.   {
  10.      if (pool[i] == clip ) return true;
  11.      i++;
  12.   }
  13.   return false
  14. }
  16. void AddClip(*AudioClip clip)
  17. {
  18.   if (!ContainsClip(clip))
  19.   {
  20.     pool[clipCount] = clip;
  21.     clipCount ++;
  22.    }
  23. }
  25. void RandomlyPlayClip()
  26. {
  27.    int i = Random(clipCount - 1); // is Random() inclusive? i cant remember.
  28.    pool[i].Play();
  29. }

Call AddClip to add a clip to the pool. It wont add duplicates.

Then you just call RandomlyPlayClip() everytime you want a random clip from the pool


  • Rottwheelers
  • Posts: 1,165
    • I can help with story design
Re: Complicated audio question
« Reply #3 on: 07 Apr 2012, 23:57 »
I think that should get me at least part of the way there, Calin, and definitely helps me get a better hold on the syntax needed to get this done. Thanks!

And thanks for your advice too, kyodai. I always forget about audio channels. I definitely want the ambient sounds to play alongside this. I just don't want it going off in the middle of a round of dialogue or something!