From 12074e15d927cf2c56d205c8c25e3abf96de8338 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 14 Jul 2022 18:11:44 -0400 Subject: [PATCH] Fix Sound --- media-layer/core/src/audio/api.cpp | 6 +++--- mods/src/sound/sound.cpp | 17 +++++++++++------ symbols/include/symbols/minecraft.h | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/media-layer/core/src/audio/api.cpp b/media-layer/core/src/audio/api.cpp index bdc70aa..a755d76 100644 --- a/media-layer/core/src/audio/api.cpp +++ b/media-layer/core/src/audio/api.cpp @@ -138,13 +138,13 @@ void media_audio_play(const char *source, const char *name, float x, float y, fl AL_ERROR_CHECK(); // Set Attenuation - alSourcei(al_source, AL_DISTANCE_MODEL, AL_LINEAR_DISTANCE); + alSourcei(al_source, AL_DISTANCE_MODEL, AL_LINEAR_DISTANCE_CLAMPED); AL_ERROR_CHECK(); - alSourcef(al_source, AL_MAX_DISTANCE, 16.0f); + alSourcef(al_source, AL_MAX_DISTANCE, 22.0f); AL_ERROR_CHECK(); alSourcef(al_source, AL_ROLLOFF_FACTOR, 1.0f); AL_ERROR_CHECK(); - alSourcef(al_source, AL_REFERENCE_DISTANCE, 0.0f); + alSourcef(al_source, AL_REFERENCE_DISTANCE, 2.0f); AL_ERROR_CHECK(); // Set Buffer diff --git a/mods/src/sound/sound.cpp b/mods/src/sound/sound.cpp index 82450a9..b99f963 100644 --- a/mods/src/sound/sound.cpp +++ b/mods/src/sound/sound.cpp @@ -56,18 +56,23 @@ std::string _sound_get_source_file() { // Play Sound // The pitch value is unsued because it causes glitchy sounds, it is seemingly unused in MCPE as well. -static void play(std::string name, float x, float y, float z, float volume, bool is_ui) { +static void play(std::string name, float x, float y, float z, float volume, float pitch, bool is_ui) { std::string source = _sound_get_source_file(); std::string resolved_name = _sound_pick(name); + if (pitch < 0.5f) { + pitch = 0.5f; + } else if (pitch > 2.0f) { + pitch = 2.0f; + } if (source.size() > 0 && resolved_name.size() > 0) { - media_audio_play(source.c_str(), resolved_name.c_str(), x, y, z, 1.0f, volume, is_ui); + media_audio_play(source.c_str(), resolved_name.c_str(), x, y, z, pitch, volume, is_ui); } } -static void SoundEngine_playUI_injection(__attribute__((unused)) unsigned char *sound_engine, std::string const& name, __attribute__((unused)) float pitch, float volume) { - play(name, 0, 0, 0, volume, true); +static void SoundEngine_playUI_injection(__attribute__((unused)) unsigned char *sound_engine, std::string const& name, float volume, float pitch) { + play(name, 0, 0, 0, volume, pitch, true); } -static void SoundEngine_play_injection(__attribute__((unused)) unsigned char *sound_engine, std::string const& name, float x, float y, float z, __attribute__((unused)) float pitch, float volume) { - play(name, x, y, z, volume, false); +static void SoundEngine_play_injection(__attribute__((unused)) unsigned char *sound_engine, std::string const& name, float x, float y, float z, float volume, float pitch) { + play(name, x, y, z, volume, pitch, false); } // Refresh Data diff --git a/symbols/include/symbols/minecraft.h b/symbols/include/symbols/minecraft.h index ded0116..c0095fa 100644 --- a/symbols/include/symbols/minecraft.h +++ b/symbols/include/symbols/minecraft.h @@ -889,10 +889,10 @@ static SelectWorldScreen_getUniqueLevelName_t Touch_SelectWorldScreen_getUniqueL // SoundEngine -typedef void (*SoundEngine_playUI_t)(unsigned char *sound_engine, std::string const& name, float pitch, float volume); +typedef void (*SoundEngine_playUI_t)(unsigned char *sound_engine, std::string const& name, float volume, float pitch); static SoundEngine_playUI_t SoundEngine_playUI = (SoundEngine_playUI_t) 0x67864; -typedef void (*SoundEngine_play_t)(unsigned char *sound_engine, std::string const& name, float x, float y, float z, float pitch, float volume); +typedef void (*SoundEngine_play_t)(unsigned char *sound_engine, std::string const& name, float x, float y, float z, float volume, float pitch); static SoundEngine_play_t SoundEngine_play = (SoundEngine_play_t) 0x67860; // Common