22 Apr 2010

This commit is contained in:
g-cont 2010-04-22 00:00:00 +04:00 committed by Alibek Omarov
parent 9a4ea1451b
commit e95dfb116b
29 changed files with 1447 additions and 792 deletions

View File

@ -1,16 +0,0 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: baserc - Win32 Release--------------------
</h3>
<h3>Command Lines</h3>
<h3>Results</h3>
baserc.dll - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

View File

@ -1,16 +0,0 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: bshift - Win32 Release--------------------
</h3>
<h3>Command Lines</h3>
<h3>Results</h3>
server.dll - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

View File

@ -1,16 +0,0 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: client - Win32 Release--------------------
</h3>
<h3>Command Lines</h3>
<h3>Results</h3>
client.dll - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

View File

@ -357,6 +357,61 @@ void CL_AddEntities( void )
//
// sound engine implementation
//
bool CL_GetEntitySpatialization( int entnum, soundinfo_t *info )
{
edict_t *pSound;
// world is always audible
if( entnum == 0 )
return true;
if( entnum < 0 || entnum >= GI->max_edicts )
{
MsgDev( D_ERROR, "CL_GetEntitySoundSpatialization: invalid entnum %d\n", entnum );
return false;
}
// while explosion entity can be died before sound played completely
if( entnum >= clgame.globals->numEntities )
return false;
pSound = CL_GetEdictByIndex( entnum );
// out of PVS, removed etc
if( !pSound ) return false;
if( !pSound->v.modelindex )
return true;
if( info->pflRadius )
{
vec3_t mins, maxs;
Mod_GetBounds( pSound->v.modelindex, mins, maxs );
*info->pflRadius = RadiusFromBounds( mins, maxs );
}
if( info->pOrigin )
{
VectorCopy( pSound->v.origin, info->pOrigin );
if( CM_GetModelType( pSound->v.modelindex ) == mod_brush )
{
vec3_t mins, maxs, center;
Mod_GetBounds( pSound->v.modelindex, mins, maxs );
VectorAverage( mins, maxs, center );
VectorAdd( info->pOrigin, center, info->pOrigin );
}
}
if( info->pAngles )
{
VectorCopy( pSound->v.angles, info->pAngles );
}
return true;
}
void CL_GetEntitySoundSpatialization( int entnum, vec3_t origin, vec3_t velocity )
{
edict_t *ent;
@ -387,42 +442,4 @@ void CL_GetEntitySoundSpatialization( int entnum, vec3_t origin, vec3_t velocity
VectorAverage( mins, maxs, midPoint );
VectorAdd( origin, midPoint, origin );
}
}
/*
=================
S_AddLoopingSounds
Entities with a sound field will generate looping sounds that are
automatically started and stopped as the entities are sent to the
client
=================
*/
void CL_AddLoopingSounds( void )
{
edict_t *ent;
int sound, e;
if( cls.state != ca_active ) return;
if( cl.refdef.paused || cls.key_dest == key_menu ) return;
if(!cl.audio_prepped ) return;
for( e = 1; e < clgame.globals->numEntities; e++ )
{
ent = EDICT_NUM( e );
if( ent->free ) continue;
switch( ent->pvClientData->current.ed_type )
{
case ED_MOVER:
case ED_AMBIENT:
case ED_NORMAL: break;
default: continue;
}
sound = ent->pvClientData->current.soundindex;
if( !sound ) continue;
S_AddLoopingSound( ent->serialnumber, cl.sound_precache[sound], 1.0f, ATTN_IDLE );
}
}

View File

