Use implicit cast

This commit is contained in:
Christian Semmler 2025-05-19 16:55:38 -07:00
parent 2f1297d211
commit 45d6cf339d
7 changed files with 57 additions and 55 deletions

View File

@ -40,7 +40,7 @@ void Lego3DWavePresenter::StartingTickle()
MxWavePresenter::StartingTickle(); MxWavePresenter::StartingTickle();
if (ma_sound_get_engine(*(MxWavePresenter::m_sound))) { if (MxWavePresenter::m_sound) {
MxU16 extraLength; MxU16 extraLength;
char* buff; char* buff;
m_action->GetExtra(extraLength, buff); m_action->GetExtra(extraLength, buff);
@ -49,7 +49,7 @@ void Lego3DWavePresenter::StartingTickle()
m_compositePresenter->GetAction()->GetExtra(extraLength, buff); m_compositePresenter->GetAction()->GetExtra(extraLength, buff);
} }
if (m_sound.Create(*(MxWavePresenter::m_sound), buff, m_volume) != SUCCESS) { if (m_sound.Create(MxWavePresenter::m_sound, buff, m_volume) != SUCCESS) {
EndAction(); EndAction();
} }
} }
@ -60,5 +60,5 @@ void Lego3DWavePresenter::StartingTickle()
void Lego3DWavePresenter::StreamingTickle() void Lego3DWavePresenter::StreamingTickle()
{ {
MxWavePresenter::StreamingTickle(); MxWavePresenter::StreamingTickle();
m_sound.UpdatePosition(*(MxWavePresenter::m_sound)); m_sound.UpdatePosition(MxWavePresenter::m_sound);
} }

View File

@ -80,9 +80,9 @@ MxResult LegoCacheSound::Create(
m_volume = p_volume; m_volume = p_volume;
MxS32 volume = m_volume * SoundManager()->GetVolume() / 100; MxS32 volume = m_volume * SoundManager()->GetVolume() / 100;
ma_sound_set_volume(*m_cacheSound, SoundManager()->GetAttenuation(volume)); ma_sound_set_volume(m_cacheSound, SoundManager()->GetAttenuation(volume));
if (m_sound.Create(*m_cacheSound, NULL, m_volume) != SUCCESS) { if (m_sound.Create(m_cacheSound, NULL, m_volume) != SUCCESS) {
return FAILURE; return FAILURE;
} }
@ -141,19 +141,19 @@ MxResult LegoCacheSound::Play(const char* p_name, MxBool p_looping)
} }
m_unk0x6a = FALSE; m_unk0x6a = FALSE;
m_sound.FUN_10011a60(*m_cacheSound, 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;
} }
if (ma_sound_seek_to_pcm_frame(*m_cacheSound, 0) != MA_SUCCESS) { if (ma_sound_seek_to_pcm_frame(m_cacheSound, 0) != MA_SUCCESS) {
return FAILURE; return FAILURE;
} }
ma_sound_set_looping(*m_cacheSound, p_looping); ma_sound_set_looping(m_cacheSound, p_looping);
if (ma_sound_start(*m_cacheSound) != MA_SUCCESS) { if (ma_sound_start(m_cacheSound) != MA_SUCCESS) {
return FAILURE; return FAILURE;
} }
@ -173,7 +173,7 @@ MxResult LegoCacheSound::Play(const char* p_name, MxBool p_looping)
// FUNCTION: BETA10 0x10066ca3 // FUNCTION: BETA10 0x10066ca3
void LegoCacheSound::Stop() void LegoCacheSound::Stop()
{ {
ma_sound_stop(*m_cacheSound); ma_sound_stop(m_cacheSound);
m_unk0x58 = FALSE; m_unk0x58 = FALSE;
m_unk0x6a = FALSE; m_unk0x6a = FALSE;
@ -190,15 +190,15 @@ void LegoCacheSound::FUN_10006be0()
{ {
if (!m_looping) { if (!m_looping) {
if (m_unk0x70) { if (m_unk0x70) {
if (!ma_sound_is_playing(*m_cacheSound)) { if (!ma_sound_is_playing(m_cacheSound)) {
return; return;
} }
m_unk0x70 = FALSE; m_unk0x70 = FALSE;
} }
if (!ma_sound_is_playing(*m_cacheSound)) { if (!ma_sound_is_playing(m_cacheSound)) {
ma_sound_stop(*m_cacheSound); 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 = "";
@ -214,14 +214,14 @@ void LegoCacheSound::FUN_10006be0()
} }
if (!m_muted) { if (!m_muted) {
if (!m_sound.UpdatePosition(*m_cacheSound)) { if (!m_sound.UpdatePosition(m_cacheSound)) {
if (!m_unk0x6a) { if (!m_unk0x6a) {
ma_sound_stop(*m_cacheSound); ma_sound_stop(m_cacheSound);
m_unk0x6a = TRUE; m_unk0x6a = TRUE;
} }
} }
else if (m_unk0x6a) { else if (m_unk0x6a) {
ma_sound_start(*m_cacheSound); ma_sound_start(m_cacheSound);
m_unk0x6a = FALSE; m_unk0x6a = FALSE;
} }
} }
@ -247,11 +247,11 @@ void LegoCacheSound::MuteSilence(MxBool p_muted)
m_muted = p_muted; m_muted = p_muted;
if (m_muted) { if (m_muted) {
ma_sound_set_volume(*m_cacheSound, ma_volume_db_to_linear(-3000.0f / 100.0f)); ma_sound_set_volume(m_cacheSound, ma_volume_db_to_linear(-3000.0f / 100.0f));
} }
else { else {
MxS32 volume = m_volume * SoundManager()->GetVolume() / 100; MxS32 volume = m_volume * SoundManager()->GetVolume() / 100;
ma_sound_set_volume(*m_cacheSound, SoundManager()->GetAttenuation(volume)); ma_sound_set_volume(m_cacheSound, SoundManager()->GetAttenuation(volume));
} }
} }
} }
@ -264,10 +264,10 @@ void LegoCacheSound::MuteStop(MxBool p_muted)
m_muted = p_muted; m_muted = p_muted;
if (m_muted) { if (m_muted) {
ma_sound_stop(*m_cacheSound); ma_sound_stop(m_cacheSound);
} }
else { else {
ma_sound_start(*m_cacheSound); ma_sound_start(m_cacheSound);
} }
} }
} }

