コード例 #1
0
DWORD FmodSoundEngine::PlayMusic(string filename, CHANNEL Ichannel, bool loop, float volume)
{
	if(Ichannel<0||Ichannel>=maxChannel)
	{
		Ichannel = GetNewChannel();
		if(Ichannel<0)
		{
			PlaySound(filename,volume);
			return NULL;
		}
	}
	nowChannel = max(nowChannel,Ichannel+1);
	FMOD::Sound *sound = (FMOD::Sound*)ReadMusic(Ansi2UTF8(filename).data());
	FMOD::Channel **channel = (FMOD::Channel**)this->channel;

	if(loop)
	{
		result = sound->setMode(FMOD_LOOP_NORMAL);
		//ERRCHECK(result);
	}
	result = system->playSound(sound, NULL, true, &channel[Ichannel]);
	//ERRCHECK(result);
	volumeDes[Ichannel] = volume*defaultVolume;
	result = channel[Ichannel]->setVolume(volumeDes[Ichannel]);
	//ERRCHECK(result);

	result = channel[Ichannel]->setPaused(false);
	//ERRCHECK(result);
	return (DWORD)sound;
}
コード例 #2
0
ファイル: SoundManager.cpp プロジェクト: thoney/MIRAGEvisApp
SkySound SoundManager::play3DSound(std::string name, float volume, float x, float y, float z, bool echo, bool loop, float fallOffStart)
{
if(mSilent) return NULL;
	
	if ("" == name)
		return false;
	if(mInitFailed) return NULL;
	FMOD::Sound* sound = 0;
	FMOD::Channel* soundChannel;
	result = mSystem->createSound(name.c_str(), FMOD_SOFTWARE | FMOD_3D, 0, &sound); 
	
	if (!sound)
	{
		printf("FMOD Error loading %s!\n", name.c_str());
		checkErrors();
		return NULL;
	}
	sound->set3DMinMaxDistance(fallOffStart, 2000);
	sound->setMode(loop ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
	mSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &soundChannel);
//	if(echo)
	//	soundChannel->addDSP(mReverb);


	FMOD_VECTOR pos = {x, y, z};
	FMOD_VECTOR vel = {0, 0, 0};
	soundChannel->setVolume(volume);
	soundChannel->set3DAttributes(&pos, &vel);

	mSystem->update();
//	printf("finished play3dsound\n");
	return soundChannel;
}
コード例 #3
0
ファイル: AudioManager.cpp プロジェクト: AlwaysGeeky/Vox
FMOD::Sound* AudioManager::PlaySound2D(FMOD::Channel** pChannel, const char* filename, bool looping, bool stream)
{
    if (m_audioEnabled)
    {
        FMOD::Sound* sound;
        *pChannel = NULL;
        FMOD::ChannelGroup *channelGroup = NULL;

        if (stream)
        {
            m_FMODResult = m_FMODSystem->createStream(filename, FMOD_DEFAULT | FMOD_2D, 0, &sound);
        }
        else
        {
            m_FMODResult = m_FMODSystem->createSound(filename, FMOD_DEFAULT | FMOD_2D, 0, &sound);
        }
        ERRCHECK(m_FMODResult);

        m_FMODResult = sound->setMode(looping == true ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
        ERRCHECK(m_FMODResult);

        m_FMODResult = m_FMODSystem->playSound(sound, channelGroup, false, pChannel);
        ERRCHECK(m_FMODResult);

        return sound;
    }

    return NULL;
}
コード例 #4
0
void _TBOX_PREFIX_App::setup()
{
    FMOD::System_Create( &mSystem );
    mSystem->init( 32, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, NULL );

    mSystem->createSound( getAssetPath( "Blank__Kytt_-_08_-_RSPN.mp3" ).string().c_str(), FMOD_SOFTWARE, NULL, &mSound );
	mSound->setMode( FMOD_LOOP_NORMAL );

	mSystem->playSound( FMOD_CHANNEL_FREE, mSound, false, &mChannel );
}
コード例 #5
0
ファイル: AudioClass.cpp プロジェクト: denghc/danmugame
void AudioClass::InitializeResource()
{
	FMOD_RESULT result;
	FMOD::Sound* snd;
	
	result = m_system->createSound("Resource\\explode.wav", FMOD_HARDWARE, 0, &snd);
	ERRCHECK(result);
	snd->setMode(FMOD_LOOP_OFF);
	SoundClass* sc = new SoundClass();
	sc->Initialize(snd, "explode");
	m_soundList.push_back(sc);

	

}
コード例 #6
0
ファイル: KSoundManager.cpp プロジェクト: allegrocm/Falcon
SkySound* KSoundManager::playSound(std::string name, float volume, float stereo, bool loop)
{
	if(mSilent) return NULL;
	if ("" == name) return NULL;
	
	FMOD::Sound* sound;
	result = mSystem->createSound(name.c_str(), FMOD_SOFTWARE | FMOD_2D, 0, &sound); 
	checkErrors();
	if(!sound) printf("Error playing %s\n", name.c_str());
	if (!sound) return NULL;

	FMOD::Channel* soundChannel;
	sound->setMode(loop ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
	mSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &soundChannel);
	soundChannel->setPan(stereo);
	soundChannel->setVolume(volume);
	mSystem->update();
	return soundChannel;
}
コード例 #7
0
ファイル: Sound.cpp プロジェクト: mcmonkey/cglory
//A method to play background music. The music will loop continually, and only one song can be played
//at a time
void SoundManager::loopMusic(const char* filePath)
{
	if(!initialized)
	{
		FMOD::System_Create(&system);
		system->init(100, FMOD_INIT_NORMAL, 0);
		initialized = true;
	}

	if(backgroundPlaying)
	{
		//Stop the background before starting the new song
		stopMusic();
	}
	FMOD::Sound *sound;
	FMOD_RESULT result = system->createStream(filePath, FMOD_DEFAULT, 0, &sound);
	sound->setMode(FMOD_LOOP_NORMAL);
	result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &bgMusic);
	backgroundPlaying = true;
}
コード例 #8
0
ファイル: AudioManager.cpp プロジェクト: AlwaysGeeky/Vox
FMOD::Sound* AudioManager::PlaySound3D(FMOD::Channel** pChannel, const char* filename, vec3 position, bool looping, bool stream)
{
    if (m_audioEnabled)
    {
        FMOD::Sound* sound;
        *pChannel = NULL;
        FMOD::ChannelGroup *channelGroup = NULL;

        if (stream)
        {
            m_FMODResult = m_FMODSystem->createStream(filename, FMOD_DEFAULT | FMOD_3D, 0, &sound);
        }
        else
        {
            m_FMODResult = m_FMODSystem->createSound(filename, FMOD_DEFAULT | FMOD_3D, 0, &sound);
        }
        ERRCHECK(m_FMODResult);

        float distanceFactor = 1.0f;
        m_FMODResult = sound->set3DMinMaxDistance(1.0f * distanceFactor, 300.0f * distanceFactor);
        ERRCHECK(m_FMODResult);

        m_FMODResult = sound->setMode(looping == true ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
        ERRCHECK(m_FMODResult);

        m_FMODResult = m_FMODSystem->playSound(sound, channelGroup, false, pChannel);
        ERRCHECK(m_FMODResult);

        FMOD_VECTOR pos = { position.x, position.y, position.z };
        FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f };

        m_FMODResult = (*pChannel)->set3DAttributes(&pos, &vel);
        ERRCHECK(m_FMODResult);

        return sound;
    }

    return NULL;
}
コード例 #9
0
	FMOD::Sound* FMODAudioClip::createStreamingSound() const
	{
		if(getReadMode() != AudioReadMode::Stream || mStreamData == nullptr)
		{
			LOGERR("Invalid audio stream data.");
			return nullptr;
		}

		FMOD_MODE flags = FMOD_CREATESTREAM;

		FMOD_CREATESOUNDEXINFO exInfo;
		memset(&exInfo, 0, sizeof(exInfo));
		exInfo.cbsize = sizeof(exInfo);
		
		// Streaming from memory not supported.
		assert(mStreamData->isFile());

		exInfo.length = mStreamSize;
		exInfo.fileoffset = mStreamOffset;

		SPtr<FileDataStream> fileStream = std::static_pointer_cast<FileDataStream>(mStreamData);
		String pathStr = fileStream->getPath().toString();

		if (is3D())
			flags |= FMOD_3D;
		else
			flags |= FMOD_2D;

		FMOD::Sound* sound = nullptr;
		FMOD::System* fmod = gFMODAudio()._getFMOD();
		if (fmod->createSound(pathStr.c_str(), flags, &exInfo, &sound) != FMOD_OK)
		{
			LOGERR("Failed creating a streaming sound.");
			return nullptr;
		}

		sound->setMode(FMOD_LOOP_OFF);
		return sound;
	}
