mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-22 10:01:46 +00:00
Merge 2b3aeabfa9 into 24c5a226ed
This commit is contained in:
commit
bc7814e36e
13 changed files with 177 additions and 111 deletions
|
|
@ -10305,9 +10305,17 @@ function audio_stream_set_looping(audio, looping)
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @param audio ModAudio
|
||||
--- @return integer loopStart
|
||||
--- @return integer loopEnd
|
||||
--- Gets an `audio` stream's loop points in samples
|
||||
function audio_stream_get_loop_points(audio)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param audio ModAudio
|
||||
--- @param loopStart integer
|
||||
--- @param loopEnd integer
|
||||
--- @param loopEnd? integer
|
||||
--- Sets an `audio` stream's loop points in samples
|
||||
function audio_stream_set_loop_points(audio, loopStart, loopEnd)
|
||||
-- ...
|
||||
|
|
@ -11608,49 +11616,49 @@ function get_coopnet_id(localIndex)
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @return number
|
||||
--- @return integer
|
||||
--- Gets the master volume level
|
||||
function get_volume_master()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @return number
|
||||
--- @return integer
|
||||
--- Gets the volume level of music
|
||||
function get_volume_level()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @return number
|
||||
--- @return integer
|
||||
--- Gets the volume level of sound effects
|
||||
function get_volume_sfx()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @return number
|
||||
--- @return integer
|
||||
--- Gets the volume level of environment sounds effects
|
||||
function get_volume_env()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param volume number
|
||||
--- @param volume integer
|
||||
--- Sets the master volume level
|
||||
function set_volume_master(volume)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param volume number
|
||||
--- @param volume integer
|
||||
--- Sets the volume level of music
|
||||
function set_volume_level(volume)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param volume number
|
||||
--- @param volume integer
|
||||
--- Sets the volume level of sound effects
|
||||
function set_volume_sfx(volume)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param volume number
|
||||
--- @param volume integer
|
||||
--- Sets the volume level of environment sounds effects
|
||||
function set_volume_env(volume)
|
||||
-- ...
|
||||
|
|
|
|||
|
|
@ -1197,7 +1197,6 @@
|
|||
--- @class ModAudio
|
||||
--- @field public filepath string
|
||||
--- @field public isStream boolean
|
||||
--- @field public baseVolume number
|
||||
--- @field public loaded boolean
|
||||
|
||||
--- @class ModFs
|
||||
|
|
|
|||
|
|
@ -5828,6 +5828,30 @@ Sets if an `audio` stream is looping or not
|
|||
|
||||
<br />
|
||||
|
||||
## [audio_stream_get_loop_points](#audio_stream_get_loop_points)
|
||||
|
||||
### Description
|
||||
Gets an `audio` stream's loop points in samples
|
||||
|
||||
### Lua Example
|
||||
`local loopStart, loopEnd = audio_stream_get_loop_points(audio)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| audio | [ModAudio](structs.md#ModAudio) |
|
||||
|
||||
### Returns
|
||||
- `integer`
|
||||
- `integer`
|
||||
|
||||
### C Prototype
|
||||
`void audio_stream_get_loop_points(struct ModAudio* audio, RET u64 *loopStart, RET u64 *loopEnd);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [audio_stream_set_loop_points](#audio_stream_set_loop_points)
|
||||
|
||||
### Description
|
||||
|
|
@ -5847,7 +5871,7 @@ Sets an `audio` stream's loop points in samples
|
|||
- None
|
||||
|
||||
### C Prototype
|
||||
`void audio_stream_set_loop_points(struct ModAudio* audio, s64 loopStart, s64 loopEnd);`
|
||||
`void audio_stream_set_loop_points(struct ModAudio* audio, s64 loopStart, OPTIONAL s64 loopEnd);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
|
|||
|
|
@ -1846,16 +1846,16 @@ Gets the CoopNet ID of a player with `localIndex` if CoopNet is being used and t
|
|||
Gets the master volume level
|
||||
|
||||
### Lua Example
|
||||
`local numberValue = get_volume_master()`
|
||||
`local integerValue = get_volume_master()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- `number`
|
||||
- `integer`
|
||||
|
||||
### C Prototype
|
||||
`f32 get_volume_master(void);`
|
||||
`u8 get_volume_master(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
@ -1867,16 +1867,16 @@ Gets the master volume level
|
|||
Gets the volume level of music
|
||||
|
||||
### Lua Example
|
||||
`local numberValue = get_volume_level()`
|
||||
`local integerValue = get_volume_level()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- `number`
|
||||
- `integer`
|
||||
|
||||
### C Prototype
|
||||
`f32 get_volume_level(void);`
|
||||
`u8 get_volume_level(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
@ -1888,16 +1888,16 @@ Gets the volume level of music
|
|||
Gets the volume level of sound effects
|
||||
|
||||
### Lua Example
|
||||
`local numberValue = get_volume_sfx()`
|
||||
`local integerValue = get_volume_sfx()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- `number`
|
||||
- `integer`
|
||||
|
||||
### C Prototype
|
||||
`f32 get_volume_sfx(void);`
|
||||
`u8 get_volume_sfx(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
@ -1909,16 +1909,16 @@ Gets the volume level of sound effects
|
|||
Gets the volume level of environment sounds effects
|
||||
|
||||
### Lua Example
|
||||
`local numberValue = get_volume_env()`
|
||||
`local integerValue = get_volume_env()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- `number`
|
||||
- `integer`
|
||||
|
||||
### C Prototype
|
||||
`f32 get_volume_env(void);`
|
||||
`u8 get_volume_env(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
@ -1935,13 +1935,13 @@ Sets the master volume level
|
|||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| volume | `number` |
|
||||
| volume | `integer` |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void set_volume_master(f32 volume);`
|
||||
`void set_volume_master(u8 volume);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
@ -1958,13 +1958,13 @@ Sets the volume level of music
|
|||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| volume | `number` |
|
||||
| volume | `integer` |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void set_volume_level(f32 volume);`
|
||||
`void set_volume_level(u8 volume);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
@ -1981,13 +1981,13 @@ Sets the volume level of sound effects
|
|||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| volume | `number` |
|
||||
| volume | `integer` |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void set_volume_sfx(f32 volume);`
|
||||
`void set_volume_sfx(u8 volume);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
@ -2004,13 +2004,13 @@ Sets the volume level of environment sounds effects
|
|||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| volume | `number` |
|
||||
| volume | `integer` |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void set_volume_env(f32 volume);`
|
||||
`void set_volume_env(u8 volume);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
|
|||
|
|
@ -1842,6 +1842,7 @@
|
|||
- [audio_stream_set_position](functions-6.md#audio_stream_set_position)
|
||||
- [audio_stream_get_looping](functions-6.md#audio_stream_get_looping)
|
||||
- [audio_stream_set_looping](functions-6.md#audio_stream_set_looping)
|
||||
- [audio_stream_get_loop_points](functions-6.md#audio_stream_get_loop_points)
|
||||
- [audio_stream_set_loop_points](functions-6.md#audio_stream_set_loop_points)
|
||||
- [audio_stream_get_frequency](functions-6.md#audio_stream_get_frequency)
|
||||
- [audio_stream_set_frequency](functions-6.md#audio_stream_set_frequency)
|
||||
|
|
|
|||
|
|
@ -1745,7 +1745,6 @@
|
|||
| ----- | ---- | ------ |
|
||||
| filepath | `string` | read-only |
|
||||
| isStream | `boolean` | read-only |
|
||||
| baseVolume | `number` | |
|
||||
| loaded | `boolean` | read-only |
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
|
|
|||
|
|
@ -1482,12 +1482,11 @@ static struct LuaObjectField sModFields[LUA_MOD_FIELD_COUNT] = {
|
|||
{ "size", LVT_U64, offsetof(struct Mod, size), true, LOT_NONE, 1, sizeof(size_t) },
|
||||
};
|
||||
|
||||
#define LUA_MOD_AUDIO_FIELD_COUNT 4
|
||||
#define LUA_MOD_AUDIO_FIELD_COUNT 3
|
||||
static struct LuaObjectField sModAudioFields[LUA_MOD_AUDIO_FIELD_COUNT] = {
|
||||
{ "baseVolume", LVT_F32, offsetof(struct ModAudio, baseVolume), false, LOT_NONE, 1, sizeof(f32) },
|
||||
{ "filepath", LVT_STRING_P, offsetof(struct ModAudio, filepath), true, LOT_NONE, 1, sizeof(const char*) },
|
||||
{ "isStream", LVT_BOOL, offsetof(struct ModAudio, isStream), true, LOT_NONE, 1, sizeof(bool) },
|
||||
{ "loaded", LVT_BOOL, offsetof(struct ModAudio, loaded), true, LOT_NONE, 1, sizeof(bool) },
|
||||
{ "filepath", LVT_STRING_P, offsetof(struct ModAudio, filepath), true, LOT_NONE, 1, sizeof(const char*) },
|
||||
{ "isStream", LVT_BOOL, offsetof(struct ModAudio, isStream), true, LOT_NONE, 1, sizeof(bool) },
|
||||
{ "loaded", LVT_BOOL, offsetof(struct ModAudio, loaded), true, LOT_NONE, 1, sizeof(bool) },
|
||||
};
|
||||
|
||||
#define LUA_MOD_FS_FIELD_COUNT 15
|
||||
|
|
|
|||
|
|
@ -30677,12 +30677,35 @@ int smlua_func_audio_stream_set_looping(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_audio_stream_get_loop_points(lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
int top = lua_gettop(L);
|
||||
if (top != 1) {
|
||||
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "audio_stream_get_loop_points", 1, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ModAudio* audio = (struct ModAudio*)smlua_to_cobject(L, 1, LOT_MODAUDIO);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "audio_stream_get_loop_points"); return 0; }
|
||||
|
||||
u64 loopStart;
|
||||
u64 loopEnd;
|
||||
|
||||
audio_stream_get_loop_points(audio, &loopStart, &loopEnd);
|
||||
|
||||
lua_pushinteger(L, loopStart);
|
||||
lua_pushinteger(L, loopEnd);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int smlua_func_audio_stream_set_loop_points(lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
int top = lua_gettop(L);
|
||||
if (top != 3) {
|
||||
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "audio_stream_set_loop_points", 3, top);
|
||||
if (top < 2 || top > 3) {
|
||||
LOG_LUA_LINE("Improper param count for '%s': Expected between %u and %u, Received %u", "audio_stream_set_loop_points", 2, 3, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -30690,8 +30713,11 @@ int smlua_func_audio_stream_set_loop_points(lua_State* L) {
|
|||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "audio_stream_set_loop_points"); return 0; }
|
||||
s64 loopStart = smlua_to_integer(L, 2);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "audio_stream_set_loop_points"); return 0; }
|
||||
s64 loopEnd = smlua_to_integer(L, 3);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "audio_stream_set_loop_points"); return 0; }
|
||||
s64 loopEnd = (s64) 0;
|
||||
if (top >= 3) {
|
||||
loopEnd = smlua_to_integer(L, 3);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "audio_stream_set_loop_points"); return 0; }
|
||||
}
|
||||
|
||||
audio_stream_set_loop_points(audio, loopStart, loopEnd);
|
||||
|
||||
|
|
@ -34207,7 +34233,7 @@ int smlua_func_get_volume_master(UNUSED lua_State* L) {
|
|||
}
|
||||
|
||||
|
||||
lua_pushnumber(L, get_volume_master());
|
||||
lua_pushinteger(L, get_volume_master());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -34222,7 +34248,7 @@ int smlua_func_get_volume_level(UNUSED lua_State* L) {
|
|||
}
|
||||
|
||||
|
||||
lua_pushnumber(L, get_volume_level());
|
||||
lua_pushinteger(L, get_volume_level());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -34237,7 +34263,7 @@ int smlua_func_get_volume_sfx(UNUSED lua_State* L) {
|
|||
}
|
||||
|
||||
|
||||
lua_pushnumber(L, get_volume_sfx());
|
||||
lua_pushinteger(L, get_volume_sfx());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -34252,7 +34278,7 @@ int smlua_func_get_volume_env(UNUSED lua_State* L) {
|
|||
}
|
||||
|
||||
|
||||
lua_pushnumber(L, get_volume_env());
|
||||
lua_pushinteger(L, get_volume_env());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -34266,7 +34292,7 @@ int smlua_func_set_volume_master(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
f32 volume = smlua_to_number(L, 1);
|
||||
u8 volume = smlua_to_integer(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_volume_master"); return 0; }
|
||||
|
||||
set_volume_master(volume);
|
||||
|
|
@ -34283,7 +34309,7 @@ int smlua_func_set_volume_level(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
f32 volume = smlua_to_number(L, 1);
|
||||
u8 volume = smlua_to_integer(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_volume_level"); return 0; }
|
||||
|
||||
set_volume_level(volume);
|
||||
|
|
@ -34300,7 +34326,7 @@ int smlua_func_set_volume_sfx(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
f32 volume = smlua_to_number(L, 1);
|
||||
u8 volume = smlua_to_integer(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_volume_sfx"); return 0; }
|
||||
|
||||
set_volume_sfx(volume);
|
||||
|
|
@ -34317,7 +34343,7 @@ int smlua_func_set_volume_env(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
f32 volume = smlua_to_number(L, 1);
|
||||
u8 volume = smlua_to_integer(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_volume_env"); return 0; }
|
||||
|
||||
set_volume_env(volume);
|
||||
|
|
@ -38576,6 +38602,7 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "audio_stream_set_position", smlua_func_audio_stream_set_position);
|
||||
smlua_bind_function(L, "audio_stream_get_looping", smlua_func_audio_stream_get_looping);
|
||||
smlua_bind_function(L, "audio_stream_set_looping", smlua_func_audio_stream_set_looping);
|
||||
smlua_bind_function(L, "audio_stream_get_loop_points", smlua_func_audio_stream_get_loop_points);
|
||||
smlua_bind_function(L, "audio_stream_set_loop_points", smlua_func_audio_stream_set_loop_points);
|
||||
smlua_bind_function(L, "audio_stream_get_frequency", smlua_func_audio_stream_get_frequency);
|
||||
smlua_bind_function(L, "audio_stream_set_frequency", smlua_func_audio_stream_set_frequency);
|
||||
|
|
|
|||
|
|
@ -192,6 +192,8 @@ u8 smlua_audio_utils_allocate_sequence(void) {
|
|||
#define MA_SOUND_SAMPLE_FLAGS (MA_SOUND_FLAG_NO_SPATIALIZATION | MA_SOUND_FLAG_NO_PITCH | MA_SOUND_FLAG_DECODE) // No pitch, pre-decode audio samples
|
||||
|
||||
static ma_engine sModAudioEngine;
|
||||
static ma_sound_group sModAudioStreamGroup;
|
||||
static ma_sound_group sModAudioSampleGroup;
|
||||
static struct DynamicPool *sModAudioPool;
|
||||
|
||||
static void smlua_audio_custom_init(void) {
|
||||
|
|
@ -201,6 +203,13 @@ static void smlua_audio_custom_init(void) {
|
|||
if (result != MA_SUCCESS) {
|
||||
LOG_ERROR("failed to init Miniaudio: %d", result);
|
||||
}
|
||||
|
||||
ma_sound_group_init(&sModAudioEngine, 0, NULL, &sModAudioStreamGroup);
|
||||
ma_sound_group_init(&sModAudioEngine, 0, NULL, &sModAudioSampleGroup);
|
||||
f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f;
|
||||
f32 sfxVolume = (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f;
|
||||
ma_sound_group_set_volume(&sModAudioStreamGroup, musicVolume);
|
||||
ma_sound_group_set_volume(&sModAudioSampleGroup, sfxVolume);
|
||||
}
|
||||
|
||||
static struct ModAudio* find_mod_audio(const char *filepath) {
|
||||
|
|
@ -263,7 +272,7 @@ struct ModAudio* audio_load_internal(const char* filename, bool isStream) {
|
|||
u16 fileCount = gLuaActiveMod->fileCount;
|
||||
for (u16 i = 0; i < fileCount; i++) {
|
||||
struct ModFile* file = &gLuaActiveMod->files[i];
|
||||
if(path_ends_with(file->relativePath, normPath)) {
|
||||
if (path_ends_with(file->relativePath, normPath)) {
|
||||
foundModFile = true;
|
||||
modFile = file;
|
||||
break;
|
||||
|
|
@ -358,7 +367,7 @@ struct ModAudio* audio_load_internal(const char* filename, bool isStream) {
|
|||
result = ma_sound_init_from_data_source(
|
||||
&sModAudioEngine, &audio->decoder,
|
||||
isStream ? MA_SOUND_STREAM_FLAGS : MA_SOUND_SAMPLE_FLAGS,
|
||||
NULL, &audio->sound
|
||||
isStream ? &sModAudioStreamGroup : &sModAudioSampleGroup, &audio->sound
|
||||
);
|
||||
if (result != MA_SUCCESS) {
|
||||
free(buffer);
|
||||
|
|
@ -387,13 +396,7 @@ void audio_stream_destroy(struct ModAudio* audio) {
|
|||
void audio_stream_play(struct ModAudio* audio, bool restart, f32 volume) {
|
||||
if (!audio_sanity_check(audio, true, "play")) { return; }
|
||||
|
||||
if (configMuteFocusLoss && !WAPI.has_focus()) {
|
||||
ma_sound_set_volume(&audio->sound, 0);
|
||||
} else {
|
||||
f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f;
|
||||
ma_sound_set_volume(&audio->sound, gMasterVolume * musicVolume * volume);
|
||||
}
|
||||
audio->baseVolume = volume;
|
||||
ma_sound_set_volume(&audio->sound, volume);
|
||||
if (restart || !ma_sound_is_playing(&audio->sound)) { ma_sound_seek_to_pcm_frame(&audio->sound, 0); }
|
||||
ma_sound_start(&audio->sound);
|
||||
}
|
||||
|
|
@ -436,13 +439,18 @@ void audio_stream_set_looping(struct ModAudio* audio, bool looping) {
|
|||
ma_sound_set_looping(&audio->sound, looping);
|
||||
}
|
||||
|
||||
void audio_stream_set_loop_points(struct ModAudio* audio, s64 loopStart, s64 loopEnd) {
|
||||
void audio_stream_get_loop_points(struct ModAudio* audio, RET u64 *loopStart, RET u64 *loopEnd) {
|
||||
ma_data_source_get_loop_point_in_pcm_frames(&audio->decoder, loopStart, loopEnd);
|
||||
}
|
||||
|
||||
void audio_stream_set_loop_points(struct ModAudio* audio, s64 loopStart, OPTIONAL s64 loopEnd) {
|
||||
if (!audio_sanity_check(audio, true, "set stream loop points for")) { return; }
|
||||
|
||||
u64 length; ma_data_source_get_length_in_pcm_frames(&audio->decoder, &length);
|
||||
if (loopStart < 0) loopStart += length;
|
||||
if (loopEnd <= 0) loopEnd += length;
|
||||
if (loopStart < 0) loopStart = length + loopStart % length;
|
||||
if (loopEnd <= 0) loopEnd = length + loopEnd % length;
|
||||
|
||||
ma_sound_set_looping(&audio->sound, true);
|
||||
ma_data_source_set_loop_point_in_pcm_frames(&audio->decoder, loopStart, loopEnd);
|
||||
}
|
||||
|
||||
|
|
@ -474,19 +482,13 @@ void audio_stream_set_frequency(struct ModAudio* audio, f32 freq) {
|
|||
f32 audio_stream_get_volume(struct ModAudio* audio) {
|
||||
if (!audio_sanity_check(audio, true, "get stream volume from")) { return 0; }
|
||||
|
||||
return audio->baseVolume;
|
||||
return ma_sound_get_volume(&audio->sound);
|
||||
}
|
||||
|
||||
void audio_stream_set_volume(struct ModAudio* audio, f32 volume) {
|
||||
if (!audio_sanity_check(audio, true, "set stream volume for")) { return; }
|
||||
|
||||
if (configMuteFocusLoss && !WAPI.has_focus()) {
|
||||
ma_sound_set_volume(&audio->sound, 0);
|
||||
} else {
|
||||
f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f;
|
||||
ma_sound_set_volume(&audio->sound, gMasterVolume * musicVolume * volume);
|
||||
}
|
||||
audio->baseVolume = volume;
|
||||
ma_sound_set_volume(&audio->sound, volume);
|
||||
}
|
||||
|
||||
// void audio_stream_set_speed(struct ModAudio* audio, f32 initial_freq, f32 speed, bool pitch) {
|
||||
|
|
@ -588,7 +590,7 @@ void audio_sample_play(struct ModAudio* audio, Vec3f position, f32 volume) {
|
|||
struct ModAudioSampleCopies* copy = calloc(1, sizeof(struct ModAudioSampleCopies));
|
||||
ma_result result = ma_decoder_init_memory(audio->buffer, audio->bufferSize, NULL, ©->decoder);
|
||||
if (result != MA_SUCCESS) { return; }
|
||||
result = ma_sound_init_from_data_source(&sModAudioEngine, ©->decoder, MA_SOUND_SAMPLE_FLAGS, NULL, ©->sound);
|
||||
result = ma_sound_init_from_data_source(&sModAudioEngine, ©->decoder, MA_SOUND_SAMPLE_FLAGS, &sModAudioSampleGroup, ©->sound);
|
||||
if (result != MA_SUCCESS) { return; }
|
||||
ma_sound_set_end_callback(©->sound, audio_sample_copy_end_callback, copy);
|
||||
copy->parent = audio;
|
||||
|
|
@ -618,33 +620,34 @@ void audio_sample_play(struct ModAudio* audio, Vec3f position, f32 volume) {
|
|||
pan = (get_sound_pan(mtx[3][0] * factor, mtx[3][2] * factor) - 0.5f) * 2.0f;
|
||||
}
|
||||
|
||||
if (configMuteFocusLoss && !WAPI.has_focus()) {
|
||||
ma_sound_set_volume(sound, 0);
|
||||
} else {
|
||||
f32 intensity = sound_get_level_intensity(dist);
|
||||
f32 sfxVolume = (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f;
|
||||
ma_sound_set_volume(sound, gMasterVolume * sfxVolume * volume * intensity);
|
||||
}
|
||||
f32 intensity = sound_get_level_intensity(dist);
|
||||
ma_sound_set_volume(sound, volume * intensity);
|
||||
ma_sound_set_pan(sound, pan);
|
||||
audio->baseVolume = volume;
|
||||
|
||||
ma_sound_start(sound);
|
||||
}
|
||||
|
||||
void audio_custom_update_volume(void) {
|
||||
gMasterVolume = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f;
|
||||
bool shouldMute = (configMuteFocusLoss && !WAPI.has_focus());
|
||||
|
||||
// Update master volume
|
||||
f32 masterVolume = shouldMute ? 0 : ((f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f);
|
||||
gMasterVolume = masterVolume;
|
||||
if (!sModAudioPool) { return; }
|
||||
if (ma_engine_get_volume(&sModAudioEngine) != masterVolume) {
|
||||
ma_engine_set_volume(&sModAudioEngine, masterVolume);
|
||||
}
|
||||
|
||||
// Update music volume
|
||||
f32 musicVolume = (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f;
|
||||
struct DynamicPoolNode* node = sModAudioPool->tail;
|
||||
while (node) {
|
||||
struct DynamicPoolNode* prev = node->prev;
|
||||
struct ModAudio* audio = node->ptr;
|
||||
if (configMuteFocusLoss && !WAPI.has_focus()) {
|
||||
ma_sound_set_volume(&audio->sound, 0);
|
||||
} else if (audio->isStream) {
|
||||
ma_sound_set_volume(&audio->sound, gMasterVolume * musicVolume * audio->baseVolume);
|
||||
}
|
||||
node = prev;
|
||||
if (ma_sound_group_get_volume(&sModAudioStreamGroup) != musicVolume) {
|
||||
ma_sound_group_set_volume(&sModAudioStreamGroup, musicVolume);
|
||||
}
|
||||
|
||||
// Update sound volume
|
||||
f32 sfxVolume = (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f;
|
||||
if (ma_sound_group_get_volume(&sModAudioSampleGroup) != sfxVolume) {
|
||||
ma_sound_group_set_volume(&sModAudioSampleGroup, sfxVolume);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -671,6 +674,8 @@ void smlua_audio_custom_deinit(void) {
|
|||
if (sModAudioPool) {
|
||||
audio_custom_shutdown();
|
||||
free(sModAudioPool);
|
||||
ma_sound_group_uninit(&sModAudioStreamGroup);
|
||||
ma_sound_group_uninit(&sModAudioSampleGroup);
|
||||
ma_engine_uninit(&sModAudioEngine);
|
||||
sModAudioPool = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
#ifndef SMLUA_AUDIO_UTILS_H
|
||||
#define SMLUA_AUDIO_UTILS_H
|
||||
|
||||
#include "pc/lua/smlua_utils.h"
|
||||
|
||||
#define MA_NO_RESOURCE_MANAGER
|
||||
#define MA_NO_GENERATION
|
||||
#define MA_NO_ENCODING
|
||||
#include "pc/utils/miniaudio.h"
|
||||
|
||||
/* |description|Resets all custom sequences back to vanilla|descriptionEnd| */
|
||||
|
|
@ -31,7 +36,6 @@ struct ModAudio {
|
|||
u32 bufferSize;
|
||||
struct ModAudioSampleCopies* sampleCopiesTail;
|
||||
bool isStream;
|
||||
f32 baseVolume;
|
||||
bool loaded;
|
||||
};
|
||||
|
||||
|
|
@ -53,8 +57,10 @@ void audio_stream_set_position(struct ModAudio* audio, f32 pos);
|
|||
bool audio_stream_get_looping(struct ModAudio* audio);
|
||||
/* |description|Sets if an `audio` stream is looping or not|descriptionEnd| */
|
||||
void audio_stream_set_looping(struct ModAudio* audio, bool looping);
|
||||
/* |description|Gets an `audio` stream's loop points in samples|descriptionEnd| */
|
||||
void audio_stream_get_loop_points(struct ModAudio* audio, RET u64 *loopStart, RET u64 *loopEnd);
|
||||
/* |description|Sets an `audio` stream's loop points in samples|descriptionEnd| */
|
||||
void audio_stream_set_loop_points(struct ModAudio* audio, s64 loopStart, s64 loopEnd);
|
||||
void audio_stream_set_loop_points(struct ModAudio* audio, s64 loopStart, OPTIONAL s64 loopEnd);
|
||||
/* |description|Gets the frequency of an `audio` stream|descriptionEnd| */
|
||||
f32 audio_stream_get_frequency(struct ModAudio* audio);
|
||||
/* |description|Sets the frequency of an `audio` stream|descriptionEnd| */
|
||||
|
|
|
|||
|
|
@ -524,40 +524,36 @@ const char* get_coopnet_id(UNUSED s8 localIndex) {
|
|||
|
||||
///
|
||||
|
||||
f32 get_volume_master(void) {
|
||||
u8 get_volume_master(void) {
|
||||
return gLuaVolumeMaster;
|
||||
}
|
||||
|
||||
f32 get_volume_level(void) {
|
||||
u8 get_volume_level(void) {
|
||||
return gLuaVolumeLevel;
|
||||
}
|
||||
|
||||
f32 get_volume_sfx(void) {
|
||||
u8 get_volume_sfx(void) {
|
||||
return gLuaVolumeSfx;
|
||||
}
|
||||
|
||||
f32 get_volume_env(void) {
|
||||
u8 get_volume_env(void) {
|
||||
return gLuaVolumeEnv;
|
||||
}
|
||||
|
||||
void set_volume_master(f32 volume) {
|
||||
void set_volume_master(u8 volume) {
|
||||
gLuaVolumeMaster = MIN(volume, 127);
|
||||
audio_custom_update_volume();
|
||||
}
|
||||
|
||||
void set_volume_level(f32 volume) {
|
||||
void set_volume_level(u8 volume) {
|
||||
gLuaVolumeLevel = MIN(volume, 127);
|
||||
audio_custom_update_volume();
|
||||
}
|
||||
|
||||
void set_volume_sfx(f32 volume) {
|
||||
void set_volume_sfx(u8 volume) {
|
||||
gLuaVolumeSfx = MIN(volume, 127);
|
||||
audio_custom_update_volume();
|
||||
}
|
||||
|
||||
void set_volume_env(f32 volume) {
|
||||
void set_volume_env(u8 volume) {
|
||||
gLuaVolumeEnv = MIN(volume, 127);
|
||||
audio_custom_update_volume();
|
||||
}
|
||||
|
||||
///
|
||||
|
|
|
|||
|
|
@ -221,21 +221,21 @@ const char* get_local_discord_id(void);
|
|||
const char* get_coopnet_id(s8 localIndex);
|
||||
|
||||
/* |description|Gets the master volume level|descriptionEnd| */
|
||||
f32 get_volume_master(void);
|
||||
u8 get_volume_master(void);
|
||||
/* |description|Gets the volume level of music|descriptionEnd| */
|
||||
f32 get_volume_level(void);
|
||||
u8 get_volume_level(void);
|
||||
/* |description|Gets the volume level of sound effects|descriptionEnd| */
|
||||
f32 get_volume_sfx(void);
|
||||
u8 get_volume_sfx(void);
|
||||
/* |description|Gets the volume level of environment sounds effects|descriptionEnd| */
|
||||
f32 get_volume_env(void);
|
||||
u8 get_volume_env(void);
|
||||
/* |description|Sets the master volume level|descriptionEnd| */
|
||||
void set_volume_master(f32 volume);
|
||||
void set_volume_master(u8 volume);
|
||||
/* |description|Sets the volume level of music|descriptionEnd| */
|
||||
void set_volume_level(f32 volume);
|
||||
void set_volume_level(u8 volume);
|
||||
/* |description|Sets the volume level of sound effects|descriptionEnd| */
|
||||
void set_volume_sfx(f32 volume);
|
||||
void set_volume_sfx(u8 volume);
|
||||
/* |description|Sets the volume level of environment sounds effects|descriptionEnd| */
|
||||
void set_volume_env(f32 volume);
|
||||
void set_volume_env(u8 volume);
|
||||
|
||||
/* |description|Gets an environment region (gas/water boxes) height value|descriptionEnd| */
|
||||
s16 get_environment_region(u8 index);
|
||||
|
|
|
|||
|
|
@ -301,6 +301,8 @@ static s16 sAudioBuffer[SAMPLES_HIGH * 2 * 2] = { 0 };
|
|||
|
||||
inline static void buffer_audio(void) {
|
||||
bool shouldMute = (configMuteFocusLoss && !WAPI.has_focus()) || (gMasterVolume == 0);
|
||||
audio_custom_update_volume();
|
||||
|
||||
if (!shouldMute) {
|
||||
set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f);
|
||||
set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue