Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Candall on Tue 05/09/2006 04:00:38

Title: Starfox style speech?
Post by: Candall on Tue 05/09/2006 04:00:38
Heya... I'm making a game which features robotic characters, and I'd very much like to handle their speech by using text while random mechanical-sounding syllables play in the background.  Is this possible?  I've tried the following...


//Repeatedly Execute Always function
function repeatedly_execute_always()
{
  while (cThirtysix.Speaking)
  {
   PlaySound(Random(2)+12);
  }
}


...to no avail.  I even tried commenting out everything but the PlaySound command, and that actually worked... so I suspect that there's something I don't understand about the .Speaking deal.  Can anyone help me out?
Title: Re: Starfox style speech?
Post by: Kweepa on Tue 05/09/2006 04:35:01
Great idea. I loved it in Banjo Kazooie too!
Writing

while (cX.Speaking) ...

In rep_ex_always is a bad idea, because if Speaking is true, this loop will never terminate. Also, the PlaySound function will be called over and over.
Instead, you should use PlaySoundEx to play the syllables on a specific channel, then in rep_ex_always, wait for the channel to be free before playing the next random syllable. Like this:

#define SYLLABLE_CHANNEL 3
function repeatedly_execute_always()
{
  if (cThirtysix.Speaking && !IsChannelPlaying(SYLLABLE_CHANNEL))
  {
    PlaySoundEx(Random(2)+12, SYLLABLE_CHANNEL);
  }
}
Title: Re: Starfox style speech?
Post by: Candall on Tue 05/09/2006 04:39:35
Thank you!

I figured out that it wasn't working at all because my character does not have a speaking view (no mouth, heheh). 

However, after I added one (just use the regular view), this caused a rapid-fire speech bonanza which resulted in a lockup.  I was expecting the rapid-fire speech, but the lockup put me off.  I'll try your code and let you know if it works ;D

EDIT:
You're quite the life-saver!  So the lockup was caused by my use of "while" instead of "if," you say?  I'll remember that.

Your code worked beautifully.  I really appreciate it.  Now I can whip up a syllable-speech module and I'll be good to go :D

EDIT 2:
This is probably asking way too much... but is it possible to somehow blend the syllables together?  It sounds cool the way it is, but it's really... choppy.  It doesn't sound like nonsense speech, it just sounds like a sequence of syllables with a slight gap... and I think the gap is the problem.  I don't see any controls in AGS for filtering sound, though.  And a little reverb would be perfect.
Title: Re: Starfox style speech?
Post by: monkey0506 on Tue 05/09/2006 08:03:34
I'm not entirely sure about what you're asking for, however, it might be better if you edited your posts instead of triple posting. Across the top of each of your posts there is a link that says "Modify". You should use this to edit your posts as double- and triple-posting is against the rules.

Of course I'm not a moderator so I really don't have the right to tell you how to act, but at least this time I tried to be more polite than last time (the mods will understand this) ;)
Title: Re: Starfox style speech?
Post by: Candall on Tue 05/09/2006 08:10:50
To my knowlege, "n-posting" is the act of posting the same info multiple times, not different thoughts.  If it bugs people, however, I won't do it, as I already know about the "Modify" button.
Title: Re: Starfox style speech?
Post by: Ashen on Tue 05/09/2006 11:27:16
n-posting CAN be posting the same thing multiple times, but it can also be making multiple responses in the same thread, without leaving a resonable gap (at least a day). Neither of these are 'acceptable' behaviour on the AGS forums, so in future - please don't do them.
It's in the READ BEFORE POSTING thread, but I appreciate it could be worded a little more clearly:

• Do not post multiple replies. This is what the "Modify" option is for. Only unregistered users are exempt from this rule, because they cannot modify any posts -- not even their own.
• Don't double-post! This means posting the same topic twice in different forums. This is annoying, wasteful, and you'll get hell for doing it. Again, CJ pays for the bandwidth of this site. Don't waste his money. Or our time.

EDIT: Changed the wording in READ BEFORE POSTING thread - hopefully it's clearer now.

EDIT 2: And to attempt to answer your latest question:
There's the 'Crosfade music tracks' option, setable on the General Settings page, and with SetGameOption. I think this might only work for sounds started by PLayMusic, but if you haven't tried it, it might be worth a go. AFAIK, there's no way to add reverb in AGS - unless someone has made / is willing to make a plugin (and I still don't know if it's even possible, sorry).
Title: Re: Starfox style speech?
Post by: Kweepa on Wed 06/09/2006 01:20:50
Quote from: Candall on Tue 05/09/2006 04:39:35
This is probably asking way too much... but is it possible to somehow blend the syllables together?  It sounds cool the way it is, but it's really... choppy.  It doesn't sound like nonsense speech, it just sounds like a sequence of syllables with a slight gap... and I think the gap is the problem.  I don't see any controls in AGS for filtering sound, though.  And a little reverb would be perfect.
To overlap the syllables, you'd probably have to make them all approximately the same length, then play them on alternating channels (eg 3 and 4). Here's how I'd do it:

#define SYLLABLE_CHANNEL_1 3
#define SYLLABLE_CHANNEL_2 4
float kSyllableLength = 0.2; // seconds, slightly less than the actual syllable length to overlap
float sSyllableTimer = 0.0;
int sNextSyllableChannel = SYLLABLE_CHANNEL_1;
function repeatedly_execute_always()
{
  if (cX.Speaking)
  {
    sSyllableTimer = sSyllableTimer - (1.0/IntToFloat(GetGameSpeed()));
    if (sSyllableTimer < 0.0)
    {
      PlaySoundEx(Random(2)+12, sNextSyllableChannel);
      sNextSyllableChannel = SYLLABLE_CHANNEL_1 + (SYLLABLE_CHANNEL_2 - sNextSyllableChannel); // toggle
      sSyllableTimer = kSyllableLength;
    }
  }
  else
  {
    sSyllableTimer = 0.0;
  }
}

Hmm, this is getting to the point where I should be checking this works in AGS before posting, but what the heck.
For the reverb, it's probably better to just apply that to each sample in an external editor.
Title: Re: Starfox style speech?
Post by: Candall on Wed 06/09/2006 02:37:17
It... it WORKED!  Wow, I was really worried that it wouldn't because my syllables are EXTREMELY short... just over a tenth of a second.  This really made it sound like complete words instead of disjointed syllables.  You're quite the genius!
Title: Re: Starfox style speech?
Post by: Kweepa on Wed 06/09/2006 02:59:46
Looking forward to the game... :=
Title: Re: Starfox style speech?
Post by: Candall on Wed 06/09/2006 03:04:59
Hehe, me too... there's still much work to be done :)