コード例 #1
0
KDuint SimpleAudioEngine::playEffect ( const KDchar* szFilePath, KDbool bLoop, KDfloat fPitch, KDfloat fPan, KDfloat fGain )
{
	if (!szFilePath)
	{
		return 0;
	}

	std::string  sPath = FileUtils::getInstance()->fullPathForFilename(szFilePath);
	KDuint		 uRet = _Hash(sPath.c_str());

	preloadEffect(szFilePath);

	SoundList::iterator it = l_aEffectList.find(uRet);
	if (it != l_aEffectList.end())
	{
		xmSoundSetRepeat(it->second, bLoop);		
		xmSoundSetVolume(it->second, fGain);
		xmSoundSetPitch(it->second, fPitch);
		xmSoundSetPan(it->second, fPan);
		xmSoundRewind(it->second);
	}
	else
	{
		uRet = 0;
	}

	return uRet;
}
コード例 #2
0
KDvoid SimpleAudioEngine::preloadBackgroundMusic ( const KDchar* szFilePath )
{
	if ( !szFilePath )
	{
		return;
	}

	std::string  sPath = FileUtils::getInstance ( )->fullPathForFilename ( szFilePath );
	KDuint		 uID   = _Hash ( sPath.c_str ( ) );

	this->stopBackgroundMusic ( true );

	SoundList::iterator it = l_aMusicList.find ( uID );
	if ( it == l_aMusicList.end ( ) )
	{
		XMSound*  pSound = xmSoundOpen ( sPath.c_str ( ), XM_SOUND_NORMAL );

		if ( pSound )
		{
			xmSoundSetCallback ( pSound, background_callBack );

			l_aMusicList.insert ( Sound ( uID, pSound ) );			
		}
	}
}
コード例 #3
0
KDvoid SimpleAudioEngine::stopBackgroundMusic ( KDbool bReleaseData )
{
	SoundList::iterator it = l_aMusicList.find ( l_uCurrentMusic );

	if ( it != l_aMusicList.end ( ) )
	{
		if ( bReleaseData )
		{
			if ( it->second )
			{
				xmSoundClose ( it->second );
			}

			l_uCurrentMusic = 0;
			l_aEffectList.erase ( l_uCurrentMusic );
		}
		else
		{
			if ( it->second )
			{
				xmSoundStop ( it->second );
			}
		}
	}

	l_bIsBackgroundPlaying = KD_FALSE;
}
コード例 #4
0
KDvoid SimpleAudioEngine::setEffectPitch(KDuint uID, KDfloat fPitch)
{
	SoundList::iterator it = l_aEffectList.find(uID);
	if (it != l_aEffectList.end())
	{
		xmSoundSetPitch(it->second, fPitch);
	}
}
コード例 #5
0
KDvoid SimpleAudioEngine::setEffectVolume ( KDuint uID, KDfloat fVolume )
{
	SoundList::iterator it = l_aEffectList.find(uID);
	if (it != l_aEffectList.end())
	{
		xmSoundSetVolume(it->second, fVolume);
	}
}
コード例 #6
0
KDvoid SimpleAudioEngine::resumeEffect ( KDuint uSoundId )
{
	SoundList::iterator it = l_aEffectList.find(uSoundId);
	if (it != l_aEffectList.end())
	{
		xmSoundResume(it->second);
	}
}
コード例 #7
0
KDvoid SimpleAudioEngine::unloadEffect ( KDuint uSoundId )
{
	SoundList::iterator it = l_aEffectList.find(uSoundId);
	if (it != l_aEffectList.end())
	{
		xmSoundClose(it->second);
		l_aEffectList.erase(uSoundId);
	}
}
コード例 #8
0
KDfloat SimpleAudioEngine::getEffectPitch ( KDuint uID )
{
	SoundList::iterator it = l_aEffectList.find(uID);
	if (it != l_aEffectList.end())
	{
		return xmSoundGetPitch(it->second);
	}

	return 0;
}
コード例 #9
0
KDvoid SimpleAudioEngine::playEffect ( KDuint uSoundId, KDbool bLoop, KDfloat fPitch, KDfloat fPan, KDfloat fGain )
{
	SoundList::iterator it = l_aEffectList.find(uSoundId);
	if (it != l_aEffectList.end())
	{
		xmSoundSetRepeat(it->second, bLoop);
		xmSoundSetVolume(it->second, fGain);
		xmSoundSetPitch(it->second, fPitch);
		xmSoundSetPan(it->second, fPan);
		xmSoundRewind(it->second);
	}
}
コード例 #10
0
KDvoid SimpleAudioEngine::resumeBackgroundMusic ( KDvoid )
{
	SoundList::iterator it = l_aMusicList.find ( l_uCurrentMusic );

	if ( it != l_aMusicList.end ( ) )
	{
		if ( it->second )
		{
			xmSoundResume ( it->second );
		}
	}
}
コード例 #11
0
KDvoid SimpleAudioEngine::rewindBackgroundMusic ( KDvoid )
{
	SoundList::iterator it = l_aMusicList.find ( l_uCurrentMusic );

	if ( it != l_aMusicList.end ( ) )
	{
		if ( it->second )
		{
			l_bIsBackgroundPlaying = KD_TRUE;
			xmSoundRewind ( it->second );
		}
	}
}
コード例 #12
0
KDvoid SimpleAudioEngine::unloadEffect ( const KDchar* szFilePath )
{
	if (!szFilePath)
	{
		return;
	}

	std::string  sPath = FileUtils::getInstance()->fullPathForFilename(szFilePath);
	KDuint		   uID = _Hash(sPath.c_str());

	SoundList::iterator it = l_aEffectList.find(uID);
	if (it != l_aEffectList.end())
	{
		xmSoundClose(it->second);
		l_aEffectList.erase(uID);
	}
}
コード例 #13
0
KDuint SimpleAudioEngine::preloadEffect(const KDchar* szFilePath, const KDchar* szKey)
{
	std::string  sPath = FileUtils::getInstance()->fullPathForFilename(szFilePath);
	KDuint		   uID = _Hash(szKey ? szKey : sPath.c_str());

	SoundList::iterator it = l_aEffectList.find(uID);
	if (it == l_aEffectList.end())
	{
		XMSound*  pSound = xmSoundOpen(sPath.c_str(), XM_SOUND_EFFECT);

		if (pSound)
		{
			l_aEffectList.insert(Sound(uID, pSound));
		}
	}

	return uID;
}
コード例 #14
0
KDvoid SimpleAudioEngine::playBackgroundMusic ( const KDchar* szFilePath, bool bLoop )
{
	if ( !szFilePath )
	{
		return;
	}

	std::string  sPath = FileUtils::getInstance ( )->fullPathForFilename ( szFilePath );
	KDuint		 uRet  = _Hash ( sPath.c_str ( ) );

	preloadBackgroundMusic ( sPath.c_str ( ) );

	SoundList::iterator it = l_aMusicList.find ( uRet );
	if ( it != l_aMusicList.end ( ) )
	{
		l_uCurrentMusic = uRet;
		xmSoundSetRepeat ( it->second, bLoop );	
		this->rewindBackgroundMusic ( );
	}
}