isle-portable/LEGO1/mxsoundmanager.cpp

203 lines
4.2 KiB
C++
Raw Normal View History

#include "mxsoundmanager.h"
2023-10-24 19:38:27 -04:00
#include "define.h"
#include "mxautolocker.h"
#include "mxomni.h"
#include "mxpresenter.h"
2023-10-24 19:38:27 -04:00
#include "mxticklemanager.h"
#include "mxwavepresenter.h"
DECOMP_SIZE_ASSERT(MxSoundManager, 0x3c);
// OFFSET: LEGO1 0x100ae740
MxSoundManager::MxSoundManager()
{
2023-10-24 19:38:27 -04:00
Init();
}
// OFFSET: LEGO1 0x100ae7d0
MxSoundManager::~MxSoundManager()
{
2023-10-24 19:38:27 -04:00
Destroy(TRUE);
}
// OFFSET: LEGO1 0x100ae830
void MxSoundManager::Init()
{
m_directSound = NULL;
2023-10-24 19:38:27 -04:00
m_dsBuffer = NULL;
}
// OFFSET: LEGO1 0x100ae840
void MxSoundManager::Destroy(MxBool p_fromDestructor)
{
2023-10-24 19:38:27 -04:00
if (this->m_thread) {
this->m_thread->Terminate();
delete this->m_thread;
}
else {
TickleManager()->UnregisterClient(this);
}
2023-10-24 19:38:27 -04:00
this->m_criticalSection.Enter();
2023-10-24 19:38:27 -04:00
if (this->m_dsBuffer) {
this->m_dsBuffer->Release();
}
2023-10-24 19:38:27 -04:00
Init();
this->m_criticalSection.Leave();
2023-10-24 19:38:27 -04:00
if (!p_fromDestructor) {
MxAudioManager::Destroy();
}
}
// OFFSET: LEGO1 0x100ae8b0
MxResult MxSoundManager::Create(MxU32 p_frequencyMS, MxBool p_createThread)
{
MxResult status = FAILURE;
MxBool locked = FALSE;
if (MxAudioManager::InitPresenters() != SUCCESS)
goto done;
m_criticalSection.Enter();
locked = TRUE;
if (DirectSoundCreate(NULL, &m_directSound, NULL) != DS_OK)
goto done;
if (m_directSound->SetCooperativeLevel(MxOmni::GetInstance()->GetWindowHandle(), DSSCL_PRIORITY) != DS_OK)
goto done;
DSBUFFERDESC desc;
memset(&desc, 0, sizeof(desc));
desc.dwSize = sizeof(desc);
if (MxOmni::IsSound3D())
desc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRL3D;
else
desc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLVOLUME;
if (m_directSound->CreateSoundBuffer(&desc, &m_dsBuffer, NULL) != DS_OK) {
if (!MxOmni::IsSound3D())
goto done;
MxOmni::SetSound3D(FALSE);
desc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLVOLUME;
if (m_directSound->CreateSoundBuffer(&desc, &m_dsBuffer, NULL) != DS_OK)
goto done;
}
WAVEFORMATEX format;
format.wFormatTag = WAVE_FORMAT_PCM;
if (MxOmni::IsSound3D())
format.nChannels = 2;
else
format.nChannels = 1;
format.nSamplesPerSec = 11025; // KHz
format.wBitsPerSample = 16;
format.nBlockAlign = format.nChannels * 2;
format.nAvgBytesPerSec = format.nBlockAlign * 11025;
format.cbSize = 0;
status = m_dsBuffer->SetFormat(&format);
if (p_createThread) {
m_thread = new MxTickleThread(this, p_frequencyMS);
if (!m_thread || m_thread->Start(0, 0) != SUCCESS)
goto done;
}
else
TickleManager()->RegisterClient(this, p_frequencyMS);
status = SUCCESS;
done:
if (status != SUCCESS)
Destroy();
if (locked)
m_criticalSection.Leave();
return status;
}
// OFFSET: LEGO1 0x100aeab0
void MxSoundManager::Destroy()
{
Destroy(FALSE);
}
// OFFSET: LEGO1 0x100aeac0
void MxSoundManager::SetVolume(MxS32 p_volume)
{
MxAudioManager::SetVolume(p_volume);
m_criticalSection.Enter();
MxPresenter* presenter;
MxPresenterListCursor cursor(m_presenters);
while (cursor.Next(presenter))
((MxAudioPresenter*) presenter)->vtable60(((MxAudioPresenter*) presenter)->vtable5c());
m_criticalSection.Leave();
}
// OFFSET: LEGO1 0x100aebd0
MxPresenter* MxSoundManager::FUN_100aebd0(const MxAtomId& p_atomId, MxU32 p_objectId)
{
MxAutoLocker lock(&m_criticalSection);
MxPresenter* presenter;
MxPresenterListCursor cursor(m_presenters);
while (cursor.Next(presenter)) {
if (presenter->GetAction()->GetAtomId().GetInternal() == p_atomId.GetInternal() &&
presenter->GetAction()->GetObjectId() == p_objectId)
return presenter;
}
return NULL;
}
// OFFSET: LEGO1 0x100aecf0
MxS32 MxSoundManager::FUN_100aecf0(MxU32 p_unk)
{
if (!p_unk)
return -10000;
return g_mxcoreCount[p_unk];
}
// OFFSET: LEGO1 0x100aed10
void MxSoundManager::vtable0x34()
{
MxAutoLocker lock(&m_criticalSection);
MxPresenter* presenter;
MxPresenterListCursor cursor(m_presenters);
while (cursor.Next(presenter))
if (presenter->IsA("MxWavePresenter"))
((MxWavePresenter*) presenter)->VTable0x64();
}
// OFFSET: LEGO1 0x100aee10
void MxSoundManager::vtable0x38()
{
MxAutoLocker lock(&m_criticalSection);
MxPresenter* presenter;
MxPresenterListCursor cursor(m_presenters);
while (cursor.Next(presenter))
if (presenter->IsA("MxWavePresenter"))
((MxWavePresenter*) presenter)->VTable0x68();
}