예제 #1
0
	void FMODAudioListener::setVelocity(const Vector3& velocity)
	{
		AudioListener::setVelocity(velocity);

		FMOD::System* fmod = gFMODAudio()._getFMOD();
		FMOD_VECTOR value = { velocity.x, velocity.y, velocity.z };

		fmod->set3DListenerAttributes(mId, nullptr, &value, nullptr, nullptr);
	}
예제 #2
0
	void FMODAudioListener::setUp(const Vector3& up)
	{
		AudioListener::setUp(up);

		FMOD::System* fmod = gFMODAudio()._getFMOD();
		FMOD_VECTOR value = { up.x, up.y, up.z };

		fmod->set3DListenerAttributes(mId, nullptr, nullptr, nullptr, &value);
	}
예제 #3
0
	void FMODAudioListener::setDirection(const Vector3& direction)
	{
		AudioListener::setDirection(direction);

		FMOD::System* fmod = gFMODAudio()._getFMOD();
		FMOD_VECTOR value = { direction.x, direction.y, direction.z };

		fmod->set3DListenerAttributes(mId, nullptr, nullptr, &value, nullptr);
	}
예제 #4
0
	void FMODAudioListener::setPosition(const Vector3& position)
	{
		AudioListener::setPosition(position);

		FMOD::System* fmod = gFMODAudio()._getFMOD();
		FMOD_VECTOR value = { position.x, position.y, position.z };

		fmod->set3DListenerAttributes(mId, &value, nullptr, nullptr, nullptr);
	}
예제 #5
0
	void FMOD_System::Update( const float& posX, const float& posY, const float& posZ, 
		const float& forwardX, const float& forwardY, const float& forwardZ, 
		const float& ballPosX, const float& ballPosY, const float& ballPosZ )
	{
		FMOD_VECTOR position = { posX, posY, posZ };
		FMOD_VECTOR forward = { forwardX, forwardY, forwardZ };
		system->set3DListenerAttributes( 0, &position, nullptr, &forward, nullptr );
		ballPosition.x = ballPosX;
		ballPosition.y = ballPosY;
		ballPosition.z = ballPosZ;
		system->update();
	}
예제 #6
0
	void FMODAudioListener::rebuild(INT32 id)
	{
		mId = id;

		FMOD::System* fmod = gFMODAudio()._getFMOD();
		FMOD_VECTOR position = { mPosition.x, mPosition.y, mPosition.z };
		FMOD_VECTOR velocity = { mVelocity.x, mVelocity.y, mVelocity.z };
		FMOD_VECTOR forward = { mDirection.x, mDirection.y, mDirection.z };
		FMOD_VECTOR up = { mUp.x, mUp.y, mUp.z };

		fmod->set3DListenerAttributes(mId, &position, &velocity, &forward, &up);
	}
