From 499518adde58c913f1ea4c241b3b1208bfc18a83 Mon Sep 17 00:00:00 2001 From: Lord-Giganticus <70081529+Lord-Giganticus@users.noreply.github.com> Date: Sat, 21 May 2022 23:17:35 -0500 Subject: [PATCH] Add function to load music via https URLs (#100) --- autogen/lua_definitions/functions.lua | 6 ++++++ docs/lua/functions-4.md | 20 ++++++++++++++++++++ docs/lua/functions.md | 1 + src/pc/lua/smlua_functions_autogen.c | 12 ++++++++++++ src/pc/lua/utils/smlua_audio_utils.c | 10 +++++++++- src/pc/lua/utils/smlua_audio_utils.h | 2 ++ 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index afb08b4a3..683001cc2 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -7211,6 +7211,12 @@ function audio_stream_load(filename) -- ... end +--- @param url string +--- @return BassAudio +function audio_stream_loadURL(url) + -- ... +end + --- @param audio BassAudio --- @return nil function audio_stream_pause(audio) diff --git a/docs/lua/functions-4.md b/docs/lua/functions-4.md index 09c8a99f5..ee9e3091b 100644 --- a/docs/lua/functions-4.md +++ b/docs/lua/functions-4.md @@ -4767,6 +4767,26 @@
+## [audio_stream_loadURL](#audio_stream_loadURL) + +### Lua Example +`local BassAudioValue = audio_stream_loadURL(url)` + +### Parameters +| Field | Type | +| ----- | ---- | +| url | `string` | + +### Returns +[BassAudio](structs.md#BassAudio) + +### C Prototype +`struct BassAudio* audio_stream_loadURL(const char* url);` + +[:arrow_up_small:](#) + +
+ ## [audio_stream_pause](#audio_stream_pause) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 3866c0efe..3ae990722 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1344,6 +1344,7 @@ - [audio_stream_get_tempo](functions-4.md#audio_stream_get_tempo) - [audio_stream_get_volume](functions-4.md#audio_stream_get_volume) - [audio_stream_load](functions-4.md#audio_stream_load) + - [audio_stream_loadURL](functions-4.md#audio_stream_loadURL) - [audio_stream_pause](functions-4.md#audio_stream_pause) - [audio_stream_play](functions-4.md#audio_stream_play) - [audio_stream_set_frequency](functions-4.md#audio_stream_set_frequency) diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 1d9360098..f4d25699e 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -14857,6 +14857,17 @@ int smlua_func_audio_stream_load(lua_State* L) { return 1; } +int smlua_func_audio_stream_loadURL(lua_State* L) { + if(!smlua_functions_valid_param_count(L, 1)) { return 0; } + + const char* url = smlua_to_string(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1"); return 0; } + + smlua_push_object(L, LOT_BASSAUDIO, audio_stream_loadURL(url)); + + return 1; +} + int smlua_func_audio_stream_pause(lua_State* L) { if(!smlua_functions_valid_param_count(L, 1)) { return 0; } @@ -17565,6 +17576,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "audio_stream_get_tempo", smlua_func_audio_stream_get_tempo); smlua_bind_function(L, "audio_stream_get_volume", smlua_func_audio_stream_get_volume); smlua_bind_function(L, "audio_stream_load", smlua_func_audio_stream_load); + smlua_bind_function(L, "audio_stream_loadURL", smlua_func_audio_stream_loadURL); smlua_bind_function(L, "audio_stream_pause", smlua_func_audio_stream_pause); smlua_bind_function(L, "audio_stream_play", smlua_func_audio_stream_play); smlua_bind_function(L, "audio_stream_set_frequency", smlua_func_audio_stream_set_frequency); diff --git a/src/pc/lua/utils/smlua_audio_utils.c b/src/pc/lua/utils/smlua_audio_utils.c index 09914b5ec..b80e8de59 100644 --- a/src/pc/lua/utils/smlua_audio_utils.c +++ b/src/pc/lua/utils/smlua_audio_utils.c @@ -422,4 +422,12 @@ void audio_custom_shutdown(void) { } } sBassAudioCount = 0; -} \ No newline at end of file +} + +struct BassAudio* audio_stream_loadURL(const char* url) { + HSTREAM stream = BASS_StreamCreateURL(url, 0, 0, NULL, NULL); + struct BassAudio* res = malloc(sizeof(struct BassAudio)); + res->handle = stream; + res->rawData = NULL; + return res; +} diff --git a/src/pc/lua/utils/smlua_audio_utils.h b/src/pc/lua/utils/smlua_audio_utils.h index 513c66821..3b9a15fd2 100644 --- a/src/pc/lua/utils/smlua_audio_utils.h +++ b/src/pc/lua/utils/smlua_audio_utils.h @@ -33,6 +33,8 @@ void audio_stream_set_tempo(struct BassAudio* audio, f32 tempo); f32 audio_stream_get_volume(struct BassAudio* audio); void audio_stream_set_volume(struct BassAudio* audio, f32 volume); void audio_stream_set_speed(struct BassAudio* audio, f32 initial_freq, f32 speed, bool pitch); +struct BassAudio* audio_stream_loadURL(const char* url); + struct BassAudio* audio_sample_load(const char* filename); void audio_sample_destroy(struct BassAudio* audio);