Implement 3D sound, WIP

This commit is contained in:
Christian Semmler 2024-06-08 16:33:21 -04:00
parent 7d20a4c870
commit 707a18ca17
12 changed files with 147 additions and 221 deletions

View File

@ -334,7 +334,7 @@ add_library(omni STATIC
register_lego1_target(omni) register_lego1_target(omni)
set_property(TARGET omni PROPERTY ARCHIVE_OUTPUT_NAME "omni$<$<CONFIG:Debug>:d>") set_property(TARGET omni PROPERTY ARCHIVE_OUTPUT_NAME "omni$<$<CONFIG:Debug>:d>")
target_include_directories(omni PRIVATE "${CMAKE_SOURCE_DIR}/LEGO1/omni/include" "${CMAKE_SOURCE_DIR}/LEGO1" "${CMAKE_SOURCE_DIR}/util") target_include_directories(omni PRIVATE "${CMAKE_SOURCE_DIR}/LEGO1/omni/include" "${CMAKE_SOURCE_DIR}/LEGO1" "${CMAKE_SOURCE_DIR}/util")
target_link_libraries(omni PRIVATE dsound winmm libsmacker miniaudio) target_link_libraries(omni PRIVATE winmm libsmacker miniaudio)
add_library(lego1 SHARED add_library(lego1 SHARED
LEGO1/define.cpp LEGO1/define.cpp
@ -497,7 +497,7 @@ if (ISLE_BUILD_APP)
target_link_libraries(isle PRIVATE SDL3::SDL3 iniparser-static) target_link_libraries(isle PRIVATE SDL3::SDL3 iniparser-static)
# Link DSOUND, WINMM, and LEGO1 # Link DSOUND, WINMM, and LEGO1
target_link_libraries(isle PRIVATE dsound winmm lego1) target_link_libraries(isle PRIVATE winmm lego1)
# Make sure filenames are ALL CAPS # Make sure filenames are ALL CAPS
set_property(TARGET isle PROPERTY OUTPUT_NAME ISLE) set_property(TARGET isle PROPERTY OUTPUT_NAME ISLE)

View File

@ -4,7 +4,7 @@
#include "decomp.h" #include "decomp.h"
#include "mxtypes.h" #include "mxtypes.h"
#include <dsound.h> #include <miniaudio.h>
class LegoActor; class LegoActor;
class LegoROI; class LegoROI;
@ -17,10 +17,10 @@ class Lego3DSound {
virtual ~Lego3DSound(); virtual ~Lego3DSound();
void Init(); void Init();
MxResult Create(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char* p_name, MxS32 p_volume); MxResult Create(ma_sound* p_sound, const char* p_name, MxS32 p_volume);
void Destroy(); void Destroy();
MxU32 UpdatePosition(LPDIRECTSOUNDBUFFER p_directSoundBuffer); MxU32 UpdatePosition(ma_sound* p_sound);
void FUN_10011a60(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char* p_name); void FUN_10011a60(ma_sound* p_sound, const char* p_name);
void Reset(); void Reset();
MxS32 SetDistance(MxS32 p_min, MxS32 p_max); MxS32 SetDistance(MxS32 p_min, MxS32 p_max);
@ -28,15 +28,14 @@ class Lego3DSound {
// Lego3DSound::`scalar deleting destructor' // Lego3DSound::`scalar deleting destructor'
private: private:
LPDIRECTSOUND3DBUFFER m_ds3dBuffer; // 0x08 ma_sound* m_sound;
LegoROI* m_roi; // 0x0c LegoROI* m_roi; // 0x0c
LegoROI* m_positionROI; // 0x10 LegoROI* m_positionROI; // 0x10
MxBool m_enabled; // 0x14 MxBool m_enabled; // 0x14
MxBool m_isActor; // 0x15 MxBool m_isActor; // 0x15
LegoActor* m_actor; // 0x18 LegoActor* m_actor; // 0x18
double m_frequencyFactor; // 0x20 double m_frequencyFactor; // 0x20
DWORD m_dwFrequency; // 0x28 MxS32 m_volume; // 0x2c
MxS32 m_volume; // 0x2c
}; };
// GLOBAL: LEGO1 0x100db6c0 // GLOBAL: LEGO1 0x100db6c0

View File

@ -5,6 +5,7 @@
#include "lego3dsound.h" #include "lego3dsound.h"
#include "mxcore.h" #include "mxcore.h"
#include "mxstring.h" #include "mxstring.h"
#include "mxwavepresenter.h"
// VTABLE: LEGO1 0x100d4718 // VTABLE: LEGO1 0x100d4718
// SIZE 0x88 // SIZE 0x88
@ -27,7 +28,7 @@ class LegoCacheSound : public MxCore {
} }
virtual MxResult Create( virtual MxResult Create(
LPPCMWAVEFORMAT p_pwfx, MxWavePresenter::WaveFormat& p_pwfx,
MxString p_mediaSrcPath, MxString p_mediaSrcPath,
MxS32 p_volume, MxS32 p_volume,
MxU8* p_data, MxU8* p_data,
@ -54,20 +55,24 @@ class LegoCacheSound : public MxCore {
void CopyData(MxU8* p_data, MxU32 p_dataSize); void CopyData(MxU8* p_data, MxU32 p_dataSize);
MxString FUN_10006d80(const MxString& p_str); MxString FUN_10006d80(const MxString& p_str);
LPDIRECTSOUNDBUFFER m_dsBuffer; // 0x08 // [library:audio] WAVE_FORMAT_PCM (audio in .SI files only used this format)
undefined m_unk0x0c[4]; // 0x0c static const MxU32 supportedFormatTag = 1;
Lego3DSound m_sound; // 0x10
MxU8* m_data; // 0x40 ma_audio_buffer m_buffer;
MxU32 m_dataSize; // 0x44 ma_sound m_cacheSound;
MxString m_unk0x48; // 0x48 undefined m_unk0x0c[4]; // 0x0c
MxBool m_unk0x58; // 0x58 Lego3DSound m_sound; // 0x10
PCMWAVEFORMAT m_wfx; // 0x59 MxU8* m_data; // 0x40
MxBool m_looping; // 0x69 MxU32 m_dataSize; // 0x44
MxBool m_unk0x6a; // 0x6a MxString m_unk0x48; // 0x48
MxS32 m_volume; // 0x6c MxBool m_unk0x58; // 0x58
MxBool m_unk0x70; // 0x70 MxWavePresenter::WaveFormat m_wfx; // 0x59
MxString m_unk0x74; // 0x74 MxBool m_looping; // 0x69
MxBool m_muted; // 0x84 MxBool m_unk0x6a; // 0x6a
MxS32 m_volume; // 0x6c
MxBool m_unk0x70; // 0x70
MxString m_unk0x74; // 0x74
MxBool m_muted; // 0x84
}; };
#endif // LEGOCACHSOUND_H #endif // LEGOCACHSOUND_H

View File

@ -36,12 +36,12 @@ class LegoLoadCacheSoundPresenter : public MxWavePresenter {
void Init(); void Init();
void Destroy(MxBool p_fromDestructor); void Destroy(MxBool p_fromDestructor);
LegoCacheSound* m_cacheSound; // 0x6c LegoCacheSound* m_cacheSound; // 0x6c
MxU8* m_data; // 0x70 MxU8* m_data; // 0x70
MxU8* m_pData; // 0x74 MxU8* m_pData; // 0x74
MxU32 m_dataSize; // 0x78 MxU32 m_dataSize; // 0x78
MxBool m_unk0x7c; // 0x7c MxBool m_unk0x7c; // 0x7c
PCMWAVEFORMAT m_pcmWaveFormat; // 0x7d WaveFormat m_waveFormat; // 0x7d
}; };
// SYNTHETIC: LEGO1 0x10018460 // SYNTHETIC: LEGO1 0x10018460

View File

@ -27,7 +27,6 @@ class LegoSoundManager : public MxSoundManager {
void Init(); void Init();
void Destroy(MxBool p_fromDestructor); void Destroy(MxBool p_fromDestructor);
LPDIRECTSOUND3DLISTENER m_listener; // 0x3c
LegoCacheSoundManager* m_cacheSoundManager; // 0x40 LegoCacheSoundManager* m_cacheSoundManager; // 0x40
}; };

View File

@ -26,7 +26,7 @@ Lego3DSound::~Lego3DSound()
// FUNCTION: LEGO1 0x10011680 // FUNCTION: LEGO1 0x10011680
void Lego3DSound::Init() void Lego3DSound::Init()
{ {
m_ds3dBuffer = NULL; m_sound = NULL;
m_roi = NULL; m_roi = NULL;
m_positionROI = NULL; m_positionROI = NULL;
m_actor = NULL; m_actor = NULL;
@ -37,23 +37,25 @@ void Lego3DSound::Init()
// FUNCTION: LEGO1 0x100116a0 // FUNCTION: LEGO1 0x100116a0
// FUNCTION: BETA10 0x10039647 // FUNCTION: BETA10 0x10039647
MxResult Lego3DSound::Create(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char* p_name, MxS32 p_volume) MxResult Lego3DSound::Create(ma_sound* p_sound, const char* p_name, MxS32 p_volume)
{ {
m_volume = p_volume; m_volume = p_volume;
if (MxOmni::IsSound3D()) { if (MxOmni::IsSound3D()) {
p_directSoundBuffer->QueryInterface(IID_IDirectSound3DBuffer, (LPVOID*) &m_ds3dBuffer); m_sound = p_sound;
if (m_ds3dBuffer == NULL) {
return FAILURE;
}
m_ds3dBuffer->SetMinDistance(15.0f, DS3D_IMMEDIATE); ma_sound_set_min_distance(m_sound, 15.0f);
m_ds3dBuffer->SetMaxDistance(100.0f, DS3D_IMMEDIATE); ma_sound_set_max_distance(m_sound, 100.0f);
m_ds3dBuffer->SetPosition(0.0f, 0.0f, -40.0f, DS3D_IMMEDIATE); ma_sound_set_position(m_sound, 0.0f, 0.0f, -40.0f);
m_ds3dBuffer->SetConeOutsideVolume(-10000, DS3D_IMMEDIATE);
// [library:audio] Which rolloff?
ma_sound_set_rolloff(m_sound, 1.0f);
// [library:audio] Do we need this?
// m_ds3dBuffer->SetConeOutsideVolume(-10000, DS3D_IMMEDIATE);
} }
if (m_ds3dBuffer == NULL || p_name == NULL) { if (m_sound == NULL || p_name == NULL) {
return SUCCESS; return SUCCESS;
} }
@ -86,7 +88,7 @@ MxResult Lego3DSound::Create(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char
if (MxOmni::IsSound3D()) { if (MxOmni::IsSound3D()) {
const float* position = m_positionROI->GetWorldPosition(); const float* position = m_positionROI->GetWorldPosition();
m_ds3dBuffer->SetPosition(position[0], position[1], position[2], DS3D_IMMEDIATE); ma_sound_set_position(m_sound, position[0], position[1], position[2]);
} }
LegoEntity* entity = m_roi->GetEntity(); LegoEntity* entity = m_roi->GetEntity();
@ -94,13 +96,11 @@ MxResult Lego3DSound::Create(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char
m_actor = ((LegoActor*) entity); m_actor = ((LegoActor*) entity);
} }
p_directSoundBuffer->GetFrequency(&m_dwFrequency);
if (m_actor != NULL) { if (m_actor != NULL) {
m_frequencyFactor = m_actor->GetSoundFrequencyFactor(); m_frequencyFactor = m_actor->GetSoundFrequencyFactor();
if (m_frequencyFactor != 0.0) { if (m_frequencyFactor != 0.0) {
p_directSoundBuffer->SetFrequency(m_frequencyFactor * m_dwFrequency); ma_sound_set_pitch(p_sound, m_frequencyFactor);
} }
} }
@ -110,10 +110,7 @@ MxResult Lego3DSound::Create(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char
// FUNCTION: LEGO1 0x10011880 // FUNCTION: LEGO1 0x10011880
void Lego3DSound::Destroy() void Lego3DSound::Destroy()
{ {
if (m_ds3dBuffer) { m_sound = NULL;
m_ds3dBuffer->Release();
m_ds3dBuffer = NULL;
}
if (m_enabled && m_roi && CharacterManager()) { if (m_enabled && m_roi && CharacterManager()) {
if (m_isActor) { if (m_isActor) {
@ -129,7 +126,7 @@ void Lego3DSound::Destroy()
// FUNCTION: LEGO1 0x100118e0 // FUNCTION: LEGO1 0x100118e0
// FUNCTION: BETA10 0x10039a2a // FUNCTION: BETA10 0x10039a2a
MxU32 Lego3DSound::UpdatePosition(LPDIRECTSOUNDBUFFER p_directSoundBuffer) MxU32 Lego3DSound::UpdatePosition(ma_sound* p_sound)
{ {
MxU32 updated = FALSE; MxU32 updated = FALSE;
@ -146,8 +143,8 @@ MxU32 Lego3DSound::UpdatePosition(LPDIRECTSOUNDBUFFER p_directSoundBuffer)
return FALSE; return FALSE;
} }
if (m_ds3dBuffer != NULL) { if (m_sound != NULL) {
m_ds3dBuffer->SetPosition(position[0], position[1], position[2], DS3D_IMMEDIATE); ma_sound_set_position(m_sound, position[0], position[1], position[2]);
} }
else { else {
MxS32 newVolume = m_volume; MxS32 newVolume = m_volume;
@ -165,8 +162,7 @@ MxU32 Lego3DSound::UpdatePosition(LPDIRECTSOUNDBUFFER p_directSoundBuffer)
} }
newVolume = newVolume * SoundManager()->GetVolume() / 100; newVolume = newVolume * SoundManager()->GetVolume() / 100;
newVolume = SoundManager()->GetAttenuation(newVolume); ma_sound_set_volume(p_sound, SoundManager()->GetAttenuation(newVolume));
p_directSoundBuffer->SetVolume(newVolume);
} }
updated = TRUE; updated = TRUE;
@ -175,7 +171,7 @@ MxU32 Lego3DSound::UpdatePosition(LPDIRECTSOUNDBUFFER p_directSoundBuffer)
if (m_actor != NULL) { if (m_actor != NULL) {
if (abs(m_frequencyFactor - m_actor->GetSoundFrequencyFactor()) > 0.0001) { if (abs(m_frequencyFactor - m_actor->GetSoundFrequencyFactor()) > 0.0001) {
m_frequencyFactor = m_actor->GetSoundFrequencyFactor(); m_frequencyFactor = m_actor->GetSoundFrequencyFactor();
p_directSoundBuffer->SetFrequency(m_frequencyFactor * m_dwFrequency); ma_sound_set_pitch(p_sound, m_frequencyFactor);
updated = TRUE; updated = TRUE;
} }
} }
@ -185,13 +181,13 @@ MxU32 Lego3DSound::UpdatePosition(LPDIRECTSOUNDBUFFER p_directSoundBuffer)
// FUNCTION: LEGO1 0x10011a60 // FUNCTION: LEGO1 0x10011a60
// FUNCTION: BETA10 0x10039d04 // FUNCTION: BETA10 0x10039d04
void Lego3DSound::FUN_10011a60(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char* p_name) void Lego3DSound::FUN_10011a60(ma_sound* p_sound, const char* p_name)
{ {
assert(p_directSoundBuffer); assert(p_sound);
if (p_name == NULL) { if (p_name == NULL) {
if (m_ds3dBuffer != NULL) { if (m_sound != NULL) {
m_ds3dBuffer->SetMode(DS3DMODE_DISABLE, DS3D_IMMEDIATE); ma_sound_set_spatialization_enabled(m_sound, MA_FALSE);
} }
} }
else { else {
@ -222,16 +218,10 @@ void Lego3DSound::FUN_10011a60(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const ch
m_positionROI = m_roi; m_positionROI = m_roi;
} }
if (m_ds3dBuffer != NULL) { if (m_sound != NULL) {
DWORD dwMode; ma_sound_set_spatialization_enabled(m_sound, MA_TRUE);
m_ds3dBuffer->GetMode(&dwMode);
if (dwMode & DS3DMODE_DISABLE) {
m_ds3dBuffer->SetMode(DS3DMODE_NORMAL, DS3D_IMMEDIATE);
}
const float* position = m_positionROI->GetWorldPosition(); const float* position = m_positionROI->GetWorldPosition();
m_ds3dBuffer->SetPosition(position[0], position[1], position[2], DS3D_IMMEDIATE); ma_sound_set_position(m_sound, position[0], position[1], position[2]);
} }
else { else {
const float* position = m_positionROI->GetWorldPosition(); const float* position = m_positionROI->GetWorldPosition();
@ -256,8 +246,7 @@ void Lego3DSound::FUN_10011a60(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const ch
} }
newVolume = newVolume * SoundManager()->GetVolume() / 100; newVolume = newVolume * SoundManager()->GetVolume() / 100;
newVolume = SoundManager()->GetAttenuation(newVolume); ma_sound_set_volume(p_sound, SoundManager()->GetAttenuation(newVolume));
p_directSoundBuffer->SetVolume(newVolume);
} }
} }
@ -266,13 +255,11 @@ void Lego3DSound::FUN_10011a60(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const ch
m_actor = ((LegoActor*) entity); m_actor = ((LegoActor*) entity);
} }
p_directSoundBuffer->GetFrequency(&m_dwFrequency);
if (m_actor != NULL) { if (m_actor != NULL) {
m_frequencyFactor = m_actor->GetSoundFrequencyFactor(); m_frequencyFactor = m_actor->GetSoundFrequencyFactor();
if (m_frequencyFactor != 0.0) { if (m_frequencyFactor != 0.0) {
p_directSoundBuffer->SetFrequency(m_frequencyFactor * m_dwFrequency); ma_sound_set_pitch(p_sound, m_frequencyFactor);
} }
} }
} }
@ -299,12 +286,12 @@ void Lego3DSound::Reset()
MxS32 Lego3DSound::SetDistance(MxS32 p_min, MxS32 p_max) MxS32 Lego3DSound::SetDistance(MxS32 p_min, MxS32 p_max)
{ {
if (MxOmni::IsSound3D()) { if (MxOmni::IsSound3D()) {
if (m_ds3dBuffer == NULL) { if (m_sound == NULL) {
return -1; return -1;
} }
m_ds3dBuffer->SetMinDistance(p_min, DS3D_IMMEDIATE); ma_sound_set_min_distance(m_sound, p_min);
m_ds3dBuffer->SetMaxDistance(p_max, DS3D_IMMEDIATE); ma_sound_set_max_distance(m_sound, p_max);
return 0; return 0;
} }

View File

@ -40,23 +40,20 @@ void Lego3DWavePresenter::StartingTickle()
MxWavePresenter::StartingTickle(); MxWavePresenter::StartingTickle();
/* if (ma_sound_get_engine(&(MxWavePresenter::m_sound))) {
if (m_dsBuffer != NULL) { MxU16 extraLength;
MxU16 extraLength; char* buff;
char* buff; m_action->GetExtra(extraLength, buff);
m_action->GetExtra(extraLength, buff);
if (!strcmp(buff, "FROM_PARENT") && m_compositePresenter != NULL) { if (!strcmp(buff, "FROM_PARENT") && m_compositePresenter != NULL) {
m_compositePresenter->GetAction()->GetExtra(extraLength, buff); m_compositePresenter->GetAction()->GetExtra(extraLength, buff);
}
if (m_sound.Create(m_dsBuffer, buff, m_volume) != SUCCESS) {
m_dsBuffer->Release();
m_dsBuffer = NULL;
EndAction();
}
} }
*/
if (m_sound.Create(&(MxWavePresenter::m_sound), buff, m_volume) != SUCCESS) {
ma_sound_uninit(&(MxWavePresenter::m_sound));
EndAction();
}
}
} }
// FUNCTION: LEGO1 0x1004a8b0 // FUNCTION: LEGO1 0x1004a8b0

View File

@ -4,6 +4,8 @@
#include "misc.h" #include "misc.h"
#include "mxomni.h" #include "mxomni.h"
#include <assert.h>
DECOMP_SIZE_ASSERT(LegoCacheSound, 0x88) DECOMP_SIZE_ASSERT(LegoCacheSound, 0x88)
// FUNCTION: LEGO1 0x100064d0 // FUNCTION: LEGO1 0x100064d0
@ -21,7 +23,8 @@ LegoCacheSound::~LegoCacheSound()
// FUNCTION: LEGO1 0x100066d0 // FUNCTION: LEGO1 0x100066d0
void LegoCacheSound::Init() void LegoCacheSound::Init()
{ {
m_dsBuffer = NULL; SDL_zero(m_buffer);
SDL_zero(m_cacheSound);
m_data = NULL; m_data = NULL;
m_unk0x58 = FALSE; m_unk0x58 = FALSE;
memset(&m_wfx, 0, sizeof(m_wfx)); memset(&m_wfx, 0, sizeof(m_wfx));
@ -35,60 +38,53 @@ void LegoCacheSound::Init()
// FUNCTION: LEGO1 0x10006710 // FUNCTION: LEGO1 0x10006710
// FUNCTION: BETA10 0x10066505 // FUNCTION: BETA10 0x10066505
MxResult LegoCacheSound::Create( MxResult LegoCacheSound::Create(
LPPCMWAVEFORMAT p_pwfx, MxWavePresenter::WaveFormat& p_pwfx,
MxString p_mediaSrcPath, MxString p_mediaSrcPath,
MxS32 p_volume, MxS32 p_volume,
MxU8* p_data, MxU8* p_data,
MxU32 p_dataSize MxU32 p_dataSize
) )
{ {
/* // [library:audio] These should never be null
WAVEFORMATEX wfx; assert(p_data != NULL && p_dataSize != 0);
wfx.wFormatTag = p_pwfx->wf.wFormatTag;
wfx.nChannels = p_pwfx->wf.nChannels;
wfx.nSamplesPerSec = p_pwfx->wf.nSamplesPerSec;
wfx.nAvgBytesPerSec = p_pwfx->wf.nAvgBytesPerSec;
wfx.nBlockAlign = p_pwfx->wf.nBlockAlign;
wfx.wBitsPerSample = p_pwfx->wBitsPerSample;
wfx.cbSize = 0;
DSBUFFERDESC desc; assert(p_pwfx.m_formatTag == supportedFormatTag);
memset(&desc, 0, sizeof(desc)); assert(p_pwfx.m_bitsPerSample == 8 || p_pwfx.m_bitsPerSample == 16);
desc.dwSize = sizeof(desc);
if (MxOmni::IsSound3D()) { CopyData(p_data, p_dataSize);
desc.dwFlags =
DSBCAPS_STATIC | DSBCAPS_LOCSOFTWARE | DSBCAPS_CTRL3D | DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLVOLUME; ma_format format = p_pwfx.m_bitsPerSample == 16 ? ma_format_s16 : ma_format_u8;
} ma_uint32 bytesPerFrame = ma_get_bytes_per_frame(format, p_pwfx.m_channels);
else { ma_uint32 bufferSizeInFrames = p_dataSize / bytesPerFrame;
desc.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME; ma_audio_buffer_config config =
ma_audio_buffer_config_init(format, p_pwfx.m_channels, bufferSizeInFrames, m_data, NULL);
config.sampleRate = p_pwfx.m_samplesPerSec;
if (ma_audio_buffer_init(&config, &m_buffer) != MA_SUCCESS) {
return FAILURE;
} }
desc.dwBufferBytes = p_dataSize; if (ma_sound_init_from_data_source(
desc.lpwfxFormat = &wfx; SoundManager()->GetEngine(),
&m_buffer,
if (SoundManager()->GetDirectSound()->CreateSoundBuffer(&desc, &m_dsBuffer, NULL) != DS_OK) { MxOmni::IsSound3D() ? 0 : MA_SOUND_FLAG_NO_SPATIALIZATION,
NULL,
&m_cacheSound
) != MA_SUCCESS) {
return FAILURE; return FAILURE;
} }
m_volume = p_volume; m_volume = p_volume;
MxS32 volume = m_volume * SoundManager()->GetVolume() / 100; MxS32 volume = m_volume * SoundManager()->GetVolume() / 100;
MxS32 attenuation = SoundManager()->GetAttenuation(volume); ma_sound_set_volume(&m_cacheSound, SoundManager()->GetAttenuation(volume));
m_dsBuffer->SetVolume(attenuation);
if (m_sound.Create(m_dsBuffer, NULL, m_volume) != SUCCESS) { if (m_sound.Create(&m_cacheSound, NULL, m_volume) != SUCCESS) {
m_dsBuffer->Release();
m_dsBuffer = NULL;
return FAILURE; return FAILURE;
} }
if (p_data != NULL && p_dataSize != 0) {
CopyData(p_data, p_dataSize);
}
m_unk0x48 = FUN_10006d80(p_mediaSrcPath); m_unk0x48 = FUN_10006d80(p_mediaSrcPath);
m_wfx = *p_pwfx;*/ m_wfx = p_pwfx;
return SUCCESS; return SUCCESS;
} }
@ -105,11 +101,8 @@ void LegoCacheSound::CopyData(MxU8* p_data, MxU32 p_dataSize)
// FUNCTION: LEGO1 0x10006920 // FUNCTION: LEGO1 0x10006920
void LegoCacheSound::Destroy() void LegoCacheSound::Destroy()
{ {
if (m_dsBuffer) { ma_sound_uninit(&m_cacheSound);
m_dsBuffer->Stop(); ma_audio_buffer_uninit(&m_buffer);
m_dsBuffer->Release();
m_dsBuffer = NULL;
}
delete[] m_data; delete[] m_data;
Init(); Init();
@ -121,7 +114,7 @@ LegoCacheSound* LegoCacheSound::Clone()
{ {
LegoCacheSound* pnew = new LegoCacheSound(); LegoCacheSound* pnew = new LegoCacheSound();
if (pnew->Create(&m_wfx, m_unk0x48, m_volume, m_data, m_dataSize) == SUCCESS) { if (pnew->Create(m_wfx, m_unk0x48, m_volume, m_data, m_dataSize) == SUCCESS) {
return pnew; return pnew;
} }
@ -138,35 +131,20 @@ MxResult LegoCacheSound::Play(const char* p_name, MxBool p_looping)
} }
m_unk0x6a = FALSE; m_unk0x6a = FALSE;
m_sound.FUN_10011a60(m_dsBuffer, p_name); m_sound.FUN_10011a60(&m_cacheSound, p_name);
if (p_name != NULL) { if (p_name != NULL) {
m_unk0x74 = p_name; m_unk0x74 = p_name;
} }
DWORD dwStatus; if (ma_sound_seek_to_pcm_frame(&m_cacheSound, 0) != MA_SUCCESS) {
m_dsBuffer->GetStatus(&dwStatus); return FAILURE;
if (dwStatus == DSBSTATUS_BUFFERLOST) {
m_dsBuffer->Restore();
m_dsBuffer->GetStatus(&dwStatus);
} }
if (dwStatus != DSBSTATUS_BUFFERLOST) { ma_sound_set_looping(&m_cacheSound, p_looping);
LPVOID pvAudioPtr1, pvAudioPtr2;
DWORD dwAudioBytes1, dwAudioBytes2;
if (m_dsBuffer->Lock(0, m_dataSize, &pvAudioPtr1, &dwAudioBytes1, &pvAudioPtr2, &dwAudioBytes2, 0) == DS_OK) { if (ma_sound_start(&m_cacheSound) != MA_SUCCESS) {
memcpy(pvAudioPtr1, m_data, dwAudioBytes1); return FAILURE;
if (dwAudioBytes2 != 0) {
memcpy(pvAudioPtr2, m_data + dwAudioBytes1, dwAudioBytes2);
}
m_dsBuffer->Unlock(pvAudioPtr1, dwAudioBytes1, pvAudioPtr2, dwAudioBytes2);
m_dsBuffer->SetCurrentPosition(0);
m_dsBuffer->Play(0, 0, p_looping);
}
} }
if (p_looping == FALSE) { if (p_looping == FALSE) {
@ -184,12 +162,7 @@ MxResult LegoCacheSound::Play(const char* p_name, MxBool p_looping)
// FUNCTION: LEGO1 0x10006b80 // FUNCTION: LEGO1 0x10006b80
void LegoCacheSound::FUN_10006b80() void LegoCacheSound::FUN_10006b80()
{ {
DWORD dwStatus; ma_sound_stop(&m_cacheSound);
m_dsBuffer->GetStatus(&dwStatus);
if (dwStatus) {
m_dsBuffer->Stop();
}
m_unk0x58 = FALSE; m_unk0x58 = FALSE;
m_unk0x6a = FALSE; m_unk0x6a = FALSE;
@ -204,19 +177,16 @@ void LegoCacheSound::FUN_10006b80()
void LegoCacheSound::FUN_10006be0() void LegoCacheSound::FUN_10006be0()
{ {
if (!m_looping) { if (!m_looping) {
DWORD dwStatus;
m_dsBuffer->GetStatus(&dwStatus);
if (m_unk0x70) { if (m_unk0x70) {
if (dwStatus == 0) { if (!ma_sound_is_playing(&m_cacheSound)) {
return; return;
} }
m_unk0x70 = FALSE; m_unk0x70 = FALSE;
} }
if (dwStatus == 0) { if (!ma_sound_is_playing(&m_cacheSound)) {
m_dsBuffer->Stop(); ma_sound_stop(&m_cacheSound);
m_sound.Reset(); m_sound.Reset();
if (m_unk0x74.GetLength() != 0) { if (m_unk0x74.GetLength() != 0) {
m_unk0x74 = ""; m_unk0x74 = "";
@ -228,16 +198,16 @@ void LegoCacheSound::FUN_10006be0()
} }
if (m_unk0x74.GetLength() != 0 && !m_muted) { if (m_unk0x74.GetLength() != 0 && !m_muted) {
if (!m_sound.UpdatePosition(m_dsBuffer)) { if (!m_sound.UpdatePosition(&m_cacheSound)) {
if (m_unk0x6a) { if (m_unk0x6a) {
return; return;
} }
m_dsBuffer->Stop(); ma_sound_stop(&m_cacheSound);
m_unk0x6a = TRUE; m_unk0x6a = TRUE;
} }
else if (m_unk0x6a) { else if (m_unk0x6a) {
m_dsBuffer->Play(0, 0, m_looping); ma_sound_start(&m_cacheSound);
m_unk0x6a = FALSE; m_unk0x6a = FALSE;
} }
} }
@ -262,10 +232,10 @@ void LegoCacheSound::Mute(MxBool p_muted)
m_muted = p_muted; m_muted = p_muted;
if (m_muted) { if (m_muted) {
m_dsBuffer->Stop(); ma_sound_stop(&m_cacheSound);
} }
else { else {
m_dsBuffer->Play(0, 0, m_looping); ma_sound_start(&m_cacheSound);
} }
} }
} }

View File

@ -43,7 +43,6 @@ void LegoLoadCacheSoundPresenter::Destroy(MxBool p_fromDestructor)
void LegoLoadCacheSoundPresenter::ReadyTickle() void LegoLoadCacheSoundPresenter::ReadyTickle()
{ {
MxStreamChunk* chunk = NextChunk(); MxStreamChunk* chunk = NextChunk();
return EndAction();
if (chunk) { if (chunk) {
WaveFormat* header = (WaveFormat*) chunk->GetData(); WaveFormat* header = (WaveFormat*) chunk->GetData();
@ -54,7 +53,7 @@ void LegoLoadCacheSoundPresenter::ReadyTickle()
m_pData = data; m_pData = data;
m_cacheSound = new LegoCacheSound(); m_cacheSound = new LegoCacheSound();
// m_pcmWaveFormat = header->m_pcmWaveFormat; m_waveFormat = *header;
m_subscriber->FreeDataChunk(chunk); m_subscriber->FreeDataChunk(chunk);
ProgressTickleState(e_streaming); ProgressTickleState(e_streaming);
@ -70,7 +69,7 @@ void LegoLoadCacheSoundPresenter::StreamingTickle()
if (chunk) { if (chunk) {
if (chunk->GetChunkFlags() & DS_CHUNK_END_OF_STREAM) { if (chunk->GetChunkFlags() & DS_CHUNK_END_OF_STREAM) {
m_cacheSound->Create( m_cacheSound->Create(
&m_pcmWaveFormat, m_waveFormat,
((MxDSSound*) m_action)->GetMediaSrcPath(), ((MxDSSound*) m_action)->GetMediaSrcPath(),
((MxDSSound*) m_action)->GetVolume(), ((MxDSSound*) m_action)->GetVolume(),
m_data + 2, m_data + 2,

View File

@ -22,7 +22,6 @@ LegoSoundManager::~LegoSoundManager()
void LegoSoundManager::Init() void LegoSoundManager::Init()
{ {
m_cacheSoundManager = NULL; m_cacheSoundManager = NULL;
m_listener = NULL;
} }
// FUNCTION: LEGO1 0x100299b0 // FUNCTION: LEGO1 0x100299b0
@ -43,31 +42,9 @@ MxResult LegoSoundManager::Create(MxU32 p_frequencyMS, MxBool p_createThread)
MxResult result = FAILURE; MxResult result = FAILURE;
if (MxSoundManager::Create(10, FALSE) == SUCCESS) { if (MxSoundManager::Create(10, FALSE) == SUCCESS) {
/*
m_criticalSection.Enter(); m_criticalSection.Enter();
locked = TRUE; locked = TRUE;
m_cacheSoundManager = new LegoCacheSoundManager;
if (MxOmni::IsSound3D()) {
if (m_dsBuffer->QueryInterface(IID_IDirectSound3DListener, (LPVOID*) &m_listener) != DS_OK) {
goto done;
}
MxOmni* omni = MxOmni::GetInstance();
LPDIRECTSOUND sound;
if (omni && omni->GetSoundManager() && (sound = omni->GetSoundManager()->GetDirectSound())) {
DSCAPS caps;
memset(&caps, 0, sizeof(DSCAPS));
caps.dwSize = sizeof(DSCAPS);
if (sound->GetCaps(&caps) == S_OK && caps.dwMaxHw3DAllBuffers == 0) {
m_listener->SetDistanceFactor(0.026315790f, 0);
m_listener->SetRolloffFactor(10, 0);
}
}
}
m_cacheSoundManager = new LegoCacheSoundManager;*/
result = SUCCESS; result = SUCCESS;
} }
@ -107,29 +84,22 @@ void LegoSoundManager::UpdateListener(
const float* p_velocity const float* p_velocity
) )
{ {
if (m_listener != NULL) { if (MxOmni::IsSound3D()) {
// [library:audio]
// miniaudio expects the right-handed OpenGL coordinate system, while LEGO Island
// uses DirectX' left-handed system? Figure out the proper conversions
if (p_position != NULL) { if (p_position != NULL) {
m_listener->SetPosition(p_position[0], p_position[1], p_position[2], DS3D_DEFERRED); ma_engine_listener_set_position(&m_engine, 0, p_position[0], p_position[1], p_position[2]);
} }
if (p_direction != NULL && p_up != NULL) { if (p_direction != NULL && p_up != NULL) {
m_listener->SetOrientation( ma_engine_listener_set_direction(&m_engine, 0, p_direction[0], p_direction[1], p_direction[2]);
p_direction[0], ma_engine_listener_set_world_up(&m_engine, 0, p_up[0], p_up[1], p_up[2]);
p_direction[1],
p_direction[2],
p_up[0],
p_up[1],
p_up[2],
DS3D_DEFERRED
);
} }
if (p_velocity != NULL) { if (p_velocity != NULL) {
m_listener->SetVelocity(p_velocity[0], p_velocity[1], p_velocity[2], DS3D_DEFERRED); ma_engine_listener_set_velocity(&m_engine, 0, p_velocity[0], p_velocity[1], p_velocity[2]);
}
if (p_position != NULL || (p_direction != NULL && p_up != NULL) || p_velocity != NULL) {
m_listener->CommitDeferredSettings();
} }
} }
} }

View File

@ -6,7 +6,6 @@
#include "mxaudiomanager.h" #include "mxaudiomanager.h"
#include <SDL3/SDL_audio.h> #include <SDL3/SDL_audio.h>
#include <dsound.h>
#include <miniaudio.h> #include <miniaudio.h>
// VTABLE: LEGO1 0x100dc128 // VTABLE: LEGO1 0x100dc128

View File

@ -197,7 +197,8 @@ void MxWavePresenter::StreamingTickle()
// FUNCTION: LEGO1 0x100b20c0 // FUNCTION: LEGO1 0x100b20c0
void MxWavePresenter::DoneTickle() void MxWavePresenter::DoneTickle()
{ {
if (!ma_sound_get_engine(&m_sound) || m_action->GetFlags() & MxDSAction::c_bit7 || !ma_sound_is_playing(&m_sound)) { if (!ma_sound_get_engine(&m_sound) || m_action->GetFlags() & MxDSAction::c_bit7 ||
ma_pcm_rb_pointer_distance(&m_rb) == 0) {
MxMediaPresenter::DoneTickle(); MxMediaPresenter::DoneTickle();
} }
} }