Exemple #1
0
void AudioController::update(float elapsedTime)
{
    AudioListener* listener = AudioListener::getInstance();
    if (listener)
    {
        AL_CHECK( alListenerf(AL_GAIN, listener->getGain()) );
        AL_CHECK( alListenerfv(AL_ORIENTATION, (ALfloat*)listener->getOrientation()) );
        AL_CHECK( alListenerfv(AL_VELOCITY, (ALfloat*)&listener->getVelocity()) );
        AL_CHECK( alListenerfv(AL_POSITION, (ALfloat*)&listener->getPosition()) );
    }
}
void Audio3DTest::drawDebugText(int x, int y)
{
    _font->start();
    static const int V_SPACE = 16;
    AudioListener* audioListener = AudioListener::getInstance();
    drawVector3("Listener Position", audioListener->getPosition(), x, y);
    drawVector3("Listener Forward", audioListener->getOrientationForward(), x, y+=V_SPACE);
    drawVector3("Listener Up", audioListener->getOrientationUp(), x, y+=V_SPACE);
    drawVector3("Listener Velocity", audioListener->getVelocity(), x, y+=V_SPACE);
    _font->finish();
}
Exemple #3
0
void AudioController::update(long elapsedTime)
{
    AudioListener* listener = AudioListener::getInstance();
    if (listener)
    {
#ifndef __ANDROID__
        alListenerf(AL_GAIN, listener->getGain());
        alListenerfv(AL_ORIENTATION, (ALfloat*)listener->getOrientation());
        alListenerfv(AL_VELOCITY, (ALfloat*)&listener->getVelocity());
        alListenerfv(AL_POSITION, (ALfloat*)&listener->getPosition());
#else
        if (!_listenerObject)
        {
            const SLInterfaceID interfaces[3] = {SL_IID_3DDOPPLER, SL_IID_3DLOCATION};
            const SLboolean required[3] = {SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE};
            SLresult result = (*_engineEngine)->CreateListener(_engineEngine, &_listenerObject, 2, interfaces, required);
            if (result != SL_RESULT_SUCCESS)
            {
                WARN_VARG("AudioController: failed to create listener (%u).", result);
                return;
            }

            result = (*_listenerObject)->Realize(_listenerObject, SL_BOOLEAN_FALSE);
            if (result != SL_RESULT_SUCCESS)
            {
                WARN("AudioController: failed to realize listener.");
                return;
            }

            // Get the doppler interface in order to set the listener's velocity.
            result = (*_listenerObject)->GetInterface(_listenerObject, SL_IID_3DDOPPLER, &_listenerDoppler);
            if (result != SL_RESULT_SUCCESS)
            {
                WARN("AudioController: Unable to retrieve listener doppler interface.");
                return;
            }

            // Get the location interface in order to set the listener's position and orientation.
            result = (*_listenerObject)->GetInterface(_listenerObject, SL_IID_3DLOCATION, &_listenerLocation);
            if (result != SL_RESULT_SUCCESS)
            {
                WARN("AudioController: Unable to retrieve listener location interface.");
                return;
            }
        }
        
        SLVec3D f;
        f.x = listener->getOrientationForward().x;
        f.y = listener->getOrientationForward().y;
        f.z = listener->getOrientationForward().z;
        SLVec3D a;
        a.x = listener->getOrientationUp().x;
        a.y = listener->getOrientationUp().y;
        a.z = listener->getOrientationUp().z;
        SLresult result = (*_listenerLocation)->SetOrientationVectors(_listenerLocation, &f, &a);
        if (result != SL_RESULT_SUCCESS)
        {
            WARN("AudioController: Unable to set listener orientation.");
        }

        SLVec3D p;
        p.x = listener->getPosition().x;
        p.y = listener->getPosition().y;
        p.z = listener->getPosition().z;
        result = (*_listenerLocation)->SetLocationCartesian(_listenerLocation, &p);
        if (result != SL_RESULT_SUCCESS)
        {
            WARN("AudioController: Unable to set listener location.");
        }

        SLVec3D v;
        v.x = listener->getVelocity().x;
        v.y = listener->getVelocity().y;
        v.z = listener->getVelocity().z;
        result = (*_listenerDoppler)->SetVelocityCartesian(_listenerDoppler, &v);
        if (result != SL_RESULT_SUCCESS)
        {
            WARN("AudioController: Unable to set listener velocity.");
        }
#endif
    }
}