#include "stdafx.h" #include "SGameMilesSoundMgr.h" #include "K3DTypes.h" #include #include #include "SGameWorld.h" #include "SWorldLocationDB.h" bool SGameMilesSoundBufferInfoTable::GetSoundBufferData( const char *szFileName, float *pfMaxDist, float *pfMinDist, float *pfVolume, float *pfReverbDry, float *pfReverbWet, bool *pbSfx) { if( m_pMSoundMgr ) { /* int nWorldID, nCurTime, nWeatherID; m_pMSoundMgr->GetCurrentEnvironmentInfo( nWorldID, nCurTime, nWeatherID ); const WorldLocationBase* pWorldLocation = GetWorldLocationDB().GetWLData( nWorldID, nCurTime, nWeatherID ); if( pWorldLocation )*/ { if ( pfMaxDist != NULL) *pfMaxDist = 1000.0f; if ( pfMinDist != NULL) *pfMinDist = 100.0f; if ( pfVolume != NULL) *pfVolume = 1.0f; //범위 0.0f ~ 1.0f // if ( pfReverbDry != NULL) *pfReverbDry = pWorldLocation->environmental_sound_volume / 100.0f; //원음 볼륨 // if ( pfReverbWet != NULL) *pfReverbWet = pWorldLocation->environmental_sound_reverb / 100.0f; //울림 볼륨 ( 볼륨이 0이면 안나옴~ ) m_pMSoundMgr->GetGameDryWetVolume( pfReverbDry, pfReverbWet ); if ( pbSfx != NULL) *pbSfx = true; return true; } } if ( pfMaxDist != NULL) *pfMaxDist = 1000.0f; if ( pfMinDist != NULL) *pfMinDist = 100.0f; if ( pfVolume != NULL) *pfVolume = 1.0f; //범위 0.0f ~ 1.0f if ( pfReverbDry != NULL) *pfReverbDry = 1.0f; //원음 볼륨 if ( pfReverbWet != NULL) *pfReverbWet = 0.0f; //울림 볼륨 ( 볼륨이 0이면 안나옴~ ) if ( pbSfx != NULL) *pbSfx = false; return true; } bool SGameMilesSoundBufferInfoTable::GetGameDryWetVolume( float *pfReverbDry, float *pfReverbWet ) { if( m_pMSoundMgr ) { m_pMSoundMgr->GetGameDryWetVolume( pfReverbDry, pfReverbWet ); if( pfReverbDry != NULL ) *pfReverbDry /= 100.0f; if( pfReverbWet != NULL ) *pfReverbWet /= 100.0f; return true; } if ( pfReverbDry != NULL) *pfReverbDry = 1.0f; //원음 볼륨 if ( pfReverbWet != NULL) *pfReverbWet = 0.0f; //울림 볼륨 ( 볼륨이 0이면 안나옴~ ) return false; } bool SGameMilesSoundBufferInfoTable::GetGameLowPassCutOff( float *pfCutOff ) { if( m_pMSoundMgr ) { m_pMSoundMgr->GetGameLowPassCutOff( pfCutOff ); return true; } return false; } SGameMilesSoundMgr::SGameMilesSoundMgr() : m_pSoundMng( NULL ) , m_pBufferInfoTable( NULL ) , m_nPlayRate( 22000 ) , m_nMasterVolume( 100 ) , m_nBgmVolume( 100 ) , m_nEnvVolume( 100 ) , m_nSfxVolume( 100 ) , m_pMusic( NULL ) , m_pBgm( NULL ) , m_pGameWorld( NULL ) , m_bMasterMute( false ) , m_fCutOff( 1.0f ) { m_pMusic = new MusicKey; m_pBgm = new MusicKey; } SGameMilesSoundMgr::~SGameMilesSoundMgr() { StopMusic(); StopBgm(); SAFE_DELETE( m_pSoundMng ); SAFE_DELETE( m_pBufferInfoTable ); SAFE_DELETE( m_pMusic ); SAFE_DELETE( m_pBgm ); m_pGameWorld = NULL; } bool SGameMilesSoundMgr::Initialize( HWND hWnd ) { std::string strPath; if( ENV().IsExist("res") ) { strPath = ENV().GetString( "res", "./Resource/" ); strPath += "Redist/"; } else { TCHAR *pEnd = NULL; TCHAR szFullFileName[MAX_PATH] = { 0, }; GetModuleFileName(NULL, szFullFileName, MAX_PATH); pEnd = _tcsrchr( szFullFileName, _T('\\')) + 1; if (!pEnd) { return false; } *pEnd = _T('\0'); lstrcat(szFullFileName, _T("Redist\\")); strPath = szFullFileName; } // strPath = "E:\\Project\\resource\\Redist\\"; m_pBufferInfoTable = new SGameMilesSoundBufferInfoTable( this ); m_pSoundMng = new ISoundManager; if( !m_pSoundMng->Initialize( m_pBufferInfoTable, strPath.c_str(), hWnd, "Use Windows speaker configuration" ) ) { SetSoundMute( true ); return false; } SetRoomType( ENVIRONMENT_GENERIC ); SetLowPassCutOff( 18000 ); SetSoundMute( false ); return true; } void SGameMilesSoundMgr::Process( DWORD dwTime ) { } void SGameMilesSoundMgr::SetGameWorld( class SGameWorld* pGameWorld ) { m_pGameWorld = pGameWorld; } void SGameMilesSoundMgr::SetRoomType( int nRoomType ) { m_pSoundMng->SetRoomType( nRoomType ); } void SGameMilesSoundMgr::SetLowPassCutOff( float fCutOff ) { m_fCutOff = fCutOff / 44100.0f; //44100디폴트 hz ( 0.0f ~ 1.0f ) } void SGameMilesSoundMgr::GetCurrentEnvironmentInfo( int& nWorldID, int& nCurTime, int& nWeatherID ) { if( m_pGameWorld ) { m_pGameWorld->GetCurrentEnvironmentInfo( nWorldID, nCurTime, nWeatherID ); } else { nWorldID = -1; nCurTime = -1; nWeatherID = -1; } } void SGameMilesSoundMgr::GetGameDryWetVolume( float *pfReverbDry, float *pfReverbWet ) { if( m_pGameWorld ) { *pfReverbDry = m_pGameWorld->GetGameDryVolume(); *pfReverbWet = m_pGameWorld->GetGameWetVolume(); } else { *pfReverbDry = 1.0f; *pfReverbWet = 0.0f; } } void SGameMilesSoundMgr::GetGameLowPassCutOff( float *pfCutOff ) { *pfCutOff = m_fCutOff; } void SGameMilesSoundMgr::SetSfxVolume( int nVolume ) { m_nSfxVolume = nVolume; m_pSoundMng->SetSfxVolume( nVolume ); } int SGameMilesSoundMgr::GetSfxVolume() { return m_nSfxVolume; } void SGameMilesSoundMgr::SetEnvVolume( int nVolume ) { m_nEnvVolume = nVolume; m_pSoundMng->SetEnvVolume( m_nEnvVolume ); } int SGameMilesSoundMgr::GetEnvVolume() { return m_nEnvVolume; } void SGameMilesSoundMgr::SetBgmVolume( int nVolume ) { m_nBgmVolume = nVolume; m_pSoundMng->SetBgmVolume( nVolume ); } int SGameMilesSoundMgr::GetBgmVolume() { return m_nBgmVolume; } void SGameMilesSoundMgr::SetMasterVolume( int nVolume ) { m_nMasterVolume = nVolume; m_pSoundMng->SetMasterVolume( nVolume ); } int SGameMilesSoundMgr::GetMasterVolume() { return m_nMasterVolume; } void SGameMilesSoundMgr::SetSfxMute( bool bMute ) { if( m_pSoundMng->GetMuteBuffer() == bMute ) return; m_pSoundMng->SetMute_Buffer( bMute ); if( bMute ) m_pSoundMng->SetSfxVolume( 0 ); else m_pSoundMng->SetSfxVolume( m_nSfxVolume ); } void SGameMilesSoundMgr::SetEnvMute( bool bMute ) { if( m_pMusic->IsMuteStream() == bMute ) return; m_pMusic->MusicMute( bMute ); if( bMute ) { StopMusic(); } else { PlayMusic( m_pMusic->m_strPlayMusicName.c_str(), m_pMusic->m_bMusicLoop ); } } void SGameMilesSoundMgr::SetBgmMute( bool bMute ) { if( m_pBgm->IsMuteStream() == bMute ) return; m_pBgm->MusicMute( bMute ); if( bMute ) { StopBgm(); } else { PlayBGM( m_pBgm->m_strPlayMusicName.c_str(), m_pBgm->m_bMusicLoop ); } } void SGameMilesSoundMgr::SetSoundMute( bool bMute ) { if( m_bMasterMute == bMute ) return; SetSfxMute( bMute ); SetEnvMute( bMute ); SetBgmMute( bMute ); if( bMute ) m_pSoundMng->SetMasterVolume( 0 ); else m_pSoundMng->SetMasterVolume( m_nMasterVolume ); m_pSoundMng->SetMute_Stream( bMute ); m_bMasterMute = bMute; } int SGameMilesSoundMgr::ForcePlayMusic( const char *szKeyName, int nVolume, bool bLoop ) { StopMusic(); if( nVolume == -1 ) nVolume = 100; int nLoopCount = 1; if( bLoop ) nLoopCount = 0; int nIndex = m_pSoundMng->Play_Stream( szKeyName, nLoopCount, nVolume, nVolume, CallBack ); if( nIndex != -1 ) { m_pMusic->m_strPlayMusicName = szKeyName; m_pMusic->m_bMusicLoop = bLoop; } return nIndex; } int SGameMilesSoundMgr::PlayMusic( const char *szKeyName, int nVolume, bool bLoop ) { StopMusic(); if( m_pMusic->IsMuteStream() ) return -1; if( m_pSoundMng->GetMuteStream() ) return -1; if( nVolume == -1 ) nVolume = 100; int nLoopCount = 1; if( bLoop ) nLoopCount = 0; int nIndex = m_pSoundMng->Play_Stream( szKeyName, nLoopCount, nVolume, nVolume, CallBack ); if( nIndex != -1 ) { m_pMusic->m_strPlayMusicName = szKeyName; m_pMusic->m_bMusicLoop = bLoop; } return nIndex; } void SGameMilesSoundMgr::SwapPlayMusic( const char *szKeyName, int nFadeInTime, int nFadeOutTime, int nVolume, bool bLoop ) { //FadeIn 볼륨 업 //FadeOut 볼륨 다운 //FadeIn == true 볼륨업 == false 볼륨 다운 if( !m_pMusic->m_strPlayMusicName.empty() ) { if( m_pSoundMng->IsPlayStream( m_pMusic->m_strPlayMusicName.c_str() ) ) { int nIndex = m_pSoundMng->GetStreamIndex( m_pMusic->m_strPlayMusicName.c_str() ); if( nIndex != -1 ) { if( !m_pMusic->m_strFilterMusicName.empty() ) { m_pSoundMng->Stop_Stream( m_pMusic->m_strFilterMusicName.c_str() ); m_pSoundMng->UnLoad_Stream( m_pMusic->m_strFilterMusicName.c_str() ); m_pMusic->ResetFilter(); } SetFadeStream( m_pMusic->m_strPlayMusicName.c_str(), nFadeOutTime, false ); m_pMusic->SetFilter( m_pMusic->m_strPlayMusicName.c_str(), MusicKey::FILTER_VOLUME_RAMP ); } } } if( m_pMusic->IsMuteStream() ) return; if( m_pSoundMng->GetMuteStream() ) return; m_pMusic->m_strPlayMusicName = szKeyName; if( m_pMusic->m_strPlayMusicName.empty() ) return; int nIndex = m_pSoundMng->GetStreamIndex( szKeyName ); if( nIndex != -1 ) { if( m_pSoundMng->IsPlayStream( szKeyName ) ) { SetFadeStream( szKeyName, nFadeInTime, true ); return; } } if( nVolume == -1 ) nVolume = 100; int nLoopCount = 1; if( bLoop ) nLoopCount = 0; m_pMusic->m_bMusicLoop = bLoop; m_pSoundMng->Play_Stream( szKeyName, nLoopCount, nVolume, nVolume, CallBack ); SetFadeStream( szKeyName, nFadeInTime, true ); } void SGameMilesSoundMgr::StopMusic() { if( !m_pMusic->m_strPlayMusicName.empty() ) { m_pSoundMng->Stop_Stream( m_pMusic->m_strPlayMusicName.c_str() ); m_pSoundMng->UnLoad_Stream( m_pMusic->m_strPlayMusicName.c_str() ); m_pMusic->Reset(); } if( !m_pMusic->m_strFilterMusicName.empty() ) { m_pSoundMng->Stop_Stream( m_pMusic->m_strFilterMusicName.c_str() ); m_pSoundMng->UnLoad_Stream( m_pMusic->m_strFilterMusicName.c_str() ); m_pMusic->ResetFilter(); } } int SGameMilesSoundMgr::PlayBGM( const char *szKeyName, int nVolume, bool bLoop ) { StopBgm(); if( m_pBgm->IsMuteStream() ) return -1; if( m_pSoundMng->GetMuteStream() ) return -1; if( nVolume == -1 ) nVolume = 100; int nLoopCount = 1; if( bLoop ) nLoopCount = 0; int nIndex = m_pSoundMng->Play_Bgm_Stream( szKeyName, nLoopCount, nVolume, nVolume, CallBack ); if( nIndex != -1 ) { m_pBgm->m_strPlayMusicName = szKeyName; m_pBgm->m_bMusicLoop = bLoop; } return nIndex; } void SGameMilesSoundMgr::SwapPlayBGM( const char *szKeyName, int nFadeInTime, int nFadeOutTime, int nVolume, bool bLoop ) { if( !m_pBgm->m_strPlayMusicName.empty() ) { if( m_pSoundMng->IsPlayStream( m_pBgm->m_strPlayMusicName.c_str() ) ) { int nIndex = m_pSoundMng->GetStreamIndex( m_pBgm->m_strPlayMusicName.c_str() ); if( nIndex != -1 ) { if( !m_pBgm->m_strFilterMusicName.empty() ) { m_pSoundMng->Stop_Stream( m_pBgm->m_strFilterMusicName.c_str() ); m_pSoundMng->UnLoad_Stream( m_pBgm->m_strFilterMusicName.c_str() ); m_pBgm->ResetFilter(); } SetFadeStream( m_pBgm->m_strPlayMusicName.c_str(), nFadeOutTime, false ); m_pBgm->SetFilter( m_pBgm->m_strPlayMusicName.c_str(), MusicKey::FILTER_VOLUME_RAMP ); } } } if( m_pBgm->IsMuteStream() ) return; if( m_pSoundMng->GetMuteStream() ) return; m_pBgm->m_strPlayMusicName = szKeyName; if( m_pBgm->m_strPlayMusicName.empty() ) return; int nIndex = m_pSoundMng->GetStreamIndex( szKeyName ); if( nIndex != -1 ) { if( m_pSoundMng->IsPlayStream( szKeyName ) ) { SetFadeStream( szKeyName, nFadeInTime, true ); return; } } if( nVolume == -1 ) nVolume = 100; int nLoopCount = 1; if( bLoop ) nLoopCount = 0; m_pBgm->m_bMusicLoop = bLoop; m_pSoundMng->Play_Bgm_Stream( szKeyName, nLoopCount, nVolume, nVolume, CallBack ); SetFadeStream( szKeyName, nFadeInTime, true ); } void SGameMilesSoundMgr::StopBgm() { if( !m_pBgm->m_strPlayMusicName.empty() ) { m_pSoundMng->Stop_Stream( m_pBgm->m_strPlayMusicName.c_str() ); m_pSoundMng->UnLoad_Stream( m_pBgm->m_strPlayMusicName.c_str() ); m_pBgm->Reset(); } if( !m_pBgm->m_strFilterMusicName.empty() ) { m_pSoundMng->Stop_Stream( m_pBgm->m_strFilterMusicName.c_str() ); m_pSoundMng->UnLoad_Stream( m_pBgm->m_strFilterMusicName.c_str() ); m_pBgm->ResetFilter(); } } void SGameMilesSoundMgr::SetFadeStream( const char* szFileName, int nTime, bool bFadeIn ) { m_pSoundMng->SetFade_Stream( szFileName, nTime, bFadeIn ); } void SGameMilesSoundMgr::UnLoadAllStream() { m_pSoundMng->UnLoadAllStream(); } bool SGameMilesSoundMgr::IsPlayMusic() { if( m_pMusic->m_strPlayMusicName.empty() && ( m_pMusic->IsMuteStream() || m_pSoundMng->GetMuteStream() ) ) { return false; } return m_pSoundMng->IsPlayStream( m_pMusic->m_strPlayMusicName.c_str() ); } bool SGameMilesSoundMgr::IsPlayBGM() { if( m_pBgm->m_strPlayMusicName.empty() && ( m_pBgm->IsMuteStream() || m_pSoundMng->GetMuteStream() ) ) { return false; } return m_pSoundMng->IsPlayStream( m_pBgm->m_strPlayMusicName.c_str() ); } int SGameMilesSoundMgr::StartSound( const char *szKeyName, int nVolume, bool bLoop ) { if( m_pSoundMng->GetMuteBuffer() ) return -1; int nLoopCnt = 1; if( bLoop ) nLoopCnt = 0; if( nVolume == -1 ) nVolume = 100; static TSoundKey tSoundKey2D; if ( m_pSoundMng->Play_Sound2D( false, &tSoundKey2D, szKeyName, nLoopCnt, nVolume, nVolume, m_nPlayRate ) ) { return tSoundKey2D.m_nBufferIndex; } return -1; } int SGameMilesSoundMgr::PlaySound3D( const char *szKeyName, float x, float y, float z, int nVolume, bool bLoop, bool bReverb, bool bLowPass ) { if( m_pSoundMng->GetMuteBuffer() ) return -1; int nLoopCnt = 1; if( bLoop ) nLoopCnt = 0; if( nVolume == -1 ) nVolume = 100; static TSoundKey tSoundKey3D; if ( m_pSoundMng->Play_Sound( false, &tSoundKey3D, szKeyName, x, y, z, nLoopCnt, nVolume, nVolume, m_nPlayRate, bReverb, bLowPass ) ) { return tSoundKey3D.m_nBufferIndex; } return -1; } void SGameMilesSoundMgr::StopAllSound() { m_pSoundMng->Stop_AllSound(); } void SGameMilesSoundMgr::StopSound( const char *szKeyName ) { m_pSoundMng->Stop_Sound( szKeyName ); } void SGameMilesSoundMgr::StopSound( int nBufferIndex ) { m_pSoundMng->Stop_Sound( nBufferIndex ); } void SGameMilesSoundMgr::StopSound( int nBufferIndex, int nSampleIndex ) { m_pSoundMng->Stop_Sound( nBufferIndex, nSampleIndex ); } void SGameMilesSoundMgr::UnLoadSound( const char *szKeyName ) { m_pSoundMng->UnLoad( szKeyName ); } void SGameMilesSoundMgr::SetListenerPosition( float x, float y, float z ) { m_pSoundMng->SetPosition( x, y, z ); } void SGameMilesSoundMgr::SetSampleListenerPosition( int nBuffer, int nSampleBuffer, float x, float y, float z ) { m_pSoundMng->SetPosition_Sample( nBuffer, nSampleBuffer, x, y, z ); } void SGameMilesSoundMgr::SetOrientation( float face_x, float face_y, float face_z, float up_x, float up_y, float up_z ) { m_pSoundMng->SetOrientation( face_x, face_y, face_z, up_x, up_y, up_z ); } //마일즈 컬백함수 - 로비에서 BGM끝났을때 다음 BGM Play시키는 용도. void AILCALLBACK SGameMilesSoundMgr::CallBack( HSTREAM stream ) { }