improve audio::ope_PCM_stream error messages & feat: specifying stream path without extension

This commit is contained in:
MihailRis 2026-10-27 14:20:01 +03:00
parent 575bfb28e0
commit f19cb75534
2 changed files with 16 additions and 4 deletions

View file

@ -262,6 +262,18 @@ std::unique_ptr<Sound> audio::create_sound(
}
std::unique_ptr<PCMStream> audio::open_PCM_stream(const io::path& file) {
if (!io::exists(file)) {
io::path candidate = file.string() + ".wav";
if (io::exists(candidate)) {
return wav::create_stream(candidate);
}
candidate = file.string() + ".ogg";
if (io::exists(candidate)) {
return ogg::create_stream(candidate);
}
throw std::runtime_error("file not found '" + file.string() + "'");
}
std::string ext = file.extension();
if (ext == ".wav" || ext == ".WAV") {
return wav::create_stream(file);

View file

@ -4,9 +4,9 @@
#include "engine/EnginePaths.hpp"
#include "api_lua.hpp"
inline const char* DEFAULT_CHANNEL = "regular";
static inline const char* DEFAULT_CHANNEL = "regular";
inline int extract_channel_index(lua::State* L, int idx) {
static int extract_channel_index(lua::State* L, int idx) {
const char* channel = DEFAULT_CHANNEL;
if (lua::isstring(L, idx)) {
channel = lua::tostring(L, idx);
@ -18,7 +18,7 @@ inline int extract_channel_index(lua::State* L, int idx) {
return index;
}
inline audio::speakerid_t play_sound(
static audio::speakerid_t play_sound(
const char* name,
bool relative,
lua::Number x,
@ -54,7 +54,7 @@ inline audio::speakerid_t play_sound(
);
}
inline audio::speakerid_t play_stream(
static audio::speakerid_t play_stream(
const char* filename,
bool relative,
lua::Number x,