void FmodExMultiple3DSoundPlayerApp::update()
{
	
	
	//Update camera
	Vec3f camDirection = camCenter;
	camDirection.normalize();
	camEye = camInitialEye + camDistance * camDirection;
	cam.setViewDirection(camCenter);
	cam.setEyePoint(camEye);
	gl::setMatrices( cam );
	gl::rotate( sceneRotation );
	
	//Update 3D Sounds
	
	Vec3f up = cam.getWorldUp();
	up.invert();
	
	listenerUp.x = up.x;
	listenerUp.y = up.y; 
	listenerUp.z = up.z;
	listenerPos.x = camEye.x; 
	listenerPos.y = camEye.y;  
	listenerPos.z = camEye.z;
	//forward = camCenter - camEye;
	//forward.normalize();
	listenerForward.x = camCenter.x; 
	listenerForward.y = camCenter.y; 
	listenerForward.z = camCenter.z;
	sys->set3DListenerAttributes( 0, &listenerPos, &listenerVelocity, &listenerForward, &listenerUp);
	
	if(!player1.getIsPlaying())
		player1.play();
	
	if(!player2.getIsPlaying())
		player2.play();	
	
	player1.channel->set3DAttributes( &sound3DPosition1, &sound3DVelocity1);
	player2.channel->set3DAttributes( &sound3DPosition2, &sound3DVelocity2);
	
	//we update the fmod sound system
	sys->update();
	//FmodexUpdate();
	
}
예제 #8
0
파일: main.cpp 프로젝트: sethcoder/SDK
int main(int argc, char *argv[])
{
    FMOD::System    *system;
    FMOD::Sound     *sound1, *sound2, *sound3;
    FMOD::Channel   *channel1 = 0, *channel2 = 0, *channel3 = 0;
    FMOD_RESULT      result;
    int              key;
    bool             listenerflag = true;
    FMOD_VECTOR      listenerpos  = { 0.0f, 0.0f, -1.0f * DISTANCEFACTOR };
    unsigned int     version;

    printf("===============================================================\n");
    printf("3d Example.  Copyright (c) Firelight Technologies 2004-2005.\n");
    printf("===============================================================\n");
    printf("This example plays 2 3D sounds in hardware.  Optionally you can\n");
    printf("play a 2D hardware sound as well.\n");
    printf("===============================================================\n\n");

    /*
        Create a System object and initialize.
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);
    
    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }

    result = system->init(100, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);
    
    /*
        Set the distance units. (meters/feet etc).
    */
    result = system->set3DSettings(1.0, DISTANCEFACTOR, 1.0f);
    ERRCHECK(result);

    /*
        Load some sounds
    */
    result = system->createSound("../media/drumloop.wav", FMOD_HARDWARE | FMOD_3D, 0, &sound1);
    ERRCHECK(result);
    result = sound1->set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR);
    ERRCHECK(result);
    result = sound1->setMode(FMOD_LOOP_NORMAL);
    ERRCHECK(result);

    result = system->createSound("../media/jaguar.wav", FMOD_HARDWARE | FMOD_3D, 0, &sound2);
    ERRCHECK(result);
    result = sound2->set3DMinMaxDistance(2.0f * DISTANCEFACTOR, 10000.0f * DISTANCEFACTOR);
    ERRCHECK(result);
    result = sound2->setMode(FMOD_LOOP_NORMAL);
    ERRCHECK(result);

    result = system->createSound("../media/swish.wav", FMOD_HARDWARE | FMOD_2D, 0, &sound3);
    ERRCHECK(result);

    /*
        Play sounds at certain positions
    */
    {
        FMOD_VECTOR pos = { -10.0f * DISTANCEFACTOR, 0.0f, 0.0f };
        FMOD_VECTOR vel = {  0.0f, 0.0f, 0.0f };

        result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel1);
        ERRCHECK(result);
        result = channel1->set3DAttributes(&pos, &vel);
        ERRCHECK(result);
        result = channel1->setPaused(false);
        ERRCHECK(result);
    }

    {
        FMOD_VECTOR pos = { 15.0f * DISTANCEFACTOR, 0.0f, 0.0f };
        FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f };

        result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel2);
        ERRCHECK(result);
        result = channel2->set3DAttributes(&pos, &vel);
        ERRCHECK(result);
        result = channel2->setPaused(false);
        ERRCHECK(result);
    }

    /*
        Display help
    */
    {
        int num3d = 0, num2d = 0;

        result = system->getHardwareChannels(&num2d, &num3d, 0);
        ERRCHECK(result);
    
        printf("Hardware 2D channels : %d\n", num2d);
        printf("Hardware 3D channels : %d\n", num3d);
    }

    printf("=========================================================================\n");
    printf("Press 1        Pause/Unpause 16bit 3D sound at any time\n");
    printf("      2        Pause/Unpause 8bit 3D sound at any time\n");
    printf("      3        Play 16bit STEREO 2D sound at any time\n");
    printf("      <        Move listener left (in still mode)\n");
    printf("      >        Move listener right (in still mode)\n");
    printf("      SPACE    Stop/Start listener automatic movement\n");
    printf("      ESC      Quit\n");
    printf("=========================================================================\n");

    /*
        Main loop
    */
    do
    {
        if (kbhit())
        {
            key = getch();

            if (key == '1') 
            {
                bool paused;
                channel1->getPaused(&paused);
                channel1->setPaused(!paused);
            }

            if (key == '2') 
            {
                bool paused;
                channel2->getPaused(&paused);
                channel2->setPaused(!paused);
            }

            if (key == '3') 
            {
                result = system->playSound(FMOD_CHANNEL_FREE, sound3, false, &channel3);
                ERRCHECK(result);
            }

            if (key == ' ')
            {
                listenerflag = !listenerflag;
            }

            if (!listenerflag)
            {
                if (key == '<') 
                {
                    listenerpos.x -= 1.0f * DISTANCEFACTOR;
                    if (listenerpos.x < -35 * DISTANCEFACTOR)
                    {
                        listenerpos.x = -35 * DISTANCEFACTOR;
                    }
                }
                if (key == '>') 
                {
                    listenerpos.x += 1.0f * DISTANCEFACTOR;
                    if (listenerpos.x > 36 * DISTANCEFACTOR)
                    {
                        listenerpos.x = 36 * DISTANCEFACTOR;
                    }
                }
            }
        }

        // ==========================================================================================
        // UPDATE THE LISTENER
        // ==========================================================================================
        {
            static float t = 0;
            static FMOD_VECTOR lastpos = { 0.0f, 0.0f, 0.0f };
            FMOD_VECTOR forward        = { 0.0f, 0.0f, 1.0f };
            FMOD_VECTOR up             = { 0.0f, 1.0f, 0.0f };
            FMOD_VECTOR vel;

            if (listenerflag)
            {
                listenerpos.x = (float)sin(t * 0.05f) * 33.0f * DISTANCEFACTOR; // left right pingpong
            }

            // ********* NOTE ******* READ NEXT COMMENT!!!!!
            // vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
            vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME);
            vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME);
            vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME);

            // store pos for next time
            lastpos = listenerpos;

            result = system->set3DListenerAttributes(0, &listenerpos, &vel, &forward, &up);
            ERRCHECK(result);

            t += (30 * (1.0f / (float)INTERFACE_UPDATETIME));    // t is just a time value .. it increments in 30m/s steps in this example

            // print out a small visual display
            {
                char s[80];

                sprintf(s, "|.......................<1>......................<2>....................|");

                s[(int)(listenerpos.x / DISTANCEFACTOR) + 35] = 'L';
                printf("%s\r", s);
            }
        }

        system->update();

        Sleep(INTERFACE_UPDATETIME - 1);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = sound1->release();
    ERRCHECK(result);
    result = sound2->release();
    ERRCHECK(result);
    result = sound3->release();
    ERRCHECK(result);

    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}
