Game Development Community

AlxCreateSource returns invalid handle?

by Jari · in Torque Game Engine · 06/27/2006 (7:40 am) · 6 replies

Hi I'm using script like this to play audio files:

%resourcehandle = alxCreateSource(AudioMessage, %filename);

%soundHandle = alxPlay(%resourcehandle);

That works but if I want to get some info about the playing file nothing seems to work:
(I hope this code works because I had to modify it a bit after copying and pasting)

%st1 = alxGetStreamDuration(%soundHandle);
%st2 = alxGetStreamDuration(%resourcehandle);

echo(%soundHandle SPC %st1 SPC %st2); // should print print: "1 -1 -1"

Debugging lead to this function in the engine:

F32 alxGetStreamDuration( AUDIOHANDLE handle )
{
   StreamingList::iterator itr = mStreamingList.findImage(handle);
   if( !itr )
      return -1.f; // returns from here when debugging while handle was "1"

   return (*itr)->getTotalTime();
}

See, the handle seems to be invalid... is this a bug or am I just using the handles in wrong way?

I hope this report/question was clear!

Jari.

#1
06/27/2006 (8:21 am)
Your title says AlxCreateSource returns invalid handle, and then at the top of your post you're saying that alxCreateSource and alxPlay work as intended. Which is correct?

Anyway, alxGetStreamDuration never worked for me, and always returned -1 eventho the handle existed. Probably another bug.
#2
06/27/2006 (1:16 pm)
Good point Stefan, sorry about the confusing title, what I meant by it was that the handle returned by AlxCreateSource is valid only for alxPlay but not for alxGetStreamDuration and some others.
#3
06/27/2006 (1:18 pm)
You sure the other functions are working correctly? A quick glance over them it seems like they use and grab the handle in the same way AlxPlay does.

I assumed alxGetStreamDuration was broken. What other functions are having this problem?
#4
06/27/2006 (1:19 pm)
Looks like I just found the reason the handle wasn't "good enough" for the alxGetStreamDuration(), because it needed to be "streaming".

So the AudioDescription needs to look like this:

new AudioDescription(AudioSoundPlayer)
{
   volume   = 1.0;
   isLooping= false;
   is3D     = false;
   type     = $MessageAudioType;
  isStreaming = true; // this was required
};
#5
06/27/2006 (1:38 pm)
Good point :) Hopefully there's no nasty side effects.
#6
06/27/2006 (6:52 pm)
There is in fact side effects, the sound is left looping, but not in a way as normal loop but the "last buffer" is left looping creating a noise (As far as I know the audio stream is in pieces (buffers) so that's why I said "last buffer").
And if I stop the audio stream after the stream position is over it's total duration then no sound can be heard at all on short audio's. This problem does not happen with longer streams though.