From 4765653cb3af905a9b20f1e5f2277e50d801c43b Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 20 Feb 2022 19:04:21 +0100 Subject: Add metadata header to media files The following properties are supported: - Sound: "loop". Must be either 0 or 1 - Images: "transparent". Must be either 0 or 1 These headers are only used for non-PS1 builds, since .TIM and .VAG files do already implement such information. --- src/sfx/CMakeLists.txt | 2 +- src/sfx/sdl-1.2/inc/sfx/port.h | 11 +++++++++++ src/sfx/sdl-1.2/src/sound.c | 21 +++++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src/sfx') diff --git a/src/sfx/CMakeLists.txt b/src/sfx/CMakeLists.txt index 3453d2e..6b774fd 100644 --- a/src/sfx/CMakeLists.txt +++ b/src/sfx/CMakeLists.txt @@ -10,7 +10,7 @@ elseif(SDL1_2_BUILD) "sdl-1.2/src/sound.c") set(inc ${inc} "sdl-1.2/inc") set(deps ${deps} SDL_mixer) - set(privdeps ${privdeps} SDL) + set(privdeps ${privdeps} SDL header) endif() add_library(sfx ${src}) diff --git a/src/sfx/sdl-1.2/inc/sfx/port.h b/src/sfx/sdl-1.2/inc/sfx/port.h index d8418f7..2279229 100644 --- a/src/sfx/sdl-1.2/inc/sfx/port.h +++ b/src/sfx/sdl-1.2/inc/sfx/port.h @@ -2,10 +2,21 @@ #define SFX_SDL1_2_H #include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif struct sound { Mix_Chunk *chunk; + bool loop; }; +#ifdef __cplusplus +} +#endif + #endif /* SFX_SDL1_2_H */ diff --git a/src/sfx/sdl-1.2/src/sound.c b/src/sfx/sdl-1.2/src/sound.c index e843923..e3e9a8b 100644 --- a/src/sfx/sdl-1.2/src/sound.c +++ b/src/sfx/sdl-1.2/src/sound.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -12,13 +13,13 @@ void sfx_free(struct sound *const s) int sfx_play(const struct sound *const s) { - if (Mix_PlayChannel(-1, s->chunk, 0) < 0) + if (Mix_PlayChannel(-1, s->chunk, s->loop ? -1 : 0) < 0) return -1; return 0; } -int sfx_sound_from_fp(struct sound *const s, FILE *const f) +static int load_data(struct sound *const s, FILE *const f) { int ret = -1; SDL_RWops *const ops = SDL_RWFromFP(f, 0); @@ -41,6 +42,22 @@ end: return ret; } +static int load_header(struct sound *const s, FILE *const f) +{ + if (header_load_bool(f, "loop", &s->loop)) + return -1; + + return 0; +} + +int sfx_sound_from_fp(struct sound *const s, FILE *const f) +{ + if (load_header(s, f) || load_data(s, f)) + return -1; + + return 0; +} + void sfx_deinit(void) { Mix_CloseAudio(); -- cgit v1.2.3