Пример #1
0
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;
}
Пример #2
0
FMOD::Sound* Sltn::getSound(const char* ptr)
{
    string str(ptr);

    // Check if the sound is already loaded
    std::map<std::string, FMOD::Sound*>::const_iterator it = m_Sounds.find(str); //map<string,sf::Texture>::const_iterator
    if (it != m_Sounds.end()) return (*it).second;

    // We don't wan't' fmod to concern about errors
    if (!FileExists(str)) {
        cerr << "File sound not found: " << str << "\n";
        return nullptr;
    }

    // Realy load the stuff:
    FMOD_RESULT      result;
    FMOD::Sound* pSound;
    result = system->createSound(Common_MediaPath(ptr), FMOD_3D, 0, &pSound);
    ERRCHECK(result);
    result = pSound->set3DMinMaxDistance(0.5f * FMOD_DistanceFactor, 5000.0f * FMOD_DistanceFactor);
    ERRCHECK(result);
    // result = ptr->setMode(FMOD_LOOP_NORMAL);
    // ERRCHECK(result);

    m_Sounds.insert(std::pair<std::string, FMOD::Sound*>(str, pSound));
    return pSound;
}
Пример #3
0
//Method for loading 3D SFX
TDSFX* AudioManager::load3D(string filename, string name, Position* position, FMOD::System *system){
	FMOD::Sound *sound;

	FMOD_RESULT result = system->createSound(filename.c_str(), FMOD_3D, 0, &sound);

	checkProblem(result);

	result = sound->set3DMinMaxDistance(0.5f * DISTANCE_FACTOR, 5000.0f * DISTANCE_FACTOR);

	checkProblem(result);

	TDSFX *sound2 = new TDSFX(name, sound, position);

	return sound2;
}
Пример #4
0
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;
}
Пример #5
0
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;
}