@ -38,6 +38,20 @@ edict_t *CL_GetEdictByIndex( int index )
return EDICT_NUM( index );
}
/*
====================
CL_GetEntityMouth
get pointer to mouth state
====================
*/
mouth_t *CL_GetEntityMouth( edict_t *ent )
{
if( !CL_IsValidEdict( ent ))
return NULL;
return &ent->pvClientData->mouth;
}
/*
=============
CL_AllocString
@ -145,7 +159,7 @@ byte CL_GetMouthOpen( int entityIndex )
if( !ed || ed->free || !ed->pvClientData )
return 0;
return ed->pvClientData->mouth.open;
return ed->pvClientData->mouth.mouthopen;
}
lerpframe_t *CL_GetLerpFrame( int entityIndex )
@ -1984,8 +1998,8 @@ pfnStopAllSounds
*/
void pfnStopAllSounds( edict_t *ent, int entchannel )
{
// FIXME: this code is wrong
S_StopAllSounds ();
if( !CL_IsValidEdict( ent )) return;
S_StopSound( ent->serialnumber, entchannel );
}
/*

View File

@ -339,12 +339,14 @@ void CL_ParseSoundPacket( sizebuf_t *msg )
if( flags & SND_VOLUME )
volume = MSG_ReadByte( msg ) / 255.0f;
else volume = VOL_NORM;
if( flags & SND_SOUNDLEVEL )
{
int soundlevel = MSG_ReadByte( msg );
attenuation = SNDLVL_TO_ATTN( soundlevel );
}
else attenuation = ATTN_NONE;
if( flags & SND_PITCH )
pitch = MSG_ReadByte( msg );
else pitch = PITCH_NORM;
@ -358,6 +360,7 @@ void CL_ParseSoundPacket( sizebuf_t *msg )
pos = pos_;
MSG_ReadPos( msg, pos );
}
S_StartSound( pos, entnum, channel, cl.sound_precache[sound_num], volume, attenuation, pitch, flags );
}

View File

@ -624,6 +624,18 @@ int CL_PointContents( const vec3_t p )
return World_ConvertContents( CL_BaseContents( p, NULL ));
}
/*
============
CL_TraceLine
soundlib light version
============
*/
trace_t CL_TraceLine( const vec3_t start, const vec3_t end )
{
return CL_Move( start, vec3_origin, vec3_origin, end, MOVE_NOMONSTERS, NULL );
}
/*
============
CL_TestPlayerPosition

View File

@ -166,13 +166,6 @@ typedef enum
scrshot_skyshot // skybox view
} e_scrshot;
typedef struct
{
byte open; // 0 = mouth closed, 255 = mouth agape
byte sndcount; // counter for running average
int sndavg; // running average
} mouth_t;
// cl_private_edict_t
struct cl_priv_s
{
@ -473,6 +466,7 @@ bool CL_IsValidEdict( const edict_t *e );
const char *CL_ClassName( const edict_t *e );
void CL_SetEventIndex( const char *szEvName, int ev_index );
void CL_TextMessageParse( byte *pMemFile, int fileSize );
mouth_t *CL_GetEntityMouth( edict_t *ent );
// TriAPI implementation
void TriRenderMode( kRenderMode_t mode );
@ -560,7 +554,6 @@ void CL_UpdateBaseVelocity( edict_t *ent );
// cl_frame.c
//
void CL_GetEntitySoundSpatialization( int ent, vec3_t origin, vec3_t velocity );
void CL_AddLoopingSounds( void );
//
// cl_effects.c

View File

@ -173,6 +173,7 @@ void pfnGetGameDir( char *szGetGameDir );
const char *pfnCmd_Args( void );
const char *pfnCmd_Argv( int argc );
int pfnCmd_Argc( void );
int pfnIsInGame( void );
float pfnTime( void );
/*
@ -219,13 +220,16 @@ void CL_CharEvent( int key );
void Tri_DrawTriangles( int fTrans );
int CL_PointContents( const vec3_t point );
void CL_StudioFxTransform( edict_t *ent, float transform[4][4] );
bool CL_GetEntitySpatialization( int entnum, soundinfo_t *info );
void CL_GetEntitySoundSpatialization( int ent, vec3_t origin, vec3_t velocity );
bool CL_GetAttachment( int entityIndex, int number, vec3_t origin, vec3_t angles );
bool CL_SetAttachment( int entityIndex, int number, vec3_t origin, vec3_t angles );
void CL_StudioEvent( dstudioevent_t *event, edict_t *ent );
bool CL_GetComment( const char *demoname, char *comment );
trace_t CL_TraceLine( const vec3_t start, const vec3_t end );
lerpframe_t *CL_GetLerpFrame( int entityIndex );
edict_t *CL_GetEdictByIndex( int index );
mouth_t *CL_GetEntityMouth( edict_t *ent );
edict_t *CL_GetLocalPlayer( void );
int CL_GetMaxClients( void );
byte CL_GetMouthOpen( int entityIndex );

View File

@ -206,6 +206,7 @@ _inline bool CM_BoxVisible( const vec3_t mins, const vec3_t maxs )
#define S_RawSamples if( se ) se->StreamRawSamples
#define S_FadeClientVolume if( se ) se->FadeClientVolume
#define S_StopAllSounds if( se ) se->StopAllSounds
#define S_StopSound if( se ) se->StopSound
#define S_AddLoopingSound if( se ) se->AddLoopingSound
#define S_Activate if( se ) se->Activate
#define S_Update if( se ) se->RenderFrame

View File

@ -1,16 +0,0 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: engine - Win32 Release--------------------
</h3>
<h3>Command Lines</h3>
<h3>Results</h3>
engine.dll - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

View File

@ -220,13 +220,18 @@ bool Host_InitSound( void )
if( host_nosound->integer )
return result;
// phys callback
si.api_size = sizeof( vsound_imp_t );
// sound callbacks
si.GetEntitySpatialization = CL_GetEntitySpatialization;
si.GetSoundSpatialization = CL_GetEntitySoundSpatialization;
si.TraceLine = CL_TraceLine;
si.PointContents = CL_PointContents;
si.GetClientEdict = CL_GetEdictByIndex;
si.AddLoopingSounds = CL_AddLoopingSounds;
si.GetEntityMouth = CL_GetEntityMouth;
si.GetServerTime = CL_GetServerTime;
si.IsInGame = pfnIsInGame;
si.IsActive = CL_Active;
Sys_LoadLibrary( host_audio->string, &vsound_dll );

View File

@ -1,61 +0,0 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: launch - Win32 Release--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\DOCUME~1\ÌÈØÀ\LOCALS~1\Temp\RSP59B0.tmp" with contents
[
/nologo /MD /W3 /GX /O2 /I "./" /I "imagelib" /I "../public" /I "../common" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fo"..\temp\launch\!release/" /Fd"..\temp\launch\!release/" /FD /c
"D:\Xash3D\src_main\launch\soundlib\snd_utils.c"
]
Creating command line "cl.exe @"C:\DOCUME~1\ÌÈØÀ\LOCALS~1\Temp\RSP59B0.tmp""
Creating temporary file "C:\DOCUME~1\ÌÈØÀ\LOCALS~1\Temp\RSP59B1.tmp" with contents
[
zlib.lib png.lib jpg.lib ogg.lib vorbis.lib user32.lib gdi32.lib shell32.lib advapi32.lib winmm.lib /nologo /dll /pdb:none /machine:I386 /nodefaultlib:"libc" /nodefaultlib:"libcmt" /out:"..\temp\launch\!release/launch.dll" /implib:"..\temp\launch\!release/launch.lib" /libpath:"./imagelib" /libpath:"./soundlib" /opt:nowin98
"\Xash3D\src_main\temp\launch\!release\cmd.obj"
"\Xash3D\src_main\temp\launch\!release\console.obj"
"\Xash3D\src_main\temp\launch\!release\cpuinfo.obj"
"\Xash3D\src_main\temp\launch\!release\crclib.obj"
"\Xash3D\src_main\temp\launch\!release\cvar.obj"
"\Xash3D\src_main\temp\launch\!release\export.obj"
"\Xash3D\src_main\temp\launch\!release\filesystem.obj"
"\Xash3D\src_main\temp\launch\!release\img_bmp.obj"
"\Xash3D\src_main\temp\launch\!release\img_dds.obj"
"\Xash3D\src_main\temp\launch\!release\img_jpg.obj"
"\Xash3D\src_main\temp\launch\!release\img_main.obj"
"\Xash3D\src_main\temp\launch\!release\img_pcx.obj"
"\Xash3D\src_main\temp\launch\!release\img_png.obj"
"\Xash3D\src_main\temp\launch\!release\img_tga.obj"
"\Xash3D\src_main\temp\launch\!release\img_utils.obj"
"\Xash3D\src_main\temp\launch\!release\img_vtf.obj"
"\Xash3D\src_main\temp\launch\!release\img_wad.obj"
"\Xash3D\src_main\temp\launch\!release\library.obj"
"\Xash3D\src_main\temp\launch\!release\memlib.obj"
"\Xash3D\src_main\temp\launch\!release\network.obj"
"\Xash3D\src_main\temp\launch\!release\parselib.obj"
"\Xash3D\src_main\temp\launch\!release\patch.obj"
"\Xash3D\src_main\temp\launch\!release\snd_main.obj"
"\Xash3D\src_main\temp\launch\!release\snd_ogg.obj"
"\Xash3D\src_main\temp\launch\!release\snd_raw.obj"
"\Xash3D\src_main\temp\launch\!release\snd_utils.obj"
"\Xash3D\src_main\temp\launch\!release\snd_wav.obj"
"\Xash3D\src_main\temp\launch\!release\stdlib.obj"
"\Xash3D\src_main\temp\launch\!release\system.obj"
"\Xash3D\src_main\temp\launch\!release\utils.obj"
]
Creating command line "link.exe @"C:\DOCUME~1\ÌÈØÀ\LOCALS~1\Temp\RSP59B1.tmp""
Creating temporary file "C:\DOCUME~1\ÌÈØÀ\LOCALS~1\Temp\RSP59B2.bat" with contents
[
@echo off
copy \Xash3D\src_main\temp\launch\!release\launch.dll "D:\Xash3D\bin\launch.dll"
]
Creating command line ""C:\DOCUME~1\ÌÈØÀ\LOCALS~1\Temp\RSP59B2.bat""
Compiling...
cl.exe terminated at user request.
</pre>
</body>
</html>

View File

@ -135,6 +135,25 @@ _inline float rsqrt( float number )
return y;
}
// remap a value in the range [A,B] to [C,D].
_inline float RemapVal( float val, float A, float B, float C, float D )
{
return C + (D - C) * (val - A) / (B - A);
}
_inline float ApproachVal( float target, float value, float speed )
{
float delta = target - value;
if( delta > speed )
value += speed;
else if( delta < -speed )
value -= speed;
else value = target;
return value;
}
_inline static bool VectorCompareEpsilon( const vec3_t v1, const vec3_t v2, const float epsilon )
{
vec3_t d;
@ -216,7 +235,7 @@ _inline void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs )
}
}
_inline void VectorVectors(vec3_t forward, vec3_t right, vec3_t up)
_inline void VectorVectors( vec3_t forward, vec3_t right, vec3_t up )
{
float d;
@ -230,6 +249,32 @@ _inline void VectorVectors(vec3_t forward, vec3_t right, vec3_t up)
CrossProduct(right, forward, up);
}
_inline void VectorAngles( const vec3_t forward, vec3_t angles )
{
float tmp, yaw, pitch;
if( forward[1] == 0 && forward[0] == 0 )
{
yaw = 0.0f;
if( forward[2] > 0 )
pitch = 270.0f;
else pitch = 90.0f;
}
else
{
yaw = ( atan2( forward[1], forward[0] ) * 180 / M_PI );
if( yaw < 0 ) yaw += 360;
tmp = com.sqrt( forward[0] * forward[0] + forward[1] * forward[1] );
pitch = ( atan2( -forward[2], tmp ) * 180 / M_PI );
if( pitch < 0 ) pitch += 360;
}
angles[0] = pitch;
angles[1] = yaw;
angles[2] = 0;
}
// similar to MakeNormalVectors but for rotational matrices
// (FIXME: weird, what's the diff between this and VectorVectors?)
_inline void NormalVectorToAxis( const vec3_t forward, vec3_t axis[3] )

View File

@ -13,6 +13,21 @@ typedef int sound_t;
#define CHAN_NO_PHS_ADD (1<<3) // send to all clients, not just ones in PHS (ATTN 0 will also do this)
#define CHAN_RELIABLE (1<<4) // send by reliable message, not datagram
typedef struct
{
byte mouthopen; // 0 = mouth closed, 255 = mouth agape
byte sndcount; // counter for running average
int sndavg; // running average
} mouth_t;
typedef struct
{
// requested outputs ( NULL == not requested )
float *pOrigin; // vec3_t
float *pAngles; // vec3_t
float *pflRadius; // vec_t
} soundinfo_t;
/*
==============================================================================
@ -33,10 +48,9 @@ typedef struct vsound_exp_s
sound_t (*RegisterSound)( const char *name );
void (*EndRegistration)( void );
void (*StartSound)( const vec3_t pos, int ent, int chan, sound_t sfx, float vol, float attn, float pitch, int flags );
void (*StartSound)( const vec3_t pos, int ent, int chan, sound_t sfx, float vol, float attn, int pitch, int flags );
void (*StreamRawSamples)( int samples, int rate, int width, int channels, const byte *data );
bool (*AddLoopingSound)( int entnum, sound_t handle, float volume, float attn );
bool (*StartLocalSound)( const char *name, float volume, float pitch, const float *origin );
bool (*StartLocalSound)( const char *name, float volume, int pitch, const float *origin );
void (*FadeClientVolume)( float fadePercent, float fadeOutSeconds, float holdTime, float fadeInSeconds );
void (*StartBackgroundTrack)( const char *introTrack, const char *loopTrack );
void (*StopBackgroundTrack)( void );
@ -45,6 +59,7 @@ typedef struct vsound_exp_s
void (*StopStreaming)( void );
void (*RenderFrame)( ref_params_t *fd );
void (*StopSound)( int entnum, int channel );
void (*StopAllSounds)( void );
void (*FreeSounds)( void );
@ -57,11 +72,15 @@ typedef struct vsound_imp_s
// interface validator
size_t api_size; // must matched with sizeof(vsound_imp_t)
trace_t (*TraceLine)( const vec3_t start, const vec3_t end );
bool (*GetEntitySpatialization)( int entnum, soundinfo_t *info );
void (*GetSoundSpatialization)( int entnum, vec3_t origin, vec3_t velocity );
int (*PointContents)( const vec3_t point );
edict_t *(*GetClientEdict)( int index );
void (*AddLoopingSounds)( void );
mouth_t *(*GetEntityMouth)( edict_t *ent );
int (*GetServerTime)( void );
bool (*IsInGame)( void ); // returns false for menu, console, etc
bool (*IsActive)( void ); // returns true when client is completely in-game
} vsound_imp_t;
#endif//VSOUND_API_H

View File

@ -35,7 +35,6 @@ vsound_exp_t DLLEXPORT *CreateAPI( stdlib_api_t *input, vsound_imp_t *engfuncs )
snd.FadeClientVolume = S_FadeClientVolume;
snd.StartSound = S_StartSound;
snd.StreamRawSamples = S_StreamRawSamples;
snd.AddLoopingSound = S_AddLoopingSound;
snd.StartLocalSound = S_StartLocalSound;
snd.StartBackgroundTrack = S_StartBackgroundTrack;
snd.StopBackgroundTrack = S_StopBackgroundTrack;
@ -44,6 +43,7 @@ vsound_exp_t DLLEXPORT *CreateAPI( stdlib_api_t *input, vsound_imp_t *engfuncs )
snd.StopStreaming = S_StopStreaming;
snd.RenderFrame = S_Update;
snd.StopSound = S_StopSound;
snd.StopAllSounds = S_StopAllSounds;
snd.FreeSounds = S_FreeSounds;

View File

@ -128,7 +128,7 @@ float S_GetMasterVolume( void )
{
float scale = 1.0f;
if( soundfade.percent != 0 )
if( si.IsInGame() && soundfade.percent != 0 )
{
scale = bound( 0.0f, soundfade.percent / 100.0f, 1.0f );
scale = 1.0f - scale;
@ -397,66 +397,6 @@ channel_t *S_PickChannel( int entnum, int channel )
return ch;
}
/*
=================
S_AddLoopingSounds
Entities with a sound field will generate looping sounds that are
automatically started and stopped as the entities are sent to the
client
=================
*/
bool S_AddLoopingSound( int entnum, sound_t handle, float volume, float attn )
{
channel_t *ch;
sfx_t *sfx = NULL;
int i;
if(!al_state.initialized )
return false;
sfx = S_GetSfxByHandle( handle );
// default looped sound it's terrible :)
if( !sfx || !sfx->loaded || sfx->default_sound )
return false;
// if this entity is already playing the same sound effect on an
// active channel, then simply update it
for( i = 0, ch = s_channels; i < al_state.num_channels; i++, ch++ )
{
if( ch->sfx != sfx ) continue;
if( !ch->loopsound ) continue;
if( ch->loopnum != entnum ) continue;
if( ch->loopframe + 1 != al_state.framecount )
continue;
ch->loopframe = al_state.framecount;
break;
}
if( i != al_state.num_channels )
return false;
// otherwise pick a channel and start the sound effect
ch = S_PickChannel( 0, 0 );
if( !ch )
{
MsgDev( D_ERROR, "dropped sound \"sound/%s\"\n", sfx->name );
return false;
}
ch->loopsound = true;
ch->loopnum = entnum;
ch->loopframe = al_state.framecount;
ch->fixedPosition = false;
ch->volume = 1.0f;
ch->pitch = 1.0f;
ch->distanceMult = 1.0f / ATTN_NORM;
S_SpatializeChannel( ch );
S_PlayChannel( ch, sfx );
return true;
}
/*
=================
S_AllocPlaySound
@ -561,7 +501,7 @@ if origin is NULL, the sound will be dynamically sourced from the entity.
entchannel 0 will never override a playing sound.
=================
*/
void S_StartSound( const vec3_t pos, int entnum, int channel, sound_t handle, float vol, float attn, float pitch, int flags )
void S_StartSound( const vec3_t pos, int entnum, int channel, sound_t handle, float vol, float attn, int pitch, int flags )
{
playSound_t *ps, *sort;
sfx_t *sfx = NULL;
@ -617,7 +557,7 @@ S_StartLocalSound
menu sound
=================
*/
bool S_StartLocalSound( const char *name, float volume, float pitch, const float *origin )
bool S_StartLocalSound( const char *name, float volume, int pitch, const float *origin )
{
sound_t sfxHandle;
@ -629,6 +569,18 @@ bool S_StartLocalSound( const char *name, float volume, float pitch, const float
return true;
}
/*
==================
S_StopAllSounds
stop all sounds for entity on a channel.
==================
*/
void S_StopSound( int entnum, int channel )
{
S_StopAllSounds(); // FIXME: this is incorrect!
}
/*
=================
S_StopAllSounds
@ -750,9 +702,6 @@ void S_Update( ref_params_t *fd )
// Stream background track
S_StreamBackgroundTrack();
// Add looping sounds
si.AddLoopingSounds();
// Issue playSounds
S_IssuePlaySounds();

View File

@ -9,6 +9,7 @@
#include <windows.h>
#include "launch_api.h"
#include "qfiles_ref.h"
#include "engine_api.h" // trace_t declaration
#include "vsound_api.h"
#include "s_openal.h"
@ -185,14 +186,14 @@ void S_Activate( bool active );
void S_SoundList_f( void );
bool S_CheckForErrors( void );
void S_Update( ref_params_t *fd );
void S_StartSound( const vec3_t pos, int ent, int chan, sound_t sfx, float vol, float attn, float pitch, int flags );
void S_StartSound( const vec3_t pos, int ent, int chan, sound_t sfx, float vol, float attn, int pitch, int flags );
void S_StreamRawSamples( int samples, int rate, int width, int channels, const byte *data );
bool S_AddLoopingSound( int entnum, sound_t handle, float volume, float attn );
void S_StartBackgroundTrack( const char *intro, const char *loop );
channel_t *S_PickChannel( int entNum, int entChannel );
void S_FadeClientVolume( float fadePercent, float fadeOutSeconds, float holdTime, float fadeInSeconds );
int S_StartLocalSound( const char *name, float volume, float pitch, const float *org );
int S_StartLocalSound( const char *name, float volume, int pitch, const float *org );
sfx_t *S_GetSfxByHandle( sound_t handle );
void S_StopSound( int entnum, int channel );
void S_StreamBackgroundTrack( void );
void S_StopBackgroundTrack( void );
void S_ClearSoundBuffer( void );

View File

@ -610,6 +610,42 @@ int SNDDMA_GetDMAPos( void )
return s;
}
/*
==============
SNDDMA_GetSoundtime
update global soundtime
===============
*/
int SNDDMA_GetSoundtime( void )
{
static int buffers, oldsamplepos;
int samplepos, fullsamples;
fullsamples = dma.samples / dma.channels;
// it is possible to miscount buffers
// if it has wrapped twice between
// calls to S_Update. Oh well.
samplepos = SNDDMA_GetDMAPos();
if( samplepos < oldsamplepos )
{
buffers++; // buffer wrapped
if( paintedtime > 0x40000000 )
{
// time to chop things off to avoid 32 bit limits
buffers = 0;
paintedtime = fullsamples;
S_StopAllSounds();
}
}
oldsamplepos = samplepos;
return (buffers * fullsamples + samplepos / dma.channels);
}
/*
==============
SNDDMA_BeginPainting
@ -723,6 +759,16 @@ void SNDDMA_Shutdown( void )
SNDDMA_FreeSound();
}
/*
===========
S_PrintDeviceName
===========
*/
void S_PrintDeviceName( void )
{
if( snd_isdirect ) Msg( "Audio: DirectSound\n" );
if( snd_iswave ) Msg( "Audio: WaveOutput\n" );
}
/*
===========

View File

@ -1036,7 +1036,6 @@ void SXRVB_DoAMod( int count )
fmod = (sxmod_mod->integer > 0);
// process each sample in the paintbuffer...
while( countr-- )
{
if( dma.channels == 2 )
@ -1235,21 +1234,19 @@ void SX_RoomFX( int endtime, int fFilter, int fTimefx )
int roomType;
// return right away if fx processing is turned off
if( sxroom_off->value != 0.0 )
if( sxroom_off->value != 0.0f )
return;
sampleCount = endtime - paintedtime;
if( sampleCount < 0 )
return;
if( sampleCount < 0 ) return;
fReset = false;
if( listener_waterlevel > 2 )
if( s_listener.waterlevel > 2 )
roomType = sxroomwater_type->integer;
else roomType = sxroom_type->integer;
// only process legacy roomtypes here
if( roomType >= CSXROOM )
return;
if( roomType >= CSXROOM ) return;
if( roomType != sxroom_typeprev )
{

View File

@ -34,7 +34,6 @@ vsound_exp_t DLLEXPORT *CreateAPI( stdlib_api_t *input, vsound_imp_t *engfuncs )
snd.FadeClientVolume = S_FadeClientVolume;
snd.StartSound = S_StartSound;
snd.StreamRawSamples = S_StreamRawSamples;
snd.AddLoopingSound = S_AddLoopingSound;
snd.StartLocalSound = S_StartLocalSound;
snd.StartBackgroundTrack = S_StartBackgroundTrack;
snd.StopBackgroundTrack = S_StopBackgroundTrack;
@ -42,7 +41,8 @@ vsound_exp_t DLLEXPORT *CreateAPI( stdlib_api_t *input, vsound_imp_t *engfuncs )
snd.StartStreaming = S_StartStreaming;
snd.StopStreaming = S_StopStreaming;
snd.RenderFrame = S_Update;
snd.RenderFrame = S_RenderFrame;
snd.StopSound = S_StopSound;
snd.StopAllSounds = S_StopAllSounds;
snd.FreeSounds = S_FreeSounds;

View File

@ -124,6 +124,17 @@ bool S_TestSoundChar( const char *pch, char c )
return false;
}
// return pointer to first valid character in file name
char *S_SkipSoundChar( const char *pch )
{
char *pcht = (char *)pch;
// check first character
if( *pcht == '!' )
pcht++;
return pcht;
}
/*
=================
S_UploadSound
@ -357,9 +368,6 @@ sound_t S_RegisterSound( const char *name )
{
sfx_t *sfx;
if( !sound_started )
return -1;
sfx = S_FindSound( name );
if( !sfx ) return -1;

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +1,7 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// snd_mix.c -- portable code to mix sounds for snd_dma.c
//=======================================================================
// Copyright XashXT Group 2009 ©
// s_mix.c - portable code to mix sounds
//=======================================================================
#include "sound.h"
@ -90,20 +74,6 @@ void S_TransferPaintBuffer( int endtime )
pbuf = (dword *)dma.buffer;
if( s_testsound->integer )
{
int i, count;
// write a fixed sine wave
count = (endtime - paintedtime);
for( i = 0; i < count; i++ )
{
paintbuffer[i].left = com.sin(( paintedtime + i ) * 0.1f ) * 20000 * 256;
paintbuffer[i].right = paintbuffer[i].left;
}
}
if( dma.samplebits == 16 && dma.channels == 2 )
{
// optimized case
@ -211,23 +181,23 @@ void S_MixAllChannels( int endtime, int end )
// paint in the channels.
for( i = 0, ch = channels; i < total_channels; i++, ch++ )
{
if( !ch->sfx ) continue;
if( !ch->leftvol && !ch->rightvol )
continue;
sc = S_LoadSound( ch->sfx );
if( !sc ) continue;
ltime = paintedtime;
while( ltime < end )
{
if( !ch->sfx || ( !ch->leftvol && !ch->rightvol ))
break;
// paint up to end
if( ch->end < end )
count = ch->end - ltime;
else count = end - ltime;
// max painting is to the end of the buffer
count = end - ltime;
// might be stopped by running out of data
if( ch->end - ltime < count ) count = ch->end - ltime;
sc = S_LoadSound( ch->sfx );
if( !sc ) break;
if( count > 0 && ch->sfx )
if( count > 0 )
{
if( sc->width == 1 )
S_PaintChannelFrom8( ch, sc, count );
@ -241,7 +211,7 @@ void S_MixAllChannels( int endtime, int end )
{
if( ch->autosound && ch->use_loop )
{
// autolooping sounds always go back to start
// autolooped sounds always go back to start
ch->pos = 0;
ch->end = ltime + sc->samples;
}
@ -250,7 +220,12 @@ void S_MixAllChannels( int endtime, int end )
ch->pos = sc->loopStart;
ch->end = ltime + sc->samples - ch->pos;
}
else ch->sfx = NULL; // channel just stopped
else
{
// channel just stopped
ch->sfx = NULL;
break;
}
}
}
}
@ -258,8 +233,7 @@ void S_MixAllChannels( int endtime, int end )
void S_PaintChannels( int endtime )
{
playsound_t *ps;
int i, end;
int end;
snd_vol = S_GetMasterVolume () * 256;
@ -270,22 +244,6 @@ void S_PaintChannels( int endtime )
if( endtime - paintedtime > PAINTBUFFER_SIZE )
end = paintedtime + PAINTBUFFER_SIZE;
// start any playsounds
while( 1 )
{
ps = s_pendingplays.next;
if( ps == &s_pendingplays )
break; // no more pending sounds
if( ps->begin <= paintedtime )
{
S_IssuePlaysound( ps );
continue;
}
if( ps->begin < end ) end = ps->begin; // stop here
break;
}
// clear the paint buffer
if( s_rawend < paintedtime )
{
@ -293,7 +251,7 @@ void S_PaintChannels( int endtime )
}
else
{
int stop;
int i, stop;
// copy from the streaming sound source
stop = (end < s_rawend) ? end : s_rawend;

46
snd_dx/s_mouth.c Normal file
View File

@ -0,0 +1,46 @@
//=======================================================================
// Copyright XashXT Group 2010 ©
// s_mouth.c - animate mouth
//=======================================================================
#include "sound.h"
#include "const.h"
void SND_InitMouth( int entnum, int entchannel )
{
if(( entchannel == CHAN_VOICE || entchannel == CHAN_STREAM ) && entnum > 0 )
{
edict_t *clientEntity;
// init mouth movement vars
clientEntity = si.GetClientEdict( entnum );
if( clientEntity )
{
mouth_t *m = si.GetEntityMouth( clientEntity );
if( m )
{
m->mouthopen = 0;
m->sndavg = 0;
m->sndcount = 0;
}
}
}
}
void SND_CloseMouth( channel_t *ch )
{
edict_t *clientEntity = si.GetClientEdict( ch->entnum );
if( clientEntity )
{
mouth_t *m = si.GetEntityMouth( clientEntity );
if( m && ( ch->entchannel == CHAN_VOICE || ch->entchannel == CHAN_STREAM ))
{
// shut mouth
m->mouthopen = 0;
}
}
}

View File

@ -17,7 +17,6 @@ S_StartBackgroundTrack
*/
void S_StartBackgroundTrack( const char *introTrack, const char *loopTrack )
{
if( !sound_started ) return;
S_StopBackgroundTrack();
// start it up
@ -31,8 +30,6 @@ void S_StartBackgroundTrack( const char *introTrack, const char *loopTrack )
void S_StopBackgroundTrack( void )
{
if( !sound_started ) return;
S_StopStreaming();
// UNDONE: close background track
@ -60,10 +57,8 @@ void S_StreamRawSamples( int samples, int rate, int width, int channels, const b
int i, src, dst;
float scale;
if( !sound_started )
return;
if( s_rawend < paintedtime ) s_rawend = paintedtime;
if( s_rawend < paintedtime )
s_rawend = paintedtime;
scale = (float)rate / dma.speed;
if( channels == 2 && width == 2 )

22
snd_dx/s_vox.c Normal file
View File

@ -0,0 +1,22 @@
//=======================================================================
// Copyright XashXT Group 2010 ©
// s_vox.c - npc sentences
//=======================================================================
#include "sound.h"
#include "const.h"
void VOX_SetChanVol( channel_t *ch )
{
float scale = 1.0f; // FIXME: get volume from words
if( scale == 1.0f ) return;
ch->rightvol = (int)( ch->rightvol * scale );
ch->leftvol = (int)( ch->leftvol * scale );
}
// link all sounds in sentence, start playing first word.
void VOX_LoadSound( channel_t *pchan, const char *pszin )
{
}

View File

@ -138,8 +138,16 @@ SOURCE=.\s_mix.c
# End Source File
# Begin Source File
SOURCE=.\s_mouth.c
# End Source File
# Begin Source File
SOURCE=.\s_stream.c
# End Source File
# Begin Source File
SOURCE=.\s_vox.c
# End Source File
# End Group
# Begin Group "Header Files"

View File

@ -9,6 +9,7 @@
#include <windows.h>
#include "launch_api.h"
#include "qfiles_ref.h"
#include "engine_api.h" // trace_t declaration
#include "vsound_api.h"
extern stdlib_api_t com;
@ -34,23 +35,6 @@ typedef struct sfx_s
struct sfx_s *hashNext;
} sfx_t;
// a playsound_t will be generated by each call to S_StartSound,
// when the mixer reaches playsound->begin, the playsound will
// be assigned to a channel
typedef struct playsound_s
{
struct playsound_s *prev, *next;
sfx_t *sfx;
float volume;
float attenuation;
int entnum;
int entchannel;
bool fixed_origin; // use origin field instead of entnum's origin
bool use_loop;
vec3_t origin;
uint begin; // begin on this sample
} playsound_t;
// structure used for fading in and out client sound volume.
typedef struct
{
@ -76,27 +60,58 @@ typedef struct
typedef struct
{
sfx_t *sfx; // sfx number
int leftvol; // 0-255 volume
int rightvol; // 0-255 volume
int end; // end time in global paintsamples
int pos; // sample position in sfx
int leftvol; // 0-255 left volume
int rightvol; // 0-255 right volume
int dleftvol; // 0-255 left volume - doppler outgoing wav
int drightvol; // 0-255 right volume - doppler outgoing wav
int entnum; // entity soundsource
int entchannel; // sound channel (CHAN_STREAM, CHAN_VOICE, etc.)
vec3_t origin; // only use if fixed_origin is set
vec3_t direction; // initially null, then used entity direction
bool staticsound; // use origin instead of fetching entnum's origin
float dist_mult; // distance multiplier (attenuation/clipK)
int master_vol; // 0-255 master volume
bool isSentence; // bit who indicated sentence
int basePitch; // base pitch percent (100% is normal pitch playback)
float pitch; // real-time pitch after any modulation or shift by dynamic data
bool bfirstpass; // true if this is first time sound is spatialized
float ob_gain; // gain drop if sound source obscured from listener
float ob_gain_target; // target gain while crossfading between ob_gain & ob_gain_target
float ob_gain_inc; // crossfade increment
bool bTraced; // true if channel was already checked this frame for obscuring
float radius; // radius of this sound effect
bool doppler_effect; // this chanel has doppler effect
// obsolete. remove ?
int looping; // where to loop, -1 = no looping OBSOLETE?
int entnum; // to allow overriding a specific sound
int loopnum; // entity num that playing autosound
int loopframe; // for stopping looping sounds
int entchannel; //
vec3_t origin; // only use if fixed_origin is set
vec_t dist_mult; // distance multiplier (attenuation/clipK)
int master_vol; // 0-255 master volume
bool fixed_origin; // use origin instead of fetching entnum's origin
bool autosound; // from an entity->sound, cleared each frame
bool use_loop; // don't loop default and local sounds
bool fsentence; // bit who indicated sentence
bool use_delay; // delayed start
} channel_t;
typedef struct
{
vec3_t origin; // simorg
vec3_t vieworg; // simorg + view_ofs
vec3_t velocity;
vec3_t forward;
vec3_t right;
vec3_t up;
int entnum;
int waterlevel;
float frametime; // used for sound fade
bool ingame; // listener in-game ?
} listener_t;
typedef struct
{
int rate;
@ -126,19 +141,20 @@ typedef struct
====================================================================
*/
#define Host_Error com.error
#define Host_Error com.error
#define Z_Malloc( size ) Mem_Alloc( sndpool, size )
// initializes cycling through a DMA buffer and returns information on it
bool SNDDMA_Init( void *hInst );
int SNDDMA_GetDMAPos( void );
int SNDDMA_GetSoundtime( void );
void SNDDMA_Shutdown( void );
void SNDDMA_BeginPainting( void );
void SNDDMA_Submit( void );
//====================================================================
#define MAX_CHANNELS 64
#define MAX_DYNAMIC_CHANNELS 24
#define MAX_CHANNELS 128
#define MAX_RAW_SAMPLES 8192
extern portable_samplepair_t paintbuffer[];
@ -146,35 +162,27 @@ extern channel_t channels[MAX_CHANNELS];
extern int total_channels;
extern int paintedtime;
extern int s_rawend;
extern vec3_t listener_origin;
extern vec3_t listener_forward;
extern vec3_t listener_right;
extern vec3_t listener_up;
extern int listener_waterlevel;
extern dma_t dma;
extern playsound_t s_pendingplays;
extern bool sound_started;
extern listener_t s_listener;
extern cvar_t *s_check_errors;
extern cvar_t *s_volume;
extern cvar_t *s_nosound;
extern cvar_t *s_loadas8bit;
extern cvar_t *s_khz;
extern cvar_t *s_show;
extern cvar_t *s_mixahead;
extern cvar_t *s_testsound;
extern cvar_t *s_primary;
extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
void S_InitScaletable( void );
wavdata_t *S_LoadSound( sfx_t *sfx );
void S_IssuePlaysound( playsound_t *ps );
void S_PaintChannels( int endtime );
float S_GetMasterVolume( void );
void S_PrintDeviceName( void );
// s_load.c
bool S_TestSoundChar( const char *pch, char c );
char *S_SkipSoundChar( const char *pch );
// s_dsp.c
void SX_Init( void );
@ -188,21 +196,36 @@ void S_SoundList_f( void );
void S_SoundInfo_f( void );
// if origin is NULL, the sound will be dynamically sourced from the entity
void S_StartSound( const vec3_t pos, int ent, int chan, sound_t sfx, float vol, float attn, float pitch, int flags );
void S_StartSound( const vec3_t pos, int ent, int chan, sound_t sfx, float vol, float attn, int pitch, int flags );
void S_StartStaticSound( const vec3_t pos, int ent, int chan, sound_t handle, float fvol, float attn, int pitch, int flags );
void S_StreamRawSamples( int samples, int rate, int width, int channels, const byte *data );
bool S_AddLoopingSound( int entnum, sound_t handle, float volume, float attn );
void S_StartBackgroundTrack( const char *intro, const char *loop );
channel_t *S_PickChannel( int entNum, int entChannel );
channel_t *SND_PickDynamicChannel( int entnum, int channel, sfx_t *sfx );
channel_t *SND_PickStaticChannel( int entnum, sfx_t *sfx );
void S_FadeClientVolume( float fadePercent, float fadeOutSeconds, float holdTime, float fadeInSeconds );
int S_StartLocalSound( const char *name, float volume, float pitch, const float *org );
int S_StartLocalSound( const char *name, float volume, int pitch, const float *org );
sfx_t *S_GetSfxByHandle( sound_t handle );
void S_StopSound( int entnum, int channel );
void S_StopBackgroundTrack( void );
void S_Update( ref_params_t *fd );
void S_RenderFrame( ref_params_t *fd );
void S_StartStreaming( void );
void S_StopStreaming( void );
void S_StopAllSounds( void );
void S_FreeSounds( void );
//
// s_mouth.c
//
void SND_InitMouth( int entnum, int entchannel );
void SND_CloseMouth( channel_t *ch );
//
// s_vox.c
//
void VOX_SetChanVol( channel_t *ch );
void VOX_LoadSound( channel_t *pchan, const char *psz );
void S_BeginRegistration( void );
sound_t S_RegisterSound( const char *sample );
void S_EndRegistration( void );