コード例 #1
0
ファイル: soundmanager.cpp プロジェクト: werdanith/openmw
    void SoundManager::playPlaylist(std::string playlist)
    {
        if (playlist == "")
        {
            if(!isMusicPlaying())
            {
                startRandomTitle();
            }
            return;
        }

        if(!setPlaylist(playlist))
        {
            startRandomTitle();
        }
        else if (!isMusicPlaying())
        {
            startRandomTitle();
        }
    }
コード例 #2
0
ファイル: soundmanagerimp.cpp プロジェクト: valistar/openmw
    void SoundManager::updateSounds(float duration)
    {
        static float timePassed = 0.0;

        timePassed += duration;
        if(timePassed < (1.0f/30.0f))
            return;
        timePassed = 0.0f;

        // Make sure music is still playing
        if(!isMusicPlaying())
            startRandomTitle();

        MWWorld::Ptr player =
            MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
        const ESM::Cell *cell = player.getCell()->cell;

        Environment env = Env_Normal;
        if((cell->mData.mFlags&cell->HasWater) && mListenerPos.z < cell->mWater)
            env = Env_Underwater;

        mOutput->updateListener(
            mListenerPos,
            mListenerDir,
            mListenerUp,
            env
        );

        // Check if any sounds are finished playing, and trash them
        SoundMap::iterator snditer = mActiveSounds.begin();
        while(snditer != mActiveSounds.end())
        {
            if(!snditer->first->isPlaying())
                mActiveSounds.erase(snditer++);
            else
            {
                snditer->first->update();
                snditer++;
            }
        }
    }
コード例 #3
0
ファイル: soundmanagerimp.cpp プロジェクト: poweryang1/openmw
    void SoundManager::updateSounds(float duration)
    {
        static float timePassed = 0.0;

        timePassed += duration;
        if(timePassed < (1.0f/30.0f))
            return;
        duration = timePassed;
        timePassed = 0.0f;

        // Make sure music is still playing
        if(!isMusicPlaying())
            startRandomTitle();

        Environment env = Env_Normal;
        if (mListenerUnderwater)
        {
            env = Env_Underwater;
            //play underwater sound
            if(!(mUnderwaterSound && mUnderwaterSound->isPlaying()))
                mUnderwaterSound = playSound("Underwater", 1.0f, 1.0f, Play_TypeSfx, Play_LoopNoEnv);
        }
        else if(mUnderwaterSound)
        {
            mUnderwaterSound->stop();
            mUnderwaterSound.reset();
        }

        mOutput->updateListener(
            mListenerPos,
            mListenerDir,
            mListenerUp,
            env
        );

        // Check if any sounds are finished playing, and trash them
        // Lower volume on fading out sounds
        SoundMap::iterator snditer = mActiveSounds.begin();
        while(snditer != mActiveSounds.end())
        {
            if(!snditer->first->isPlaying())
                mActiveSounds.erase(snditer++);
            else
            {
                const MWWorld::Ptr &ptr = snditer->second.first;
                if(!ptr.isEmpty())
                {
                    const ESM::Position &pos = ptr.getRefData().getPosition();
                    const osg::Vec3f objpos(pos.asVec3());
                    snditer->first->setPosition(objpos);

                    if ((snditer->first->mFlags & Play_RemoveAtDistance)
                            && (mListenerPos - ptr.getRefData().getPosition().asVec3()).length2() > 2000*2000)
                    {
                        mActiveSounds.erase(snditer++);
                        continue;
                    }
                }
                //update fade out
                if(snditer->first->mFadeOutTime>0)
                {
                    float soundDuration=duration;
                    if(soundDuration>snditer->first->mFadeOutTime)
                        soundDuration=snditer->first->mFadeOutTime;
                    snditer->first->setVolume(snditer->first->mVolume
                                    - soundDuration / snditer->first->mFadeOutTime * snditer->first->mVolume);
                    snditer->first->mFadeOutTime -= soundDuration;
                }
                snditer->first->update();
                ++snditer;
            }
        }
    }
コード例 #4
0
    void SoundManager::updateSounds(float duration)
    {
        static float timePassed = 0.0;

        timePassed += duration;
        if(timePassed < (1.0f/30.0f))
            return;
        duration = timePassed;
        timePassed = 0.0f;

        // Make sure music is still playing
        if(!isMusicPlaying())
            startRandomTitle();

        MWWorld::Ptr player =
            MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
        const ESM::Cell *cell = player.getCell()->mCell;

        Environment env = Env_Normal;
        if((cell->mData.mFlags&cell->HasWater) && mListenerPos.z < cell->mWater)
        {
            env = Env_Underwater;
            //play underwater sound
            if(!(mUnderwaterSound && mUnderwaterSound->isPlaying()))
                mUnderwaterSound = playSound("Underwater", 1.0f, 1.0f, Play_TypeSfx, Play_LoopNoEnv);
        }
        else if(mUnderwaterSound)
        {
            mUnderwaterSound->stop();
            mUnderwaterSound.reset();
        }

        mOutput->updateListener(
            mListenerPos,
            mListenerDir,
            mListenerUp,
            env
        );

        // Check if any sounds are finished playing, and trash them
        // Lower volume on fading out sounds
        SoundMap::iterator snditer = mActiveSounds.begin();
        while(snditer != mActiveSounds.end())
        {
            if(!snditer->first->isPlaying())
                mActiveSounds.erase(snditer++);
            else
            {
                const MWWorld::Ptr &ptr = snditer->second.first;
                if(!ptr.isEmpty())
                {
                    const ESM::Position &pos = ptr.getRefData().getPosition();
                    const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]);
                    snditer->first->setPosition(objpos);
                }
                //update fade out
                if(snditer->first->mFadeOutTime>0)
                {
                    float soundDuration=duration;
                    if(soundDuration>snditer->first->mFadeOutTime)
                        soundDuration=snditer->first->mFadeOutTime;
                    snditer->first->setVolume(snditer->first->mVolume
                                    - soundDuration / snditer->first->mFadeOutTime * snditer->first->mVolume);
                    snditer->first->mFadeOutTime -= soundDuration;               
                }
                snditer->first->update();
                ++snditer;
            }
        }
    }
コード例 #5
0
ファイル: audio.cpp プロジェクト: Arikado/Wii-Homebrew
int cAudio :: PlayMusic( string filename, int loops, bool force, unsigned int FadeInms )
{
	if( !bMusic || !bInitialised )
	{
		return 0;
	}

	if( !valid_file( filename ) )
	{
		printf( "Couldn't find music file : %s\n", filename.c_str() );
		return 0;
	}

	ResumeMusic();

	if( !isMusicPlaying() || force ) 
	{
		if( Music )
		{
			if( force )
			{
				HaltMusic();
			}

			Mix_FreeMusic( Music );
			Music = NULL;
		}

		Music = Mix_LoadMUS( filename.c_str() );

		if( Music )
		{
			Music_Played++;
			
			if( !FadeInms ) // No Fading
			{
				Mix_PlayMusic( Music, loops );
			}
			else // Fade the Music in
			{
				Mix_FadeInMusic( Music, loops, FadeInms );
			}

		}
		else 
		{
			if( bDebug )
			{
				printf( "PlayMusic couldn't play music file : %s\n", filename.c_str() );
			}

			return 0;
		}
	}
	else
	{
		Music = Mix_LoadMUS( filename.c_str() );
	}
	
	return 1;
}