View File

@ -96,16 +96,16 @@ void LegoSoundManager::UpdateListener(
// uses DirectX' left-handed system. The Z-axis needs to be inverted. // uses DirectX' left-handed system. The Z-axis needs to be inverted.
if (p_position != NULL) { if (p_position != NULL) {
ma_engine_listener_set_position(*m_engine, 0, p_position[0], p_position[1], -p_position[2]); 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) {
ma_engine_listener_set_direction(*m_engine, 0, p_direction[0], p_direction[1], -p_direction[2]); ma_engine_listener_set_direction(m_engine, 0, p_direction[0], p_direction[1], -p_direction[2]);
ma_engine_listener_set_world_up(*m_engine, 0, p_up[0], p_up[1], -p_up[2]); ma_engine_listener_set_world_up(m_engine, 0, p_up[0], p_up[1], -p_up[2]);
} }
if (p_velocity != NULL) { if (p_velocity != NULL) {
ma_engine_listener_set_velocity(*m_engine, 0, p_velocity[0], p_velocity[1], -p_velocity[2]); ma_engine_listener_set_velocity(m_engine, 0, p_velocity[0], p_velocity[1], -p_velocity[2]);
} }
} }
} }

View File

@ -44,7 +44,7 @@ class MxMiniaudio {
return nullptr; return nullptr;
} }
T* operator*() operator T*()
{ {
assert(m_initialized); assert(m_initialized);
if (m_initialized) { if (m_initialized) {
@ -54,6 +54,8 @@ class MxMiniaudio {
return nullptr; return nullptr;
} }
explicit operator bool() { return m_initialized; }
private: private:
T m_object; T m_object;
bool m_initialized; bool m_initialized;

View File

@ -22,7 +22,7 @@ class MxSoundManager : public MxAudioManager {
virtual void Pause(); // vtable+0x34 virtual void Pause(); // vtable+0x34
virtual void Resume(); // vtable+0x38 virtual void Resume(); // vtable+0x38
ma_engine* GetEngine() { return *m_engine; } ma_engine* GetEngine() { return m_engine; }
float GetAttenuation(MxU32 p_volume); float GetAttenuation(MxU32 p_volume);

View File

@ -94,9 +94,9 @@ MxResult MxSoundManager::Create(MxU32 p_frequencyMS, MxBool p_createThread)
SDL_AudioSpec spec; SDL_AudioSpec spec;
SDL_zero(spec); SDL_zero(spec);
spec.freq = ma_engine_get_sample_rate(*m_engine); spec.freq = ma_engine_get_sample_rate(m_engine);
spec.format = SDL_AUDIO_F32; spec.format = SDL_AUDIO_F32;
spec.channels = ma_engine_get_channels(*m_engine); spec.channels = ma_engine_get_channels(m_engine);
if ((m_stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, &AudioStreamCallback, this)) == if ((m_stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, &AudioStreamCallback, this)) ==
NULL) { NULL) {
@ -140,11 +140,11 @@ void MxSoundManager::AudioStreamCallback(
g_buffer.reserve(p_additionalAmount); g_buffer.reserve(p_additionalAmount);
MxSoundManager* manager = (MxSoundManager*) p_userdata; MxSoundManager* manager = (MxSoundManager*) p_userdata;
ma_uint32 bytesPerFrame = ma_get_bytes_per_frame(ma_format_f32, ma_engine_get_channels(*manager->m_engine)); ma_uint32 bytesPerFrame = ma_get_bytes_per_frame(ma_format_f32, ma_engine_get_channels(manager->m_engine));
ma_uint32 bufferSizeInFrames = (ma_uint32) p_additionalAmount / bytesPerFrame; ma_uint32 bufferSizeInFrames = (ma_uint32) p_additionalAmount / bytesPerFrame;
ma_uint64 framesRead; ma_uint64 framesRead;
if (ma_engine_read_pcm_frames(*manager->m_engine, g_buffer.data(), bufferSizeInFrames, &framesRead) == MA_SUCCESS) { if (ma_engine_read_pcm_frames(manager->m_engine, g_buffer.data(), bufferSizeInFrames, &framesRead) == MA_SUCCESS) {
SDL_PutAudioStreamData(manager->m_stream, g_buffer.data(), framesRead * bytesPerFrame); SDL_PutAudioStreamData(manager->m_stream, g_buffer.data(), framesRead * bytesPerFrame);
} }
} }

View File

@ -71,11 +71,11 @@ MxBool MxWavePresenter::WriteToSoundBuffer(void* p_audioPtr, MxU32 p_length)
ma_uint32 acquiredFrames = requestedFrames; ma_uint32 acquiredFrames = requestedFrames;
void* bufferOut; void* bufferOut;
ma_pcm_rb_acquire_write(*m_rb, &acquiredFrames, &bufferOut); ma_pcm_rb_acquire_write(m_rb, &acquiredFrames, &bufferOut);
// [library:audio] If there isn't enough space in the buffer for a full chunk, try again later. // [library:audio] If there isn't enough space in the buffer for a full chunk, try again later.
if (acquiredFrames != requestedFrames) { if (acquiredFrames != requestedFrames) {
ma_pcm_rb_commit_write(*m_rb, 0); ma_pcm_rb_commit_write(m_rb, 0);
return FALSE; return FALSE;
} }
@ -89,7 +89,7 @@ MxBool MxWavePresenter::WriteToSoundBuffer(void* p_audioPtr, MxU32 p_length)
memset((ma_uint8*) bufferOut + p_length, m_silenceData, acquiredBytes - p_length); memset((ma_uint8*) bufferOut + p_length, m_silenceData, acquiredBytes - p_length);
} }
ma_pcm_rb_commit_write(*m_rb, acquiredFrames); ma_pcm_rb_commit_write(m_rb, acquiredFrames);
return TRUE; return TRUE;
} }
} }
@ -161,13 +161,13 @@ void MxWavePresenter::StartingTickle()
goto done; goto done;
} }
ma_pcm_rb_set_sample_rate(*m_rb, sampleRate); ma_pcm_rb_set_sample_rate(m_rb, sampleRate);
} }
if (m_sound.Init( if (m_sound.Init(
ma_sound_init_from_data_source, ma_sound_init_from_data_source,
MSoundManager()->GetEngine(), MSoundManager()->GetEngine(),
m_action->IsLooping() ? (ma_data_source*) *m_ab.m_buffer : (ma_data_source*) *m_rb, m_action->IsLooping() ? (ma_data_source*) m_ab.m_buffer : (ma_data_source*) m_rb,
m_is3d ? 0 : MA_SOUND_FLAG_NO_SPATIALIZATION, m_is3d ? 0 : MA_SOUND_FLAG_NO_SPATIALIZATION,
nullptr nullptr
) != MA_SUCCESS) { ) != MA_SUCCESS) {
@ -178,8 +178,8 @@ void MxWavePresenter::StartingTickle()
// There is an issue with certain spatialized sounds causing an audio glitch. // There is an issue with certain spatialized sounds causing an audio glitch.
// To temporarily resolve this, we can disable the Doppler effect. // To temporarily resolve this, we can disable the Doppler effect.
// More info: https://github.com/mackron/miniaudio/issues/885 // More info: https://github.com/mackron/miniaudio/issues/885
ma_sound_set_doppler_factor(*m_sound, 0.0f); ma_sound_set_doppler_factor(m_sound, 0.0f);
ma_sound_set_looping(*m_sound, m_action->IsLooping() ? m_action->GetLoopCount() > 1 : MA_TRUE); ma_sound_set_looping(m_sound, m_action->IsLooping() ? m_action->GetLoopCount() > 1 : MA_TRUE);
SetVolume(((MxDSSound*) m_action)->GetVolume()); SetVolume(((MxDSSound*) m_action)->GetVolume());
ProgressTickleState(e_streaming); ProgressTickleState(e_streaming);
@ -222,8 +222,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 || if (!m_sound || m_action->GetFlags() & MxDSAction::c_bit7 || m_action->GetFlags() & MxDSAction::c_looping ||
m_action->GetFlags() & MxDSAction::c_looping || ma_pcm_rb_pointer_distance(*m_rb) == 0) { ma_pcm_rb_pointer_distance(m_rb) == 0) {
MxMediaPresenter::DoneTickle(); MxMediaPresenter::DoneTickle();
} }
} }
@ -251,7 +251,7 @@ MxResult MxWavePresenter::PutData()
} }
if (!m_started) { if (!m_started) {
if (ma_sound_start(*m_sound) == MA_SUCCESS) { if (ma_sound_start(m_sound) == MA_SUCCESS) {
m_started = TRUE; m_started = TRUE;
} }
} }
@ -261,10 +261,10 @@ MxResult MxWavePresenter::PutData()
break; break;
} }
assert(!ma_sound_is_playing(*m_sound)); assert(!ma_sound_is_playing(m_sound));
ma_sound_seek_to_pcm_frame(*m_sound, 0); ma_sound_seek_to_pcm_frame(m_sound, 0);
if (ma_sound_start(*m_sound) == MA_SUCCESS) { if (ma_sound_start(m_sound) == MA_SUCCESS) {
m_started = TRUE; m_started = TRUE;
} }
} }
@ -280,8 +280,8 @@ void MxWavePresenter::EndAction()
AUTOLOCK(m_criticalSection); AUTOLOCK(m_criticalSection);
MxMediaPresenter::EndAction(); MxMediaPresenter::EndAction();
if (ma_sound_get_engine(*m_sound)) { if (m_sound) {
ma_sound_stop(*m_sound); ma_sound_stop(m_sound);
} }
} }
} }
@ -292,10 +292,10 @@ void MxWavePresenter::SetVolume(MxS32 p_volume)
m_criticalSection.Enter(); m_criticalSection.Enter();
m_volume = p_volume; m_volume = p_volume;
if (ma_sound_get_engine(*m_sound)) { if (m_sound) {
MxS32 volume = p_volume * MxOmni::GetInstance()->GetSoundManager()->GetVolume() / 100; MxS32 volume = p_volume * MxOmni::GetInstance()->GetSoundManager()->GetVolume() / 100;
float attenuation = MxOmni::GetInstance()->GetSoundManager()->GetAttenuation(volume); float attenuation = MxOmni::GetInstance()->GetSoundManager()->GetAttenuation(volume);
ma_sound_set_volume(*m_sound, attenuation); ma_sound_set_volume(m_sound, attenuation);
} }
m_criticalSection.Leave(); m_criticalSection.Leave();
@ -310,8 +310,8 @@ void MxWavePresenter::Enable(MxBool p_enable)
if (p_enable) { if (p_enable) {
m_started = FALSE; m_started = FALSE;
} }
else if (ma_sound_get_engine(*m_sound)) { else if (m_sound) {
ma_sound_stop(*m_sound); ma_sound_stop(m_sound);
} }
} }
} }
@ -343,8 +343,8 @@ void MxWavePresenter::ParseExtra()
void MxWavePresenter::Pause() void MxWavePresenter::Pause()
{ {
if (!m_paused && m_started) { if (!m_paused && m_started) {
if (ma_sound_get_engine(*m_sound)) { if (m_sound) {
ma_sound_stop(*m_sound); ma_sound_stop(m_sound);
} }
m_paused = TRUE; m_paused = TRUE;
} }
@ -354,15 +354,15 @@ void MxWavePresenter::Pause()
void MxWavePresenter::Resume() void MxWavePresenter::Resume()
{ {
if (m_paused) { if (m_paused) {
if (ma_sound_get_engine(*m_sound) && m_started) { if (m_sound && m_started) {
switch (m_currentTickleState) { switch (m_currentTickleState) {
case e_streaming: case e_streaming:
case e_repeating: case e_repeating:
ma_sound_start(*m_sound); ma_sound_start(m_sound);
break; break;
case e_done: case e_done:
if (!ma_sound_at_end(*m_sound)) { if (!ma_sound_at_end(m_sound)) {
ma_sound_start(*m_sound); ma_sound_start(m_sound);
} }
} }
} }