mirror of
https://github.com/isledecomp/isle.git
synced 2025-10-24 17:04:17 +00:00
Reorganize sources and files (#414)
* Reorganize sources * Refactor * Remove relative paths * Renames * Fix gitignore * Remove stuff * Try fixing format script * Fix format * Fix format * Fix naming script * Test format * Fix format
This commit is contained in:
committed by
GitHub
parent
6a85e62406
commit
c47206617d
78
LEGO1/omni/src/audio/mxaudiomanager.cpp
Normal file
78
LEGO1/omni/src/audio/mxaudiomanager.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "mxaudiomanager.h"
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxAudioManager, 0x30);
|
||||
|
||||
// GLOBAL: LEGO1 0x10102108
|
||||
MxS32 MxAudioManager::g_count = 0;
|
||||
|
||||
// FUNCTION: LEGO1 0x10029910
|
||||
MxS32 MxAudioManager::GetVolume()
|
||||
{
|
||||
return this->m_volume;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b8d00
|
||||
MxAudioManager::MxAudioManager()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b8d90
|
||||
MxAudioManager::~MxAudioManager()
|
||||
{
|
||||
Destroy(TRUE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b8df0
|
||||
void MxAudioManager::Init()
|
||||
{
|
||||
this->m_volume = 100;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b8e00
|
||||
void MxAudioManager::Destroy(MxBool p_fromDestructor)
|
||||
{
|
||||
this->m_criticalSection.Enter();
|
||||
g_count--;
|
||||
Init();
|
||||
this->m_criticalSection.Leave();
|
||||
|
||||
if (!p_fromDestructor)
|
||||
MxMediaManager::Destroy();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b8e40
|
||||
MxResult MxAudioManager::InitPresenters()
|
||||
{
|
||||
MxResult result = FAILURE;
|
||||
MxBool success = FALSE;
|
||||
|
||||
if (MxMediaManager::InitPresenters() == SUCCESS) {
|
||||
this->m_criticalSection.Enter();
|
||||
success = TRUE;
|
||||
result = SUCCESS;
|
||||
g_count++;
|
||||
}
|
||||
|
||||
if (result)
|
||||
Destroy();
|
||||
|
||||
if (success)
|
||||
this->m_criticalSection.Leave();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b8e90
|
||||
void MxAudioManager::Destroy()
|
||||
{
|
||||
Destroy(FALSE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b8ea0
|
||||
void MxAudioManager::SetVolume(MxS32 p_volume)
|
||||
{
|
||||
this->m_criticalSection.Enter();
|
||||
this->m_volume = p_volume;
|
||||
this->m_criticalSection.Leave();
|
||||
}
|
||||
17
LEGO1/omni/src/audio/mxaudiopresenter.cpp
Normal file
17
LEGO1/omni/src/audio/mxaudiopresenter.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "mxaudiopresenter.h"
|
||||
|
||||
#include "decomp.h"
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxAudioPresenter, 0x54);
|
||||
|
||||
// FUNCTION: LEGO1 0x1000d260
|
||||
MxS32 MxAudioPresenter::GetVolume()
|
||||
{
|
||||
return m_volume;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1000d270
|
||||
void MxAudioPresenter::SetVolume(MxS32 p_volume)
|
||||
{
|
||||
m_volume = p_volume;
|
||||
}
|
||||
326
LEGO1/omni/src/audio/mxbackgroundaudiomanager.cpp
Normal file
326
LEGO1/omni/src/audio/mxbackgroundaudiomanager.cpp
Normal file
@@ -0,0 +1,326 @@
|
||||
#include "mxbackgroundaudiomanager.h"
|
||||
|
||||
#include "legoomni.h"
|
||||
#include "mxcompositepresenter.h"
|
||||
#include "mxdssound.h"
|
||||
#include "mxomni.h"
|
||||
#include "mxpresenter.h"
|
||||
#include "mxstreamer.h"
|
||||
#include "mxticklemanager.h"
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxBackgroundAudioManager, 0x150)
|
||||
|
||||
// FUNCTION: LEGO1 0x1007ea90
|
||||
MxBackgroundAudioManager::MxBackgroundAudioManager()
|
||||
{
|
||||
NotificationManager()->Register(this);
|
||||
m_unk0xa0 = 0;
|
||||
m_unk0x138 = 0;
|
||||
m_unk0x13c = 0;
|
||||
m_unk0x140 = 0;
|
||||
m_targetVolume = 0;
|
||||
m_unk0x148 = 0;
|
||||
m_musicEnabled = FALSE;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007ec20
|
||||
MxBackgroundAudioManager::~MxBackgroundAudioManager()
|
||||
{
|
||||
TickleManager()->UnregisterClient(this);
|
||||
NotificationManager()->Unregister(this);
|
||||
DestroyMusic();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007ece0
|
||||
MxResult MxBackgroundAudioManager::Create(MxAtomId& p_script, MxU32 p_frequencyMS)
|
||||
{
|
||||
MxResult result = OpenMusic(p_script);
|
||||
|
||||
if (result == SUCCESS) {
|
||||
TickleManager()->RegisterClient(this, p_frequencyMS);
|
||||
m_musicEnabled = TRUE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007ed20
|
||||
MxResult MxBackgroundAudioManager::OpenMusic(MxAtomId& p_script)
|
||||
{
|
||||
if (m_script.GetInternal())
|
||||
DestroyMusic();
|
||||
|
||||
MxResult result = FAILURE;
|
||||
|
||||
if (Streamer()->Open(p_script.GetInternal(), 0)) {
|
||||
m_script = p_script;
|
||||
result = SUCCESS;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007ed70
|
||||
void MxBackgroundAudioManager::DestroyMusic()
|
||||
{
|
||||
if (m_script.GetInternal()) {
|
||||
MxDSAction ds;
|
||||
ds.SetAtomId(m_script);
|
||||
ds.SetUnknown24(-2);
|
||||
DeleteObject(ds);
|
||||
Streamer()->Close(m_script.GetInternal());
|
||||
m_musicEnabled = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007ee40
|
||||
MxResult MxBackgroundAudioManager::Tickle()
|
||||
{
|
||||
switch (m_unk0x13c) {
|
||||
case MxPresenter::TickleState_Starting:
|
||||
FadeInOrFadeOut();
|
||||
return SUCCESS;
|
||||
case MxPresenter::TickleState_Streaming:
|
||||
FUN_1007ee70();
|
||||
return SUCCESS;
|
||||
case MxPresenter::TickleState_Repeating:
|
||||
FUN_1007ef40();
|
||||
return SUCCESS;
|
||||
default:
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007ee70
|
||||
void MxBackgroundAudioManager::FUN_1007ee70()
|
||||
{
|
||||
if (m_unk0xa0 && m_unk0xa0->GetAction()) {
|
||||
DeleteObject(*m_unk0x138->GetAction());
|
||||
}
|
||||
|
||||
if (m_unk0x138) {
|
||||
m_unk0xa0 = m_unk0x138;
|
||||
m_action1 = m_action2;
|
||||
m_unk0x138 = NULL;
|
||||
m_action2.SetObjectId(-1);
|
||||
m_action2.SetAtomId(MxAtomId());
|
||||
m_unk0x13c = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007ef40
|
||||
void MxBackgroundAudioManager::FUN_1007ef40()
|
||||
{
|
||||
MxU32 compare;
|
||||
MxU32 volume;
|
||||
if (m_unk0xa0 == NULL) {
|
||||
if (m_unk0x138) {
|
||||
compare = 30;
|
||||
if (m_unk0x148 == 0) {
|
||||
compare = m_unk0x148;
|
||||
}
|
||||
volume = m_unk0x138->GetVolume();
|
||||
if (volume < compare) {
|
||||
if (m_unk0x140 + m_unk0x138->GetVolume() <= compare) {
|
||||
compare = m_unk0x140 + compare;
|
||||
}
|
||||
m_unk0x138->SetVolume(compare);
|
||||
}
|
||||
else {
|
||||
m_unk0x138->SetVolume(compare);
|
||||
m_unk0xa0 = m_unk0x138;
|
||||
m_action1 = m_action2;
|
||||
m_unk0x138 = NULL;
|
||||
m_action2.SetObjectId(-1);
|
||||
m_action2.SetAtomId(MxAtomId());
|
||||
m_unk0x13c = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_unk0xa0->GetAction() != NULL) {
|
||||
if (m_unk0xa0->GetVolume() == 0) {
|
||||
DeleteObject(*m_unk0xa0->GetAction());
|
||||
}
|
||||
else {
|
||||
compare = m_unk0xa0->GetVolume();
|
||||
volume = 0;
|
||||
if (compare != m_unk0x140 && -1 < compare - m_unk0x140) {
|
||||
volume = m_unk0xa0->GetVolume() - m_unk0x140;
|
||||
}
|
||||
m_unk0x138->SetVolume(volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007f0e0
|
||||
void MxBackgroundAudioManager::FadeInOrFadeOut()
|
||||
{
|
||||
// This function probably is the fade in/out routine
|
||||
if (m_unk0xa0 != NULL) {
|
||||
undefined4 volume = m_unk0xa0->GetVolume();
|
||||
MxU32 compare = 30;
|
||||
if (m_unk0x148 == 0) {
|
||||
compare = m_targetVolume;
|
||||
}
|
||||
|
||||
if (volume < compare) {
|
||||
volume = m_unk0x140 + volume;
|
||||
if (compare <= volume) {
|
||||
volume = compare;
|
||||
}
|
||||
m_unk0xa0->SetVolume(volume);
|
||||
}
|
||||
else if (compare < volume) {
|
||||
volume = volume - m_unk0x140;
|
||||
if (volume <= compare) {
|
||||
volume = compare;
|
||||
}
|
||||
m_unk0xa0->SetVolume(volume);
|
||||
}
|
||||
else {
|
||||
m_unk0xa0->SetVolume(volume);
|
||||
m_unk0x13c = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_unk0x13c = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007f170
|
||||
MxLong MxBackgroundAudioManager::Notify(MxParam& p_param)
|
||||
{
|
||||
switch (((MxNotificationParam&) p_param).GetNotification()) {
|
||||
case c_notificationStartAction:
|
||||
StartAction(p_param);
|
||||
return 1;
|
||||
case c_notificationEndAction:
|
||||
StopAction(p_param);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007f1b0
|
||||
void MxBackgroundAudioManager::StartAction(MxParam& p_param)
|
||||
{
|
||||
// TODO: the sender is most likely a MxAudioPresenter?
|
||||
m_unk0x138 = (MxAudioPresenter*) ((MxNotificationParam&) p_param).GetSender();
|
||||
m_action2.SetAtomId(m_unk0x138->GetAction()->GetAtomId());
|
||||
m_action2.SetObjectId(m_unk0x138->GetAction()->GetObjectId());
|
||||
m_targetVolume = ((MxDSSound*) (m_unk0x138->GetAction()))->GetVolume();
|
||||
m_unk0x138->SetVolume(0);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007f200
|
||||
void MxBackgroundAudioManager::StopAction(MxParam& p_param)
|
||||
{
|
||||
if (((MxNotificationParam&) p_param).GetSender() == m_unk0xa0) {
|
||||
m_unk0xa0 = NULL;
|
||||
m_action1.SetAtomId(MxAtomId());
|
||||
m_action1.SetObjectId(-1);
|
||||
}
|
||||
else if (((MxNotificationParam&) p_param).GetSender() == m_unk0x138) {
|
||||
m_unk0x138 = NULL;
|
||||
m_action2.SetAtomId(MxAtomId());
|
||||
m_action2.SetObjectId(-1);
|
||||
}
|
||||
|
||||
Lego()->HandleActionEnd(p_param);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007f2f0
|
||||
MxResult MxBackgroundAudioManager::PlayMusic(MxDSAction& p_action, undefined4 p_unk0x140, undefined4 p_unk0x13c)
|
||||
{
|
||||
if (!m_musicEnabled) {
|
||||
return SUCCESS;
|
||||
}
|
||||
if (m_action2.GetObjectId() == -1 && m_action1.GetObjectId() != p_action.GetObjectId()) {
|
||||
MxDSAction action;
|
||||
action.SetAtomId(GetCurrentAction().GetAtomId());
|
||||
action.SetObjectId(GetCurrentAction().GetObjectId());
|
||||
action.SetUnknown24(GetCurrentAction().GetUnknown24());
|
||||
|
||||
m_action2.SetAtomId(p_action.GetAtomId());
|
||||
m_action2.SetObjectId(p_action.GetObjectId());
|
||||
m_action2.SetUnknown84(this);
|
||||
m_action2.SetOrigin(this);
|
||||
|
||||
MxResult result = Start(&m_action2);
|
||||
|
||||
GetCurrentAction().SetAtomId(action.GetAtomId());
|
||||
GetCurrentAction().SetObjectId(action.GetObjectId());
|
||||
GetCurrentAction().SetUnknown24(action.GetUnknown24());
|
||||
|
||||
if (result == SUCCESS) {
|
||||
m_unk0x13c = p_unk0x13c;
|
||||
m_unk0x140 = p_unk0x140;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007f470
|
||||
void MxBackgroundAudioManager::Stop()
|
||||
{
|
||||
if (m_action2.GetObjectId() != -1)
|
||||
DeleteObject(m_action2);
|
||||
|
||||
m_unk0x138 = 0;
|
||||
m_action2.SetAtomId(MxAtomId());
|
||||
m_action2.SetObjectId(-1);
|
||||
|
||||
if (m_action1.GetObjectId() != -1)
|
||||
DeleteObject(m_action1);
|
||||
|
||||
m_unk0xa0 = 0;
|
||||
m_action1.SetAtomId(MxAtomId());
|
||||
m_unk0x148 = 0;
|
||||
m_action1.SetObjectId(-1);
|
||||
m_unk0x13c = 0;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007f570
|
||||
void MxBackgroundAudioManager::LowerVolume()
|
||||
{
|
||||
if (m_unk0x148 == 0) {
|
||||
if (m_unk0x13c == 0) {
|
||||
m_unk0x13c = 2;
|
||||
}
|
||||
m_unk0x140 = 20;
|
||||
}
|
||||
m_unk0x148++;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007f5b0
|
||||
void MxBackgroundAudioManager::RaiseVolume()
|
||||
{
|
||||
if (m_unk0x148 != 0) {
|
||||
m_unk0x148--;
|
||||
if (m_unk0x148 == 0) {
|
||||
if (m_unk0x13c == 0) {
|
||||
m_unk0x13c = 2;
|
||||
}
|
||||
m_unk0x140 = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007f5f0
|
||||
void MxBackgroundAudioManager::Enable(MxBool p_enable)
|
||||
{
|
||||
if (this->m_musicEnabled != p_enable) {
|
||||
this->m_musicEnabled = p_enable;
|
||||
if (!p_enable) {
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1007f650
|
||||
void MxBackgroundAudioManager::Init()
|
||||
{
|
||||
this->m_unk0xa0 = 0;
|
||||
this->m_unk0x13c = 0;
|
||||
}
|
||||
50
LEGO1/omni/src/audio/mxloopingmidipresenter.cpp
Normal file
50
LEGO1/omni/src/audio/mxloopingmidipresenter.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "mxloopingmidipresenter.h"
|
||||
|
||||
#include "decomp.h"
|
||||
#include "mxdssound.h"
|
||||
#include "mxmusicmanager.h"
|
||||
#include "mxomni.h"
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxLoopingMIDIPresenter, 0x58);
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2a80
|
||||
void MxLoopingMIDIPresenter::StreamingTickle()
|
||||
{
|
||||
if (m_action->GetLoopCount()) {
|
||||
MxMIDIPresenter::StreamingTickle();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_chunk) {
|
||||
m_chunk = NextChunk();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_chunk->GetTime() + m_action->GetDuration() <= m_action->GetElapsedTime()) {
|
||||
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
||||
m_currentTickleState = TickleState_Done;
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2ae0
|
||||
void MxLoopingMIDIPresenter::DoneTickle()
|
||||
{
|
||||
if (m_action->GetLoopCount())
|
||||
MxMIDIPresenter::DoneTickle();
|
||||
else
|
||||
EndAction();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2b00
|
||||
MxResult MxLoopingMIDIPresenter::PutData()
|
||||
{
|
||||
m_criticalSection.Enter();
|
||||
|
||||
if (m_currentTickleState == TickleState_Streaming && m_chunk && !MusicManager()->GetMIDIInitialized()) {
|
||||
SetVolume(((MxDSSound*) m_action)->GetVolume());
|
||||
MusicManager()->FUN_100c09c0(m_chunk->GetData(), !m_action->GetLoopCount() ? -1 : m_action->GetLoopCount());
|
||||
}
|
||||
|
||||
m_criticalSection.Leave();
|
||||
return SUCCESS;
|
||||
}
|
||||
128
LEGO1/omni/src/audio/mxmidipresenter.cpp
Normal file
128
LEGO1/omni/src/audio/mxmidipresenter.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "mxmidipresenter.h"
|
||||
|
||||
#include "decomp.h"
|
||||
#include "legoomni.h"
|
||||
#include "mxautolocker.h"
|
||||
#include "mxdssound.h"
|
||||
#include "mxmusicmanager.h"
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxMIDIPresenter, 0x58);
|
||||
|
||||
// FUNCTION: LEGO1 0x100c25e0
|
||||
MxMIDIPresenter::MxMIDIPresenter()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c27c0
|
||||
MxMIDIPresenter::~MxMIDIPresenter()
|
||||
{
|
||||
Destroy(TRUE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2820
|
||||
void MxMIDIPresenter::Init()
|
||||
{
|
||||
m_chunk = NULL;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2830
|
||||
void MxMIDIPresenter::Destroy(MxBool p_fromDestructor)
|
||||
{
|
||||
if (MusicManager()) {
|
||||
MusicManager()->DeinitializeMIDI();
|
||||
}
|
||||
|
||||
m_criticalSection.Enter();
|
||||
|
||||
if (m_subscriber && m_chunk)
|
||||
m_subscriber->FUN_100b8390(m_chunk);
|
||||
Init();
|
||||
|
||||
m_criticalSection.Leave();
|
||||
|
||||
if (!p_fromDestructor)
|
||||
MxMusicPresenter::Destroy();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2890
|
||||
void MxMIDIPresenter::ReadyTickle()
|
||||
{
|
||||
MxStreamChunk* chunk = NextChunk();
|
||||
|
||||
if (chunk) {
|
||||
m_subscriber->FUN_100b8390(chunk);
|
||||
ParseExtra();
|
||||
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
||||
m_currentTickleState = TickleState_Starting;
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c28d0
|
||||
void MxMIDIPresenter::StartingTickle()
|
||||
{
|
||||
MxStreamChunk* chunk = FUN_100b5650();
|
||||
|
||||
if (chunk && m_action->GetElapsedTime() >= chunk->GetTime()) {
|
||||
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
||||
m_currentTickleState = TickleState_Streaming;
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2910
|
||||
void MxMIDIPresenter::StreamingTickle()
|
||||
{
|
||||
if (m_chunk) {
|
||||
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
||||
m_currentTickleState = TickleState_Done;
|
||||
}
|
||||
else
|
||||
m_chunk = NextChunk();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2940
|
||||
void MxMIDIPresenter::DoneTickle()
|
||||
{
|
||||
if (!MusicManager()->GetMIDIInitialized())
|
||||
EndAction();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2960
|
||||
void MxMIDIPresenter::Destroy()
|
||||
{
|
||||
Destroy(FALSE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2970
|
||||
MxResult MxMIDIPresenter::PutData()
|
||||
{
|
||||
m_criticalSection.Enter();
|
||||
|
||||
if (m_currentTickleState == TickleState_Streaming && m_chunk && !MusicManager()->GetMIDIInitialized()) {
|
||||
SetVolume(((MxDSSound*) m_action)->GetVolume());
|
||||
|
||||
if (MusicManager()->FUN_100c09c0(m_chunk->GetData(), 1))
|
||||
EndAction();
|
||||
}
|
||||
|
||||
m_criticalSection.Leave();
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c29e0
|
||||
void MxMIDIPresenter::EndAction()
|
||||
{
|
||||
if (m_action) {
|
||||
MxAutoLocker lock(&m_criticalSection);
|
||||
|
||||
MxMediaPresenter::EndAction();
|
||||
MusicManager()->DeinitializeMIDI();
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2a60
|
||||
void MxMIDIPresenter::SetVolume(MxS32 p_volume)
|
||||
{
|
||||
m_volume = p_volume;
|
||||
MusicManager()->SetMultiplier(p_volume);
|
||||
}
|
||||
162
LEGO1/omni/src/audio/mxmusicmanager.cpp
Normal file
162
LEGO1/omni/src/audio/mxmusicmanager.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
#include "mxmusicmanager.h"
|
||||
|
||||
#include "mxomni.h"
|
||||
#include "mxticklemanager.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxMusicManager, 0x58);
|
||||
|
||||
// FUNCTION: LEGO1 0x100c05a0
|
||||
MxMusicManager::MxMusicManager()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c0630
|
||||
MxMusicManager::~MxMusicManager()
|
||||
{
|
||||
Destroy(TRUE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c0690
|
||||
void MxMusicManager::Init()
|
||||
{
|
||||
m_multiplier = 100;
|
||||
InitData();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c06a0
|
||||
void MxMusicManager::InitData()
|
||||
{
|
||||
m_midiStreamH = 0;
|
||||
m_midiInitialized = FALSE;
|
||||
m_unk0x38 = 0;
|
||||
m_unk0x3c = 0;
|
||||
m_unk0x40 = 0;
|
||||
m_unk0x44 = 0;
|
||||
m_unk0x48 = 0;
|
||||
m_midiHdrP = NULL;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c06c0
|
||||
void MxMusicManager::Destroy(MxBool p_fromDestructor)
|
||||
{
|
||||
if (m_thread) {
|
||||
m_thread->Terminate();
|
||||
if (m_thread) {
|
||||
delete m_thread;
|
||||
}
|
||||
}
|
||||
else {
|
||||
TickleManager()->UnregisterClient(this);
|
||||
}
|
||||
|
||||
m_criticalSection.Enter();
|
||||
DeinitializeMIDI();
|
||||
Init();
|
||||
m_criticalSection.Leave();
|
||||
|
||||
if (!p_fromDestructor) {
|
||||
MxAudioManager::Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c07f0
|
||||
void MxMusicManager::SetMIDIVolume()
|
||||
{
|
||||
MxS32 result = (m_volume * m_multiplier) / 0x64;
|
||||
HMIDISTRM streamHandle = m_midiStreamH;
|
||||
|
||||
if (streamHandle) {
|
||||
MxS32 volume = CalculateVolume(result);
|
||||
midiOutSetVolume((HMIDIOUT) streamHandle, volume);
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c0840
|
||||
MxResult MxMusicManager::Create(MxU32 p_frequencyMS, MxBool p_createThread)
|
||||
{
|
||||
MxResult status = FAILURE;
|
||||
MxBool locked = FALSE;
|
||||
|
||||
if (MxAudioManager::InitPresenters() == SUCCESS) {
|
||||
if (p_createThread) {
|
||||
m_criticalSection.Enter();
|
||||
locked = TRUE;
|
||||
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;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c0930
|
||||
void MxMusicManager::Destroy()
|
||||
{
|
||||
Destroy(FALSE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c0940
|
||||
void MxMusicManager::SetVolume(MxS32 p_volume)
|
||||
{
|
||||
MxAudioManager::SetVolume(p_volume);
|
||||
m_criticalSection.Enter();
|
||||
SetMIDIVolume();
|
||||
m_criticalSection.Leave();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c0970
|
||||
void MxMusicManager::SetMultiplier(MxS32 p_multiplier)
|
||||
{
|
||||
m_criticalSection.Enter();
|
||||
m_multiplier = p_multiplier;
|
||||
SetMIDIVolume();
|
||||
m_criticalSection.Leave();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c09a0
|
||||
MxS32 MxMusicManager::CalculateVolume(MxS32 p_volume)
|
||||
{
|
||||
MxS32 result = (p_volume * 0xffff) / 100;
|
||||
return (result << 0x10) | result;
|
||||
}
|
||||
|
||||
// STUB: LEGO1 0x100c09c0
|
||||
undefined4 MxMusicManager::FUN_100c09c0(MxU8* p_data, MxS32 p_loopCount)
|
||||
{
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c0b20
|
||||
void MxMusicManager::DeinitializeMIDI()
|
||||
{
|
||||
m_criticalSection.Enter();
|
||||
|
||||
if (m_midiInitialized) {
|
||||
m_midiInitialized = FALSE;
|
||||
midiStreamStop(m_midiStreamH);
|
||||
midiOutUnprepareHeader((HMIDIOUT) m_midiStreamH, m_midiHdrP, sizeof(MIDIHDR));
|
||||
midiOutSetVolume((HMIDIOUT) m_midiStreamH, m_midiVolume);
|
||||
midiStreamClose(m_midiStreamH);
|
||||
delete m_midiHdrP;
|
||||
InitData();
|
||||
}
|
||||
|
||||
m_criticalSection.Leave();
|
||||
}
|
||||
59
LEGO1/omni/src/audio/mxmusicpresenter.cpp
Normal file
59
LEGO1/omni/src/audio/mxmusicpresenter.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "mxmusicpresenter.h"
|
||||
|
||||
#include "decomp.h"
|
||||
#include "mxmusicmanager.h"
|
||||
#include "mxomni.h"
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxMusicPresenter, 0x54);
|
||||
|
||||
// FUNCTION: LEGO1 0x100c22c0
|
||||
MxMusicPresenter::MxMusicPresenter()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c24e0
|
||||
MxMusicPresenter::~MxMusicPresenter()
|
||||
{
|
||||
Destroy(TRUE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2540
|
||||
void MxMusicPresenter::Init()
|
||||
{
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c2550
|
||||
void MxMusicPresenter::Destroy(MxBool p_fromDestructor)
|
||||
{
|
||||
if (MusicManager()) {
|
||||
MusicManager()->RemovePresenter(*this);
|
||||
}
|
||||
|
||||
m_criticalSection.Enter();
|
||||
Init();
|
||||
m_criticalSection.Leave();
|
||||
|
||||
if (!p_fromDestructor) {
|
||||
MxMediaPresenter::Destroy(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c25a0
|
||||
MxResult MxMusicPresenter::AddToManager()
|
||||
{
|
||||
MxResult result = FAILURE;
|
||||
|
||||
if (MusicManager()) {
|
||||
result = SUCCESS;
|
||||
MusicManager()->AddPresenter(*this);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100c25d0
|
||||
void MxMusicPresenter::Destroy()
|
||||
{
|
||||
Destroy(FALSE);
|
||||
}
|
||||
202
LEGO1/omni/src/audio/mxsoundmanager.cpp
Normal file
202
LEGO1/omni/src/audio/mxsoundmanager.cpp
Normal file
@@ -0,0 +1,202 @@
|
||||
#include "mxsoundmanager.h"
|
||||
|
||||
#include "define.h"
|
||||
#include "mxautolocker.h"
|
||||
#include "mxomni.h"
|
||||
#include "mxpresenter.h"
|
||||
#include "mxticklemanager.h"
|
||||
#include "mxwavepresenter.h"
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxSoundManager, 0x3c);
|
||||
|
||||
// FUNCTION: LEGO1 0x100ae740
|
||||
MxSoundManager::MxSoundManager()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100ae7d0
|
||||
MxSoundManager::~MxSoundManager()
|
||||
{
|
||||
Destroy(TRUE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100ae830
|
||||
void MxSoundManager::Init()
|
||||
{
|
||||
m_directSound = NULL;
|
||||
m_dsBuffer = NULL;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100ae840
|
||||
void MxSoundManager::Destroy(MxBool p_fromDestructor)
|
||||
{
|
||||
if (this->m_thread) {
|
||||
this->m_thread->Terminate();
|
||||
delete this->m_thread;
|
||||
}
|
||||
else {
|
||||
TickleManager()->UnregisterClient(this);
|
||||
}
|
||||
|
||||
this->m_criticalSection.Enter();
|
||||
|
||||
if (this->m_dsBuffer) {
|
||||
this->m_dsBuffer->Release();
|
||||
}
|
||||
|
||||
Init();
|
||||
this->m_criticalSection.Leave();
|
||||
|
||||
if (!p_fromDestructor) {
|
||||
MxAudioManager::Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: 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;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100aeab0
|
||||
void MxSoundManager::Destroy()
|
||||
{
|
||||
Destroy(FALSE);
|
||||
}
|
||||
|
||||
// FUNCTION: 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)->SetVolume(((MxAudioPresenter*) presenter)->GetVolume());
|
||||
|
||||
m_criticalSection.Leave();
|
||||
}
|
||||
|
||||
// FUNCTION: 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;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100aecf0
|
||||
MxS32 MxSoundManager::FUN_100aecf0(MxU32 p_undefined)
|
||||
{
|
||||
if (!p_undefined)
|
||||
return -10000;
|
||||
return g_mxcoreCount[p_undefined];
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100aed10
|
||||
void MxSoundManager::Pause()
|
||||
{
|
||||
MxAutoLocker lock(&m_criticalSection);
|
||||
|
||||
MxPresenter* presenter;
|
||||
MxPresenterListCursor cursor(m_presenters);
|
||||
|
||||
while (cursor.Next(presenter))
|
||||
if (presenter->IsA("MxWavePresenter"))
|
||||
((MxWavePresenter*) presenter)->Pause();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100aee10
|
||||
void MxSoundManager::Resume()
|
||||
{
|
||||
MxAutoLocker lock(&m_criticalSection);
|
||||
|
||||
MxPresenter* presenter;
|
||||
MxPresenterListCursor cursor(m_presenters);
|
||||
|
||||
while (cursor.Next(presenter))
|
||||
if (presenter->IsA("MxWavePresenter"))
|
||||
((MxWavePresenter*) presenter)->Resume();
|
||||
}
|
||||
45
LEGO1/omni/src/audio/mxsoundpresenter.cpp
Normal file
45
LEGO1/omni/src/audio/mxsoundpresenter.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "mxsoundpresenter.h"
|
||||
|
||||
#include "decomp.h"
|
||||
#include "mxsoundmanager.h"
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxSoundPresenter, 0x54)
|
||||
|
||||
// FUNCTION: LEGO1 0x1000d430
|
||||
MxSoundPresenter::~MxSoundPresenter()
|
||||
{
|
||||
Destroy(TRUE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1000d490
|
||||
void MxSoundPresenter::Destroy()
|
||||
{
|
||||
Destroy(FALSE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b1a50
|
||||
void MxSoundPresenter::Destroy(MxBool p_fromDestructor)
|
||||
{
|
||||
if (MSoundManager())
|
||||
MSoundManager()->RemovePresenter(*this);
|
||||
|
||||
this->m_criticalSection.Enter();
|
||||
MxMediaPresenter::Init();
|
||||
this->m_criticalSection.Leave();
|
||||
|
||||
if (!p_fromDestructor)
|
||||
MxMediaPresenter::Destroy(FALSE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b1aa0
|
||||
MxResult MxSoundPresenter::AddToManager()
|
||||
{
|
||||
MxResult ret = FAILURE;
|
||||
|
||||
if (MSoundManager()) {
|
||||
ret = SUCCESS;
|
||||
MSoundManager()->AddPresenter(*this);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
375
LEGO1/omni/src/audio/mxwavepresenter.cpp
Normal file
375
LEGO1/omni/src/audio/mxwavepresenter.cpp
Normal file
@@ -0,0 +1,375 @@
|
||||
#include "mxwavepresenter.h"
|
||||
|
||||
#include "decomp.h"
|
||||
#include "define.h"
|
||||
#include "legoomni.h"
|
||||
#include "mxautolocker.h"
|
||||
#include "mxdssound.h"
|
||||
#include "mxomni.h"
|
||||
#include "mxsoundmanager.h"
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxWavePresenter, 0x6c);
|
||||
DECOMP_SIZE_ASSERT(MxWavePresenter::WaveFormat, 0x1c);
|
||||
|
||||
// FUNCTION: LEGO1 0x1000d640
|
||||
MxWavePresenter::~MxWavePresenter()
|
||||
{
|
||||
Destroy(TRUE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1000d6a0
|
||||
void MxWavePresenter::Destroy()
|
||||
{
|
||||
Destroy(FALSE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x1000d6b0
|
||||
MxBool MxWavePresenter::IsPaused()
|
||||
{
|
||||
return m_paused;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b1ad0
|
||||
void MxWavePresenter::Init()
|
||||
{
|
||||
m_waveFormat = NULL;
|
||||
m_dsBuffer = NULL;
|
||||
m_chunkLength = 0;
|
||||
m_lockSize = 0;
|
||||
m_writtenChunks = 0;
|
||||
m_started = FALSE;
|
||||
m_unk0x66 = FALSE;
|
||||
m_paused = FALSE;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b1af0
|
||||
MxResult MxWavePresenter::AddToManager()
|
||||
{
|
||||
MxResult result = MxSoundPresenter::AddToManager();
|
||||
Init();
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b1b10
|
||||
void MxWavePresenter::Destroy(MxBool p_fromDestructor)
|
||||
{
|
||||
if (m_dsBuffer) {
|
||||
m_dsBuffer->Stop();
|
||||
m_dsBuffer->Release();
|
||||
}
|
||||
|
||||
if (m_waveFormat)
|
||||
delete[] ((MxU8*) m_waveFormat);
|
||||
|
||||
Init();
|
||||
|
||||
if (!p_fromDestructor)
|
||||
MxSoundPresenter::Destroy(FALSE);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b1b60
|
||||
MxS8 MxWavePresenter::GetPlayedChunks()
|
||||
{
|
||||
DWORD dwCurrentPlayCursor, dwCurrentWriteCursor;
|
||||
MxS8 playedChunks = -1;
|
||||
|
||||
if (m_dsBuffer->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor) == DS_OK)
|
||||
playedChunks = dwCurrentPlayCursor / m_chunkLength;
|
||||
|
||||
return playedChunks;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b1ba0
|
||||
MxBool MxWavePresenter::FUN_100b1ba0()
|
||||
{
|
||||
return !m_started || GetPlayedChunks() != m_writtenChunks;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b1bd0
|
||||
void MxWavePresenter::WriteToSoundBuffer(void* p_audioPtr, MxU32 p_length)
|
||||
{
|
||||
DWORD dwStatus;
|
||||
LPVOID pvAudioPtr1;
|
||||
DWORD dwOffset;
|
||||
LPVOID pvAudioPtr2;
|
||||
DWORD dwAudioBytes1;
|
||||
DWORD dwAudioBytes2;
|
||||
|
||||
dwOffset = m_chunkLength * m_writtenChunks;
|
||||
m_dsBuffer->GetStatus(&dwStatus);
|
||||
|
||||
if (dwStatus == DSBSTATUS_BUFFERLOST) {
|
||||
m_dsBuffer->Restore();
|
||||
m_dsBuffer->GetStatus(&dwStatus);
|
||||
}
|
||||
|
||||
if (dwStatus != DSBSTATUS_BUFFERLOST) {
|
||||
if (m_action->GetFlags() & MxDSAction::Flag_Looping) {
|
||||
m_writtenChunks++;
|
||||
m_lockSize = p_length;
|
||||
}
|
||||
else {
|
||||
m_writtenChunks = 1 - m_writtenChunks;
|
||||
m_lockSize = m_chunkLength;
|
||||
}
|
||||
|
||||
if (m_dsBuffer->Lock(dwOffset, m_lockSize, &pvAudioPtr1, &dwAudioBytes1, &pvAudioPtr2, &dwAudioBytes2, 0) ==
|
||||
DS_OK) {
|
||||
memcpy(pvAudioPtr1, p_audioPtr, p_length);
|
||||
|
||||
if (m_lockSize > p_length && !(m_action->GetFlags() & MxDSAction::Flag_Looping)) {
|
||||
memset((MxU8*) pvAudioPtr1 + p_length, m_silenceData, m_lockSize - p_length);
|
||||
}
|
||||
|
||||
m_dsBuffer->Unlock(pvAudioPtr1, m_lockSize, pvAudioPtr2, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b1cf0
|
||||
void MxWavePresenter::ReadyTickle()
|
||||
{
|
||||
MxStreamChunk* chunk = NextChunk();
|
||||
|
||||
if (chunk) {
|
||||
m_waveFormat = (WaveFormat*) new MxU8[chunk->GetLength()];
|
||||
memcpy(m_waveFormat, chunk->GetData(), chunk->GetLength());
|
||||
m_subscriber->FUN_100b8390(chunk);
|
||||
ParseExtra();
|
||||
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
||||
m_currentTickleState = TickleState_Starting;
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b1d50
|
||||
void MxWavePresenter::StartingTickle()
|
||||
{
|
||||
MxStreamChunk* chunk = NextChunk();
|
||||
|
||||
if (chunk && m_action->GetElapsedTime() >= chunk->GetTime()) {
|
||||
MxU32 length = chunk->GetLength();
|
||||
WAVEFORMATEX waveFormatEx;
|
||||
|
||||
m_chunkLength = length;
|
||||
memset(&waveFormatEx, 0, sizeof(waveFormatEx));
|
||||
|
||||
waveFormatEx.wFormatTag = m_waveFormat->m_waveFormatEx.wFormatTag;
|
||||
waveFormatEx.nChannels = m_waveFormat->m_waveFormatEx.nChannels;
|
||||
waveFormatEx.nSamplesPerSec = m_waveFormat->m_waveFormatEx.nSamplesPerSec;
|
||||
waveFormatEx.nAvgBytesPerSec = m_waveFormat->m_waveFormatEx.nAvgBytesPerSec;
|
||||
waveFormatEx.nBlockAlign = m_waveFormat->m_waveFormatEx.nBlockAlign;
|
||||
waveFormatEx.wBitsPerSample = m_waveFormat->m_waveFormatEx.wBitsPerSample;
|
||||
|
||||
if (waveFormatEx.wBitsPerSample == 8)
|
||||
m_silenceData = 0x7F;
|
||||
|
||||
if (waveFormatEx.wBitsPerSample == 16)
|
||||
m_silenceData = 0;
|
||||
|
||||
DSBUFFERDESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.dwSize = sizeof(desc);
|
||||
|
||||
if (m_unk0x66)
|
||||
desc.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRL3D | DSBCAPS_CTRLVOLUME;
|
||||
else
|
||||
desc.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME;
|
||||
|
||||
if (m_action->GetFlags() & MxDSAction::Flag_Looping)
|
||||
desc.dwBufferBytes = m_waveFormat->m_waveFormatEx.nAvgBytesPerSec *
|
||||
(m_action->GetDuration() / m_action->GetLoopCount()) / 1000;
|
||||
else
|
||||
desc.dwBufferBytes = 2 * length;
|
||||
|
||||
desc.lpwfxFormat = &waveFormatEx;
|
||||
|
||||
if (MSoundManager()->GetDirectSound()->CreateSoundBuffer(&desc, &m_dsBuffer, NULL) != DS_OK) {
|
||||
EndAction();
|
||||
}
|
||||
else {
|
||||
SetVolume(((MxDSSound*) m_action)->GetVolume());
|
||||
m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState;
|
||||
m_currentTickleState = TickleState_Streaming;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b1ea0
|
||||
void MxWavePresenter::StreamingTickle()
|
||||
{
|
||||
if (!m_currentChunk) {
|
||||
if (!(m_action->GetFlags() & MxDSAction::Flag_Looping)) {
|
||||
MxStreamChunk* chunk = FUN_100b5650();
|
||||
|
||||
if (chunk && chunk->GetFlags() & MxDSChunk::Flag_End && !(chunk->GetFlags() & MxDSChunk::Flag_Bit16)) {
|
||||
chunk->SetFlags(chunk->GetFlags() | MxDSChunk::Flag_Bit16);
|
||||
|
||||
m_currentChunk = new MxStreamChunk;
|
||||
MxU8* data = new MxU8[m_chunkLength];
|
||||
|
||||
memset(data, m_silenceData, m_chunkLength);
|
||||
|
||||
m_currentChunk->SetLength(m_chunkLength);
|
||||
m_currentChunk->SetData(data);
|
||||
m_currentChunk->SetTime(chunk->GetTime() + 1000);
|
||||
m_currentChunk->SetFlags(MxDSChunk::Flag_Bit1);
|
||||
}
|
||||
}
|
||||
|
||||
MxMediaPresenter::StreamingTickle();
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b20c0
|
||||
void MxWavePresenter::DoneTickle()
|
||||
{
|
||||
if (m_dsBuffer) {
|
||||
DWORD dwCurrentPlayCursor, dwCurrentWriteCursor;
|
||||
m_dsBuffer->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor);
|
||||
|
||||
MxS8 playedChunks = dwCurrentPlayCursor / m_chunkLength;
|
||||
if (m_action->GetFlags() & MxDSAction::Flag_Bit7 || m_action->GetFlags() & MxDSAction::Flag_Looping ||
|
||||
m_writtenChunks != playedChunks || m_lockSize + (m_chunkLength * playedChunks) <= dwCurrentPlayCursor)
|
||||
MxMediaPresenter::DoneTickle();
|
||||
}
|
||||
else
|
||||
MxMediaPresenter::DoneTickle();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b2130
|
||||
void MxWavePresenter::AppendChunk(MxStreamChunk* p_chunk)
|
||||
{
|
||||
WriteToSoundBuffer(p_chunk->GetData(), p_chunk->GetLength());
|
||||
if (IsEnabled())
|
||||
m_subscriber->FUN_100b8390(p_chunk);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b2160
|
||||
MxResult MxWavePresenter::PutData()
|
||||
{
|
||||
MxAutoLocker lock(&m_criticalSection);
|
||||
|
||||
if (IsEnabled()) {
|
||||
switch (m_currentTickleState) {
|
||||
case TickleState_Streaming:
|
||||
if (m_currentChunk && FUN_100b1ba0()) {
|
||||
WriteToSoundBuffer(m_currentChunk->GetData(), m_currentChunk->GetLength());
|
||||
m_subscriber->FUN_100b8390(m_currentChunk);
|
||||
m_currentChunk = NULL;
|
||||
}
|
||||
|
||||
if (!m_started) {
|
||||
m_dsBuffer->SetCurrentPosition(0);
|
||||
|
||||
if (m_dsBuffer->Play(0, 0, DSBPLAY_LOOPING) == DS_OK)
|
||||
m_started = TRUE;
|
||||
}
|
||||
break;
|
||||
case TickleState_Repeating:
|
||||
if (m_started)
|
||||
break;
|
||||
|
||||
m_dsBuffer->SetCurrentPosition(0);
|
||||
|
||||
if (m_dsBuffer->Play(0, 0, m_action->GetLoopCount() > 1) == DS_OK)
|
||||
m_started = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b2280
|
||||
void MxWavePresenter::EndAction()
|
||||
{
|
||||
if (m_action) {
|
||||
MxAutoLocker lock(&m_criticalSection);
|
||||
MxMediaPresenter::EndAction();
|
||||
|
||||
if (m_dsBuffer)
|
||||
m_dsBuffer->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b2300
|
||||
void MxWavePresenter::SetVolume(MxS32 p_volume)
|
||||
{
|
||||
m_criticalSection.Enter();
|
||||
|
||||
m_volume = p_volume;
|
||||
if (m_dsBuffer != NULL) {
|
||||
MxS32 volume = p_volume * MxOmni::GetInstance()->GetSoundManager()->GetVolume() / 100;
|
||||
MxS32 otherVolume = MxOmni::GetInstance()->GetSoundManager()->FUN_100aecf0(volume);
|
||||
m_dsBuffer->SetVolume(otherVolume);
|
||||
}
|
||||
|
||||
m_criticalSection.Leave();
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b2360
|
||||
void MxWavePresenter::Enable(MxBool p_enable)
|
||||
{
|
||||
if (IsEnabled() != p_enable) {
|
||||
MxSoundPresenter::Enable(p_enable);
|
||||
|
||||
if (p_enable) {
|
||||
m_writtenChunks = 0;
|
||||
m_started = FALSE;
|
||||
}
|
||||
else if (m_dsBuffer)
|
||||
m_dsBuffer->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b23a0
|
||||
void MxWavePresenter::ParseExtra()
|
||||
{
|
||||
char extraCopy[512];
|
||||
|
||||
MxSoundPresenter::ParseExtra();
|
||||
*((MxU16*) &extraCopy[0]) = m_action->GetExtraLength();
|
||||
char* extraData = m_action->GetExtraData();
|
||||
|
||||
if (*((MxU16*) &extraCopy[0])) {
|
||||
MxU16 len = *((MxU16*) &extraCopy[0]);
|
||||
memcpy(extraCopy, extraData, len);
|
||||
extraCopy[len] = '\0';
|
||||
|
||||
char soundValue[512];
|
||||
if (KeyValueStringParse(soundValue, g_strSOUND, extraCopy)) {
|
||||
if (!strcmpi(soundValue, "FALSE"))
|
||||
Enable(FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b2440
|
||||
void MxWavePresenter::Pause()
|
||||
{
|
||||
if (!m_paused && m_started) {
|
||||
if (m_dsBuffer)
|
||||
m_dsBuffer->Stop();
|
||||
m_paused = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100b2470
|
||||
void MxWavePresenter::Resume()
|
||||
{
|
||||
if (m_paused) {
|
||||
if (m_dsBuffer && m_started) {
|
||||
switch (m_currentTickleState) {
|
||||
case TickleState_Streaming:
|
||||
m_dsBuffer->Play(0, 0, DSBPLAY_LOOPING);
|
||||
break;
|
||||
case TickleState_Repeating:
|
||||
m_dsBuffer->Play(0, 0, m_action->GetLoopCount() > 1);
|
||||
break;
|
||||
case TickleState_Done:
|
||||
m_dsBuffer->Play(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
m_paused = FALSE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user