462 lines
8.6 KiB
C++
462 lines
8.6 KiB
C++
#include "stdafx.h"
|
|
|
|
#include "WTYPES.h"
|
|
#include <sound/XStreamReader.h>
|
|
|
|
#include "K3DTypes.h"
|
|
#include <kfile/KFiler.h>
|
|
#include "KResourceManager.h"
|
|
|
|
|
|
//#include <kfile/KFileManager.h>
|
|
|
|
//#include "./Util/KSystemMacro.h"
|
|
|
|
|
|
|
|
#include "SGameSound.h"
|
|
|
|
|
|
#include <sound/GlobalCutOffFreqTable.h> //해주기 - 나중에 로우필터 각 소리마다 해주게 되면 빼준다.
|
|
|
|
|
|
//==============================================================================
|
|
/*
|
|
struct AudiereStreamAdapter : public audiere::RefImplementation<audiere::File>
|
|
{
|
|
public:
|
|
AudiereStreamAdapter( KStream * p )
|
|
{
|
|
pStream = p;
|
|
};
|
|
|
|
~AudiereStreamAdapter()
|
|
{
|
|
if(pStream)
|
|
{
|
|
delete pStream;
|
|
}
|
|
};
|
|
|
|
bool IsValid()
|
|
{
|
|
return pStream ? true : false;
|
|
}
|
|
|
|
virtual int ADR_CALL read(void* buffer, int size)
|
|
{
|
|
return (int)pStream->Read( buffer, size );
|
|
};
|
|
|
|
virtual bool ADR_CALL seek(int position, SeekMode mode)
|
|
{
|
|
KStream::enum_seek_origin nOrigin;
|
|
|
|
if( mode == SEEK_CUR ) nOrigin = KStream::seekCur;
|
|
if( mode == SEEK_END ) nOrigin = KStream::seekEnd;
|
|
if( mode == SEEK_SET ) nOrigin = KStream::seekSet;
|
|
|
|
pStream->Seek( position, nOrigin );
|
|
|
|
return true;
|
|
};
|
|
|
|
virtual int ADR_CALL tell()
|
|
{
|
|
return (int)pStream->Tell();
|
|
};
|
|
|
|
KStream *pStream;
|
|
};
|
|
*/
|
|
struct StreamAdapter : public XStreamReader
|
|
{
|
|
StreamAdapter( KStream * p )
|
|
{
|
|
pStream = p;
|
|
}
|
|
|
|
bool IsValid()
|
|
{
|
|
return pStream ? true : false;
|
|
}
|
|
|
|
size_t Read( void * p, size_t len )
|
|
{
|
|
return pStream->Read( p, len );
|
|
}
|
|
bool Seek( long pos, int cur )
|
|
{
|
|
KStream::enum_seek_origin nOrigin;
|
|
|
|
if( cur == SEEK_CUR ) nOrigin = KStream::seekCur;
|
|
if( cur == SEEK_END ) nOrigin = KStream::seekEnd;
|
|
if( cur == SEEK_SET ) nOrigin = KStream::seekSet;
|
|
|
|
pStream->Seek( pos, nOrigin );
|
|
|
|
return true;
|
|
}
|
|
|
|
bool IsEOF()
|
|
{
|
|
return pStream->Eos();
|
|
}
|
|
|
|
~StreamAdapter()
|
|
{
|
|
KFileManager::Instance().DeleteStream( pStream );
|
|
}
|
|
|
|
KStream *pStream;
|
|
};
|
|
|
|
SSoundManager::SSoundManager()
|
|
{
|
|
m_pMusicPlayer = new XMusicPlayer;
|
|
m_pSoundMng = new XSoundManager;
|
|
m_nNewIndex = 0;
|
|
|
|
#ifdef _STOOL
|
|
m_hWnd = NULL;
|
|
#endif
|
|
|
|
m_bIsUseAble = false;
|
|
|
|
m_bSFX_Mute = false;
|
|
m_bBGM_Mute = false;
|
|
|
|
m_bMuteLoop = false;
|
|
}
|
|
|
|
SSoundManager::~SSoundManager()
|
|
{
|
|
m_hashSound.clear();
|
|
|
|
//순서 있음. DeInit을 맨 나중에..
|
|
DeInit();
|
|
SAFE_DELETE(m_pSoundMng);
|
|
SAFE_DELETE(m_pMusicPlayer);
|
|
}
|
|
|
|
void SSoundManager::SetMute( bool bFlag )
|
|
{
|
|
m_bSFX_Mute = bFlag;
|
|
}
|
|
|
|
void SSoundManager::SetMusicMute( bool bFlag )
|
|
{
|
|
m_bBGM_Mute = bFlag;
|
|
|
|
if( m_bBGM_Mute )
|
|
{
|
|
SetMusicVolume(0);
|
|
}
|
|
else
|
|
{
|
|
SetMusicVolume( GetMusicVolume() ); //이전 값 복구
|
|
|
|
//음소거 해제 시 PlayMusic 마지막으로 호출 된것을 다시 플레이
|
|
if( !m_strMuteMusicName.empty() )
|
|
{
|
|
PlayMusic( m_strMuteMusicName.c_str(), m_bMuteLoop );
|
|
}
|
|
}
|
|
}
|
|
|
|
int SSoundManager::StartSound( const char * pName, bool bUse3D, bool bLoop, int nVolume , bool bStream)
|
|
{
|
|
if( m_bSFX_Mute ) return -1;
|
|
|
|
if(nVolume==-1)
|
|
{
|
|
nVolume = 100;
|
|
}
|
|
|
|
int nIndex = PreLoad( pName, bUse3D ,bStream);
|
|
|
|
if( nIndex >= 0 )
|
|
return m_pSoundMng->Play( nIndex, bUse3D, bLoop, nVolume, bStream);
|
|
|
|
return nIndex;
|
|
}
|
|
|
|
int SSoundManager::StartSound( const char * pName, bool bUse3D, float x, float y, float z, bool bLoop, int nVolume , bool bStream)
|
|
{
|
|
if( m_bSFX_Mute ) return -1;
|
|
|
|
if(nVolume==-1)
|
|
{
|
|
nVolume = 100;
|
|
}
|
|
|
|
int nIndex = PreLoad( pName, bUse3D ,bStream);
|
|
|
|
if( nIndex >= 0 )
|
|
return m_pSoundMng->Play( nIndex, x, y, z, bLoop, nVolume, bStream);
|
|
|
|
return nIndex;
|
|
}
|
|
|
|
int SSoundManager::PreLoad( const char * pName, bool bUse3D , bool bStream)
|
|
{
|
|
if( bStream)
|
|
{
|
|
return PreLoad_Stream(pName, bUse3D);
|
|
}
|
|
else
|
|
{
|
|
return PreLoad_Buffer(pName, bUse3D);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
int SSoundManager::PreLoad_Buffer( const char * pName, bool bUse3D )
|
|
{
|
|
if( !m_bIsUseAble ) return -3;
|
|
|
|
int nIndex = -1;
|
|
|
|
if( m_hashSound.lookup( pName, nIndex ) == false )
|
|
{
|
|
AudiereStreamAdapter file( KFileManager::Instance().CreateStreamFromResource( pName ) );
|
|
file.ref();
|
|
|
|
if( !file.IsValid() )
|
|
{
|
|
return -2;
|
|
}
|
|
|
|
if( m_pSoundMng->Load( m_nNewIndex, pName, &file, bUse3D ,false) )
|
|
{
|
|
//Load 완료~
|
|
m_pSoundMng->SetMinMax( m_nNewIndex, 0, 100 );
|
|
m_hashSound.add( pName, m_nNewIndex );
|
|
nIndex = m_nNewIndex;
|
|
m_nNewIndex++;
|
|
}
|
|
else
|
|
{ //Load Fail
|
|
#ifdef _STOOL
|
|
std::string str;
|
|
str = "지원 안되는 Wav 화일 : ";
|
|
str += pName;
|
|
MessageBox( m_hWnd, str.c_str(), "wav Error",MB_OK|MB_ICONERROR );
|
|
#endif
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return nIndex;
|
|
}
|
|
|
|
|
|
|
|
int SSoundManager::PreLoad_Stream( const char * pName, bool bUse3D )
|
|
{
|
|
if( !m_bIsUseAble ) return -3;
|
|
|
|
int nIndex = -1;
|
|
///PS: InputStream로 사용할때
|
|
if( m_hashSound.lookup( pName, nIndex ) == false )
|
|
{
|
|
//ps : InputStream 으로 할때
|
|
AudiereStreamAdapter *pfile = new AudiereStreamAdapter( KFileManager::Instance().CreateStreamFromResource( pName ) );
|
|
|
|
|
|
if( !pfile->IsValid() )
|
|
{
|
|
delete pfile;
|
|
return -2;
|
|
}
|
|
|
|
if( m_pSoundMng->Load( m_nNewIndex, pName, pfile, bUse3D , true) )
|
|
{
|
|
//Load 완료~
|
|
m_pSoundMng->SetMinMax( m_nNewIndex, 0, 100 );
|
|
m_hashSound.add( pName, m_nNewIndex );
|
|
nIndex = m_nNewIndex;
|
|
m_nNewIndex++;
|
|
}
|
|
else
|
|
{ //Load Fail
|
|
delete pfile;
|
|
return -1;
|
|
}
|
|
}
|
|
return nIndex;
|
|
}
|
|
|
|
bool SSoundManager::IsMusicPlaying()
|
|
{
|
|
if( m_bBGM_Mute ) return true; //바꿀 필요 없으므로
|
|
if( !m_bIsUseAble ) return true;
|
|
|
|
return m_pMusicPlayer->IsPlaying();
|
|
}
|
|
|
|
bool SSoundManager::ForcePlayMusic( const char * pName, bool bLoop )
|
|
{
|
|
if( !m_bIsUseAble ) return false;
|
|
|
|
// _oprint( "ForcePlayMusic : %s\n", pName );
|
|
|
|
if( _stricmp( pName, m_strMusicName.c_str() ) == 0 && m_pMusicPlayer->IsPlaying() )
|
|
return true;
|
|
|
|
bool bRtn = m_pMusicPlayer->Swap( pName, 100, 25 );
|
|
m_pMusicPlayer->Play( bLoop );
|
|
return bRtn;
|
|
}
|
|
|
|
bool SSoundManager::PlayMusic( const char * pName, bool bLoop )
|
|
{
|
|
_oprint( "PlayMusic : %s\n", pName );
|
|
|
|
m_strMuteMusicName = pName;
|
|
m_bMuteLoop = bLoop;
|
|
|
|
if( m_bBGM_Mute )
|
|
return false;
|
|
|
|
if( !m_bIsUseAble ) return false;
|
|
|
|
if( _stricmp( pName, m_strMusicName.c_str() ) == 0 && m_pMusicPlayer->IsPlaying() )
|
|
return true;
|
|
|
|
bool bRtn = m_pMusicPlayer->Swap( pName, 100, 25 );
|
|
m_strMusicName = pName;
|
|
m_pMusicPlayer->SetLoop( true );
|
|
m_pMusicPlayer->Play( bLoop );
|
|
return bRtn;
|
|
}
|
|
|
|
void SSoundManager::StopMusic()
|
|
{
|
|
if( !m_bIsUseAble ) return;
|
|
m_pMusicPlayer->Stop();
|
|
}
|
|
|
|
|
|
bool SSoundManager::Init( void* hWnd, bool bGlobal, bool bUse3D, bool bIsStereo, unsigned freq, unsigned bit )
|
|
{
|
|
#ifdef _STOOL
|
|
m_hWnd = (HWND)hWnd;
|
|
#endif
|
|
|
|
if( !m_pMusicPlayer->Init() ) return false;
|
|
|
|
m_bIsUseAble = m_pSoundMng->Init( hWnd );
|
|
|
|
return m_bIsUseAble;
|
|
}
|
|
|
|
bool SSoundManager::DeInit()
|
|
{
|
|
if( !m_bIsUseAble ) return false;
|
|
|
|
m_pMusicPlayer->DeInit();
|
|
|
|
return m_pSoundMng->DeInit();
|
|
}
|
|
|
|
bool SSoundManager::UnLoad( unsigned short idx )
|
|
{
|
|
if( !m_bIsUseAble ) return false;
|
|
|
|
return m_pSoundMng->UnLoad(idx);
|
|
}
|
|
|
|
bool SSoundManager::SetMinMax( unsigned short idx, float fMin, float fMax )
|
|
{
|
|
if( !m_bIsUseAble ) return false;
|
|
|
|
return m_pSoundMng->SetMinMax( idx, fMin, fMax );
|
|
}
|
|
|
|
bool SSoundManager::SetListenerPosition( float x, float y, float z )
|
|
{
|
|
if( !m_bIsUseAble ) return false;
|
|
|
|
return m_pSoundMng->SetListenerPosition( x, y, z );
|
|
}
|
|
|
|
bool SSoundManager::SetCameraPosition( float x, float y, float z )
|
|
{
|
|
if( !m_bIsUseAble ) return false;
|
|
|
|
return m_pSoundMng->SetCameraPosition( x, y, z );
|
|
}
|
|
|
|
bool SSoundManager::SetVolume( int nVolume )
|
|
{
|
|
if( !m_bIsUseAble ) return false;
|
|
|
|
return m_pSoundMng->SetVolume(nVolume);
|
|
}
|
|
|
|
int SSoundManager::GetVolume()
|
|
{
|
|
if( !m_bIsUseAble ) return 0;
|
|
|
|
return m_pSoundMng->GetVolume();
|
|
}
|
|
|
|
void SSoundManager::SetMusicVolume( int nVolume )
|
|
{
|
|
if( !m_bIsUseAble ) return;
|
|
|
|
m_pMusicPlayer->SetVolume( nVolume );
|
|
}
|
|
|
|
int SSoundManager::GetMusicVolume()
|
|
{
|
|
if( !m_bIsUseAble ) return 0;
|
|
|
|
return m_pMusicPlayer->GetVolume();
|
|
}
|
|
|
|
|
|
|
|
void SSoundManager::StopSound( const char * pName, int play_id )
|
|
{
|
|
if( !m_bIsUseAble ) return;
|
|
|
|
int nIndex = -1;
|
|
if( m_hashSound.lookup( pName, nIndex ) == false )
|
|
return;
|
|
|
|
m_pSoundMng->Stop( nIndex, play_id );
|
|
}
|
|
|
|
|
|
|
|
|
|
//해주기- 거리에 따른 자동 로우필터 함수 들어가면 이함수 빼주기.
|
|
bool SSoundManager::SetLowFilter( const char * pName, int play_id, int frequency )
|
|
{
|
|
if( !m_bIsUseAble ) return false;
|
|
|
|
int nIndex = -1;
|
|
if( m_hashSound.lookup( pName, nIndex ) == false )
|
|
return false;
|
|
|
|
return m_pSoundMng->SetLowFilter( nIndex, play_id, frequency);
|
|
}
|
|
|
|
|
|
//해주기 - 거리에 따른 자동 로우필터를 각 소리마다 set하게 되면 이부분 알맞게 변경해준다.
|
|
void SSoundManager::SetCutOffFreqRate( float fDistMin, float fDist, float fDistData)
|
|
{
|
|
GCutOffFreqTable *pCutOff = GCutOffFreqTable::GetCutOffFreqTable(); //싱글톤 접근자.
|
|
pCutOff->SetCutOffFreqRate( fDistMin, fDist, fDistData);
|
|
}
|
|
|
|
|
|
|
|
|