From 49c5c785bff754f2d7e466d3fa7f571a6606e613 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 12 Jan 2023 02:48:44 -0800 Subject: [PATCH 1/4] Remove musictype_t, S_MusicType and I_SongType return implementation string Lua API change: S_MusicType now returns string instead of number --- src/deh_tables.c | 13 ------------- src/i_sound.h | 16 +--------------- src/lua_baselib.c | 2 +- src/p_setup.c | 1 + src/s_sound.c | 2 +- src/s_sound.h | 3 +-- src/sdl/new_sound.cpp | 14 +++++++------- 7 files changed, 12 insertions(+), 39 deletions(-) diff --git a/src/deh_tables.c b/src/deh_tables.c index 474db3b43..ba35d6a94 100644 --- a/src/deh_tables.c +++ b/src/deh_tables.c @@ -20,7 +20,6 @@ #include "lua_script.h" // Lua stuff #include "m_cond.h" // Emblem constants #include "v_video.h" // video flags (for lua) -#include "i_sound.h" // musictype_t (for lua) #include "g_state.h" // gamestate_t (for lua) #include "r_data.h" // patchalphastyle_t #include "k_boss.h" // spottype_t (for lua) @@ -6776,18 +6775,6 @@ struct int_const_s const INT_CONST[] = { {"MA_NOCUTSCENES",MA_NOCUTSCENES}, {"MA_INGAME",MA_INGAME}, - // music types - {"MU_NONE", MU_NONE}, - {"MU_WAV", MU_WAV}, - {"MU_MOD", MU_MOD}, - {"MU_MID", MU_MID}, - {"MU_OGG", MU_OGG}, - {"MU_MP3", MU_MP3}, - {"MU_FLAC", MU_FLAC}, - {"MU_GME", MU_GME}, - {"MU_MOD_EX", MU_MOD_EX}, - {"MU_MID_EX", MU_MID_EX}, - // gamestates {"GS_NULL",GS_NULL}, {"GS_LEVEL",GS_LEVEL}, diff --git a/src/i_sound.h b/src/i_sound.h index a26aa5a8a..cacb96923 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -22,20 +22,6 @@ extern "C" { #endif -// copied from SDL mixer, plus GME -typedef enum { - MU_NONE, - MU_WAV, - MU_MOD, - MU_MID, - MU_OGG, - MU_MP3, - MU_FLAC, - MU_GME, - MU_MOD_EX, // libopenmpt - MU_MID_EX // Non-native MIDI -} musictype_t; - /** \brief Sound subsystem runing and waiting */ extern UINT8 sound_started; @@ -139,7 +125,7 @@ void I_ShutdownMusic(void); // MUSIC PROPERTIES /// ------------------------ -musictype_t I_SongType(void); +const char *I_SongType(void); boolean I_SongPlaying(void); boolean I_SongPaused(void); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 54f3bacf1..6e855717d 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2603,7 +2603,7 @@ static int lib_sMusicType(lua_State *L) return LUA_ErrInvalid(L, "player_t"); } if (!player || P_IsLocalPlayer(player)) - lua_pushinteger(L, S_MusicType()); + lua_pushstring(L, S_MusicType()); else lua_pushnil(L); return 1; diff --git a/src/p_setup.c b/src/p_setup.c index 52441c62e..1e0a6b08e 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -36,6 +36,7 @@ #include "r_fps.h" // R_ResetViewInterpolation in level load #include "s_sound.h" +#include "i_sound.h" // I_FreeSfx #include "st_stuff.h" #include "w_wad.h" #include "z_zone.h" diff --git a/src/s_sound.c b/src/s_sound.c index 0d3746d33..b8b621f95 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1701,7 +1701,7 @@ boolean S_MusicNotInFocus(void) ); } -musictype_t S_MusicType(void) +const char *S_MusicType(void) { return I_SongType(); } diff --git a/src/s_sound.h b/src/s_sound.h index bc55cc0e7..bd3ad99e4 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -14,7 +14,6 @@ #ifndef __S_SOUND__ #define __S_SOUND__ -#include "i_sound.h" // musictype_t #include "sounds.h" #include "m_fixed.h" #include "command.h" @@ -162,7 +161,7 @@ boolean S_MusicDisabled(void); boolean S_MusicPlaying(void); boolean S_MusicPaused(void); boolean S_MusicNotInFocus(void); -musictype_t S_MusicType(void); +const char *S_MusicType(void); const char *S_MusicName(void); boolean S_MusicExists(const char *mname); diff --git a/src/sdl/new_sound.cpp b/src/sdl/new_sound.cpp index 0415778f1..fc948dbb5 100644 --- a/src/sdl/new_sound.cpp +++ b/src/sdl/new_sound.cpp @@ -338,27 +338,27 @@ void I_ShutdownMusic(void) { // MUSIC PROPERTIES /// ------------------------ -musictype_t I_SongType(void) { +const char* I_SongType(void) { if (!music_player) - return MU_NONE; + return nullptr; SdlAudioLockHandle _; std::optional music_type = music_player->music_type(); if (music_type == std::nullopt) { - return MU_NONE; + return nullptr; } switch (*music_type) { case audio::MusicType::kOgg: - return MU_OGG; + return "OGG"; case audio::MusicType::kGme: - return MU_GME; + return "GME"; case audio::MusicType::kMod: - return MU_MOD; + return "Mod"; default: - return MU_NONE; + return nullptr; } } From 4e51ad6c786440caf71473bf3deac6ca1cae5b43 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 12 Jan 2023 02:30:16 -0800 Subject: [PATCH 2/4] Add devmode music Song: Song: DEMOZ Format: OGG Volume: 50/100 Loop A: 00:00.65 Loop B: 01:06.00 Elapsed: 01:09.00 --- src/doomdef.h | 2 +- src/m_cheat.c | 1 + src/s_sound.c | 4 +--- src/s_sound.h | 1 + src/st_stuff.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index ffffd59d5..5318ee3e7 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -564,7 +564,7 @@ typedef enum DBG_DETAILED = 0x00000002, DBG_PLAYER = 0x00000004, DBG_RENDER = 0x00000008, - //DBG_NIGHTSBASIC = 0x00000010, // free + DBG_MUSIC = 0x00000010, //DBG_NIGHTS = 0x00000020, // free DBG_POLYOBJ = 0x00000040, DBG_GAMELOGIC = 0x00000080, diff --git a/src/m_cheat.c b/src/m_cheat.c index edd23041c..3124db460 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -690,6 +690,7 @@ struct debugFlagNames_s const debug_flag_names[] = {"Lua", DBG_LUA}, {"RNG", DBG_RNG}, {"Randomizer", DBG_RNG}, // alt name + {"Music", DBG_MUSIC}, {NULL, 0} }; diff --git a/src/s_sound.c b/src/s_sound.c index b8b621f95..d5557f43a 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1364,7 +1364,7 @@ int musicdef_volume; // // Find music def by 6 char name // -static musicdef_t *S_FindMusicDef(const char *name) +musicdef_t *S_FindMusicDef(const char *name) { musicdef_t *def = musicdefstart; @@ -2461,8 +2461,6 @@ static inline void PrintMusicDefField(const char *label, const char *field) static void PrintSongAuthors(const musicdef_t *def) { - CONS_Printf("Volume: %d/100\n\n", def->volume); - PrintMusicDefField("Title: ", def->title); PrintMusicDefField("Author: ", def->author); diff --git a/src/s_sound.h b/src/s_sound.h index bd3ad99e4..14192b377 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -202,6 +202,7 @@ extern int musicdef_volume; void S_LoadMusicDefs(UINT16 wadnum); void S_InitMusicDefs(void); +musicdef_t *S_FindMusicDef(const char *name); void S_ShowMusicCredit(void); // diff --git a/src/st_stuff.c b/src/st_stuff.c index 3f7e793eb..5216edc8c 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -357,6 +357,60 @@ static INT32 SCR(INT32 r) // ========================================================================= // Devmode information + +static void ST_pushDebugString(INT32 *height, const char *string) +{ + V_DrawRightAlignedString(320, *height, V_MONOSPACE, string); + *height -= 8; +} + +static void ST_pushDebugTimeMS(INT32 *height, const char *label, UINT32 ms) +{ + ST_pushDebugString(height, va("%s%02d:%05.2f", label, + ms / 60000, ms % 60000 / 1000.f)); +} + +static void ST_drawMusicDebug(INT32 *height) +{ + char mname[7]; + UINT16 mflags; // unused + boolean looping; + + const musicdef_t *def; + const char *format; + + if (!S_MusicInfo(mname, &mflags, &looping)) + { + ST_pushDebugString(height, "Song: "); + return; + } + + def = S_FindMusicDef(mname); + format = S_MusicType(); + + ST_pushDebugTimeMS(height, " Elapsed: ", S_GetMusicPosition()); + ST_pushDebugTimeMS(height, looping + ? " Loop B: " + : "Duration: ", S_GetMusicLength()); + + if (looping) + { + ST_pushDebugTimeMS(height, " Loop A: ", S_GetMusicLoopPoint()); + } + + if (def) + { + ST_pushDebugString(height, va(" Volume: %4d/100", def->volume)); + } + + if (format) + { + ST_pushDebugString(height, va(" Format: %8s", S_MusicType())); + } + + ST_pushDebugString(height, va(" Song: %8s", mname)); +} + static void ST_drawDebugInfo(void) { INT32 height = 192; @@ -419,6 +473,11 @@ static void ST_drawDebugInfo(void) height -= 32; } + if (cht_debug & DBG_MUSIC) + { + ST_drawMusicDebug(&height); + } + if (cht_debug & DBG_MEMORY) V_DrawRightAlignedString(320, height, V_MONOSPACE, va("Heap used: %7sKB", sizeu1(Z_TagsUsage(0, INT32_MAX)>>10))); } From 398c137c1a38aa3faa7f66d7c43b94bef61b1d71 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 12 Jan 2023 04:34:27 -0800 Subject: [PATCH 3/4] Fix reported loop point for GME --- src/audio/gme.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio/gme.cpp b/src/audio/gme.cpp index 38279dd98..5c2f63595 100644 --- a/src/audio/gme.cpp +++ b/src/audio/gme.cpp @@ -92,7 +92,7 @@ std::optional Gme::loop_point_seconds() const { if (loop_point_ms == -1) return std::nullopt; - return loop_point_ms / 44100.f; + return loop_point_ms / 1000.f; } float Gme::position_seconds() const { From f7787e45ec513cea80f47d8138cb05d9ac365f58 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 12 Jan 2023 04:34:47 -0800 Subject: [PATCH 4/4] Expose current position for XMP --- src/audio/music_player.cpp | 2 ++ src/audio/xmp.cpp | 10 ++++++++++ src/audio/xmp.hpp | 1 + src/audio/xmp_player.cpp | 5 +++++ src/audio/xmp_player.hpp | 1 + 5 files changed, 19 insertions(+) diff --git a/src/audio/music_player.cpp b/src/audio/music_player.cpp index bb85a01de..d1801e65b 100644 --- a/src/audio/music_player.cpp +++ b/src/audio/music_player.cpp @@ -260,6 +260,8 @@ public: return ogg_inst_->position_seconds(); if (gme_inst_) return gme_inst_->position_seconds(); + if (xmp_inst_) + return xmp_inst_->position_seconds(); return std::nullopt; } diff --git a/src/audio/xmp.cpp b/src/audio/xmp.cpp index 9e88f2a7f..574792a2d 100644 --- a/src/audio/xmp.cpp +++ b/src/audio/xmp.cpp @@ -116,6 +116,16 @@ float Xmp::duration_seconds() const { return static_cast(info.total_time) / 1000.f; } +template +float Xmp::position_seconds() const { + SRB2_ASSERT(instance_ != nullptr); + SRB2_ASSERT(module_loaded_ == true); + + xmp_frame_info info; + xmp_get_frame_info(instance_, &info); + return static_cast(info.time) / 1000.f; +} + template void Xmp::seek(int position_ms) { SRB2_ASSERT(instance_ != nullptr); diff --git a/src/audio/xmp.hpp b/src/audio/xmp.hpp index a5b443bfa..a0cbc8538 100644 --- a/src/audio/xmp.hpp +++ b/src/audio/xmp.hpp @@ -56,6 +56,7 @@ public: void looping(bool looping) { looping_ = looping; }; void reset(); float duration_seconds() const; + float position_seconds() const; void seek(int position_ms); ~Xmp(); diff --git a/src/audio/xmp_player.cpp b/src/audio/xmp_player.cpp index a08ee8bb5..e2bcb703b 100644 --- a/src/audio/xmp_player.cpp +++ b/src/audio/xmp_player.cpp @@ -48,6 +48,11 @@ float XmpPlayer::duration_seconds() const { return xmp_.duration_seconds(); } +template +float XmpPlayer::position_seconds() const { + return xmp_.position_seconds(); +} + template void XmpPlayer::seek(float position_seconds) { xmp_.seek(static_cast(std::round(position_seconds * 1000.f))); diff --git a/src/audio/xmp_player.hpp b/src/audio/xmp_player.hpp index 5829dbd8a..ed24689cd 100644 --- a/src/audio/xmp_player.hpp +++ b/src/audio/xmp_player.hpp @@ -37,6 +37,7 @@ public: void looping(bool looping) { xmp_.looping(looping); } void reset() { xmp_.reset(); } float duration_seconds() const; + float position_seconds() const; void seek(float position_seconds); };