コード例 #10
0
ファイル: KSoundManager.cpp プロジェクト: allegrocm/Falcon
SkySound* KSoundManager::play3DSound(std::string name, float volume, float x, float y, float z, bool loop, float fallOffStart, float delay)
{
	if(mSilent) return NULL;
	if ("" == name) return NULL;
	if(mInitFailed) return NULL;
	
	FMOD::Sound* sound = 0;
	FMOD::Channel* soundChannel;
	result = mSystem->createSound(name.c_str(), FMOD_SOFTWARE | FMOD_3D, 0, &sound); 
	
	if (!sound)
	{
		printf("FMOD Error loading %s!\n", name.c_str());
		checkErrors();
		return NULL;
	}
	sound->set3DMinMaxDistance(fallOffStart, 2000);
	sound->setMode(loop ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
	bool delayed = (delay > 0);
	mSystem->playSound(FMOD_CHANNEL_FREE, sound, delayed, &soundChannel);

	FMOD_VECTOR pos = {x, y, z};
	FMOD_VECTOR vel = {0, 0, 0};
	soundChannel->setVolume(volume);
	soundChannel->set3DAttributes(&pos, &vel);
	mSystem->update();
	
	//if this sound is delayed, queue it up
	if(delayed)
	{
		DelayedSound s;
		s.delay = delay;
		s.sound = soundChannel;
		mDelayedSounds.push_back(s);
	}
	return soundChannel;
}
コード例 #11
0
ファイル: ZHMusic.cpp プロジェクト: zhvirus/zhangtina
bool Music::addToPlayList(TCHAR* fileName)
{


	if(_ifExist(fileName,_soundList))
	{
		return false;
	}
	else
	{
		//´´½¨ÒôÀÖÁ÷
		FMOD::Sound* soundTemp;

		try{
		
		_system->createStream(fileName, FMOD_HARDWARE, 0, &soundTemp);}  //´´½¨ÉùÒô 
		catch(...)
		{
			
		}

		soundTemp->setMode(FMOD_LOOP_OFF);  //¹Ø±ÕÑ­»·  

		SoundStruct* temp	=	new SoundStruct;
		temp->soundName	=	new TCHAR[MAX_PATH];
		strcpy(temp->soundName,fileName);
		//temp->channel	=	soundTemp;


		_soundList.insert(std::make_pair(temp,soundTemp));

		_soundListSize	=	_soundList.size();

		return true;
	}

}
コード例 #12
0
ファイル: SoundManager.cpp プロジェクト: thoney/MIRAGEvisApp
bool SoundManager::playSound(std::string name, float volume, float stereo, bool echo, bool loop)
{if(mSilent) return true;
	if ("" == name)
		return false;
	//fading = false;
	FMOD::Sound* sound;
	result = mSystem->createSound(name.c_str(), FMOD_SOFTWARE | FMOD_2D, 0, &sound); 
	checkErrors();

	if (!sound) return false;



	FMOD::Channel* soundChannel;
	sound->setMode(loop ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
	mSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &soundChannel);
//	if(echo)
	//	soundChannel->addDSP(mEcho);
	soundChannel->setPan(stereo);
	soundChannel->setVolume(volume);
//	printf("finished play sound\n");
	mSystem->update();
	return true;
}
コード例 #13
0
void StepTwoApp::setup()
{
    FMODListDevices();
    FMODErrorCheck(FMOD::System_Create( &mSystem ));
    FMODErrorCheck(mSystem->setDriver(0));
	FMOD_INITFLAGS flags = FMOD_INIT_NORMAL; // right-click, Go To Definition
	FMODErrorCheck(mSystem->init( 32, flags, NULL ));

    vector<fs::path> paths;
    paths.push_back( getAssetPath("gong-loud-hit.mp3") );
    paths.push_back( getAssetPath("orch-hit.wav") );
    paths.push_back( getAssetPath("trumpethit07.wav") );
    
    for(auto& path: paths) {
        FMOD::Sound* sound;
        mSystem->createSound( path.string().c_str(), FMOD_SOFTWARE, NULL, &sound );
        
        // You can change the mode of sounds at any time.
        FMOD_MODE mode = FMOD_SOFTWARE | FMOD_2D | FMOD_LOOP_OFF;
        FMODErrorCheck( sound->setMode( mode ) );
        
        mSounds.push_back(sound);
    }
}
コード例 #14
0
DWORD FmodSoundEngine::PlayMusic(int sound_id, CHANNEL Ichannel, bool loop, float volume)
{
	if(Ichannel<0||Ichannel>=maxChannel)
	{
		Ichannel = GetNewChannel();
		if(Ichannel<0)
			return NULL;
	}
	FMOD::Sound *sound = (FMOD::Sound*)playMusic[sound_id];
	FMOD::Channel **channel = (FMOD::Channel**)this->channel;
	nowChannel = max(nowChannel,Ichannel+1);
	if(loop)
	{
		result = sound->setMode(FMOD_LOOP_NORMAL);
		//ERRCHECK(result);
	}
	if(Ichannel==0){
		float freq;
		sound->getDefaults(&freq,NULL);
		music_sampleRate = freq;
	}
	result = system->playSound(sound, NULL, true, &channel[Ichannel]);
	//ERRCHECK(result);
	volumeDes[Ichannel] = volume*defaultVolume;
	result = channel[Ichannel]->setVolume(volumeDes[Ichannel]);
	//ERRCHECK(result);
	SetPosition(Ichannel, sound_id, 0);
	//ERRCHECK(result);
	result = channel[Ichannel]->setPaused(false);
	//ERRCHECK(result);

	if(Ichannel==0)
		Update(0);

	return (DWORD)sound;
}
コード例 #15
0
ファイル: main.cpp プロジェクト: YanisBreton/wolf3d
int main(int argc, char *argv[])
{
    FMOD::System          *system  = 0;
    FMOD::Sound           *sound   = 0;
    FMOD::Channel         *channel = 0;
    FMOD_RESULT            result;
    FMOD_CREATESOUNDEXINFO exinfo;
    int                    key, driver, recorddriver, numdrivers, count;
    unsigned int           version;    

    /*
        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;
    }

    /* 
        System initialization
    */
    printf("---------------------------------------------------------\n");    
    printf("Select OUTPUT type\n");    
    printf("---------------------------------------------------------\n");    
    printf("1 :  OSS        - Open Sound System\n");
    printf("2 :  ALSA       - Advanced Linux Sound Architecture\n");
    printf("3 :  ESD        - Enlightenment Sound Daemon\n");
    printf("4 :  PULSEAUDIO - Pulse Audio Sound Server\n");
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    do
    {
        key = getch();
    } while (key != 27 && key < '1' && key > '5');
    
    switch (key)
    {
        case '1' :  result = system->setOutput(FMOD_OUTPUTTYPE_OSS);
                    break;
        case '2' :  result = system->setOutput(FMOD_OUTPUTTYPE_ALSA);
                    break;
        case '3' :  result = system->setOutput(FMOD_OUTPUTTYPE_ESD);
                    break;
        case '4' :  result = system->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO);
                    break;
        default  :  return 1; 
    }  
    ERRCHECK(result);
    
    /*
        Enumerate playback devices
    */

    result = system->getNumDrivers(&numdrivers);
    ERRCHECK(result);

    printf("---------------------------------------------------------\n");    
    printf("Choose a PLAYBACK driver\n");
    printf("---------------------------------------------------------\n");    
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

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

        printf("%d : %s\n", count + 1, name);
    }
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    do
    {
        key = getch();
        if (key == 27)
        {
            return 0;
        }
        driver = key - '1';
    } while (driver < 0 || driver >= numdrivers);

    result = system->setDriver(driver);
    ERRCHECK(result);

    /*
        Enumerate record devices
    */

    result = system->getRecordNumDrivers(&numdrivers);
    ERRCHECK(result);

    printf("---------------------------------------------------------\n");    
    printf("Choose a RECORD driver\n");
    printf("---------------------------------------------------------\n");    
    for (count=0; count < numdrivers; count++)
    {
        char name[256];

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

        printf("%d : %s\n", count + 1, name);
    }
    printf("---------------------------------------------------------\n");
    printf("Press a corresponding number or ESC to quit\n");

    recorddriver = 0;
    do
    {
        key = getch();
        if (key == 27)
        {
            return 0;
        }
        recorddriver = key - '1';
    } while (recorddriver < 0 || recorddriver >= numdrivers);

    printf("\n");
  
    result = system->init(32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

    exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.numchannels      = 2;
    exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
    exinfo.defaultfrequency = 44100;
    exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;
    
    result = system->createSound(0, FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &exinfo, &sound);
    ERRCHECK(result);

    printf("===================================================================\n");
    printf("Recording example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("===================================================================\n");
    printf("\n");
    printf("Press 'r' to record a 5 second segment of audio and write it to a wav file.\n");
    printf("Press 'p' to play the 5 second segment of audio.\n");
    printf("Press 'l' to turn looping on/off.\n");
    printf("Press 's' to stop recording and playback.\n");
    printf("Press 'w' to save the 5 second segment to a wav file.\n");
    printf("Press 'Esc' to quit\n");
    printf("\n");

    /*
        Main loop.
    */
    do
    {
        static FMOD::Channel *channel = 0;
        static bool  looping    = false;
        bool         recording  = false;
        bool         playing    = false;
        unsigned int recordpos = 0;
        unsigned int playpos = 0;
        unsigned int length;

        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case 'r' :
                case 'R' :
                {
                    result = system->recordStart(recorddriver, sound, looping);
                    ERRCHECK(result);
                    break;
                }
                case 'p' :
                case 'P' :
                {
                    if (looping)
                    {
                        sound->setMode(FMOD_LOOP_NORMAL);
                    }
                    else
                    {
                        sound->setMode(FMOD_LOOP_OFF);
                    }
                    ERRCHECK(result);

                    result = system->playSound(FMOD_CHANNEL_REUSE, sound, false, &channel);
                    ERRCHECK(result);
                    break;
                }
                case 'l' :
                case 'L' :
                {
                    looping = !looping;
                    break;
                }
                case 's' :
                case 'S' :
                {
                    result = system->recordStop(recorddriver);
                    if (channel)
                    {
                        channel->stop();
                        channel = 0;
                    }
                    break;
                }
                case 'w' :
                case 'W' :
                {
                    printf("Writing to record.wav ...                                                     \r");

                    SaveToWav(sound);
                    Sleep(500);
                    break;
                }
            }
        }

        sound->getLength(&length, FMOD_TIMEUNIT_PCM);
        ERRCHECK(result);

        system->isRecording(recorddriver, &recording);
        ERRCHECK(result);

        system->getRecordPosition(recorddriver, &recordpos);
        ERRCHECK(result);

        if (channel)
        {
            channel->isPlaying(&playing);
            ERRCHECK(result);

            channel->getPosition(&playpos, FMOD_TIMEUNIT_PCM);
            ERRCHECK(result);
        }

        printf("State: %-19s. Record pos = %6d : Play pos = %6d : Loop %-3s\r", recording ? playing ? "Recording / playing" : "Recording" : playing ? "Playing" : "Idle", recordpos, playpos, looping ? "On" : "Off");
        fflush(stdout);

        system->update();

        fflush(stdout);
        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    result = sound->release();
    ERRCHECK(result);

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

    return 0;
}
コード例 #16
0
ファイル: ZHMusic.cpp プロジェクト: zhvirus/zhangtina
bool Music::playMusic(TCHAR* fileName,bool loop,bool single,float volume)
{
	try{



	FMOD::Sound* soundTemp	=	NULL;
	
	std::map<SoundStruct*,FMOD::Sound*>::iterator ite;

		for(ite=_recycle.begin();ite!=_recycle.end();ite++)
		{
			if((strcmp(((*ite).first)->soundName,fileName))==0)
			{

				soundTemp	=	(*ite).second;
				if(single==true)
				{
					unsigned int curTime	=	static_cast<unsigned int>(timeGetTime());
					if(curTime-((*ite).first)->_lastTime<((*ite).first)->_len+200)
						return true;
					else
					{
											
						((*ite).first)->_lastTime		=	curTime;
					}


				}

				//soundTemp->
			}


		}


	if(soundTemp==NULL)
	{
	
		
		if(	FMOD_OK!=_system->createStream(fileName, FMOD_HARDWARE, 0, &soundTemp))  //´´½¨ÉùÒô
		{

			return false;
		}

		soundTemp->setMode(FMOD_LOOP_OFF);  //¹Ø±ÕÑ­»·  


		if(loop)
			soundTemp->setMode(FMOD_LOOP_NORMAL);
		else
			soundTemp->setMode(FMOD_LOOP_OFF);

		_system->playSound(FMOD_CHANNEL_FREE, soundTemp, false, &_channel);		 
		_channel->setVolume(volume);    //²¥·ÅÉùÒô

		SoundStruct* temp	=	new SoundStruct;
		temp->_lastTime	=	static_cast<unsigned int>(timeGetTime());
		temp->soundName	=	new TCHAR[MAX_PATH];
		strcpy(temp->soundName,fileName);
		temp->channel	=	_channel;
		
		unsigned int llen=0;
		soundTemp->getLength(&llen,FMOD_TIMEUNIT_MS);
		temp->_len	=	llen;

		_recycle.insert(std::make_pair(temp,soundTemp));
		
		return true;

	}

	if(loop)
		soundTemp->setMode(FMOD_LOOP_NORMAL);
	else
		soundTemp->setMode(FMOD_LOOP_OFF);



	_system->playSound(FMOD_CHANNEL_FREE, soundTemp, false, &_channel);		 
	_channel->setVolume(volume);    //²¥·ÅÉùÒô
	
	}
	catch(...)
	{

	}
	
	return true;
}
コード例 #17
0
bool DuckHuntMain::Init()
{
	if (!D3DApp::Init())
		return false;

	// Must init Effects first since InputLayouts depend on shader signatures.
	Effects::InitAll(md3dDevice);
	InputLayouts::InitAll(md3dDevice);
	RenderStates::InitAll(md3dDevice);
	mCrosshair = new Crosshair(md3dDevice);
	mTexMgr.Init(md3dDevice);
	DuckHuntMain::ShowCursors(false);
	mSky = new Sky(md3dDevice, L"Textures/desertcube1024.dds", 5000.0f);
	mSmap = new ShadowMap(md3dDevice, SMapSize, SMapSize);
	Terrain::InitInfo tii;
	tii.HeightMapFilename = L"Textures/myT5.raw";
	tii.LayerMapFilename0 = L"Textures/grass.dds";
	tii.LayerMapFilename1 = L"Textures/darkdirt.dds";
	tii.LayerMapFilename2 = L"Textures/stone.dds";
	tii.LayerMapFilename3 = L"Textures/lightdirt.dds";
	tii.LayerMapFilename4 = L"Textures/snow.dds";
	tii.BlendMapFilename = L"Textures/blend.dds";
	tii.HeightScale = 50.0f;
	tii.HeightmapWidth = 2049;
	tii.HeightmapHeight = 2049;
	tii.CellSpacing = 0.5f;

	mTerrain.Init(md3dDevice, md3dImmediateContext, tii);
	//Sound
	result = FMOD::System_Create(&mSystem);
	result = mSystem->init(32, FMOD_INIT_NORMAL, 0);
	result = mSystem->createSound("Sounds/GunFire.wav", FMOD_DEFAULT, 0, &mGunFire);
	result = mGunFire->setMode(FMOD_LOOP_OFF);






	mCam.SetLens(0.25f*MathHelper::Pi, AspectRatio(), 1.0f, 1000.0f);
	mSsao = new Ssao(md3dDevice, md3dImmediateContext, mClientWidth, mClientHeight, mCam.GetFovY(), mCam.GetFarZ());

	BuildScreenQuadGeometryBuffers();

	testModelDuck = new BasicModel(md3dDevice, mTexMgr, "Models\\duck.obj", L"Textures\\DUCK.jpg");



	BasicModelInstance testInstanceDuck;
	BasicModelInstance testInstanceDuck2;
	BasicModelInstance testInstanceDuck3;
	BasicModelInstance testInstanceDuck4;

	testInstanceDuck.Model = testModelDuck;
	testInstanceDuck2.Model = testModelDuck;
	testInstanceDuck3.Model = testModelDuck;
	testInstanceDuck4.Model = testModelDuck;



	//Duck 1
	XMMATRIX modelScale = XMMatrixScaling(1.0f, 1.0f, -1.0f);
	XMMATRIX modelRot = XMMatrixRotationY(0.0f);
	XMMATRIX modelOffset = XMMatrixTranslation(0.0f, 0.0f, 0.0f);
	//Duck 2
	XMMATRIX modelScale2 = XMMatrixScaling(2.0f, 2.0f, -1.0f);
	XMMATRIX modelRot2 = XMMatrixRotationY(-1.0f);
	XMMATRIX modelOffset2 = XMMatrixTranslation(1.0f, 1.0f, -1.0f);
	//Duck3
	XMMATRIX modelScale3 = XMMatrixScaling(1.5f, 1.5f, 1.5f);
	XMMATRIX modelRot3 = XMMatrixRotationY(0.5f);
	XMMATRIX modelOffset3 = XMMatrixTranslation(2.0f, 1.0f, -1.0f);
	//Duck4
	XMMATRIX modelScale4 = XMMatrixScaling(0.5f, 0.5f, -1.0f);
	XMMATRIX modelRot4 = XMMatrixRotationY(1.0f);
	XMMATRIX modelOffset4 = XMMatrixTranslation(0.5f, 1.0f, -1.0f);


	//Duck 1
	XMStoreFloat4x4(&testInstanceDuck.World, modelScale*modelRot*modelOffset);
	mModelInstances.push_back(testInstanceDuck);

	//Duck 2
	XMStoreFloat4x4(&testInstanceDuck2.World, modelScale2*modelRot2*modelOffset2);
	mModelInstances.push_back(testInstanceDuck2);

	//Duck 3
	XMStoreFloat4x4(&testInstanceDuck3.World, modelScale3*modelRot3*modelOffset3);
	mModelInstances.push_back(testInstanceDuck3);

	//Duck 4
	XMStoreFloat4x4(&testInstanceDuck4.World, modelScale4*modelRot4*modelOffset4);
	mModelInstances.push_back(testInstanceDuck4);


	//create collision box
	for (unsigned i = 0; i < mModelInstances.size(); i++)
	{
		mModelInstances[i].Model->CreateCollisionBox(mModelInstances[i].Model->BasicVertices);
	}






	//
	// Compute scene bounding box.
	//

	XMFLOAT3 minPt(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity);
	XMFLOAT3 maxPt(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity);
	for (UINT i = 0; i < mModelInstances.size(); ++i)
	{
		for (UINT j = 0; j < mModelInstances[i].Model->BasicVertices.size(); ++j)
		{
			XMFLOAT3 P = mModelInstances[i].Model->BasicVertices[j].Pos;

			minPt.x = MathHelper::Min(minPt.x, P.x);
			minPt.y = MathHelper::Min(minPt.x, P.x);
			minPt.z = MathHelper::Min(minPt.x, P.x);

			maxPt.x = MathHelper::Max(maxPt.x, P.x);
			maxPt.y = MathHelper::Max(maxPt.x, P.x);
			maxPt.z = MathHelper::Max(maxPt.x, P.x);
		}
	}

	//
	// Derive scene bounding sphere from bounding box.
	//
	mSceneBounds.Center = XMFLOAT3(
		0.5f*(minPt.x + maxPt.x),
		0.5f*(minPt.y + maxPt.y),
		0.5f*(minPt.z + maxPt.z));

	XMFLOAT3 extent(
		0.5f*(maxPt.x - minPt.x),
		0.5f*(maxPt.y - minPt.y),
		0.5f*(maxPt.z - minPt.z));

	mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z);

	return true;
}
コード例 #18
0
int DM_CDAudio_Play(int track, int looped)
{
    if(!fmodSystem) return false;
    if(!numDrives)
    {
        DSFMOD_TRACE("CDAudio_Play: No CD drives available.");
        return false;
    }

    // Use a bigger stream buffer for CD audio.
    fmodSystem->setStreamBufferSize(64*1024, FMOD_TIMEUNIT_RAWBYTES);

    // Get the drive name.
    /// @todo Make drive selection configurable.
    FMOD_RESULT result;
    char driveName[80];
    fmodSystem->getCDROMDriveName(0, driveName, sizeof(driveName), 0, 0, 0, 0);
    DSFMOD_TRACE("CDAudio_Play: CD drive name: '" << driveName << "'");

    FMOD::Sound *trackSound = nullptr;
    bool needRelease = false;

#if MACOSX
    for(char* ptr = driveName; *ptr; ptr++)
    {
        if(*ptr == '/') *ptr = ':';
    }

    // The CD tracks are mapped to files.
    char trackPath[200];
    sprintf(trackPath, "/Volumes/%s/%i Audio Track.aiff", driveName, track);
    DSFMOD_TRACE("CDAudio_Play: Opening track: " << trackPath);

    result = fmodSystem->createStream(trackPath, (looped? FMOD_LOOP_NORMAL : 0), 0, &trackSound);
    DSFMOD_TRACE("CDAudio_Play: Track " << track << " => Sound " << trackSound);
    DSFMOD_ERRCHECK(result);

    needRelease = true;
#else
#ifdef WIN32
    /// @todo Check if there is a data track.
    // (Hexen CD) The audio tracks begin at #1 even though there is a data track.
    track--;
#endif

    if(!cdSound)
    {
        // Get info about the CD tracks.
        result = fmodSystem->createStream(driveName, FMOD_OPENONLY, 0, &cdSound);
        DSFMOD_TRACE("CDAudio_Play: Opening CD, cdSound " << cdSound);
        DSFMOD_ERRCHECK(result);
        if(result != FMOD_OK) return false;
    }
    DENG2_ASSERT(cdSound);

    int numTracks = 0;
    result = cdSound->getNumSubSounds(&numTracks);
    DSFMOD_TRACE("CDAudio_Play: Number of tracks = " << numTracks);
    if(result != FMOD_OK) return false;

    // The subsounds are indexed starting from zero (CD track 1 == subsound 0).
    track--;

    if(track >= numTracks)
    {
        DSFMOD_TRACE("CDAudio_Play: Track " << track << " out of bounds.");
        return false;
    }

    result = cdSound->getSubSound(track, &trackSound);
    DSFMOD_ERRCHECK(result);
    DSFMOD_TRACE("CDAudio_Play: Track " << track + 1 << " got subsound " << trackSound);

    if(looped)
    {
        trackSound->setMode(FMOD_LOOP_NORMAL);
    }
#endif

    return DMFmod_Music_PlaySound(trackSound, needRelease); // takes ownership
}
コード例 #19
0
ファイル: main.cpp プロジェクト: YanisBreton/wolf3d
int main(int argc, char *argv[])
{
    FMOD::System     *system   = 0;
    FMOD::Sound      *playlist = 0;
    FMOD::Sound      *sound    = 0;
    FMOD::Channel    *channel  = 0;
    FMOD_TAG          tag;
    FMOD_RESULT       result;
    FMOD_SOUND_TYPE   soundtype;
    bool              isplaylist = false;
    char             *title = NULL;
    int               count = 0;
    int               key;
    unsigned int      version;
    char              file[128];
    
    /*
        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(32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);

    result = system->createSound("../media/playlist.m3u", FMOD_DEFAULT, 0, &playlist);
    ERRCHECK(result);

    result = playlist->getFormat(&soundtype, 0, 0, 0);
    ERRCHECK(result);

    isplaylist = (soundtype == FMOD_SOUND_TYPE_PLAYLIST);

    printf("===================================================================\n");
    printf("PlayList Example.  Copyright (c) Firelight Technologies 2004-2011.\n");
    printf("===================================================================\n");
    printf("\n");
    printf("Press 'n'     to play next sound in playlist\n");
    printf("Press 'space' to pause/unpause current sound\n");
    printf("Press 'Esc'   to quit\n");
    printf("\n");

    if (isplaylist)
    {
        printf("PLAYLIST loaded.\n");
        /*
            Get the first song in the playlist, create the sound and then play it.
        */
        result = playlist->getTag("FILE", count, &tag);
        ERRCHECK(result);

        sprintf(file, "../media/%s", (char *)tag.data);

        result = system->createSound(file, FMOD_DEFAULT, 0, &sound);
        ERRCHECK(result);

        result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
        ERRCHECK(result);

        playlist->getTag("TITLE", count, &tag);
        title = (char *)tag.data;

        count++;
    }
    else
    {
        printf("SOUND loaded.\n");

        /*
            This is just a normal sound, so just play it.
        */
        sound = playlist;

        result = sound->setMode(FMOD_LOOP_NORMAL);
        ERRCHECK(result);

        result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
        ERRCHECK(result);
    }

    printf("\n");

    /*
        Main loop.
    */
    do
    {
        bool  isplaying = false;

        if (channel && isplaylist)
        {
            /*
                When sound has finished playing, play the next sound in the playlist
            */

            channel->isPlaying(&isplaying);
            if (!isplaying)
            {
                if (sound)
                {
                    sound->release();

                    sound = NULL;
                }

                result = playlist->getTag("FILE", count, &tag);
                if (result != FMOD_OK)
                {
                    count = 0;
                }
                else
                {
                    printf("playing next song in playlist...\n");

                    sprintf(file, "../media/%s", (char *)tag.data);

                    result = system->createSound(file, FMOD_DEFAULT, 0, &sound);
                    ERRCHECK(result);

                    result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
                    ERRCHECK(result);

                    playlist->getTag("TITLE", count, &tag);
                    title = (char *)tag.data;

                    count++;
                }
            }
        }


        if (kbhit())
        {
            key = getch();

            switch (key)
            {
                case 'n' :
                {
                    /*
                        Play the next song in the playlist
                    */
                    if (channel && isplaylist)
                    {
                        channel->stop();
                    }

                    break;
                }
                case ' ' :
                {
                    if (channel)
                    {
                        bool paused;

                        channel->getPaused(&paused);
                        channel->setPaused(!paused);
                    }
                }
            }
        }

        system->update();

        {
            unsigned int ms = 0;
            unsigned int lenms = 0;
            bool         paused = 0;

            if (channel)
            {
                if (sound)
                {
                    result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS);
                    if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                    {
                        ERRCHECK(result);
                    }
                }

                result = channel->getPaused(&paused);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }

                result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }
            }

            printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : "Playing ", title);
            fflush(stdout);
        }

        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        Shut down
    */
    if (sound)
    {
        result = sound->release();
        ERRCHECK(result);
    }
    if (isplaylist)
    {
        result = playlist->release();
        ERRCHECK(result);
    }
    result = system->close();
    ERRCHECK(result);
    result = system->release();
    ERRCHECK(result);

    return 0;
}