예제 #9
0
int main(int argc, char *argv[])
{
    FMOD::System    *system;
    FMOD::Sound     *sound1, *sound2, *sound3;
    FMOD::Channel   *channel1 = 0, *channel2 = 0, *channel3 = 0;
    FMOD_RESULT      result;
    int              key, numdrivers;
    bool             listenerflag = true;
    FMOD_VECTOR      listenerpos  = { 0.0f, 0.0f, -1.0f * DISTANCEFACTOR };
    unsigned int     version;
    FMOD_SPEAKERMODE speakermode;
    FMOD_CAPS        caps;
    char             name[256];

    printf("===============================================================\n");
    printf("3d Example.  Copyright (c) Firelight Technologies 2004-2015.\n");
    printf("===============================================================\n");
    printf("This example plays 2 3D sounds in hardware.  Optionally you can\n");
    printf("play a 2D hardware sound as well.\n");
    printf("===============================================================\n\n");

    /*
        Create a System object and initialize.
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);
    
    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }
    
    result = system->getNumDrivers(&numdrivers);
    ERRCHECK(result);

    if (numdrivers == 0)
    {
        result = system->setOutput(FMOD_OUTPUTTYPE_NOSOUND);
        ERRCHECK(result);
    }
    else
    {
        result = system->getDriverCaps(0, &caps, 0, &speakermode);
        ERRCHECK(result);

        result = system->setSpeakerMode(speakermode);       /* Set the user selected speaker mode. */
        ERRCHECK(result);

        if (caps & FMOD_CAPS_HARDWARE_EMULATED)             /* The user has the 'Acceleration' slider set to off!  This is really bad for latency!. */
        {                                                   /* You might want to warn the user about this. */
            result = system->setDSPBufferSize(1024, 10);
            ERRCHECK(result);
        }

        result = system->getDriverInfo(0, name, 256, 0);
        ERRCHECK(result);

        if (strstr(name, "SigmaTel"))   /* Sigmatel sound devices crackle for some reason if the format is PCM 16bit.  PCM floating point output seems to solve it. */
        {
            result = system->setSoftwareFormat(48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0,0, FMOD_DSP_RESAMPLER_LINEAR);
            ERRCHECK(result);
        }
    }

    result = system->init(100, FMOD_INIT_NORMAL, 0);
    if (result == FMOD_ERR_OUTPUT_CREATEBUFFER)         /* Ok, the speaker mode selected isn't supported by this soundcard.  Switch it back to stereo... */
    {
        result = system->setSpeakerMode(FMOD_SPEAKERMODE_STEREO);
        ERRCHECK(result);
            
        result = system->init(100, FMOD_INIT_NORMAL, 0);/* ... and re-init. */
        ERRCHECK(result);
    }

    
    /*
        Set the distance units. (meters/feet etc).
    */
    result = system->set3DSettings(1.0, DISTANCEFACTOR, 1.0f);
    ERRCHECK(result);

    /*
        Load some sounds
    */
    result = system->createSound("../media/drumloop.wav", FMOD_3D, 0, &sound1);
    ERRCHECK(result);
    result = sound1->set3DMinMaxDistance(0.5f * DISTANCEFACTOR, 5000.0f * DISTANCEFACTOR);
    ERRCHECK(result);
    result = sound1->setMode(FMOD_LOOP_NORMAL);
    ERRCHECK(result);

    result = system->createSound("../media/jaguar.wav", FMOD_3D, 0, &sound2);
    ERRCHECK(result);
    result = sound2->set3DMinMaxDistance(0.5f * DISTANCEFACTOR, 5000.0f * DISTANCEFACTOR);
    ERRCHECK(result);
    result = sound2->setMode(FMOD_LOOP_NORMAL);
    ERRCHECK(result);

    result = system->createSound("../media/swish.wav", FMOD_SOFTWARE | FMOD_2D, 0, &sound3);
    ERRCHECK(result);

    /*
        Play sounds at certain positions
    */
    {
        FMOD_VECTOR pos = { -10.0f * DISTANCEFACTOR, 0.0f, 0.0f };
        FMOD_VECTOR vel = {  0.0f, 0.0f, 0.0f };

        result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel1);
        ERRCHECK(result);
        result = channel1->set3DAttributes(&pos, &vel);
        ERRCHECK(result);
        result = channel1->setPaused(false);
        ERRCHECK(result);
    }

    {
        FMOD_VECTOR pos = { 15.0f * DISTANCEFACTOR, 0.0f, 0.0f };
        FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f };

        result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel2);
        ERRCHECK(result);
        result = channel2->set3DAttributes(&pos, &vel);
        ERRCHECK(result);
        result = channel2->setPaused(false);
        ERRCHECK(result);
    }

    /*
        Display help
    */
    {
        int numchannels;

        result = system->getHardwareChannels(&numchannels);
        ERRCHECK(result);
    
        printf("Hardware channels : %d\n", numchannels);
    }

    printf("=========================================================================\n");
    printf("Press 1        Pause/Unpause 16bit 3D sound at any time\n");
    printf("      2        Pause/Unpause 8bit 3D sound at any time\n");
    printf("      3        Play 16bit STEREO 2D sound at any time\n");
    printf("      <        Move listener left (in still mode)\n");
    printf("      >        Move listener right (in still mode)\n");
    printf("      SPACE    Stop/Start listener automatic movement\n");
    printf("      ESC      Quit\n");
    printf("=========================================================================\n");

    /*
        Main loop
    */
    do
    {
        if (_kbhit())
        {
            key = _getch();

            if (key == '1') 
            {
                bool paused;
                channel1->getPaused(&paused);
                channel1->setPaused(!paused);
            }

            if (key == '2') 
            {
                bool paused;
                channel2->getPaused(&paused);
                channel2->setPaused(!paused);
            }

            if (key == '3') 
            {
                result = system->playSound(FMOD_CHANNEL_FREE, sound3, false, &channel3);
                ERRCHECK(result);
            }

            if (key == ' ')
            {
                listenerflag = !listenerflag;
            }

            if (!listenerflag)
            {
                if (key == '<') 
                {
                    listenerpos.x -= 1.0f * DISTANCEFACTOR;
                    if (listenerpos.x < -35 * DISTANCEFACTOR)
                    {
                        listenerpos.x = -35 * DISTANCEFACTOR;
                    }
                }
                if (key == '>') 
                {
                    listenerpos.x += 1.0f * DISTANCEFACTOR;
                    if (listenerpos.x > 36 * DISTANCEFACTOR)
                    {
                        listenerpos.x = 36 * DISTANCEFACTOR;
                    }
                }
            }
        }

        // ==========================================================================================
        // UPDATE THE LISTENER
        // ==========================================================================================
        {
            static float t = 0;
            static FMOD_VECTOR lastpos = { 0.0f, 0.0f, 0.0f };
            FMOD_VECTOR forward        = { 0.0f, 0.0f, 1.0f };
            FMOD_VECTOR up             = { 0.0f, 1.0f, 0.0f };
            FMOD_VECTOR vel;

            if (listenerflag)
            {
                listenerpos.x = (float)sin(t * 0.05f) * 33.0f * DISTANCEFACTOR; // left right pingpong
            }

            // ********* NOTE ******* READ NEXT COMMENT!!!!!
            // vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
            vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME);
            vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME);
            vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME);

            // store pos for next time
            lastpos = listenerpos;

            result = system->set3DListenerAttributes(0, &listenerpos, &vel, &forward, &up);
            ERRCHECK(result);

            t += (30 * (1.0f / (float)INTERFACE_UPDATETIME));    // t is just a time value .. it increments in 30m/s steps in this example

            // print out a small visual display
            {
                char s[80];

                sprintf(s, "|.......................<1>......................<2>....................|");

                s[(int)(listenerpos.x / DISTANCEFACTOR) + 35] = 'L';
                printf("%s\r", s);
            }
        }

        system->update();

        Sleep(INTERFACE_UPDATETIME - 1);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = sound1->release();
    ERRCHECK(result);
    result = sound2->release();
    ERRCHECK(result);
    result = sound3->release();
    ERRCHECK(result);

    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}