Make audio streams update volume
This commit is contained in:
parent
7c01e405e0
commit
cb729dc40a
|
@ -109,7 +109,7 @@ override_disallowed_functions = {
|
|||
"src/pc/lua/utils/smlua_obj_utils.h": [ "spawn_object_remember_field" ],
|
||||
"src/game/camera.h": [ "update_camera", "init_camera", "stub_camera", "^reset_camera", "move_point_along_spline" ],
|
||||
"src/game/behavior_actions.h": [ "bhv_dust_smoke_loop", "bhv_init_room" ],
|
||||
"src/pc/lua/utils/smlua_audio_utils.h": [ "smlua_audio_utils_override", "audio_custom_shutdown", "smlua_audio_custom_init", "smlua_audio_custom_deinit", "audio_sample_destroy_pending_copies"],
|
||||
"src/pc/lua/utils/smlua_audio_utils.h": [ "smlua_audio_utils_override", "audio_custom_shutdown", "smlua_audio_custom_init", "smlua_audio_custom_deinit", "audio_sample_destroy_pending_copies", "audio_custom_update_volume" ],
|
||||
"src/pc/djui/djui_hud_utils.h": [ "djui_hud_render_texture", "djui_hud_render_texture_raw", "djui_hud_render_texture_tile", "djui_hud_render_texture_tile_raw" ],
|
||||
"src/pc/lua/utils/smlua_level_utils.h": [ "smlua_level_util_reset" ],
|
||||
"src/pc/lua/utils/smlua_text_utils.h": [ "smlua_text_utils_init", "smlua_text_utils_shutdown", "smlua_text_utils_reset_all" ],
|
||||
|
|
|
@ -1066,6 +1066,7 @@
|
|||
--- @field public selectable boolean
|
||||
|
||||
--- @class ModAudio
|
||||
--- @field public baseVolume number
|
||||
--- @field public file ModFile
|
||||
--- @field public isStream boolean
|
||||
--- @field public sampleCopiesTail ModAudioSampleCopies
|
||||
|
|
|
@ -1449,6 +1449,7 @@
|
|||
|
||||
| Field | Type | Access |
|
||||
| ----- | ---- | ------ |
|
||||
| baseVolume | `number` | |
|
||||
| file | [ModFile](structs.md#ModFile) | |
|
||||
| isStream | `boolean` | |
|
||||
| sampleCopiesTail | [ModAudioSampleCopies](structs.md#ModAudioSampleCopies) | |
|
||||
|
|
|
@ -3,16 +3,20 @@
|
|||
#include "djui_panel_menu.h"
|
||||
#include "pc/utils/misc.h"
|
||||
#include "pc/configfile.h"
|
||||
#include "pc/lua/utils/smlua_audio_utils.h"
|
||||
|
||||
static void djui_panel_sound_value_change(UNUSED struct DjuiBase* caller) {
|
||||
audio_custom_update_volume();
|
||||
}
|
||||
|
||||
void djui_panel_sound_create(struct DjuiBase* caller) {
|
||||
struct DjuiThreePanel* panel = djui_panel_menu_create(DLANG(SOUND, SOUND));
|
||||
struct DjuiBase* body = djui_three_panel_get_body(panel);
|
||||
|
||||
{
|
||||
djui_slider_create(body, DLANG(SOUND, MASTER_VOLUME), &configMasterVolume, 0, 127, NULL);
|
||||
djui_slider_create(body, DLANG(SOUND, MUSIC_VOLUME), &configMusicVolume, 0, 127, NULL);
|
||||
djui_slider_create(body, DLANG(SOUND, SFX_VOLUME), &configSfxVolume, 0, 127, NULL);
|
||||
djui_slider_create(body, DLANG(SOUND, ENV_VOLUME), &configEnvVolume, 0, 127, NULL);
|
||||
djui_slider_create(body, DLANG(SOUND, MASTER_VOLUME), &configMasterVolume, 0, 127, djui_panel_sound_value_change);
|
||||
djui_slider_create(body, DLANG(SOUND, MUSIC_VOLUME), &configMusicVolume, 0, 127, djui_panel_sound_value_change);
|
||||
djui_slider_create(body, DLANG(SOUND, SFX_VOLUME), &configSfxVolume, 0, 127, djui_panel_sound_value_change);
|
||||
djui_slider_create(body, DLANG(SOUND, ENV_VOLUME), &configEnvVolume, 0, 127, djui_panel_sound_value_change);
|
||||
djui_checkbox_create(body, DLANG(SOUND, FADEOUT), &configFadeoutDistantSounds, NULL);
|
||||
djui_button_create(body, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back);
|
||||
}
|
||||
|
|
|
@ -1197,8 +1197,9 @@ static struct LuaObjectField sModFields[LUA_MOD_FIELD_COUNT] = {
|
|||
// { "size", LVT_???, offsetof(struct Mod, size), true, LOT_??? }, <--- UNIMPLEMENTED
|
||||
};
|
||||
|
||||
#define LUA_MOD_AUDIO_FIELD_COUNT 3
|
||||
#define LUA_MOD_AUDIO_FIELD_COUNT 4
|
||||
static struct LuaObjectField sModAudioFields[LUA_MOD_AUDIO_FIELD_COUNT] = {
|
||||
{ "baseVolume", LVT_F32, offsetof(struct ModAudio, baseVolume), false, LOT_NONE },
|
||||
{ "file", LVT_COBJECT_P, offsetof(struct ModAudio, file), false, LOT_MODFILE },
|
||||
{ "isStream", LVT_BOOL, offsetof(struct ModAudio, isStream), false, LOT_NONE },
|
||||
{ "sampleCopiesTail", LVT_COBJECT_P, offsetof(struct ModAudio, sampleCopiesTail), false, LOT_MODAUDIOSAMPLECOPIES },
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "pc/mods/mods_utils.h"
|
||||
#include "pc/utils/misc.h"
|
||||
#include "pc/debuglog.h"
|
||||
#include "pc/pc_main.h"
|
||||
#include "audio/external.h"
|
||||
|
||||
struct AudioOverride {
|
||||
|
@ -280,9 +281,10 @@ void audio_stream_play(struct ModAudio* audio, bool restart, f32 volume) {
|
|||
if (!audio_sanity_check(audio, true, "play")) {
|
||||
return;
|
||||
}
|
||||
f32 masterVolume = (f32)configMasterVolume / 127.0f;
|
||||
f32 musicVolume = (f32)configMusicVolume / 127.0f;
|
||||
f32 masterVolume = (f32)configMasterVolume / 127.0f * gLuaVolumeMaster;
|
||||
f32 musicVolume = (f32)configMusicVolume / 127.0f * gLuaVolumeLevel;
|
||||
ma_sound_set_volume(&audio->sound, masterVolume * musicVolume * volume);
|
||||
audio->baseVolume = volume;
|
||||
if (restart || !ma_sound_is_playing(&audio->sound)) { ma_sound_seek_to_pcm_frame(&audio->sound, 0); }
|
||||
ma_sound_start(&audio->sound);
|
||||
}
|
||||
|
@ -509,14 +511,29 @@ void audio_sample_play(struct ModAudio* audio, Vec3f position, f32 volume) {
|
|||
}
|
||||
|
||||
f32 intensity = sound_get_level_intensity(dist);
|
||||
f32 masterVolume = (f32)configMasterVolume / 127.0f;
|
||||
f32 sfxVolume = (f32)configSfxVolume / 127.0f;
|
||||
f32 masterVolume = (f32)configMasterVolume / 127.0f * gLuaVolumeMaster;
|
||||
f32 sfxVolume = (f32)configSfxVolume / 127.0f * gLuaVolumeSfx;
|
||||
ma_sound_set_volume(sound, masterVolume * sfxVolume * volume * intensity);
|
||||
ma_sound_set_pan(sound, pan);
|
||||
audio->baseVolume = volume;
|
||||
|
||||
ma_sound_start(sound);
|
||||
}
|
||||
|
||||
void audio_custom_update_volume(void) {
|
||||
struct DynamicPoolNode* node = sModAudio->tail;
|
||||
while (node) {
|
||||
struct DynamicPoolNode* prev = node->prev;
|
||||
struct ModAudio* audio = node->ptr;
|
||||
f32 masterVolume = (f32)configMasterVolume / 127.0f;
|
||||
f32 musicVolume = (f32)configMusicVolume / 127.0f;
|
||||
if (audio->isStream) {
|
||||
ma_sound_set_volume(&audio->sound, masterVolume * musicVolume * audio->baseVolume);
|
||||
}
|
||||
node = prev;
|
||||
}
|
||||
}
|
||||
|
||||
void audio_custom_shutdown(void) {
|
||||
if (!sModAudio) { return; }
|
||||
struct DynamicPoolNode* node = sModAudio->tail;
|
||||
|
|
|
@ -23,6 +23,7 @@ struct ModAudio {
|
|||
ma_sound sound;
|
||||
struct ModAudioSampleCopies* sampleCopiesTail;
|
||||
bool isStream;
|
||||
f32 baseVolume;
|
||||
};
|
||||
|
||||
struct ModAudio* audio_stream_load(const char* filename);
|
||||
|
@ -45,6 +46,8 @@ void audio_sample_destroy(struct ModAudio* audio);
|
|||
void audio_sample_stop(struct ModAudio* audio);
|
||||
void audio_sample_play(struct ModAudio* audio, Vec3f position, f32 volume);
|
||||
|
||||
void audio_custom_update_volume(void);
|
||||
|
||||
void audio_custom_shutdown(void);
|
||||
|
||||
void smlua_audio_custom_init(void);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "game/level_geo.h"
|
||||
#include "game/first_person_cam.h"
|
||||
#include "pc/lua/utils/smlua_math_utils.h"
|
||||
#include "pc/lua/utils/smlua_audio_utils.h"
|
||||
|
||||
#ifdef DISCORD_SDK
|
||||
#include "pc/discord/discord.h"
|
||||
|
@ -674,18 +675,22 @@ f32 get_volume_env(void) {
|
|||
|
||||
void set_volume_master(f32 volume) {
|
||||
gLuaVolumeMaster = clampf(volume, 0.0f, 1.0f);
|
||||
audio_custom_update_volume();
|
||||
}
|
||||
|
||||
void set_volume_level(f32 volume) {
|
||||
gLuaVolumeLevel = clampf(volume, 0.0f, 1.0f);
|
||||
audio_custom_update_volume();
|
||||
}
|
||||
|
||||
void set_volume_sfx(f32 volume) {
|
||||
gLuaVolumeSfx = clampf(volume, 0.0f, 1.0f);
|
||||
audio_custom_update_volume();
|
||||
}
|
||||
|
||||
void set_volume_env(f32 volume) {
|
||||
gLuaVolumeEnv = clampf(volume, 0.0f, 1.0f);
|
||||
audio_custom_update_volume();
|
||||
}
|
||||
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue