From 45d6cf339d6e380808c1092ac69413f85a627041 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Mon, 19 May 2025 16:55:38 -0700 Subject: [PATCH] Use implicit cast --- .../src/audio/lego3dwavepresenter.cpp | 6 +-- .../lego/legoomni/src/audio/legocachsound.cpp | 34 ++++++------- .../legoomni/src/audio/legosoundmanager.cpp | 8 +-- LEGO1/omni/include/mxminiaudio.h | 4 +- LEGO1/omni/include/mxsoundmanager.h | 2 +- LEGO1/omni/src/audio/mxsoundmanager.cpp | 8 +-- LEGO1/omni/src/audio/mxwavepresenter.cpp | 50 +++++++++---------- 7 files changed, 57 insertions(+), 55 deletions(-) diff --git a/LEGO1/lego/legoomni/src/audio/lego3dwavepresenter.cpp b/LEGO1/lego/legoomni/src/audio/lego3dwavepresenter.cpp index 4600ca81..38a418d4 100644 --- a/LEGO1/lego/legoomni/src/audio/lego3dwavepresenter.cpp +++ b/LEGO1/lego/legoomni/src/audio/lego3dwavepresenter.cpp @@ -40,7 +40,7 @@ void Lego3DWavePresenter::StartingTickle() MxWavePresenter::StartingTickle(); - if (ma_sound_get_engine(*(MxWavePresenter::m_sound))) { + if (MxWavePresenter::m_sound) { MxU16 extraLength; char* buff; m_action->GetExtra(extraLength, buff); @@ -49,7 +49,7 @@ void Lego3DWavePresenter::StartingTickle() 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(); } } @@ -60,5 +60,5 @@ void Lego3DWavePresenter::StartingTickle() void Lego3DWavePresenter::StreamingTickle() { MxWavePresenter::StreamingTickle(); - m_sound.UpdatePosition(*(MxWavePresenter::m_sound)); + m_sound.UpdatePosition(MxWavePresenter::m_sound); } diff --git a/LEGO1/lego/legoomni/src/audio/legocachsound.cpp b/LEGO1/lego/legoomni/src/audio/legocachsound.cpp index 6bf384d9..864659da 100644 --- a/LEGO1/lego/legoomni/src/audio/legocachsound.cpp +++ b/LEGO1/lego/legoomni/src/audio/legocachsound.cpp @@ -80,9 +80,9 @@ MxResult LegoCacheSound::Create( m_volume = p_volume; 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; } @@ -141,19 +141,19 @@ MxResult LegoCacheSound::Play(const char* p_name, MxBool p_looping) } m_unk0x6a = FALSE; - m_sound.FUN_10011a60(*m_cacheSound, p_name); + m_sound.FUN_10011a60(m_cacheSound, p_name); if (p_name != NULL) { 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; } - 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; } @@ -173,7 +173,7 @@ MxResult LegoCacheSound::Play(const char* p_name, MxBool p_looping) // FUNCTION: BETA10 0x10066ca3 void LegoCacheSound::Stop() { - ma_sound_stop(*m_cacheSound); + ma_sound_stop(m_cacheSound); m_unk0x58 = FALSE; m_unk0x6a = FALSE; @@ -190,15 +190,15 @@ void LegoCacheSound::FUN_10006be0() { if (!m_looping) { if (m_unk0x70) { - if (!ma_sound_is_playing(*m_cacheSound)) { + if (!ma_sound_is_playing(m_cacheSound)) { return; } m_unk0x70 = FALSE; } - if (!ma_sound_is_playing(*m_cacheSound)) { - ma_sound_stop(*m_cacheSound); + if (!ma_sound_is_playing(m_cacheSound)) { + ma_sound_stop(m_cacheSound); m_sound.Reset(); if (m_unk0x74.GetLength() != 0) { m_unk0x74 = ""; @@ -214,14 +214,14 @@ void LegoCacheSound::FUN_10006be0() } if (!m_muted) { - if (!m_sound.UpdatePosition(*m_cacheSound)) { + if (!m_sound.UpdatePosition(m_cacheSound)) { if (!m_unk0x6a) { - ma_sound_stop(*m_cacheSound); + ma_sound_stop(m_cacheSound); m_unk0x6a = TRUE; } } else if (m_unk0x6a) { - ma_sound_start(*m_cacheSound); + ma_sound_start(m_cacheSound); m_unk0x6a = FALSE; } } @@ -247,11 +247,11 @@ void LegoCacheSound::MuteSilence(MxBool p_muted) m_muted = p_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 { 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; if (m_muted) { - ma_sound_stop(*m_cacheSound); + ma_sound_stop(m_cacheSound); } else { - ma_sound_start(*m_cacheSound); + ma_sound_start(m_cacheSound); } } } diff --git a/LEGO1/lego/legoomni/src/audio/legosoundmanager.cpp b/LEGO1/lego/legoomni/src/audio/legosoundmanager.cpp index 68e7683c..1d53e64d 100644 --- a/LEGO1/lego/legoomni/src/audio/legosoundmanager.cpp +++ b/LEGO1/lego/legoomni/src/audio/legosoundmanager.cpp @@ -96,16 +96,16 @@ void LegoSoundManager::UpdateListener( // uses DirectX' left-handed system. The Z-axis needs to be inverted. 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) { - 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_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]); } 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]); } } } diff --git a/LEGO1/omni/include/mxminiaudio.h b/LEGO1/omni/include/mxminiaudio.h index c14b53f1..41bae048 100644 --- a/LEGO1/omni/include/mxminiaudio.h +++ b/LEGO1/omni/include/mxminiaudio.h @@ -44,7 +44,7 @@ class MxMiniaudio { return nullptr; } - T* operator*() + operator T*() { assert(m_initialized); if (m_initialized) { @@ -54,6 +54,8 @@ class MxMiniaudio { return nullptr; } + explicit operator bool() { return m_initialized; } + private: T m_object; bool m_initialized; diff --git a/LEGO1/omni/include/mxsoundmanager.h b/LEGO1/omni/include/mxsoundmanager.h index 706834cb..062d3839 100644 --- a/LEGO1/omni/include/mxsoundmanager.h +++ b/LEGO1/omni/include/mxsoundmanager.h @@ -22,7 +22,7 @@ class MxSoundManager : public MxAudioManager { virtual void Pause(); // vtable+0x34 virtual void Resume(); // vtable+0x38 - ma_engine* GetEngine() { return *m_engine; } + ma_engine* GetEngine() { return m_engine; } float GetAttenuation(MxU32 p_volume); diff --git a/LEGO1/omni/src/audio/mxsoundmanager.cpp b/LEGO1/omni/src/audio/mxsoundmanager.cpp index fcaf2e19..afb9b21e 100644 --- a/LEGO1/omni/src/audio/mxsoundmanager.cpp +++ b/LEGO1/omni/src/audio/mxsoundmanager.cpp @@ -94,9 +94,9 @@ MxResult MxSoundManager::Create(MxU32 p_frequencyMS, MxBool p_createThread) SDL_AudioSpec 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.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)) == NULL) { @@ -140,11 +140,11 @@ void MxSoundManager::AudioStreamCallback( g_buffer.reserve(p_additionalAmount); 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_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); } } diff --git a/LEGO1/omni/src/audio/mxwavepresenter.cpp b/LEGO1/omni/src/audio/mxwavepresenter.cpp index ea524fd3..600d9b37 100644 --- a/LEGO1/omni/src/audio/mxwavepresenter.cpp +++ b/LEGO1/omni/src/audio/mxwavepresenter.cpp @@ -71,11 +71,11 @@ MxBool MxWavePresenter::WriteToSoundBuffer(void* p_audioPtr, MxU32 p_length) ma_uint32 acquiredFrames = requestedFrames; 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. if (acquiredFrames != requestedFrames) { - ma_pcm_rb_commit_write(*m_rb, 0); + ma_pcm_rb_commit_write(m_rb, 0); 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); } - ma_pcm_rb_commit_write(*m_rb, acquiredFrames); + ma_pcm_rb_commit_write(m_rb, acquiredFrames); return TRUE; } } @@ -161,13 +161,13 @@ void MxWavePresenter::StartingTickle() goto done; } - ma_pcm_rb_set_sample_rate(*m_rb, sampleRate); + ma_pcm_rb_set_sample_rate(m_rb, sampleRate); } if (m_sound.Init( ma_sound_init_from_data_source, 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, nullptr ) != MA_SUCCESS) { @@ -178,8 +178,8 @@ void MxWavePresenter::StartingTickle() // There is an issue with certain spatialized sounds causing an audio glitch. // To temporarily resolve this, we can disable the Doppler effect. // More info: https://github.com/mackron/miniaudio/issues/885 - 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_doppler_factor(m_sound, 0.0f); + ma_sound_set_looping(m_sound, m_action->IsLooping() ? m_action->GetLoopCount() > 1 : MA_TRUE); SetVolume(((MxDSSound*) m_action)->GetVolume()); ProgressTickleState(e_streaming); @@ -222,8 +222,8 @@ void MxWavePresenter::StreamingTickle() // FUNCTION: LEGO1 0x100b20c0 void MxWavePresenter::DoneTickle() { - if (!ma_sound_get_engine(*m_sound) || m_action->GetFlags() & MxDSAction::c_bit7 || - m_action->GetFlags() & MxDSAction::c_looping || ma_pcm_rb_pointer_distance(*m_rb) == 0) { + if (!m_sound || m_action->GetFlags() & MxDSAction::c_bit7 || m_action->GetFlags() & MxDSAction::c_looping || + ma_pcm_rb_pointer_distance(m_rb) == 0) { MxMediaPresenter::DoneTickle(); } } @@ -251,7 +251,7 @@ MxResult MxWavePresenter::PutData() } if (!m_started) { - if (ma_sound_start(*m_sound) == MA_SUCCESS) { + if (ma_sound_start(m_sound) == MA_SUCCESS) { m_started = TRUE; } } @@ -261,10 +261,10 @@ MxResult MxWavePresenter::PutData() break; } - assert(!ma_sound_is_playing(*m_sound)); - ma_sound_seek_to_pcm_frame(*m_sound, 0); + assert(!ma_sound_is_playing(m_sound)); + 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; } } @@ -280,8 +280,8 @@ void MxWavePresenter::EndAction() AUTOLOCK(m_criticalSection); MxMediaPresenter::EndAction(); - if (ma_sound_get_engine(*m_sound)) { - ma_sound_stop(*m_sound); + if (m_sound) { + ma_sound_stop(m_sound); } } } @@ -292,10 +292,10 @@ void MxWavePresenter::SetVolume(MxS32 p_volume) m_criticalSection.Enter(); m_volume = p_volume; - if (ma_sound_get_engine(*m_sound)) { + if (m_sound) { MxS32 volume = p_volume * MxOmni::GetInstance()->GetSoundManager()->GetVolume() / 100; float attenuation = MxOmni::GetInstance()->GetSoundManager()->GetAttenuation(volume); - ma_sound_set_volume(*m_sound, attenuation); + ma_sound_set_volume(m_sound, attenuation); } m_criticalSection.Leave(); @@ -310,8 +310,8 @@ void MxWavePresenter::Enable(MxBool p_enable) if (p_enable) { m_started = FALSE; } - else if (ma_sound_get_engine(*m_sound)) { - ma_sound_stop(*m_sound); + else if (m_sound) { + ma_sound_stop(m_sound); } } } @@ -343,8 +343,8 @@ void MxWavePresenter::ParseExtra() void MxWavePresenter::Pause() { if (!m_paused && m_started) { - if (ma_sound_get_engine(*m_sound)) { - ma_sound_stop(*m_sound); + if (m_sound) { + ma_sound_stop(m_sound); } m_paused = TRUE; } @@ -354,15 +354,15 @@ void MxWavePresenter::Pause() void MxWavePresenter::Resume() { if (m_paused) { - if (ma_sound_get_engine(*m_sound) && m_started) { + if (m_sound && m_started) { switch (m_currentTickleState) { case e_streaming: case e_repeating: - ma_sound_start(*m_sound); + ma_sound_start(m_sound); break; case e_done: - if (!ma_sound_at_end(*m_sound)) { - ma_sound_start(*m_sound); + if (!ma_sound_at_end(m_sound)) { + ma_sound_start(m_sound); } } }