Page 1 of 1

IrrKlang and/or time help [H E L P!]

Posted: Tue Apr 07, 2009 9:50 am
by Systemerror
Hey guys,

I think the best way to ask my question is to explain what I want to do, well - what I want is to create an introduction to the client about who developed the game before going to the main menu - for instance, creating a static image with the company logo, playing a sound effect and then going to the main menu.

The way I tried to approach this was to render the image, play the required sound, and then test a condition to see if the sound is playing/finished is methods to as (ISoundSource) as a param etc, but it doesn't seem to work correctly, I've managed to use the IsCurrentlyPlaying functions correctly, and isFinished, it compiled fine and all arguments are correct, but only the first condition works in the correctly set up if/else conditional statements, I've tried a few ways to test if the engine is/is not playing a specified sound but to no avail, I have looked through the IrrKlang API documentation and it appears what I am doing is correct, and debugging confirms this - can someone shed some light on this and some code would be nice.

Lastly, I tried to think of a different approach, that was, to chech if a certain amount of seconds has passed, then to perform the required task - I also looked this up in the API doc's but could not find a definitive method to do this, thus, some help there would be nice too :P

Posted: Wed Apr 22, 2009 9:05 am
by Systemerror
I really need help with this, *bump.

Posted: Wed Apr 22, 2009 12:11 pm
by hybrid
You can use the Irrlicht timer to check the time already used. For irrKlang please ask in their forum (therefore also moving too game programming forum).

Posted: Wed Apr 22, 2009 12:35 pm
by Systemerror
hybrid wrote:You can use the Irrlicht timer to check the time already used. For irrKlang please ask in their forum (therefore also moving too game programming forum).

Ok, like a time elapsed function... can you give a code example, I can't look through the documentation until tommorow as I'm not on my box.

The example structure being:

if time passed (in milliseconds I imagine so 5 nano seconds is 5000 milliseconds I believe)

//do something/show logo
else
//do something else

Posted: Wed Apr 22, 2009 12:52 pm
by Sylence
Systemerror wrote:5 nano seconds is 5000 milliseconds I believe
1 nano second is 0.000001 milliseconds.

See http://en.wikipedia.org/wiki/SI_prefix

Posted: Wed Apr 22, 2009 2:43 pm
by xDan
um...

ITimer *timer = device->getTimer();

u32 startTime = timer->getTime();

while (timer->getTime() - startTime < 5000) // wait 5 seconds
{
logoRenderUpdate();
}
//continue


it really depends on how *you* implement your main loop though

Posted: Wed Apr 22, 2009 3:24 pm
by Systemerror
Sylence wrote:
Systemerror wrote:5 nano seconds is 5000 milliseconds I believe
1 nano second is 0.000001 milliseconds.

See http://en.wikipedia.org/wiki/SI_prefix

Yeah it's 1 "standard second" to 1,000 "milliseconds", I don't know why I said nano second.

um...
ITimer *timer = device->getTimer();

u32 startTime = timer->getTime();

while (timer->getTime() - startTime < 5000) // wait 5 seconds
{
logoRenderUpdate();
}
//continue

Great that cheers, I couldn't get to the API docs :(

Posted: Thu Apr 23, 2009 4:51 pm
by Systemerror
Oh did anyone manage to find a definitive way to check when an audio track has finished playing? as I said I believe I was doing it correctly as I followed the API docs and it compiled fine also but to no avail.

Posted: Thu Apr 23, 2009 8:39 pm
by pc0de
Have a look at irrklang::ISoundStopEventReceiver. In the section of code that checks if the sound is done playing, you can check a flag that is set by the event handler:

Code: Select all

 
 bool sndIsDone=false;
 irrklang::ISound* snd;

 class MySoundEndReceiver : public irrklang::ISoundStopEventReceiver
 {
   public:
     virtual void OnSoundStopped (irrklang::ISound* sound, irrklang::E_STOP_EVENT_CAUSE reason, void* userData)
     {
        // called when the sound has ended playing
        if(userData == snd)
        {
            sndIsDone = true;
            printf("sound has ended");
        }
     }
 }

 // ...

 MySoundEndReceiver* myReceiver = new MySoundEndReceiver();
 snd = engine->play2D("speech.mp3", false, false, true); 
 if (snd)
    snd->setSoundStopEventReceiver(myReceiver, snd);

 // render loop 
 while(Device->run())
 {
     if(sndIsDone)
     {
         // proceed to menu state
     }
 }

im working on a dialog type

Posted: Thu Apr 23, 2009 8:41 pm
by moekkog
im doing a type of dialog playing sounds in times that i want if you are interested i can tell you more just tell me if you are interested