Fix Sound

This commit is contained in:
TheBrokenRail 2022-07-14 18:11:44 -04:00
parent 010aaa89e3
commit 12074e15d9
3 changed files with 16 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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