From c614f93073c5e69dc1334fd9004746154c7a06e4 Mon Sep 17 00:00:00 2001 From: vortex Date: Wed, 14 Apr 2010 18:40:16 +0000 Subject: [PATCH] DP_SND_GETSOUNDTIME extension (query sound progress on entities and length of sound files) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10082 d7cf8633-e32d-0410-b094-e92efae38249 --- clvm_cmds.c | 4 +- darkplaces.vcproj | 4360 +++++---------------------------------------- mvm_cmds.c | 4 +- prvm_cmds.c | 44 + prvm_cmds.h | 2 + snd_main.c | 33 + sound.h | 2 + svvm_cmds.c | 5 +- 8 files changed, 561 insertions(+), 3893 deletions(-) diff --git a/clvm_cmds.c b/clvm_cmds.c index 07e6a13f..f328ee11 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -4392,8 +4392,8 @@ VM_loadfromdata, // #529 VM_loadfromfile, // #530 VM_CL_setpause, // #531 float(float ispaused) setpause = #531 (DP_CSQC_SETPAUSE) VM_log, // #532 -NULL, // #533 -NULL, // #534 +VM_getsoundtime, // #533 float(entity e, float channel) getsoundtime = #533; (DP_SND_GETSOUNDTIME) +VM_soundlength, // #534 float(string sample) soundlength = #534; (DP_SND_GETSOUNDTIME) NULL, // #535 NULL, // #536 NULL, // #537 diff --git a/darkplaces.vcproj b/darkplaces.vcproj index 30bce4b3..8b931ba1 100755 --- a/darkplaces.vcproj +++ b/darkplaces.vcproj @@ -1,27 +1,23 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - @@ -3631,35 +241,17 @@ PreprocessorDefinitions="" /> - - - - - - - - - + + + + - - - @@ -3687,35 +270,9 @@ PreprocessorDefinitions="" /> - - - - - - - - - - - - @@ -3743,35 +291,9 @@ PreprocessorDefinitions="" /> - - - - - - - - - - - - @@ -3799,16 +312,12 @@ PreprocessorDefinitions="" /> + + - - - - - - @@ -3855,16 +354,12 @@ PreprocessorDefinitions="" /> + + - - - - - - @@ -3911,16 +396,12 @@ PreprocessorDefinitions="" /> + + - - - - - - @@ -3967,16 +438,12 @@ PreprocessorDefinitions="" /> + + - - - - - - @@ -4023,16 +480,12 @@ PreprocessorDefinitions="" /> + + - - - - - - @@ -4079,16 +522,12 @@ PreprocessorDefinitions="" /> + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -5459,10 +2073,6 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl" > - - @@ -5587,6 +2197,10 @@ RelativePath="input.h" > + + @@ -5671,6 +2285,10 @@ RelativePath="palette.h" > + + @@ -5827,14 +2445,6 @@ PreprocessorDefinitions="" /> - - - @@ -5843,30 +2453,6 @@ PreprocessorDefinitions="" /> - - - - - - - - - 8) + VM_Warning("VM_getsoundtime: %s: bad channel %i\n", PRVM_NAME, entchannel); + PRVM_G_FLOAT(OFS_RETURN) = (float)S_GetEntChallelPosition(entnum, entchannel); +} + +/* +========= +VM_GetSoundLen + +string soundlength (string sample) +========= +*/ +void VM_soundlength (void) +{ + const char *s; + + VM_SAFEPARMCOUNT(1, VM_soundlength); + + s = PRVM_G_STRING(OFS_PARM0); + PRVM_G_FLOAT(OFS_RETURN) = S_SoundLength(s); +} + /* ========= VM_loadfromdata diff --git a/prvm_cmds.h b/prvm_cmds.h index ad7e9638..063c0fa0 100644 --- a/prvm_cmds.h +++ b/prvm_cmds.h @@ -332,6 +332,8 @@ void VM_clientstate(void); void VM_getostype(void); void VM_getmousepos(void); void VM_gettime(void); +void VM_getsoundtime(void); +void VM_soundlength(void); void VM_loadfromdata(void); void VM_parseentitydata(void); void VM_loadfromfile(void); diff --git a/snd_main.c b/snd_main.c index 2d456a4a..309dd34c 100644 --- a/snd_main.c +++ b/snd_main.c @@ -1100,6 +1100,27 @@ sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean serversoun return sfx; } +/* +================== +S_SoundLength +================== +*/ + +float S_SoundLength(const char *name) +{ + sfx_t *sfx; + + if (!snd_initialized.integer) + return -1; + if (name == NULL || name[0] == 0) + return -1; + + sfx = S_FindName(name); + if (sfx == NULL) + return -1; + return sfx->total_length / (float) S_GetSoundRate(); +} + /* ================== S_IsSoundPrecached @@ -1671,7 +1692,19 @@ float S_GetChannelPosition (unsigned int ch_ind) return (s % sfx->total_length) / (float) S_GetSoundRate(); } +float S_GetEntChallelPosition(int entnum, int entchannel) +{ + channel_t *ch; + unsigned int i; + for (i = 0; i < total_channels; i++) + { + ch = &channels[i]; + if (ch->entnum == entnum && ch->entchannel == entchannel) + return S_GetChannelPosition(i); + } + return -1; // no playing sound in this channel +} /* ================= diff --git a/sound.h b/sound.h index 2161ee8a..c8277653 100644 --- a/sound.h +++ b/sound.h @@ -67,6 +67,7 @@ void S_Update(const matrix4x4_t *listenermatrix); void S_ExtraUpdate (void); sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean serversound); +float S_SoundLength(const char *name); void S_ClearUsed (void); void S_PurgeUnused (void); qboolean S_IsSoundPrecached (const sfx_t *sfx); @@ -85,6 +86,7 @@ void S_StopChannel (unsigned int channel_ind, qboolean lockmutex); qboolean S_SetChannelFlag (unsigned int ch_ind, unsigned int flag, qboolean value); void S_SetChannelVolume (unsigned int ch_ind, float fvol); float S_GetChannelPosition (unsigned int ch_ind); +float S_GetEntChallelPosition(int entnum, int entchannel); void S_BlockSound (void); void S_UnblockSound (void); diff --git a/svvm_cmds.c b/svvm_cmds.c index 13d56f5f..160c12ad 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -133,6 +133,7 @@ char *vm_sv_extensions = "DP_SND_OGGVORBIS " "DP_SND_SETPARAMS " "DP_SND_STEREOWAV " +"DP_SND_GETSOUNDTIME " "DP_SOLIDCORPSE " "DP_SPRITE32 " "DP_SV_BOTCLIENT " @@ -3659,8 +3660,8 @@ VM_loadfromdata, // #529 VM_loadfromfile, // #530 VM_SV_setpause, // #531 void(float pause) setpause = #531; VM_log, // #532 -NULL, // #533 -NULL, // #534 +VM_getsoundtime, // #533 float(entity e, float channel) getsoundtime = #533; (DP_SND_GETSOUNDTIME) +VM_soundlength, // #534 float(string sample) soundlength = #534; (DP_SND_GETSOUNDTIME) NULL, // #535 NULL, // #536 NULL, // #537 -- 2.39.2