250 lines
5.0 KiB
C++
250 lines
5.0 KiB
C++
// DXSoundManager.cpp : Defines the entry point for the DLL application.
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
#ifdef CK_LIB
|
|
#define CreateNewManager CreateNewSoundManager
|
|
#define RemoveManager RemoveSoundManager
|
|
#define CKGetPluginInfoCount CKGet_SoundManager_PluginInfoCount
|
|
#define CKGetPluginInfo CKGet_SoundManager_PluginInfo
|
|
#define g_PluginInfo g_SoundManager_PluginInfo
|
|
#else
|
|
#define CreateNewManager CreateNewManager
|
|
#define RemoveManager RemoveManager
|
|
#define CKGetPluginInfoCount CKGetPluginInfoCount
|
|
#define CKGetPluginInfo CKGetPluginInfo
|
|
#define g_PluginInfo g_PluginInfo
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "DxSoundManager.h"
|
|
|
|
#include <objbase.h>
|
|
#include <initguid.h>
|
|
|
|
|
|
CKPluginInfo g_PluginInfo;
|
|
#define DX7_SOUNDMANAGER_GUID CKGUID(0x77135393,0x225c679a)
|
|
|
|
char* DXSoundManagerName="DirectX Sound Manager";
|
|
|
|
long g_InitialVolume = -600;
|
|
BOOL g_InitialVolumeChanged = FALSE;
|
|
|
|
CKERROR CreateDx3SoundManager(CKContext *ctx);
|
|
CKERROR CreateDx7SoundManager(CKContext *ctx);
|
|
CKERROR CreateDx8SoundManager(CKContext *ctx);
|
|
|
|
|
|
DWORD GetDXVersion();
|
|
|
|
CKERROR CreateNewManager(CKContext* context)
|
|
{
|
|
|
|
if(GetDXVersion()>=0x0700)
|
|
return CreateDx7SoundManager(context);
|
|
else
|
|
return CreateDx3SoundManager(context);
|
|
|
|
return CK_OK;
|
|
}
|
|
|
|
CKERROR RemoveManager(CKContext* context)
|
|
{
|
|
DXSoundManager* man=(DXSoundManager*)context->GetManagerByName(DXSoundManagerName);
|
|
delete man;
|
|
return CK_OK;
|
|
}
|
|
|
|
|
|
|
|
CKPluginInfo* CKGetPluginInfo(int Index)
|
|
{
|
|
g_PluginInfo.m_Author = "Virtools";
|
|
g_PluginInfo.m_Description = "DirectX Sound Manager";
|
|
g_PluginInfo.m_Extension = "";
|
|
g_PluginInfo.m_Type = CKPLUGIN_MANAGER_DLL;
|
|
g_PluginInfo.m_Version = 0x000001;
|
|
g_PluginInfo.m_InitInstanceFct = CreateNewManager;
|
|
g_PluginInfo.m_ExitInstanceFct = RemoveManager;
|
|
g_PluginInfo.m_GUID = SOUND_MANAGER_GUID;//DX7_SOUNDMANAGER_GUID;
|
|
g_PluginInfo.m_Summary = DXSoundManagerName;
|
|
return &g_PluginInfo;
|
|
}
|
|
|
|
|
|
long FloatToDb(float f)
|
|
{
|
|
if (f <= 0.0f)
|
|
return -10000;
|
|
return (long)(2000.0*log10(f));
|
|
}
|
|
|
|
float DbToFloat(long d)
|
|
{
|
|
if (d <= -10000)
|
|
return 0.0f;
|
|
else
|
|
if (d > 0) return 1.0f;
|
|
return powf(10,d/2000.0f);
|
|
}
|
|
|
|
long FloatPanningToDb(float Panning)
|
|
{
|
|
|
|
if(Panning==0.0f)
|
|
return 0;
|
|
long l;
|
|
if(Panning>0.0f)
|
|
l = -FloatToDb(1.0f-Panning);
|
|
else
|
|
l = FloatToDb(1.0f+Panning);
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
float DbPanningToFloat(long d)
|
|
{
|
|
if (d>0) {
|
|
return 1-DbToFloat(-d);
|
|
}else
|
|
return -1.0f+DbToFloat(d);
|
|
}
|
|
|
|
|
|
|
|
DXSoundManager::DXSoundManager(CKContext *Context):CKSoundManager(Context,DXSoundManagerName)
|
|
{
|
|
}
|
|
|
|
DXSoundManager::~DXSoundManager()
|
|
{
|
|
}
|
|
|
|
|
|
//{secret}
|
|
CKERROR DXSoundManager::PostClearAll()
|
|
{
|
|
|
|
CKSoundManager::PostClearAll();
|
|
m_SoundsPlaying.Clear();
|
|
|
|
ReleaseMinions();
|
|
RegisterAttribute();
|
|
return CK_OK;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CKERROR
|
|
DXSoundManager::OnCKPause()
|
|
{
|
|
|
|
// InternalPause(m_BackSound);
|
|
|
|
|
|
// pause the playing sources
|
|
for(CK_ID* itw = m_SoundsPlaying.Begin();itw!=m_SoundsPlaying.End();itw++) {
|
|
CKWaveSound* ws = (CKWaveSound*)m_Context->GetObject(*itw);
|
|
// We check that the sound is not in 2D
|
|
if(ws) ws->Pause();
|
|
}
|
|
|
|
// We have to pause all the minions
|
|
PauseMinions();
|
|
|
|
return CK_OK;
|
|
}
|
|
|
|
CKERROR
|
|
DXSoundManager::OnCKPlay()
|
|
{
|
|
|
|
// InternalPlay(m_BackSound,TRUE);
|
|
|
|
// resume the playing sources
|
|
for(CK_ID* it = m_SoundsPlaying.Begin();it!=m_SoundsPlaying.End();it++) {
|
|
CKWaveSound* ws = (CKWaveSound*)m_Context->GetObject(*it);
|
|
// We check that the sound is not in 2D
|
|
if(ws) ws->Resume();
|
|
}
|
|
|
|
// We have to resume all the minions
|
|
ResumeMinions();
|
|
|
|
return CK_OK;
|
|
}
|
|
|
|
|
|
|
|
CKERROR
|
|
DXSoundManager::PreLaunchScene(CKScene* OldScene,CKScene* NewScene){
|
|
|
|
// Pause the playing sources
|
|
for(CK_ID* itw = m_SoundsPlaying.Begin();itw!=m_SoundsPlaying.End();itw++) {
|
|
CKWaveSound* ws = (CKWaveSound*)m_Context->GetObject(*itw);
|
|
// Pause sounds that are not in the new scene
|
|
if(!ws->IsInScene(NewScene))
|
|
ws->Pause();
|
|
}
|
|
|
|
// Stop Minions if their model is not in the New Scene
|
|
for (SoundMinion** it = m_Minions.Begin();it != m_Minions.End();) {
|
|
CKSceneObject *so = (CKSceneObject *) m_Context->GetObject((*it)->m_OriginalSound);
|
|
if(!so->IsInScene(NewScene)){
|
|
Stop(NULL,(*it)->m_Source);
|
|
ReleaseSource((*it)->m_Source);
|
|
delete *it;
|
|
it = m_Minions.Remove(it);
|
|
}else{
|
|
it++;
|
|
}
|
|
|
|
}
|
|
|
|
return CK_OK;
|
|
}
|
|
|
|
|
|
CKERROR
|
|
DXSoundManager::SequenceToBeDeleted(CK_ID *objids,int count){
|
|
|
|
|
|
CKSoundManager::SequenceToBeDeleted(objids,count);
|
|
|
|
// Stop and Remove the sound playing that must be deleted
|
|
for (CK_ID* it = m_SoundsPlaying.Begin(); it != m_SoundsPlaying.End();) {
|
|
CKWaveSound* ws = (CKWaveSound*)m_Context->GetObject(*it);
|
|
if (!ws || ws->IsToBeDeleted()){
|
|
if (ws)
|
|
ws->Stop();
|
|
it = m_SoundsPlaying.Remove(it);
|
|
} else
|
|
++it;
|
|
}
|
|
|
|
// Remove Deleted Entities from 3D Wave Sound
|
|
{
|
|
for (SoundMinion** it = m_Minions.Begin();it != m_Minions.End();it++) {
|
|
CKWaveSound* ws = (CKWaveSound*)m_Context->GetObject((*it)->m_OriginalSound);
|
|
if(ws && ws->IsToBeDeleted())
|
|
(*it)->m_OriginalSound = 0;
|
|
|
|
CKObject* o = m_Context->GetObject((*it)->m_Entity);
|
|
|
|
if(!o || o->IsToBeDeleted()){
|
|
(*it)->m_Entity = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
return CK_OK;
|
|
} |