mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-03 12:31:15 +00:00
Updated wrapper
This commit is contained in:
parent
58791ecd4e
commit
2f1297d211
@ -40,7 +40,7 @@ void Lego3DWavePresenter::StartingTickle()
|
||||
|
||||
MxWavePresenter::StartingTickle();
|
||||
|
||||
if (ma_sound_get_engine(&(MxWavePresenter::m_sound))) {
|
||||
if (ma_sound_get_engine(*(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));
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,18 +3,21 @@
|
||||
|
||||
#include "mxtypes.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <miniaudio.h>
|
||||
#include <utility>
|
||||
|
||||
template <typename T>
|
||||
class MxMiniaudio : public T {
|
||||
class MxMiniaudio {
|
||||
public:
|
||||
MxMiniaudio() : m_initialized(false) {}
|
||||
|
||||
template <typename Fn, typename... Args>
|
||||
ma_result Init(Fn p_init, Args&&... p_args)
|
||||
{
|
||||
ma_result result = p_init(std::forward<Args>(p_args)..., this);
|
||||
assert(!m_initialized);
|
||||
|
||||
ma_result result = p_init(std::forward<Args>(p_args)..., &m_object);
|
||||
if (result == MA_SUCCESS) {
|
||||
m_initialized = true;
|
||||
}
|
||||
@ -26,12 +29,33 @@ class MxMiniaudio : public T {
|
||||
void Destroy(Fn p_uninit)
|
||||
{
|
||||
if (m_initialized) {
|
||||
p_uninit(this);
|
||||
p_uninit(&m_object);
|
||||
m_initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
T* operator->()
|
||||
{
|
||||
assert(m_initialized);
|
||||
if (m_initialized) {
|
||||
return &m_object;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
T* operator*()
|
||||
{
|
||||
assert(m_initialized);
|
||||
if (m_initialized) {
|
||||
return &m_object;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
T m_object;
|
||||
bool m_initialized;
|
||||
};
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,15 +71,15 @@ 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;
|
||||
}
|
||||
|
||||
ma_uint32 acquiredBytes = acquiredFrames * ma_get_bytes_per_frame(m_rb.format, m_rb.channels);
|
||||
ma_uint32 acquiredBytes = acquiredFrames * ma_get_bytes_per_frame(m_rb->format, m_rb->channels);
|
||||
assert(p_length <= acquiredBytes);
|
||||
|
||||
memcpy(bufferOut, p_audioPtr, p_length);
|
||||
@ -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 (!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) {
|
||||
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 (ma_sound_get_engine(*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 (ma_sound_get_engine(*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 (ma_sound_get_engine(*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 (ma_sound_get_engine(*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 (ma_sound_get_engine(*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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user