From 011fd40dda7ce36cf98969ab2cdde77e1ef91386 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sat, 17 Jan 2015 00:28:49 +0000 Subject: [PATCH] CON: Add new commands "getmusicposition" and "setmusicposition" that operate on the playback position of the current music track. // Example: Switch between tracks like radio stations. getmusicposition temp starttrackvar next_music_track setmusicposition temp Only implemented for Ogg Vorbis, FLAC, and XA. Consult the devs before using these commands. git-svn-id: https://svn.eduke32.com/eduke32@4928 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/gamedef.c | 5 ++ polymer/eduke32/source/gamedef.h | 2 + polymer/eduke32/source/gameexec.c | 10 +++ .../eduke32/source/jaudiolib/include/fx_man.h | 2 + .../eduke32/source/jaudiolib/src/_multivc.h | 7 ++ polymer/eduke32/source/jaudiolib/src/flac.c | 17 +++++ polymer/eduke32/source/jaudiolib/src/fx_man.c | 27 +++++++ .../eduke32/source/jaudiolib/src/multivoc.c | 72 +++++++++++++++++++ .../eduke32/source/jaudiolib/src/multivoc.h | 4 ++ polymer/eduke32/source/jaudiolib/src/vorbis.c | 14 ++++ polymer/eduke32/source/jaudiolib/src/xa.c | 15 ++++ polymer/eduke32/source/lunatic/con_lang.lua | 2 + polymer/eduke32/source/lunatic/control.lua | 8 +++ polymer/eduke32/source/lunatic/defs.ilua | 2 + polymer/eduke32/source/lunatic/dynsymlist | 2 + polymer/eduke32/source/lunatic/lunacon.lua | 5 ++ polymer/eduke32/source/sounds.c | 16 +++++ polymer/eduke32/source/sounds.h | 2 + 18 files changed, 212 insertions(+) diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 0c4c70d49..461ffda2e 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -95,6 +95,7 @@ static struct { uint32_t keyw; uint32_t date; } g_keywdate[] = { CON_SCREENTEXT, 20130529 }, { CON_DYNAMICSOUNDREMAP, 20130530 }, { CON_SCREENSOUND, 20130628 }, + { CON_SETMUSICPOSITION, 20150115 }, }; #endif @@ -549,6 +550,8 @@ const char *keyw[] = "screentext", // 370 "dynamicsoundremap", // 371 "screensound", // 372 + "getmusicposition", // 373 + "setmusicposition", // 374 "" }; #endif @@ -4095,6 +4098,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_SECTCLEARINTERPOLATION: case CON_SETACTORANGLE: case CON_SETPLAYERANGLE: + case CON_SETMUSICPOSITION: C_GetNextVar(); continue; @@ -4109,6 +4113,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_GETPLAYERANGLE: case CON_GETTICKS: case CON_GETCURRADDRESS: + case CON_GETMUSICPOSITION: C_GetNextVarType(GAMEVAR_READONLY); continue; diff --git a/polymer/eduke32/source/gamedef.h b/polymer/eduke32/source/gamedef.h index ba0a5d304..518be7b65 100644 --- a/polymer/eduke32/source/gamedef.h +++ b/polymer/eduke32/source/gamedef.h @@ -966,6 +966,8 @@ enum ScriptKeywords_t CON_SCREENTEXT, // 370 CON_DYNAMICSOUNDREMAP, // 371 CON_SCREENSOUND, // 372 + CON_GETMUSICPOSITION, // 373 + CON_SETMUSICPOSITION, // 374 CON_END }; // KEEPINSYNC with the keyword list in lunatic/con_lang.lua diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 5836084be..12ce0b9b0 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -4841,6 +4841,16 @@ finish_qsprintf: } continue; + case CON_SETMUSICPOSITION: + insptr++; + S_SetMusicPosition(Gv_GetVarX(*insptr++)); + continue; + + case CON_GETMUSICPOSITION: + insptr++; + Gv_SetVarX(*insptr++, S_GetMusicPosition()); + continue; + case CON_ACTIVATECHEAT: insptr++; { diff --git a/polymer/eduke32/source/jaudiolib/include/fx_man.h b/polymer/eduke32/source/jaudiolib/include/fx_man.h index e0a75ac2c..f69b8a001 100644 --- a/polymer/eduke32/source/jaudiolib/include/fx_man.h +++ b/polymer/eduke32/source/jaudiolib/include/fx_man.h @@ -122,6 +122,8 @@ int32_t FX_StartDemandFeedPlayback( void ( *function )( char **ptr, uint32_t *le int32_t FX_SetVoiceCallback(int32_t handle, uint32_t callbackval); int32_t FX_SetPrintf(void (*function)(const char *, ...)); +int32_t FX_GetPosition(int32_t handle, int32_t *position); +int32_t FX_SetPosition(int32_t handle, int32_t position); #ifdef __cplusplus } diff --git a/polymer/eduke32/source/jaudiolib/src/_multivc.h b/polymer/eduke32/source/jaudiolib/src/_multivc.h index b57712a37..cd785d74b 100644 --- a/polymer/eduke32/source/jaudiolib/src/_multivc.h +++ b/polymer/eduke32/source/jaudiolib/src/_multivc.h @@ -227,6 +227,13 @@ void MV_SetVoiceMixMode( VoiceNode *voice ); void MV_SetVoiceVolume ( VoiceNode *voice, int32_t vol, int32_t left, int32_t right ); void MV_SetVoicePitch ( VoiceNode *voice, uint32_t rate, int32_t pitchoffset ); +int32_t MV_GetVorbisPosition(VoiceNode *voice); +void MV_SetVorbisPosition(VoiceNode *voice, int32_t position); +int32_t MV_GetFLACPosition(VoiceNode *voice); +void MV_SetFLACPosition(VoiceNode *voice, int32_t position); +int32_t MV_GetXAPosition(VoiceNode *voice); +void MV_SetXAPosition(VoiceNode *voice, int32_t position); + void MV_ReleaseVorbisVoice( VoiceNode * voice ); void MV_ReleaseFLACVoice( VoiceNode * voice ); void MV_ReleaseXAVoice( VoiceNode * voice ); diff --git a/polymer/eduke32/source/jaudiolib/src/flac.c b/polymer/eduke32/source/jaudiolib/src/flac.c index d9c036b52..6cbdb91d6 100644 --- a/polymer/eduke32/source/jaudiolib/src/flac.c +++ b/polymer/eduke32/source/jaudiolib/src/flac.c @@ -275,6 +275,23 @@ void error_flac_stream(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderEr // FLAC__stream_decoder_flush(fd->stream); } +int32_t MV_GetFLACPosition(VoiceNode *voice) +{ + FLAC__uint64 position = 0; + flac_data * fd = (flac_data *) voice->extra; + + FLAC__stream_decoder_get_decode_position(fd->stream, &position); + + return position; +} + +void MV_SetFLACPosition(VoiceNode *voice, int32_t position) +{ + flac_data * fd = (flac_data *) voice->extra; + + FLAC__stream_decoder_seek_absolute(fd->stream, position); +} + /*--------------------------------------------------------------------- Function: MV_GetNextFLACBlock diff --git a/polymer/eduke32/source/jaudiolib/src/fx_man.c b/polymer/eduke32/source/jaudiolib/src/fx_man.c index cca820b87..c3037c6e7 100644 --- a/polymer/eduke32/source/jaudiolib/src/fx_man.c +++ b/polymer/eduke32/source/jaudiolib/src/fx_man.c @@ -400,6 +400,33 @@ int32_t FX_PauseVoice return status; } +int32_t FX_GetPosition(int32_t handle, int32_t *position) +{ + int32_t status; + + status = MV_GetPosition(handle, position); + if (status == MV_Error) + { + FX_SetErrorCode(FX_MultiVocError); + status = FX_Warning; + } + + return status; +} + +int32_t FX_SetPosition(int32_t handle, int32_t position) +{ + int32_t status; + + status = MV_SetPosition(handle, position); + if (status == MV_Error) + { + FX_SetErrorCode(FX_MultiVocError); + status = FX_Warning; + } + + return status; +} /*--------------------------------------------------------------------- Function: FX_EndLooping diff --git a/polymer/eduke32/source/jaudiolib/src/multivoc.c b/polymer/eduke32/source/jaudiolib/src/multivoc.c index 105a98edd..7186247b6 100644 --- a/polymer/eduke32/source/jaudiolib/src/multivoc.c +++ b/polymer/eduke32/source/jaudiolib/src/multivoc.c @@ -987,6 +987,7 @@ void MV_SetVoiceMixMode(VoiceNode *voice) } + /*--------------------------------------------------------------------- Function: MV_SetVoiceVolume @@ -1063,6 +1064,77 @@ int32_t MV_PauseVoice return MV_Ok; } +int32_t MV_GetPosition(int32_t handle, int32_t *position) +{ + VoiceNode *voice; + + if (!MV_Installed) + { + MV_SetErrorCode(MV_NotInstalled); + return MV_Error; + } + + DisableInterrupts(); + + voice = MV_GetVoice(handle); + if (voice == NULL) + { + RestoreInterrupts(); + MV_SetErrorCode(MV_VoiceNotFound); + return MV_Warning; + } + +#ifdef HAVE_VORBIS + if (voice->wavetype == Vorbis) + *position = MV_GetVorbisPosition(voice); +#endif +#ifdef HAVE_FLAC + if (voice->wavetype == FLAC) + *position = MV_GetFLACPosition(voice); +#endif + if (voice->wavetype == XA) + *position = MV_GetXAPosition(voice); + + RestoreInterrupts(); + + return MV_Ok; +} + +int32_t MV_SetPosition(int32_t handle, int32_t position) +{ + VoiceNode *voice; + + if (!MV_Installed) + { + MV_SetErrorCode(MV_NotInstalled); + return MV_Error; + } + + DisableInterrupts(); + + voice = MV_GetVoice(handle); + if (voice == NULL) + { + RestoreInterrupts(); + MV_SetErrorCode(MV_VoiceNotFound); + return MV_Warning; + } + +#ifdef HAVE_VORBIS + if (voice->wavetype == Vorbis) + MV_SetVorbisPosition(voice, position); +#endif +#ifdef HAVE_FLAC + if (voice->wavetype == FLAC) + MV_SetFLACPosition(voice, position); +#endif + if (voice->wavetype == XA) + MV_SetXAPosition(voice, position); + + RestoreInterrupts(); + + return MV_Ok; +} /*--------------------------------------------------------------------- Function: MV_EndLooping diff --git a/polymer/eduke32/source/jaudiolib/src/multivoc.h b/polymer/eduke32/source/jaudiolib/src/multivoc.h index e989165c0..200e831a8 100644 --- a/polymer/eduke32/source/jaudiolib/src/multivoc.h +++ b/polymer/eduke32/source/jaudiolib/src/multivoc.h @@ -155,6 +155,10 @@ int32_t MV_PlayXA3D(char *ptr, uint32_t length, int32_t loophow, int32_t pitchof int32_t priority, uint32_t callbackval); int32_t MV_PlayXA(char *ptr, uint32_t length, int32_t loopstart, int32_t loopend, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval); + +int32_t MV_GetPosition(int32_t handle, int32_t *position); +int32_t MV_SetPosition(int32_t handle, int32_t position); + // void MV_CreateVolumeTable( int32_t index, int32_t volume, int32_t MaxVolume ); void MV_SetVolume(int32_t volume); int32_t MV_GetVolume(void); diff --git a/polymer/eduke32/source/jaudiolib/src/vorbis.c b/polymer/eduke32/source/jaudiolib/src/vorbis.c index 02024ab12..da0957bb8 100644 --- a/polymer/eduke32/source/jaudiolib/src/vorbis.c +++ b/polymer/eduke32/source/jaudiolib/src/vorbis.c @@ -201,6 +201,20 @@ static ov_callbacks vorbis_callbacks = { }; +int32_t MV_GetVorbisPosition(VoiceNode *voice) +{ + vorbis_data * vd = (vorbis_data *) voice->extra; + + return ov_pcm_tell(&vd->vf); +} + +void MV_SetVorbisPosition(VoiceNode *voice, int32_t position) +{ + vorbis_data * vd = (vorbis_data *) voice->extra; + + ov_pcm_seek(&vd->vf, position); +} + /*--------------------------------------------------------------------- Function: MV_GetNextVorbisBlock diff --git a/polymer/eduke32/source/jaudiolib/src/xa.c b/polymer/eduke32/source/jaudiolib/src/xa.c index dbb6090d9..08d1c36b9 100644 --- a/polymer/eduke32/source/jaudiolib/src/xa.c +++ b/polymer/eduke32/source/jaudiolib/src/xa.c @@ -286,6 +286,21 @@ static void decodeSoundSectStereo(XASector *ssct, xa_data * xad) xad->blocksize = count; } +int32_t MV_GetXAPosition(VoiceNode *voice) +{ + xa_data * xad = (xa_data *) voice->extra; + return xad->pos; +} + +void MV_SetXAPosition(VoiceNode *voice, int32_t position) +{ + xa_data * xad = (xa_data *) voice->extra; + + if (position < XA_DATA_START || position >= xad->length) + position = XA_DATA_START; + + xad->pos = position; +} /*--------------------------------------------------------------------- Function: MV_GetNextXABlock diff --git a/polymer/eduke32/source/lunatic/con_lang.lua b/polymer/eduke32/source/lunatic/con_lang.lua index 3b8df935a..aa720cc91 100644 --- a/polymer/eduke32/source/lunatic/con_lang.lua +++ b/polymer/eduke32/source/lunatic/con_lang.lua @@ -979,6 +979,7 @@ lpeg.P(false) + "setplayervar" + "setplayerangle" + "setplayer" + +"setmusicposition" + "setinput" + "setgamepalette" + "setgamename" + @@ -1162,6 +1163,7 @@ lpeg.P(false) + "getplayervar" + "getplayerangle" + "getplayer" + +"getmusicposition" + "getlastpal" + "getkeyname" + "getinput" + diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index d712b2885..a2aeca1f7 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -1889,6 +1889,14 @@ function _starttrack(level) end end +function _getmusicposition() + return ffic.S_GetMusicPosition() +end + +function _setmusicposition(position) + ffic.S_SetMusicPosition(position) +end + function _startlevel(volume, level) bcheck.volume_idx(volume) bcheck.level_idx(level) diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 8532fa968..e7df7a299 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -697,6 +697,8 @@ int32_t S_CheckSoundPlaying(int32_t i, int32_t num); void S_StopEnvSound(int32_t num, int32_t i); int32_t FX_StopAllSounds(void); void S_ChangeSoundPitch(int32_t num, int32_t i, int32_t pitchoffset); +int32_t S_GetMusicPosition(void); +void S_SetMusicPosition(int32_t position); int32_t minitext_(int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t sb); void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,int32_t s,int32_t pal, diff --git a/polymer/eduke32/source/lunatic/dynsymlist b/polymer/eduke32/source/lunatic/dynsymlist index 1db1f5c40..eb5e7ed3f 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist +++ b/polymer/eduke32/source/lunatic/dynsymlist @@ -230,6 +230,8 @@ S_CheckSoundPlaying; S_StopEnvSound; FX_StopAllSounds; S_ChangeSoundPitch; +S_GetMusicPosition; +S_SetMusicPosition; minitext_; G_DrawTXDigiNumZ; diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index 8c46c9667..027a9a966 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -2907,6 +2907,11 @@ local Cinner = { starttrackvar = cmd(R) / "_con._starttrack(%1)", + getmusicposition = cmd(W) + / "%1=_con._getmusicposition()", + setmusicposition = cmd(R) + / "_con._setmusicposition(%1)", + setaspect = cmd(R,R) / "_con._setaspect(%1,%2)", showview = cmd(R,R,R,R,R,R,R,R,R,R) -- 10R diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index f73731647..82bb3bd4d 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -311,6 +311,22 @@ int32_t S_PlayMusic(const char *fn, const int32_t sel) return (alt != 0); } +int32_t S_GetMusicPosition(void) +{ + int32_t position = 0; + + if (MusicIsWaveform) + FX_GetPosition(MusicVoice, &position); + + return position; +} + +void S_SetMusicPosition(int32_t position) +{ + if (MusicIsWaveform) + FX_SetPosition(MusicVoice, position); +} + void S_StopMusic(void) { MusicPaused = 0; diff --git a/polymer/eduke32/source/sounds.h b/polymer/eduke32/source/sounds.h index 31a22701a..747dea19e 100644 --- a/polymer/eduke32/source/sounds.h +++ b/polymer/eduke32/source/sounds.h @@ -104,6 +104,8 @@ void S_StopEnvSound(int32_t num,int32_t i); void S_StopMusic(void); void S_Update(void); void S_ChangeSoundPitch(int32_t num, int32_t i, int32_t pitchoffset); +int32_t S_GetMusicPosition(void); +void S_SetMusicPosition(int32_t position); static inline int32_t S_IsAmbientSFX(int32_t i) {