21 Apr 2010

This commit is contained in:
g-cont 2010-04-21 00:00:00 +04:00 committed by Alibek Omarov
parent 79a969990c
commit 9a4ea1451b
36 changed files with 1381 additions and 497 deletions

16
baserc/baserc.plg Normal file
View File

@ -0,0 +1,16 @@
<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>

16
bshift/bshift.plg Normal file
View File

@ -0,0 +1,16 @@
<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>

16
client/client.plg Normal file
View File

@ -0,0 +1,16 @@
<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

@ -122,9 +122,6 @@ int CHud :: MsgFunc_ResetHUD(const char *pszName, int iSize, void *pbuf )
// needs to clear any remaining screenfade
ClearAllFades ();
// needs to clear any remaining soundfade
CLIENT_COMMAND( "s_clearfade\n" );
// reset sensitivity
m_flMouseSensitivity = 0;

View File

@ -700,7 +700,7 @@ void CL_UpdateUserinfo( sizebuf_t *msg )
slot = MSG_ReadByte( msg );
if( slot >= MAX_CLIENTS )
Host_EndGame( "CL_ParseServerMessage: svc_updateuserinfo > MAX_CLIENTS\n" );
Host_Error( "CL_ParseServerMessage: svc_updateuserinfo > MAX_CLIENTS\n" );
player = &cl.players[slot];
active = MSG_ReadByte( msg ) ? true : false;

View File

@ -321,6 +321,9 @@ void IN_Frame( void )
{
bool shutdownMouse = false;
if( host.state == HOST_RESTART )
host.state = HOST_FRAME; // restart is finished
if( host.type == HOST_DEDICATED )
{
// let the dedicated server some sleep

16
engine/engine.plg Normal file
View File

@ -0,0 +1,16 @@
<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

@ -32,6 +32,7 @@ cvar_t *host_serverstate;
cvar_t *host_cheats;
cvar_t *host_maxfps;
cvar_t *host_minfps;
cvar_t *host_nosound;
cvar_t *host_framerate;
cvar_t *host_registered;
cvar_t *host_video;
@ -216,6 +217,9 @@ bool Host_InitSound( void )
launch_t CreateSound;
bool result = false;
if( host_nosound->integer )
return result;
// phys callback
si.api_size = sizeof( vsound_imp_t );
si.GetSoundSpatialization = CL_GetEntitySoundSpatialization;
@ -246,8 +250,7 @@ void Host_CheckRestart( void )
if( host_cphys->modified )
{
// host.state = HOST_RESTART;
S_StopAllSounds(); // don't let them loop during the restart
S_StopAllSounds(); // don't let them loop during the restart
SV_ForceMod();
CL_ForceVid();
@ -280,6 +283,14 @@ void Host_CheckRestart( void )
void Host_CheckChanges( void )
{
int num_changes;
bool audio_disabled = false;
if( host_nosound->integer )
{
if( host.state == HOST_INIT )
audio_disabled = true;
host_audio->modified = false;
}
if( host_video->modified || host_audio->modified )
{
@ -313,6 +324,8 @@ void Host_CheckChanges( void )
else SCR_Init ();
}
if( audio_disabled ) MsgDev( D_INFO, "Audio: Disabled\n" );
num_changes = 0;
// restart or change sound engine
@ -748,7 +761,8 @@ void Host_InitCommon( const int argc, const char **argv )
Host_InitEvents();
FS_LoadGameInfo( NULL );
Image_Init( GI->texmode, -1 );
Image_Init( GI->gameHint, -1 );
Sound_Init( GI->gameHint, -1 );
host.mempool = Mem_AllocPool( "Zone Engine" );
@ -860,6 +874,7 @@ void Host_Init( const int argc, const char **argv )
host_framerate = Cvar_Get( "host_framerate", "0", 0, "locks frame timing to this value in seconds" );
host_serverstate = Cvar_Get( "host_serverstate", "0", CVAR_SERVERINFO, "displays current server state" );
host_registered = Cvar_Get( "registered", "1", CVAR_SYSTEMINFO, "indicate shareware version of game" );
host_nosound = Cvar_Get( "host_nosound", "0", CVAR_SYSTEMINFO, "disable sound system" );
timescale = Cvar_Get( "timescale", "1.0", 0, "slow-mo timescale" );
s = va( "^1Xash %g ^3%s", GI->version, buildstring );
@ -877,6 +892,7 @@ void Host_Init( const int argc, const char **argv )
SV_Init();
CL_Init();
Host_CheckRestart (); // loading physic library
Host_WriteDefaultConfig ();
if( host.type == HOST_DEDICATED )

View File

@ -528,17 +528,10 @@ void SV_ForceError( void )
bool SV_NewGame( const char *mapName, bool loadGame )
{
if( !loadGame )
{
// in case we unload game dll and flush memory
Host_EndGame( "start a new game" );
}
else
{
SV_InactivateClients ();
SV_DeactivateServer ();
sv.loadgame = true;
}
SV_InactivateClients ();
SV_DeactivateServer ();
sv.loadgame = loadGame;
if( !SV_SpawnServer( mapName, NULL ))
return false;

View File

@ -632,7 +632,6 @@ void SV_Init( void )
SV_ClearSaveDir (); // delete all temporary *.hl files
MSG_Init( &net_message, net_message_buffer, sizeof( net_message_buffer ));
Host_CheckRestart ();
}
/*

View File

@ -1411,7 +1411,7 @@ void FS_CreateGameInfo( const char *filename )
com.strncat( buffer, va("title\t\t\"New Game\"\rversion\t\t\"%g\"\rviewmode\t\t\"firstperson\"\r", XASH_VERSION ), MAX_SYSPATH );
com.strncat( buffer, "gamemode\t\t\"default\"\r", MAX_SYSPATH );
com.strncat( buffer, "\nstartmap\t\t\"newmap\"\n\n", MAX_SYSPATH );
com.strncat( buffer, "\ntexmode\t\t\"Xash3D\"", MAX_SYSPATH );
com.strncat( buffer, "\ngameHint\t\t\"Xash3D\"", MAX_SYSPATH );
com.strncat( buffer, "\nsp_spawn\t\t\"info_player_start\"", MAX_SYSPATH );
com.strncat( buffer, "\ndm_spawn\t\t\"info_player_deathmatch\"", MAX_SYSPATH );
com.strncat( buffer, "\nctf_spawn\t\t\"info_player_ctf\"", MAX_SYSPATH );
@ -1462,7 +1462,7 @@ static bool FS_ParseGameInfo( const char *filename, gameinfo_t *GameInfo )
GameInfo->viewheight[1] = 12.0f;
GameInfo->sp_inhibite_ents = false;
com.strncpy( GameInfo->texmode, "Xash3D", MAX_STRING );
com.strncpy( GameInfo->gameHint, "Xash3D", MAX_STRING );
com.strncpy( GameInfo->sp_entity, "info_player_start", MAX_STRING );
com.strncpy( GameInfo->dm_entity, "info_player_deathmatch", MAX_STRING );
com.strncpy( GameInfo->ctf_entity, "info_player_ctf", MAX_STRING );
@ -1500,9 +1500,9 @@ static bool FS_ParseGameInfo( const char *filename, gameinfo_t *GameInfo )
{
PS_GetString( script, false, GameInfo->title, sizeof( GameInfo->title ));
}
else if( !com.stricmp( token.string, "texmode" ))
else if( !com.stricmp( token.string, "gameHint" ))
{
PS_GetString( script, false, GameInfo->texmode, sizeof( GameInfo->texmode ));
PS_GetString( script, false, GameInfo->gameHint, sizeof( GameInfo->gameHint ));
}
else if( !com.stricmp( token.string, "sp_spawn" ))
{

View File

@ -40,7 +40,6 @@ typedef enum
IL_HINT_Q1, // palette choosing
IL_HINT_Q2,
IL_HINT_HL,
IL_HINT_FORCE_RGBA, // force to unpack any image
} image_hint_t;
typedef struct loadformat_s
@ -49,20 +48,20 @@ typedef struct loadformat_s
const char *ext;
bool (*loadfunc)( const char *name, const byte *buffer, size_t filesize );
image_hint_t hint;
} loadformat_t;
} loadpixformat_t;
typedef struct saveformat_s
{
const char *formatstring;
const char *ext;
bool (*savefunc)( const char *name, rgbdata_t *pix );
} saveformat_t;
} savepixformat_t;
typedef struct imglib_s
{
const loadformat_t *baseformats; // used for loading internal images
const loadformat_t *loadformats;
const saveformat_t *saveformats;
const loadpixformat_t *baseformats; // used for loading internal images
const loadpixformat_t *loadformats;
const savepixformat_t *saveformats;
// current 2d image state
word width;
@ -481,7 +480,6 @@ enum
};
extern imglib_t image;
extern cvar_t *img_oldformats;
extern cvar_t *fs_wadsupport;
extern cvar_t *png_compression;
extern cvar_t *jpg_quality;

View File

@ -1,6 +1,6 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_load.c - load various image formats
// img_main.c - load & save various image formats
//=======================================================================
#include "imagelib.h"
@ -256,7 +256,7 @@ rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size )
bool dds_installed = false; // current loadformats list supported dds
bool anyformat = true;
int i, filesize = 0;
const loadformat_t *format;
const loadpixformat_t *format;
const cubepack_t *cmap;
byte *f;
@ -438,7 +438,7 @@ bool FS_SaveImage( const char *filename, rgbdata_t *pix )
const char *ext = FS_FileExtension( filename );
bool anyformat = !com_stricmp( ext, "" ) ? true : false;
string path, savename;
const saveformat_t *format;
const savepixformat_t *format;
if( !pix || !pix->buffer || anyformat ) return false;
com.strncpy( savename, filename, sizeof( savename ));

View File

@ -6,9 +6,7 @@
#include "imagelib.h"
#include "mathlib.h"
cvar_t *image_profile;
cvar_t *gl_round_down;
cvar_t *fs_textures;
cvar_t *png_compression;
cvar_t *jpg_quality;
@ -109,20 +107,20 @@ static byte palette_q2[768] =
=============================================================================
*/
// stub
static const loadformat_t load_null[] =
static const loadpixformat_t load_null[] =
{
{ NULL, NULL, NULL, IL_HINT_NO }
};
// version0 - using only dds images
static const loadformat_t load_stalker[] =
static const loadpixformat_t load_stalker[] =
{
{ "%s%s.%s", "dds", Image_LoadDDS, IL_HINT_NO },
{ NULL, NULL, NULL, IL_HINT_NO }
};
// version1 - using only Doom1 images
static const loadformat_t load_doom1[] =
static const loadpixformat_t load_doom1[] =
{
{ "%s%s.%s", "flt", Image_LoadFLT, IL_HINT_NO }, // flat textures, sprites
{ NULL, NULL, NULL, IL_HINT_NO }
@ -130,7 +128,7 @@ static const loadformat_t load_doom1[] =
// version2 - using only Quake1 images
// wad files not requires path
static const loadformat_t load_quake1[] =
static const loadpixformat_t load_quake1[] =
{
{ "%s%s.%s", "mip", Image_LoadMIP, IL_HINT_Q1 }, // q1 textures from wad or buffer
{ "%s%s.%s", "mdl", Image_LoadMDL, IL_HINT_Q1 }, // q1 alias model skins
@ -140,7 +138,7 @@ static const loadformat_t load_quake1[] =
};
// version3 - using only Quake2 images
static const loadformat_t load_quake2[] =
static const loadpixformat_t load_quake2[] =
{
{ "textures/%s%s.%s", "wal", Image_LoadWAL, IL_HINT_Q2 }, // map textures
{ "%s%s.%s", "wal", Image_LoadWAL, IL_HINT_Q2 }, // map textures
@ -151,7 +149,7 @@ static const loadformat_t load_quake2[] =
// version4 - using only Quake3 images
// g-cont: probably q3 used only explicit paths
static const loadformat_t load_quake3[] =
static const loadpixformat_t load_quake3[] =
{
{ "%s%s.%s", "jpg", Image_LoadJPG, IL_HINT_NO }, // textures or gfx
{ "%s%s.%s", "tga", Image_LoadTGA, IL_HINT_NO }, // textures or gfx
@ -160,7 +158,7 @@ static const loadformat_t load_quake3[] =
// version5 - using only Quake4(Doom3) images
// g-cont: probably q4 used only explicit paths
static const loadformat_t load_quake4[] =
static const loadpixformat_t load_quake4[] =
{
{ "%s%s.%s", "dds", Image_LoadDDS, IL_HINT_NO }, // textures or gfx
{ "%s%s.%s", "tga", Image_LoadTGA, IL_HINT_NO }, // textures or gfx
@ -169,7 +167,7 @@ static const loadformat_t load_quake4[] =
// version6 - using only Half-Life images
// wad files not requires path
static const loadformat_t load_hl1[] =
static const loadpixformat_t load_hl1[] =
{
{ "%s%s.%s", "tga", Image_LoadTGA, IL_HINT_NO }, // hl vgui menus
{ "%s%s.%s", "bmp", Image_LoadBMP, IL_HINT_NO }, // hl skyboxes
@ -183,7 +181,7 @@ static const loadformat_t load_hl1[] =
};
// version7 - using only Half-Life 2 images
static const loadformat_t load_hl2[] =
static const loadpixformat_t load_hl2[] =
{
{ "%s%s.%s", "vtf", Image_LoadVTF, IL_HINT_NO }, // hl2 dds wrapper
{ "%s%s.%s", "tga", Image_LoadTGA, IL_HINT_NO }, // for Vgui, saveshots etc
@ -191,7 +189,7 @@ static const loadformat_t load_hl2[] =
};
// version8 - studiomdl profile
static const loadformat_t load_studiomdl[] =
static const loadpixformat_t load_studiomdl[] =
{
{ "%s%s.%s", "bmp", Image_LoadBMP, IL_HINT_NO }, // classic studio textures
{ "%s%s.%s", "pcx", Image_LoadPCX, IL_HINT_NO }, // q2 skins or somewhat
@ -200,7 +198,7 @@ static const loadformat_t load_studiomdl[] =
};
// version9 - spritegen profile
static const loadformat_t load_spritegen[] =
static const loadpixformat_t load_spritegen[] =
{
{ "%s%s.%s", "bmp", Image_LoadBMP, IL_HINT_NO }, // classic sprite frames
{ "%s%s.%s", "pcx", Image_LoadPCX, IL_HINT_NO }, // q2 sprite frames
@ -208,7 +206,7 @@ static const loadformat_t load_spritegen[] =
};
// version10 - xwad profile
static const loadformat_t load_wadlib[] =
static const loadpixformat_t load_wadlib[] =
{
{ "%s%s.%s", "bmp", Image_LoadBMP, IL_HINT_NO }, // there all wad package types
{ "%s%s.%s", "pcx", Image_LoadPCX, IL_HINT_NO },
@ -220,7 +218,7 @@ static const loadformat_t load_wadlib[] =
};
// version11 - Xash3D default image profile
static const loadformat_t load_xash[] =
static const loadpixformat_t load_xash[] =
{
{ "%s%s.%s", "dds", Image_LoadDDS, IL_HINT_NO }, // cubemaps, depthmaps, 2d textures
{ "%s%s.%s", "png", Image_LoadPNG, IL_HINT_NO }, // levelshot save as .png
@ -235,7 +233,7 @@ static const loadformat_t load_xash[] =
{ NULL, NULL, NULL, IL_HINT_NO }
};
static const loadformat_t load_ximage[] =
static const loadpixformat_t load_ximage[] =
{
{ "%s%s.%s", "dds", Image_LoadDDS, IL_HINT_NO }, // cubemaps, depthmaps, 2d textures
{ "%s%s.%s", "png", Image_LoadPNG, IL_HINT_NO }, // levelshot save as .png
@ -254,13 +252,13 @@ static const loadformat_t load_ximage[] =
=============================================================================
*/
// stub
static const saveformat_t save_null[] =
static const savepixformat_t save_null[] =
{
{ NULL, NULL, NULL }
};
// version0 - extragen save formats
static const saveformat_t save_extragen[] =
static const savepixformat_t save_extragen[] =
{
{ "%s%s.%s", "tga", Image_SaveTGA }, // tga screenshots
{ "%s%s.%s", "jpg", Image_SaveJPG }, // jpg screenshots
@ -272,7 +270,7 @@ static const saveformat_t save_extragen[] =
};
// Xash3D normal instance
static const saveformat_t save_xash[] =
static const savepixformat_t save_xash[] =
{
{ "%s%s.%s", "tga", Image_SaveTGA }, // tga screenshots
{ "%s%s.%s", "jpg", Image_SaveJPG }, // tga levelshots or screenshots
@ -281,7 +279,7 @@ static const saveformat_t save_xash[] =
{ NULL, NULL, NULL }
};
static const saveformat_t save_ximage[] =
static const savepixformat_t save_ximage[] =
{
{ "%s%s.%s", "tga", Image_SaveTGA },
{ "%s%s.%s", "jpg", Image_SaveJPG },
@ -297,7 +295,6 @@ void Image_Init( void )
// init pools
Sys.imagepool = Mem_AllocPool( "ImageLib Pool" );
gl_round_down = Cvar_Get( "gl_round_down", "0", CVAR_SYSTEMINFO, "down size non-power of two textures" );
fs_textures = Cvar_Get( "fs_textures_path", "textures", CVAR_SYSTEMINFO, "textures default folder" );
png_compression = Cvar_Get( "png_compression", "9", CVAR_SYSTEMINFO, "pnglib compression level" );
jpg_quality = Cvar_Get( "jpg_quality", "7", CVAR_SYSTEMINFO, "jpglib quality level" );
Cvar_SetValue( "png_compression", bound( 0, png_compression->integer, 9 ));

View File

@ -54,7 +54,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /opt:nowin98
# ADD LINK32 zlib.lib png.lib jpg.lib user32.lib gdi32.lib shell32.lib advapi32.lib winmm.lib /nologo /dll /pdb:none /machine:I386 /nodefaultlib:"libc.lib" /libpath:"./imagelib" /opt:nowin98
# ADD LINK32 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" /libpath:"./imagelib" /libpath:"./soundlib" /opt:nowin98
# Begin Custom Build
TargetDir=\Xash3D\src_main\temp\launch\!release
InputPath=\Xash3D\src_main\temp\launch\!release\launch.dll
@ -90,7 +90,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 zlib.lib png.lib jpg.lib user32.lib gdi32.lib shell32.lib advapi32.lib winmm.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"libc.lib" /pdbtype:sept /libpath:"./imagelib"
# ADD LINK32 zlib.lib png.lib jpg.lib ogg.lib vorbis.lib user32.lib gdi32.lib shell32.lib advapi32.lib winmm.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"libcmt" /nodefaultlib:"libc" /pdbtype:sept /libpath:"./imagelib" /libpath:"./soundlib"
# Begin Custom Build
TargetDir=\Xash3D\src_main\temp\launch\!debug
InputPath=\Xash3D\src_main\temp\launch\!debug\launch.dll
@ -200,6 +200,26 @@ SOURCE=.\patch.c
# End Source File
# Begin Source File
SOURCE=.\soundlib\snd_main.c
# End Source File
# Begin Source File
SOURCE=.\soundlib\snd_ogg.c
# End Source File
# Begin Source File
SOURCE=.\soundlib\snd_raw.c
# End Source File
# Begin Source File
SOURCE=.\soundlib\snd_utils.c
# End Source File
# Begin Source File
SOURCE=.\soundlib\snd_wav.c
# End Source File
# Begin Source File
SOURCE=.\stdlib.c
# End Source File
# Begin Source File
@ -226,6 +246,10 @@ SOURCE=.\launch.h
SOURCE=.\library.h
# End Source File
# Begin Source File
SOURCE=.\soundlib\soundlib.h
# End Source File
# End Group
# Begin Group "Resource Files"

View File

@ -71,6 +71,7 @@ typedef struct system_s
bool con_silentmode;
byte *basepool;
byte *imagepool;
byte *soundpool;
byte *scriptpool;
byte *stringpool;
bool shutdown_issued;
@ -351,12 +352,19 @@ void W_Close( wfile_t *wad );
byte *FS_LoadFile (const char *path, fs_offset_t *filesizeptr );
bool FS_WriteFile (const char *filename, const void *data, fs_offset_t len);
// imagelib exports
rgbdata_t *FS_LoadImage( const char *name, const byte *buffer, size_t size );
bool Image_Process( rgbdata_t **pix, int w, int h, uint flags );
bool FS_SaveImage( const char *name, rgbdata_t *image );
bpc_desc_t *Image_GetPixelFormat( pixformat_t type );
void FS_FreeImage( rgbdata_t *pack );
// soundlib exports
wavdata_t *FS_LoadSound( const char *name, const byte *buffer, size_t size );
bool Sound_Process( wavdata_t **wav, int rate, int width, uint flags );
bool FS_SaveSound( const char *name, wavdata_t *sound );
void FS_FreeSound( wavdata_t *pack );
search_t *FS_Search(const char *pattern, int caseinsensitive );
search_t *FS_SearchDirs(const char *pattern, int caseinsensitive );
@ -525,6 +533,13 @@ void Image_Init( void );
void Image_Setup( const char *formats, const uint flags );
void Image_Shutdown( void );
//
// sndlib.c
//
void Sound_Init( void );
void Sound_Setup( const char *formats, const uint flags );
void Sound_Shutdown( void );
//
// stringtable.c
//

61
launch/launch.plg Normal file
View File

@ -0,0 +1,61 @@
<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>

BIN
launch/soundlib/ogg.lib Normal file

Binary file not shown.

149
launch/soundlib/snd_main.c Normal file
View File

@ -0,0 +1,149 @@
//=======================================================================
// Copyright XashXT Group 2010 ©
// snd_main.c - load & save various sound formats
//=======================================================================
#include "soundlib.h"
#include "mathlib.h"
// global sound variables
sndlib_t sound;
void Sound_Reset( void )
{
// reset global variables
sound.width = sound.rate = 0;
sound.channels = sound.loopstart = 0;
sound.samples = sound.flags = 0;
sound.type = WF_UNKNOWN;
sound.wav = NULL;
sound.size = 0;
}
wavdata_t *SoundPack( void )
{
wavdata_t *pack = Mem_Alloc( Sys.soundpool, sizeof( wavdata_t ));
pack->buffer = sound.wav;
pack->width = sound.width;
pack->rate = sound.rate;
pack->type = sound.type;
pack->size = sound.size;
pack->loopStart = sound.loopstart;
pack->samples = sound.samples;
pack->channels = sound.channels;
pack->flags = sound.flags;
return pack;
}
/*
================
FS_LoadSound
loading and unpack to wav any known sound
================
*/
wavdata_t *FS_LoadSound( const char *filename, const byte *buffer, size_t size )
{
const char *ext = FS_FileExtension( filename );
string path, loadname;
bool anyformat = true;
int filesize = 0;
const loadwavformat_t *format;
byte *f;
Sound_Reset(); // clear old image
com.strncpy( loadname, filename, sizeof( loadname ));
if( com.stricmp( ext, "" ))
{
// we needs to compare file extension with list of supported formats
// and be sure what is real extension, not a filename with dot
for( format = sound.loadformats; format && format->formatstring; format++ )
{
if( !com.stricmp( format->ext, ext ))
{
FS_StripExtension( loadname );
anyformat = false;
break;
}
}
}
// HACKHACK: skip any checks, load file from buffer
if( filename[0] == '#' && buffer && size ) goto load_internal;
// engine notify
if( !anyformat ) MsgDev( D_NOTE, "Note: %s will be loading only with ext .%s\n", loadname, ext );
// now try all the formats in the selected list
for( format = sound.loadformats; format && format->formatstring; format++)
{
if( anyformat || !com_stricmp( ext, format->ext ))
{
com_sprintf( path, format->formatstring, loadname, "", format->ext );
f = FS_LoadFile( path, &filesize );
if( f && filesize > 0 )
{
if( format->loadfunc( path, f, filesize ))
{
Mem_Free(f); // release buffer
return SoundPack(); // loaded
}
else Mem_Free(f); // release buffer
}
}
}
load_internal:
for( format = sound.baseformats; format && format->formatstring; format++ )
{
if( anyformat || !com_stricmp( ext, format->ext ))
{
if( buffer && size > 0 )
{
if( format->loadfunc( loadname, buffer, size ))
return SoundPack(); // loaded
}
}
}
if( !sound.loadformats || sound.loadformats->ext == NULL )
MsgDev( D_NOTE, "FS_LoadSound: soundlib offline\n" );
else if( filename[0] != '#' )
MsgDev( D_WARN, "FS_LoadSound: couldn't load \"%s\"\n", loadname );
return NULL;
}
/*
================
Sound_Save
writes image as any known format
================
*/
bool FS_SaveSound( const char *filename, wavdata_t *wav )
{
// FIXME: not implemented
return false;
}
/*
================
Sound_FreeSound
free WAV buffer
================
*/
void FS_FreeSound( wavdata_t *pack )
{
if( pack )
{
if( pack->buffer ) Mem_Free( pack->buffer );
Mem_Free( pack );
}
else MsgDev( D_WARN, "FS_FreeSound: trying to free NULL sound\n" );
}

328
launch/soundlib/snd_ogg.c Normal file
View File

@ -0,0 +1,328 @@
//=======================================================================
// Copyright XashXT Group 2010 ©
// snd_ogg.c - ogg format load & save
//=======================================================================
#include "soundlib.h"
typedef __int64 ogg_int64_t;
typedef __int32 ogg_int32_t;
typedef unsigned __int32 ogg_uint32_t;
typedef __int16 ogg_int16_t;
typedef unsigned __int16 ogg_uint16_t;
/*
=======================================================================
OGG PACK DEFINITION
=======================================================================
*/
struct ogg_chain_s
{
void *ptr;
struct alloc_chain *next;
};
typedef struct oggpack_buffer_s
{
long endbyte;
int endbit;
byte *buffer;
byte *ptr;
long storage;
} oggpack_buffer_t;
typedef struct ogg_sync_state_s
{
byte *data;
int storage;
int fill;
int returned;
int unsynced;
int headerbytes;
int bodybytes;
} ogg_sync_state_t;
typedef struct ogg_stream_state_s
{
byte *body_data;
long body_storage;
long body_fill;
long body_returned;
int *lacing_vals;
ogg_int64_t *granule_vals;
long lacing_storage;
long lacing_fill;
long lacing_packet;
long lacing_returned;
byte header[282];
int header_fill;
int e_o_s;
int b_o_s;
long serialno;
long pageno;
ogg_int64_t packetno;
ogg_int64_t granulepos;
} ogg_stream_state_t;
/*
=======================================================================
VORBIS FILE DEFINITION
=======================================================================
*/
typedef struct vorbis_info_s
{
int version;
int channels;
long rate;
long bitrate_upper;
long bitrate_nominal;
long bitrate_lower;
long bitrate_window;
void *codec_setup;
} vorbis_info_t;
typedef struct vorbis_comment_s
{
char **user_comments;
int *comment_lengths;
int comments;
char *vendor;
} vorbis_comment_t;
typedef struct vorbis_dsp_state_s
{
int analysisp;
vorbis_info_t *vi;
float **pcm;
float **pcmret;
int pcm_storage;
int pcm_current;
int pcm_returned;
int preextrapolate;
int eofflag;
long lW;
long W;
long nW;
long centerW;
ogg_int64_t granulepos;
ogg_int64_t sequence;
ogg_int64_t glue_bits;
ogg_int64_t time_bits;
ogg_int64_t floor_bits;
ogg_int64_t res_bits;
void *backend_state;
} vorbis_dsp_state_t;
typedef struct vorbis_block_s
{
float **pcm;
oggpack_buffer_t opb;
long lW;
long W;
long nW;
int pcmend;
int mode;
int eofflag;
ogg_int64_t granulepos;
ogg_int64_t sequence;
vorbis_dsp_state_t *vd;
void *localstore;
long localtop;
long localalloc;
long totaluse;
struct ogg_chain_s *reap;
long glue_bits;
long time_bits;
long floor_bits;
long res_bits;
void *internal;
} vorbis_block_t;
typedef struct ov_callbacks_s
{
size_t (*read_func)( void *ptr, size_t size, size_t nmemb, void *datasource );
int (*seek_func)( void *datasource, ogg_int64_t offset, int whence );
int (*close_func)( void *datasource );
long (*tell_func)( void *datasource );
} ov_callbacks_t;
typedef struct
{
byte *buffer;
ogg_int64_t ind;
ogg_int64_t buffsize;
} ov_decode_t;
typedef struct vorbisfile_s
{
void *datasource;
int seekable;
ogg_int64_t offset;
ogg_int64_t end;
ogg_sync_state_t oy;
int links;
ogg_int64_t *offsets;
ogg_int64_t *dataoffsets;
long *serialnos;
ogg_int64_t *pcmlengths;
vorbis_info_t *vi;
vorbis_comment_t *vc;
ogg_int64_t pcm_offset;
int ready_state;
long current_serialno;
int current_link;
double bittrack;
double samptrack;
ogg_stream_state_t os;
vorbis_dsp_state_t vd;
vorbis_block_t vb;
ov_callbacks_t callbacks;
} vorbisfile_t;
// libvorbis exports
extern int ov_open_callbacks( void *datasrc, vorbisfile_t *vf, char *initial, long ibytes, ov_callbacks_t callbacks );
extern long ov_read( vorbisfile_t *vf, char *buffer, int length, int bigendianp, int word, int sgned, int *bitstream );
extern char *vorbis_comment_query( vorbis_comment_t *vc, char *tag, int count );
extern vorbis_comment_t *ov_comment( vorbisfile_t *vf, int link );
extern ogg_int64_t ov_pcm_total( vorbisfile_t *vf, int i );
extern vorbis_info_t *ov_info( vorbisfile_t *vf, int link );
extern int ov_raw_seek( vorbisfile_t *vf, ogg_int64_t pos );
extern ogg_int64_t ov_raw_tell( vorbisfile_t *vf );
extern int ov_clear( vorbisfile_t *vf);
static size_t ovc_read( void *ptr, size_t size, size_t nb, void *datasrc )
{
ov_decode_t *oggfile = (ov_decode_t *)datasrc;
size_t remain, length;
remain = oggfile->buffsize - oggfile->ind;
length = size * nb;
if( remain < length )
length = remain - remain % size;
Mem_Copy( ptr, oggfile->buffer + oggfile->ind, length );
oggfile->ind += length;
return length / size;
}
static int ovc_seek( void *datasrc, ogg_int64_t offset, int whence )
{
ov_decode_t *oggfile = (ov_decode_t*)datasrc;
switch( whence )
{
case SEEK_SET:
break;
case SEEK_CUR:
offset += oggfile->ind;
break;
case SEEK_END:
offset += oggfile->buffsize;
break;
default:
return -1;
}
if( offset < 0 || offset > oggfile->buffsize )
return -1;
oggfile->ind = offset;
return 0;
}
static int ovc_close( void *datasrc )
{
return 0;
}
static long ovc_tell( void *datasrc )
{
return ((ov_decode_t *)datasrc)->ind;
}
/*
=================================================================
OGG decompression
=================================================================
*/
bool Sound_LoadOGG( const char *name, const byte *buffer, size_t filesize )
{
vorbisfile_t vf;
vorbis_info_t *vi;
vorbis_comment_t *vc;
ov_decode_t ov_decode;
ov_callbacks_t ov_callbacks = { ovc_read, ovc_seek, ovc_close, ovc_tell };
long done = 0, ret;
const char *comm;
int dummy;
// load the file
if( !buffer || filesize <= 0 )
return false;
// Open it with the VorbisFile API
ov_decode.buffer = (byte *)buffer;
ov_decode.buffsize = filesize;
ov_decode.ind = 0;
if( ov_open_callbacks( &ov_decode, &vf, NULL, 0, ov_callbacks ) < 0 )
{
MsgDev( D_ERROR, "Sound_LoadOGG: couldn't open ogg stream %s\n", name );
return false;
}
// get the stream information
vi = ov_info( &vf, -1 );
if( vi->channels != 1 )
{
MsgDev( D_ERROR, "Sound_LoadOGG: only mono OGG files supported (%s)\n", name );
ov_clear( &vf );
return false;
}
sound.channels = vi->channels;
sound.rate = vi->rate;
sound.width = 2; // always 16-bit PCM
sound.loopstart = -1;
sound.size = ov_pcm_total( &vf, -1 ) * vi->channels * 2; // 16 bits => "* 2"
if( !sound.size )
{
// bad ogg file
MsgDev( D_ERROR, "Sound_LoadOGG: (%s) is probably corrupted\n", name );
ov_clear( &vf );
return false;
}
sound.type = WF_PCMDATA;
sound.wav = (byte *)Mem_Alloc( Sys.soundpool, sound.size );
// decompress ogg into pcm wav format
while(( ret = ov_read( &vf, &sound.wav[done], (int)(sound.size - done), big_endian, 2, 1, &dummy )) > 0 )
done += ret;
sound.samples = done / ( vi->channels * 2 );
vc = ov_comment( &vf, -1 );
if( vc )
{
comm = vorbis_comment_query( vc, "LOOP_START", 0 );
if( comm )
{
// FXIME: implement
Msg( "ogg 'cue' %d\n", com.atoi(comm) );
//sound.loopstart = bound( 0, com.atoi( comm ), sound.samples );
}
}
// close file
ov_clear( &vf );
return true;
}

19
launch/soundlib/snd_raw.c Normal file
View File

@ -0,0 +1,19 @@
//=======================================================================
// Copyright XashXT Group 2010 ©
// snd_wav.c - snd format load (raw data)
//=======================================================================
#include "soundlib.h"
/*
============
Sound_LoadSND
============
*/
bool Sound_LoadSND( const char *name, const byte *buffer, size_t filesize )
{
// FIXME: implement
// this is doom1 raw sounds - set rate to 11025, width to 1, channels to 1
// allocate room for raw data and return - no conversions needs
return false;
}

164
launch/soundlib/snd_utils.c Normal file
View File

@ -0,0 +1,164 @@
//=======================================================================
// Copyright XashXT Group 2010 ©
// snd_utils.c - sound common tools
//=======================================================================
#include "soundlib.h"
#include "mathlib.h"
/*
=============================================================================
XASH3D LOAD IMAGE FORMATS
=============================================================================
*/
// stub
static const loadwavformat_t load_null[] =
{
{ NULL, NULL, NULL }
};
// version0 - using only ogg sounds
static const loadwavformat_t load_stalker[] =
{
{ "sound/%s%s.%s", "ogg", Sound_LoadOGG },
{ "%s%s.%s", "ogg", Sound_LoadOGG },
{ NULL, NULL, NULL }
};
// version1 - using only Doom1 sounds
static const loadwavformat_t load_doom1[] =
{
{ "%s%s.%s", "snd", Sound_LoadSND },
{ NULL, NULL, NULL }
};
// version2 - using only Quake1 sounds
static const loadwavformat_t load_quake1[] =
{
{ "sound/%s%s.%s", "wav", Sound_LoadWAV },
{ "%s%s.%s", "wav", Sound_LoadWAV },
{ NULL, NULL, NULL }
};
// version11 - Xash3D default sound profile
static const loadwavformat_t load_xash[] =
{
{ "sound/%s%s.%s", "wav", Sound_LoadWAV },
{ "%s%s.%s", "wav", Sound_LoadWAV },
{ "sound/%s%s.%s", "ogg", Sound_LoadOGG },
{ "%s%s.%s", "ogg", Sound_LoadOGG },
{ NULL, NULL, NULL }
};
/*
=============================================================================
XASH3D SAVE SOUND FORMATS
=============================================================================
*/
// stub
static const savewavformat_t save_null[] =
{
{ NULL, NULL, NULL }
};
// version1 - extract all sounds into pcm wav
static const savewavformat_t save_extragen[] =
{
{ "%s%s.%s", "wav", Sound_SaveWAV },
{ NULL, NULL, NULL }
};
void Sound_Init( void )
{
// init pools
Sys.soundpool = Mem_AllocPool( "SoundLib Pool" );
sound.baseformats = load_xash;
// install image formats (can be re-install later by Sound_Setup)
switch( Sys.app_name )
{
case HOST_NORMAL:
Sound_Setup( "default", 0 ); // re-initialized later
sound.saveformats = save_null;
break;
case HOST_RIPPER:
sound.loadformats = load_null;
sound.saveformats = save_extragen;
break;
default: // all other instances not using soundlib or will be reinstalling later
sound.loadformats = load_null;
sound.saveformats = save_null;
break;
}
sound.tempbuffer = NULL;
}
void Sound_Setup( const char *formats, const uint flags )
{
if( flags != -1 ) sound.cmd_flags = flags;
if( formats == NULL ) return; // used for change flags only
MsgDev( D_NOTE, "Sound_Init( %s )\n", formats );
// reinstall loadformats by magic keyword :)
if( !com.stricmp( formats, "Xash3D" ) || !com.stricmp( formats, "Xash" ))
{
sound.loadformats = load_xash;
}
else if( !com.stricmp( formats, "stalker" ) || !com.stricmp( formats, "S.T.A.L.K.E.R" ))
{
sound.loadformats = load_stalker;
}
else if( !com.stricmp( formats, "Doom1" ) || !com.stricmp( formats, "Doom2" ))
{
sound.loadformats = load_doom1;
}
else if( !com.stricmp( formats, "Quake1" ))
{
sound.loadformats = load_quake1;
}
else if( !com.stricmp( formats, "Quake2" ))
{
sound.loadformats = load_quake1;
}
else if( !com.stricmp( formats, "Quake3" ))
{
sound.loadformats = load_quake1;
}
else if( !com.stricmp( formats, "Quake4" ) || !com.stricmp( formats, "Doom3" ))
{
sound.loadformats = load_quake1;
}
else if( !com.stricmp( formats, "hl1" ) || !com.stricmp( formats, "Half-Life" ))
{
sound.loadformats = load_quake1;
}
else if( !com.stricmp( formats, "hl2" ) || !com.stricmp( formats, "Half-Life 2" ))
{
sound.loadformats = load_quake1;
}
else
{
sound.loadformats = load_xash; // unrecognized version, use default
}
if( Sys.app_name == HOST_RIPPER )
sound.baseformats = sound.loadformats;
}
void Sound_Shutdown( void )
{
Mem_Check(); // check for leaks
Mem_FreePool( &Sys.soundpool );
}
bool Sound_Process( wavdata_t **wav, int rate, int width, uint flags )
{
// FIXME: not implemented
return false;
}

221
launch/soundlib/snd_wav.c Normal file
View File

@ -0,0 +1,221 @@
//=======================================================================
// Copyright XashXT Group 2010 ©
// snd_wav.c - wav format load & save
//=======================================================================
#include "soundlib.h"
static const byte *iff_data;
static const byte *iff_dataPtr;
static const byte *iff_end;
static const byte *iff_lastChunk;
static int iff_chunkLen;
/*
=================
GetLittleShort
=================
*/
static short GetLittleShort( void )
{
short val = 0;
val += (*(iff_dataPtr+0) << 0);
val += (*(iff_dataPtr+1) << 8);
iff_dataPtr += 2;
return val;
}
/*
=================
GetLittleLong
=================
*/
static int GetLittleLong( void )
{
int val = 0;
val += (*(iff_dataPtr+0) << 0);
val += (*(iff_dataPtr+1) << 8);
val += (*(iff_dataPtr+2) <<16);
val += (*(iff_dataPtr+3) <<24);
iff_dataPtr += 4;
return val;
}
/*
=================
FindNextChunk
=================
*/
static void FindNextChunk( const char *name )
{
while( 1 )
{
iff_dataPtr = iff_lastChunk;
if( iff_dataPtr >= iff_end )
{
// didn't find the chunk
iff_dataPtr = NULL;
return;
}
iff_dataPtr += 4;
iff_chunkLen = GetLittleLong();
if( iff_chunkLen < 0 )
{
iff_dataPtr = NULL;
return;
}
iff_dataPtr -= 8;
iff_lastChunk = iff_dataPtr + 8 + ((iff_chunkLen + 1) & ~1);
if(!com.strncmp( iff_dataPtr, name, 4 ))
return;
}
}
/*
=================
FindChunk
=================
*/
static void FindChunk( const char *name )
{
iff_lastChunk = iff_data;
FindNextChunk( name );
}
/*
=============
Sound_LoadWAV
=============
*/
bool Sound_LoadWAV( const char *name, const byte *buffer, size_t filesize )
{
int samples;
if( !buffer || filesize <= 0 ) return false;
iff_data = buffer;
iff_end = buffer + filesize;
// dind "RIFF" chunk
FindChunk( "RIFF" );
if( !( iff_dataPtr && !com.strncmp( iff_dataPtr + 8, "WAVE", 4 )))
{
MsgDev( D_ERROR, "Sound_LoadWAV: %s missing 'RIFF/WAVE' chunks\n", name );
return false;
}
// get "fmt " chunk
iff_data = iff_dataPtr + 12;
FindChunk( "fmt " );
if( !iff_dataPtr )
{
MsgDev( D_ERROR, "Sound_LoadWAV: %s missing 'fmt ' chunk\n", name );
return false;
}
iff_dataPtr += 8;
if( GetLittleShort() != 1 )
{
MsgDev( D_ERROR, "Sound_LoadWAV: %s not a microsoft PCM format\n", name );
return false;
}
sound.channels = GetLittleShort();
if( sound.channels != 1 )
{
MsgDev( D_ERROR, "Sound_LoadWAV: only mono WAV files supported (%s)\n", name );
return false;
}
sound.rate = GetLittleLong();
iff_dataPtr += 6;
sound.width = GetLittleShort() / 8;
if( sound.width != 1 && sound.width != 2 )
{
MsgDev( D_WARN, "Sound_LoadWAV: only 8 and 16 bit WAV files supported (%s)\n", name );
return false;
}
// get cue chunk
FindChunk( "cue " );
if( iff_dataPtr )
{
iff_dataPtr += 32;
sound.loopstart = GetLittleLong();
FindNextChunk( "LIST" ); // if the next chunk is a LIST chunk, look for a cue length marker
if( iff_dataPtr )
{
if( !com.strncmp( iff_dataPtr + 28, "mark", 4 ))
{
// this is not a proper parse, but it works with CoolEdit...
iff_dataPtr += 24;
sound.samples = sound.loopstart + GetLittleLong(); // samples in loop
}
}
}
else
{
sound.loopstart = -1;
sound.samples = 0;
}
// find data chunk
FindChunk( "data" );
if( !iff_dataPtr )
{
MsgDev( D_WARN, "Sound_LoadWAV: %s missing 'data' chunk\n", name );
return false;
}
iff_dataPtr += 4;
samples = GetLittleLong() / sound.width;
if( sound.samples )
{
if( samples < sound.samples )
{
MsgDev( D_ERROR, "Sound_LoadWAV: %s has a bad loop length\n", name );
return false;
}
}
else sound.samples = samples;
if( sound.samples <= 0 )
{
MsgDev( D_ERROR, "Sound_LoadWAV: file with %i samples (%s)\n", sound.samples, name );
return false;
}
sound.type = WF_PCMDATA;
// Load the data
sound.size = sound.samples * sound.width;
sound.wav = Mem_Alloc( Sys.soundpool, sound.size );
Mem_Copy( sound.wav, buffer + (iff_dataPtr - buffer), sound.size );
return true;
}
/*
=============
Sound_SaveWAV
=============
*/
bool Sound_SaveWAV( const char *name, wavdata_t *pix )
{
// FIXME: implement
return false;
}

View File

@ -0,0 +1,68 @@
//=======================================================================
// Copyright XashXT Group 2010 ©
// soundlib.h - engine sound lib
//=======================================================================
#ifndef SOUNDLIB_H
#define SOUNDLIB_H
#include "launch.h"
#include "byteorder.h"
typedef struct loadwavformat_s
{
const char *formatstring;
const char *ext;
bool (*loadfunc)( const char *name, const byte *buffer, size_t filesize );
} loadwavformat_t;
typedef struct savewavformat_s
{
const char *formatstring;
const char *ext;
bool (*savefunc)( const char *name, wavdata_t *pix );
} savewavformat_t;
typedef struct sndlib_s
{
const loadwavformat_t *baseformats; // used for loading internal images
const loadwavformat_t *loadformats;
const savewavformat_t *saveformats;
// current sound state
int type; // sound type
word rate; // num samples per second (e.g. 11025 - 11 khz)
word width; // resolution - bum bits divided by 8 (8 bit is 1, 16 bit is 2)
word channels; // num channels (1 - mono, 2 - stereo)
int loopstart; // start looping from
uint samples; // total samplecount in sound
uint flags; // additional sound flags
size_t size; // sound unpacked size (for bounds checking)
byte *wav; // sound pointer (see sound_type for details)
byte *tempbuffer; // for convert operations
int cmd_flags;
} sndlib_t;
/*
========================================================================
.OGG sound format (OGG Vorbis)
========================================================================
*/
// defined in sound_ogg.c
extern sndlib_t sound;
//
// formats load
//
bool Sound_LoadWAV( const char *name, const byte *buffer, size_t filesize );
bool Sound_LoadOGG( const char *name, const byte *buffer, size_t filesize );
bool Sound_LoadSND( const char *name, const byte *buffer, size_t filesize ); // snd - doom1 sounds
//
// formats save
//
bool Sound_SaveWAV( const char *name, wavdata_t *pix );
#endif//SOUNDLIB_H

BIN
launch/soundlib/vorbis.lib Normal file

Binary file not shown.

View File

@ -226,6 +226,13 @@ void Sys_GetStdAPI( void )
com.ImagePFDesc = Image_GetPixelFormat; // get some info about current fmt
com.ImageConvert = Image_Process; // flip, rotate, resample etc
// built-in soundlib functions
com.SoundLoad = FS_LoadSound; // load sound from disk or wad-file
com.SoundSave = FS_SaveSound; // save sound into specified format
com.SoundFree = FS_FreeSound; // release sound buffer
com.SndlibSetup = Sound_Setup; // set soundlib global features
com.SoundConvert = Sound_Process; // resample, change resolution etc
com.Com_RandomLong = Com_RandomLong;
com.Com_RandomFloat = Com_RandomFloat;
@ -1003,6 +1010,8 @@ void Sys_Init( void )
Cvar_Init();
FS_Init();
Image_Init();
Sound_Init();
Sys_CreateInstance();
}
@ -1016,6 +1025,7 @@ void Sys_Shutdown( void )
FS_Shutdown();
Image_Shutdown();
Sound_Shutdown();
Memory_Shutdown();
Con_DestroyConsole();

View File

@ -224,7 +224,7 @@ typedef struct gameinfo_s
string startmap; // map to start singleplayer game
string trainmap; // map to start hazard course (if specified)
string title; // Game Main Title
string texmode; // configure ImageLib to use various texture formats
string gameHint; // hint to configure ImageLib and SoundLib
float version; // game version (optional)
// about mod info
@ -306,7 +306,6 @@ typically expanded to rgba buffer
NOTE: number at end of pixelformat name it's a total bitscount e.g. PF_RGB_24 == PF_RGB_888
========================================================================
*/
typedef enum
{
PF_UNKNOWN = 0,
@ -408,6 +407,55 @@ typedef struct rgbdata_s
size_t size; // for bounds checking
} rgbdata_t;
/*
========================================================================
internal sound format
typically expanded to wav buffer
========================================================================
*/
typedef enum
{
WF_UNKNOWN = 0,
WF_PCMDATA,
WF_OGGDATA,
WF_TOTALCOUNT, // must be last
} sndformat_t;
// imagelib global settings
typedef enum
{
SL_USE_LERPING = BIT(3), // lerping sounds during resample
SL_KEEP_8BIT = BIT(4), // don't expand 8bit sounds automatically up to 16 bit
SL_ALLOW_OVERWRITE = BIT(5), // allow to overwrite stored sounds
} slFlags_t;
// wavdata output flags
typedef enum
{
// wavdata->flags
SOUND_LOOPED = BIT( 0 ), // this is looped sound (contain cue markers)
// Sound_Process manipulation flags
SOUND_RESAMPLE = BIT(12), // resample sound to specified rate
SOUND_CONVERT16BIT = BIT(13), // change sound resolution from 8 bit to 16
} sndFlags_t;
typedef struct
{
word rate; // num samples per second (e.g. 11025 - 11 khz)
byte width; // resolution - bum bits divided by 8 (8 bit is 1, 16 bit is 2)
byte channels; // num channels (1 - mono, 2 - stereo)
int loopStart; // offset (in samples) at this point sound will be looping while playing more than only once
int samples; // total samplecount in wav
uint type; // compression type
uint flags; // misc sound flags
byte *buffer; // sound buffer
size_t size; // for bounds checking
} wavdata_t;
// filesystem flags
#define FS_STATIC_PATH 1 // FS_ClearSearchPath will be ignore this path
#define FS_NOWRITE_PATH 2 // default behavior - last added gamedir set as writedir. This flag disables it
@ -619,6 +667,13 @@ typedef struct stdilib_api_s
bpc_desc_t *(*ImagePFDesc)( pixformat_t imagetype ); // get const info about specified fmt
void (*ImageFree)( rgbdata_t *pack ); // release image buffer
// built-in soundlib functions
void (*SndlibSetup)( const char *formats, const uint flags ); // set main attributes
wavdata_t *(*SoundLoad)( const char *, const byte *, size_t ); // load sound from disk or buffer
bool (*SoundSave)( const char *name, wavdata_t *image ); // save sound into specified format
bool (*SoundConvert)( wavdata_t **pix, int rt, int wdth, uint flags );// sound manipulations
void (*SoundFree)( wavdata_t *pack ); // release sound buffer
// random generator
long (*Com_RandomLong)( long lMin, long lMax ); // returns random integer
float (*Com_RandomFloat)( float fMin, float fMax ); // returns random float
@ -917,6 +972,17 @@ imglib manager
#define PFDesc( x ) com.ImagePFDesc( x )
#define Image_Process com.ImageConvert
/*
===========================================
sndlib manager
===========================================
*/
#define FS_LoadSound com.SoundLoad
#define FS_SaveSound com.SoundSave
#define FS_FreeSound com.SoundFree
#define Sound_Init com.SndlibSetup
#define Sound_Process com.SoundConvert
/*
===========================================
misc utils

View File

@ -62,7 +62,6 @@ const dsproom_t eax_preset[CSXROOM] =
{ EAX_ENVIRONMENT_DIZZY, 0.4F, 17.234F, 0.666F },
};
cvar_t *host_sound;
cvar_t *s_alDevice;
cvar_t *s_allowEAX;
cvar_t *s_allowA3D;
@ -850,17 +849,6 @@ void S_StopSound_f( void )
S_StopAllSounds();
}
/*
=================
S_ClearFade_f
=================
*/
void S_ClearFade_f( void )
{
// clear any remaining soundfade
Mem_Set( &soundfade, 0, sizeof( soundfade ));
}
/*
=================
S_SoundInfo_f
@ -897,7 +885,6 @@ bool S_Init( void *hInst )
Cmd_ExecuteString( "sndlatch\n" );
host_sound = Cvar_Get("host_sound", "1", CVAR_SYSTEMINFO, "enable sound system" );
s_alDevice = Cvar_Get("s_device", "Generic Software", CVAR_LATCH_AUDIO|CVAR_ARCHIVE, "OpenAL current device name" );
s_allowEAX = Cvar_Get("s_allowEAX", "1", CVAR_LATCH_AUDIO|CVAR_ARCHIVE, "allow EAX 2.0 extension" );
s_allowA3D = Cvar_Get("s_allowA3D", "1", CVAR_LATCH_AUDIO|CVAR_ARCHIVE, "allow A3D 2.0 extension" );
@ -914,16 +901,9 @@ bool S_Init( void *hInst )
Cmd_AddCommand( "playsound", S_PlaySound_f, "playing a specified sound file" );
Cmd_AddCommand( "stopsound", S_StopSound_f, "stop all sounds" );
Cmd_AddCommand( "music", S_Music_f, "starting a background track" );
Cmd_AddCommand( "s_clearfade", S_ClearFade_f, "clear any sound fade" );
Cmd_AddCommand( "s_info", S_SoundInfo_f, "print sound system information" );
Cmd_AddCommand( "soundlist", S_SoundList_f, "display loaded sounds" );
if( !host_sound->integer )
{
MsgDev( D_INFO, "Audio: disabled\n" );
return false;
}
if(!S_Init_OpenAL())
{
MsgDev( D_INFO, "S_Init: sound system can't initialized\n" );
@ -961,7 +941,6 @@ void S_Shutdown( void )
Cmd_RemoveCommand( "stopsound" );
Cmd_RemoveCommand( "music" );
Cmd_RemoveCommand( "s_info" );
Cmd_RemoveCommand( "s_clearfade" );
Cmd_RemoveCommand( "soundlist" );
if( !al_state.initialized )

View File

@ -36,11 +36,12 @@ cvar_t *s_wavonly;
static HWND snd_hwnd;
static bool dsound_init;
static bool wav_init;
static bool snd_firsttime = true, snd_isdirect, snd_iswave;
static bool snd_firsttime = true;
static bool snd_isdirect, snd_iswave;
static bool primary_format_set;
static int snd_buffer_count = 0;
static int sample16;
static int snd_sent, snd_completed;
static int sample16;
/*
=======================================================================
@ -129,15 +130,18 @@ static bool DS_CreateBuffers( void *hInst )
pformat = format;
MsgDev( D_NOTE, "- ok\n" );
if( snd_firsttime )
MsgDev( D_NOTE, "DS_CreateBuffers: setting primary sound format " );
if( pDSPBuf->lpVtbl->SetFormat( pDSPBuf, &pformat ) != DS_OK )
{
if( snd_firsttime )
MsgDev( D_NOTE, "DS_CreateBuffers: setting primary sound format - failed\n" );
MsgDev( D_NOTE, "- failed\n" );
}
else
{
if( snd_firsttime )
MsgDev( D_NOTE, "DS_CreateBuffers: setting primary sound format - ok\n" );
MsgDev( D_NOTE, "- ok\n" );
primary_format_set = true;
}
}
@ -343,7 +347,7 @@ si_state_t SNDDMA_InitDirect( void *hInst )
MsgDev( D_NOTE, "SNDDMA_InitDirect: initializing DirectSound ");
if ( !dsound_dll.link )
if( !dsound_dll.link )
{
if( !Sys_LoadLibrary( NULL, &dsound_dll ))
{
@ -425,7 +429,7 @@ si_state_t SNDDMA_InitWav( void )
// open a waveform device for output using window callback.
MsgDev( D_NOTE, "SNDDMA_InitWav: initializing wave sound " );
if((hr = waveOutOpen((LPHWAVEOUT)&hWaveOut, WAVE_MAPPER, &format, 0, 0, CALLBACK_NULL)) != MMSYSERR_NOERROR )
if(( hr = waveOutOpen((LPHWAVEOUT)&hWaveOut, WAVE_MAPPER, &format, 0, 0, CALLBACK_NULL)) != MMSYSERR_NOERROR )
{
if( hr != MMSYSERR_ALLOCATED )
{
@ -447,7 +451,7 @@ si_state_t SNDDMA_InitWav( void )
hData = GlobalAlloc( GMEM_MOVEABLE|GMEM_SHARE, gSndBufSize );
if( !hData )
{
SNDDMA_FreeSound ();
SNDDMA_FreeSound();
return SIS_FAILURE;
}
@ -558,6 +562,7 @@ int SNDDMA_Init( void *hInst )
else snd_iswave = false;
}
}
snd_buffer_count = 1;
if( !dsound_init && !wav_init )
@ -640,7 +645,7 @@ void SNDDMA_BeginPainting( void )
{
if( hr != DSERR_BUFFERLOST )
{
MsgDev( D_ERROR, "S_TransferStereo16: lock failed with error '%s'\n", DSoundError( hr ));
MsgDev( D_ERROR, "SNDDMA_BeginPainting: lock error '%s'\n", DSoundError( hr ));
S_Shutdown ();
return;
}
@ -662,7 +667,7 @@ Also unlocks the dsound buffer
void SNDDMA_Submit( void )
{
LPWAVEHDR h;
int wResult;
int wResult;
if( !dma.buffer )
return;
@ -684,7 +689,7 @@ void SNDDMA_Submit( void )
}
// submit a few new sound blocks
while(((snd_sent - snd_completed) >> sample16 ) < 8 )
while((( snd_sent - snd_completed ) >> sample16 ) < 8 )
{
h = lpWaveHdr + ( snd_sent & WAV_MASK );
@ -699,7 +704,7 @@ void SNDDMA_Submit( void )
if( wResult != MMSYSERR_NOERROR )
{
MsgDev( D_ERROR, "S_TransferStereo16: failed to write block to device\n" );
MsgDev( D_ERROR, "SNDDMA_Submit: failed to write block to device\n" );
SNDDMA_FreeSound ();
return;
}
@ -739,5 +744,7 @@ void S_Activate( bool active )
{
if( pDS && snd_hwnd && snd_isdirect )
DS_DestroyBuffers();
else if( snd_iswave )
waveOutReset( hWaveOut );
}
}

View File

@ -7,7 +7,6 @@
vsound_imp_t si;
stdlib_api_t com;
byte *sndpool;
vsound_exp_t DLLEXPORT *CreateAPI( stdlib_api_t *input, vsound_imp_t *engfuncs )
{
@ -17,7 +16,7 @@ vsound_exp_t DLLEXPORT *CreateAPI( stdlib_api_t *input, vsound_imp_t *engfuncs )
// Sys_LoadLibrary can create fake instance, to check
// api version and api size, but second argument will be 0
// and always make exception, run simply check for avoid it
// and always make exception, run simply check to avoid it
if( engfuncs ) si = *engfuncs;
// generic functions

View File

@ -13,19 +13,12 @@
#define MAX_SFX 4096
#define MAX_SFX_HASH (MAX_SFX/4)
static int s_numSfx = 0;
static sfx_t s_knownSfx[MAX_SFX];
static sfx_t *s_sfxHashList[MAX_SFX_HASH];
static int s_numSfx = 0;
bool s_registering = false;
int s_registration_sequence = 0;
typedef struct loadformat_s
{
char *formatstring;
char *ext;
bool (*loadfunc)( const char *name, byte **wav, wavinfo_t *info );
} loadformat_t;
/*
=================
S_SoundList_f
@ -33,10 +26,9 @@ S_SoundList_f
*/
void S_SoundList_f( void )
{
int i;
sfx_t *sfx;
sfxcache_t *sc;
int size, totalSfx = 0;
wavdata_t *sc;
int i, totalSfx = 0;
int totalSize = 0;
for( i = 0, sfx = s_knownSfx; i < s_numSfx; i++, sfx++ )
@ -47,22 +39,19 @@ void S_SoundList_f( void )
sc = sfx->cache;
if( sc )
{
size = sc->length * sc->width * (sc->stereo + 1);
totalSize += size;
if( sc->loopstart >= 0 ) Msg( "L" );
else Msg( " " );
totalSize += sc->size;
if( sfx->name[0] == '#' )
Msg( " (%2db) %s : %s\n", sc->width * 8, memprint( size ), &sfx->name[1] );
else Msg( " (%2db) %s : sound/%s\n", sc->width * 8, memprint( size ), sfx->name );
if( sc->loopStart >= 0 ) Msg( "L" );
else Msg( " " );
Msg( " (%2db) %s : sound/%s\n", sc->width * 8, memprint( sc->size ), sfx->name );
totalSfx++;
}
}
Msg("-------------------------------------------\n");
Msg("%i total sounds\n", totalSfx );
Msg("%s total memory\n", memprint( totalSize ));
Msg("\n");
Msg( "-------------------------------------------\n" );
Msg( "%i total sounds\n", totalSfx );
Msg( "%s total memory\n", memprint( totalSize ));
Msg( "\n" );
}
/*
@ -72,10 +61,10 @@ S_ResampleSfx
*/
void S_ResampleSfx( sfx_t *sfx, int inrate, int inwidth, byte *data )
{
float stepscale;
int outcount, srcsample;
int i, sample, samplefrac, fracstep;
sfxcache_t *sc;
float stepscale;
int outcount, srcsample;
int i, sample, samplefrac, fracstep;
wavdata_t *sc;
if( !sfx ) return;
sc = sfx->cache;
@ -83,29 +72,28 @@ void S_ResampleSfx( sfx_t *sfx, int inrate, int inwidth, byte *data )
stepscale = (float)inrate / dma.speed; // this is usually 0.5, 1, or 2
outcount = sc->length / stepscale;
sc->length = outcount;
if( sc->loopstart != -1 )
sc->loopstart = sc->loopstart / stepscale;
outcount = sc->samples / stepscale;
sc->samples = outcount;
if( sc->loopStart != -1 )
sc->loopStart = sc->loopStart / stepscale;
sc->speed = dma.speed;
if( s_loadas8bit->integer )
sc->width = 1;
else sc->width = inwidth;
sc->stereo = 0;
sc->rate = dma.speed;
sc->width = inwidth;
sc->channels = 1; // default to Mono
// resample / decimate to the current source rate
if( stepscale == 1 && inwidth == 1 && sc->width == 1 )
{
// fast special case
for( i = 0; i < outcount; i++ )
((signed char *)sc->data)[i] = (int)((unsigned char)(data[i]) - 128);
((signed char *)sc->buffer)[i] = (int)((unsigned char)(data[i]) - 128);
}
else
{
// general case
samplefrac = 0;
fracstep = stepscale * 256;
for( i = 0; i < outcount; i++ )
{
srcsample = samplefrac >> 8;
@ -114,8 +102,8 @@ void S_ResampleSfx( sfx_t *sfx, int inrate, int inwidth, byte *data )
if( inwidth == 2 ) sample = LittleShort(((short *)data)[srcsample] );
else sample = (int)( (unsigned char)(data[srcsample]) - 128) << 8;
if( sc->width == 2 ) ((short *)sc->data)[i] = sample;
else ((signed char *)sc->data)[i] = sample >> 8;
if( sc->width == 2 ) ((short *)sc->buffer)[i] = sample;
else ((signed char *)sc->buffer)[i] = sample >> 8;
}
}
}
@ -136,243 +124,29 @@ bool S_TestSoundChar( const char *pch, char c )
return false;
}
/*
===============================================================================
WAV loading
===============================================================================
*/
static byte *iff_data;
static byte *iff_dataPtr;
static byte *iff_end;
static byte *iff_lastChunk;
static int iff_chunkLen;
/*
=================
S_GetLittleShort
=================
*/
static short S_GetLittleShort( void )
{
short val = 0;
val += (*(iff_dataPtr+0) << 0);
val += (*(iff_dataPtr+1) << 8);
iff_dataPtr += 2;
return val;
}
/*
=================
S_GetLittleLong
=================
*/
static int S_GetLittleLong( void )
{
int val = 0;
val += (*(iff_dataPtr+0) << 0);
val += (*(iff_dataPtr+1) << 8);
val += (*(iff_dataPtr+2) << 16);
val += (*(iff_dataPtr+3) << 24);
iff_dataPtr += 4;
return val;
}
/*
=================
S_FindNextChunk
=================
*/
static void S_FindNextChunk( const char *name )
{
while( 1 )
{
iff_dataPtr = iff_lastChunk;
if( iff_dataPtr >= iff_end )
{
// didn't find the chunk
iff_dataPtr = NULL;
return;
}
iff_dataPtr += 4;
iff_chunkLen = S_GetLittleLong();
if (iff_chunkLen < 0)
{
iff_dataPtr = NULL;
return;
}
iff_dataPtr -= 8;
iff_lastChunk = iff_dataPtr + 8 + ((iff_chunkLen + 1) & ~1);
if(!com.strncmp( iff_dataPtr, name, 4 ))
return;
}
}
/*
=================
S_FindChunk
=================
*/
static void S_FindChunk( const char *name )
{
iff_lastChunk = iff_data;
S_FindNextChunk( name );
}
/*
=================
S_LoadWAV
=================
*/
static bool S_LoadWAV( const char *name, byte **wav, wavinfo_t *info )
{
byte *buffer, *out;
int length, samples;
buffer = FS_LoadFile( name, &length );
if( !buffer ) return false;
iff_data = buffer;
iff_end = buffer + length;
// dind "RIFF" chunk
S_FindChunk( "RIFF" );
if( !( iff_dataPtr && !com.strncmp( iff_dataPtr + 8, "WAVE", 4 )))
{
MsgDev( D_WARN, "S_LoadWAV: missing 'RIFF/WAVE' chunks (%s)\n", name );
Mem_Free( buffer );
return false;
}
// get "fmt " chunk
iff_data = iff_dataPtr + 12;
S_FindChunk( "fmt " );
if( !iff_dataPtr )
{
MsgDev( D_WARN, "S_LoadWAV: missing 'fmt ' chunk (%s)\n", name );
Mem_Free( buffer );
return false;
}
iff_dataPtr += 8;
if( S_GetLittleShort() != 1 )
{
MsgDev( D_WARN, "S_LoadWAV: microsoft PCM format only (%s)\n", name );
Mem_Free( buffer );
return false;
}
info->channels = S_GetLittleShort();
if( info->channels != 1 )
{
MsgDev( D_WARN, "S_LoadWAV: only mono WAV files supported (%s)\n", name );
Mem_Free( buffer );
return false;
}
info->rate = S_GetLittleLong();
iff_dataPtr += 4+2;
info->width = S_GetLittleShort() / 8;
if( info->width != 1 && info->width != 2 )
{
MsgDev( D_WARN, "S_LoadWAV: only 8 and 16 bit WAV files supported (%s)\n", name );
Mem_Free( buffer );
return false;
}
// get cue chunk
S_FindChunk( "cue " );
if( iff_dataPtr )
{
iff_dataPtr += 32;
info->loopstart = S_GetLittleLong();
S_FindNextChunk( "LIST" ); // if the next chunk is a LIST chunk, look for a cue length marker
if( iff_dataPtr )
{
if( !com.strncmp((const char *)iff_dataPtr + 28, "mark", 4 ))
{
// this is not a proper parse, but it works with CoolEdit...
iff_dataPtr += 24;
info->samples = info->loopstart + S_GetLittleLong(); // samples in loop
}
}
}
else
{
info->loopstart = -1;
info->samples = 0;
}
// find data chunk
S_FindChunk( "data" );
if( !iff_dataPtr )
{
MsgDev( D_WARN, "S_LoadWAV: missing 'data' chunk (%s)\n", name );
Mem_Free( buffer );
return false;
}
iff_dataPtr += 4;
samples = S_GetLittleLong() / info->width;
if( info->samples )
{
if( samples < info->samples )
{
MsgDev( D_ERROR, "S_LoadWAV: %s has a bad loop length\n", name );
Mem_Free( buffer );
return false;
}
}
else info->samples = samples;
if( info->samples <= 0 )
{
MsgDev( D_WARN, "S_LoadWAV: file with %i samples (%s)\n", info->samples, name );
Mem_Free( buffer );
return false;
}
// Load the data
*wav = out = Z_Malloc( info->samples * info->width );
Mem_Copy( out, buffer + (iff_dataPtr - buffer), info->samples * info->width );
Mem_Free( buffer );
return true;
}
/*
=================
S_UploadSound
=================
*/
static void S_UploadSound( byte *data, wavinfo_t *info, sfx_t *sfx )
static void S_UploadSound( wavdata_t *sc, sfx_t *sfx )
{
sfxcache_t *sc;
size_t size, samples;
float stepscale;
size_t samples;
float stepscale;
byte *indata;
// calculate buffer size
stepscale = (float)info->rate / dma.speed;
samples = info->samples / stepscale;
size = samples * info->width * info->channels;
stepscale = (float)sc->rate / dma.speed;
samples = sc->samples / stepscale;
sc->size = samples * sc->width * sc->channels;
indata = sc->buffer; // detach old buffer
sfx->cache = sc;
sc = sfx->cache = Z_Malloc( size + sizeof( sfxcache_t ));
sc->length = info->samples;
sc->loopstart = info->loopstart;
sc->speed = info->rate;
sc->width = info->width;
sc->stereo = info->channels;
// UNDONE: we need resample sounds in launch.dll, not here
sc->buffer = Z_Malloc( sc->size ); // allocate room for resampled wav
S_ResampleSfx( sfx, sc->speed, sc->width, data + info->dataofs );
S_ResampleSfx( sfx, sc->rate, sc->width, indata );
Mem_Free( indata ); // no reason to keep this data
}
/*
@ -380,30 +154,35 @@ static void S_UploadSound( byte *data, wavinfo_t *info, sfx_t *sfx )
S_CreateDefaultSound
=================
*/
static void S_CreateDefaultSound( byte **wav, wavinfo_t *info )
static wavdata_t *S_CreateDefaultSound( void )
{
byte *out;
wavdata_t *sc;
int i;
info->rate = 22050;
info->width = 2;
info->channels = 1;
info->samples = 11025;
sc = Z_Malloc( sizeof( wavdata_t ));
*wav = out = Z_Malloc( info->samples * info->width );
sc->rate = 22050;
sc->width = 2;
sc->channels = 1;
sc->samples = 11025;
sc->loopStart = -1;
sc->size = sc->samples * sc->width * sc->channels;
sc->buffer = Z_Malloc( sc->size );
if( s_check_errors->integer )
{
// create 1 kHz tone as default sound
for( i = 0; i < info->samples; i++ )
((short *)out)[i] = com.sin( i * 0.1f ) * 20000;
for( i = 0; i < sc->samples; i++ )
((short *)sc->buffer)[i] = com.sin( i * 0.1f ) * 20000;
}
else
{
// create silent sound
for( i = 0; i < info->samples; i++ )
((short *)out)[i] = i;
for( i = 0; i < sc->samples; i++ )
((short *)sc->buffer)[i] = i;
}
return sc;
}
/*
@ -411,58 +190,25 @@ static void S_CreateDefaultSound( byte **wav, wavinfo_t *info )
S_LoadSound
=================
*/
loadformat_t load_formats[] =
wavdata_t *S_LoadSound( sfx_t *sfx )
{
{ "sound/%s.%s", "wav", S_LoadWAV },
{ "%s.%s", "wav", S_LoadWAV },
{ NULL, NULL }
};
sfxcache_t *S_LoadSound( sfx_t *sfx )
{
byte *data;
wavinfo_t info;
const char *ext;
string loadname, path;
loadformat_t *format;
bool anyformat;
wavdata_t *sc;
if( !sfx ) return NULL;
if( sfx->name[0] == '*' ) return NULL;
if( sfx->cache ) return sfx->cache; // see if still in memory
// load it from disk
ext = FS_FileExtension( sfx->name );
anyformat = !com.stricmp( ext, "" ) ? true : false;
sc = FS_LoadSound( sfx->name, NULL, 0 );
com.strncpy( loadname, sfx->name, sizeof( loadname ));
FS_StripExtension( loadname ); // remove extension if needed
Mem_Set( &info, 0, sizeof( info ));
// developer warning
if( !anyformat ) MsgDev( D_NOTE, "Note: %s will be loading only with ext .%s\n", loadname, ext );
// now try all the formats in the selected list
for( format = load_formats; format->formatstring; format++ )
if( sc == NULL )
{
if( anyformat || !com.stricmp( ext, format->ext ))
{
com.sprintf( path, format->formatstring, loadname, format->ext );
if( format->loadfunc( path, &data, &info ))
goto snd_loaded;
}
sc = S_CreateDefaultSound();
sfx->default_sound = true;
}
sfx->default_sound = true;
MsgDev( D_WARN, "FS_LoadSound: couldn't load %s\n", sfx->name );
S_CreateDefaultSound( &data, &info );
info.loopstart = -1;
snd_loaded:
// load it in
S_UploadSound( data, &info, sfx );
Mem_Free( data );
// upload and resample
S_UploadSound( sc, sfx );
return sfx->cache;
}
@ -557,7 +303,7 @@ static void S_FreeSound( sfx_t *sfx )
prev = &hashSfx->hashNext;
}
if( sfx->cache ) Mem_Free( sfx->cache );
if( sfx->cache ) FS_FreeSound( sfx->cache );
Mem_Set( sfx, 0, sizeof( *sfx ));
}
@ -650,7 +396,8 @@ void S_FreeSounds( void )
for( i = 0, sfx = s_knownSfx; i < s_numSfx; i++, sfx++ )
S_FreeSound( sfx );
s_numSfx = 0;
Mem_Set( s_knownSfx, 0, sizeof( s_knownSfx ));
Mem_Set( s_sfxHashList, 0, sizeof( s_sfxHashList ));
s_numSfx = 0;
}

View File

@ -34,12 +34,10 @@ playsound_t s_freeplays;
playsound_t s_pendingplays;
int s_beginofs;
cvar_t *host_sound;
cvar_t *s_check_errors;
cvar_t *s_volume;
cvar_t *s_musicvolume;
cvar_t *s_testsound;
cvar_t *s_loadas8bit;
cvar_t *s_khz;
cvar_t *s_show;
cvar_t *s_mixahead;
@ -364,8 +362,8 @@ by the update loop.
*/
void S_IssuePlaysound( playsound_t *ps )
{
channel_t *ch;
sfxcache_t *sc;
channel_t *ch;
wavdata_t *sc;
if( s_show->value ) MsgDev( D_INFO, "Issue %i\n", ps->begin );
@ -396,7 +394,7 @@ void S_IssuePlaysound( playsound_t *ps )
ch->pos = 0;
sc = S_LoadSound( ch->sfx );
ch->end = paintedtime + sc->length;
ch->end = paintedtime + sc->samples;
// free the playsound
S_FreePlaysound( ps );
@ -416,7 +414,7 @@ Entchannel 0 will never override a playing sound
*/
void S_StartSound( const vec3_t pos, int ent, int chan, sound_t handle, float fvol, float attn, float pitch, int flags )
{
sfxcache_t *sc;
wavdata_t *sc;
int vol, start;
playsound_t *ps, *sort;
sfx_t *sfx = NULL;
@ -632,8 +630,8 @@ bool S_AddLoopingSound( int entnum, sound_t handle, float volume, float attn )
ch->loopframe = s_framecount;
ch->fixed_origin = false;
ch->dist_mult = ATTN_NORM * 0.001;
ch->pos = paintedtime % sfx->cache->length;
ch->end = paintedtime + sfx->cache->length - ch->pos;
ch->pos = paintedtime % sfx->cache->samples;
ch->end = paintedtime + sfx->cache->samples - ch->pos;
// now we can spatialize channel
S_SpatializeChannel( ch );
@ -817,17 +815,6 @@ void S_StopSound_f( void )
S_StopAllSounds();
}
/*
=================
S_ClearFade_f
=================
*/
void S_ClearFade_f( void )
{
// clear any remaining soundfade
Mem_Set( &soundfade, 0, sizeof( soundfade ));
}
/*
=================
S_SoundInfo_f
@ -860,11 +847,9 @@ bool S_Init( void *hInst )
{
Cmd_ExecuteString( "sndlatch\n" );
host_sound = Cvar_Get( "host_sound", "1", CVAR_SYSTEMINFO, "enable sound system" );
s_volume = Cvar_Get( "s_volume", "0.7", CVAR_ARCHIVE, "sound volume" );
s_musicvolume = Cvar_Get("s_musicvolume", "1.0", CVAR_ARCHIVE, "background music volume" );
s_khz = Cvar_Get( "s_khz", "11", CVAR_LATCH_AUDIO|CVAR_ARCHIVE, "output sound frequency" );
s_loadas8bit = Cvar_Get( "s_loadas8bit", "1", CVAR_LATCH_AUDIO|CVAR_ARCHIVE, "resample all sounds to 8-bit" );
s_khz = Cvar_Get( "s_khz", "22", CVAR_LATCH_AUDIO|CVAR_ARCHIVE, "output sound frequency" );
s_mixahead = Cvar_Get( "s_mixahead", "0.2", CVAR_ARCHIVE, "how much sound to mix ahead of time" );
s_show = Cvar_Get( "s_show", "0", 0, "show playing sounds" );
s_testsound = Cvar_Get( "s_testsound", "0", 0, "generate sine 1 khz wave to testing audio subsystem" );
@ -876,15 +861,8 @@ bool S_Init( void *hInst )
Cmd_AddCommand( "playsound", S_Play_f, "playing a specified sound file" );
Cmd_AddCommand( "stopsound", S_StopSound_f, "stop all sounds" );
Cmd_AddCommand( "soundlist", S_SoundList_f, "display loaded sounds" );
Cmd_AddCommand( "s_clearfade", S_ClearFade_f, "clear any sound fade" );
Cmd_AddCommand( "s_info", S_SoundInfo_f, "print sound system information" );
if( !host_sound->integer )
{
MsgDev( D_INFO, "Audio: disabled\n" );
return false;
}
if( !SNDDMA_Init( hInst ))
{
MsgDev( D_INFO, "S_Init: sound system can't initialized\n" );
@ -911,7 +889,6 @@ void S_Shutdown( void )
Cmd_RemoveCommand( "playsound" );
Cmd_RemoveCommand( "stopsound" );
Cmd_RemoveCommand( "soundlist" );
Cmd_RemoveCommand( "s_clearfade" );
Cmd_RemoveCommand( "s_info" );
if( !sound_started ) return;

View File

@ -158,64 +158,55 @@ CHANNEL MIXING
===============================================================================
*/
void S_PaintChannelFrom8( channel_t *ch, sfxcache_t *sc, int count, int offset )
void S_PaintChannelFrom8( channel_t *ch, wavdata_t *sc, int count )
{
int data;
int *lscale, *rscale;
byte *sfx;
portable_samplepair_t *samp;
int i;
int i, data;
int *lscale, *rscale;
byte *sfx;
if( ch->leftvol > 255 ) ch->leftvol = 255;
if( ch->rightvol > 255 ) ch->rightvol = 255;
ch->leftvol = bound( 0, ch->leftvol, 255 );
ch->rightvol = bound( 0, ch->rightvol, 255 );
lscale = snd_scaletable[ch->leftvol>>3];
rscale = snd_scaletable[ch->rightvol>>3];
sfx = (signed char *)sc->data + ch->pos;
sfx = (signed char *)sc->buffer + ch->pos;
samp = &paintbuffer[offset];
for( i = 0; i < count; i++, samp++ )
for( i = 0; i < count; i++ )
{
data = sfx[i];
samp->left += lscale[data];
samp->right += rscale[data];
paintbuffer[i].left += lscale[data];
paintbuffer[i].right += rscale[data];
}
ch->pos += count;
}
void S_PaintChannelFrom16( channel_t *ch, sfxcache_t *sc, int count, int offset )
void S_PaintChannelFrom16( channel_t *ch, wavdata_t *sc, int count )
{
int data;
int left, right;
int leftvol, rightvol;
signed short *sfx;
portable_samplepair_t *samp;
int i;
int i, data;
int left, right;
signed short *sfx;
leftvol = ch->leftvol * snd_vol;
rightvol = ch->rightvol * snd_vol;
sfx = (signed short *)sc->data + ch->pos;
ch->leftvol = bound( 0, ch->leftvol, 255 );
ch->rightvol = bound( 0, ch->rightvol, 255 );
sfx = (signed short *)sc->buffer + ch->pos;
samp = &paintbuffer[offset];
for( i = 0; i < count; i++, samp++ )
for( i = 0; i < count; i++ )
{
data = sfx[i];
left = ( data * leftvol ) >> 8;
right = (data * rightvol) >> 8;
samp->left += left;
samp->right += right;
left = ( data * ch->leftvol ) >> 8;
right = (data * ch->rightvol) >> 8;
paintbuffer[i].left += left;
paintbuffer[i].right += right;
}
ch->pos += count;
}
void S_MixAllChannels( int endtime, int end )
{
channel_t *ch;
sfxcache_t *sc;
int i, count = 0;
int ltime;
channel_t *ch;
wavdata_t *sc;
int i, count = 0;
int ltime;
// paint in the channels.
for( i = 0, ch = channels; i < total_channels; i++, ch++ )
@ -239,8 +230,8 @@ void S_MixAllChannels( int endtime, int end )
if( count > 0 && ch->sfx )
{
if( sc->width == 1 )
S_PaintChannelFrom8( ch, sc, count, ltime - paintedtime );
else S_PaintChannelFrom16( ch, sc, count, ltime - paintedtime );
S_PaintChannelFrom8( ch, sc, count );
else S_PaintChannelFrom16( ch, sc, count );
ltime += count;
}
@ -249,14 +240,15 @@ void S_MixAllChannels( int endtime, int end )
if( ltime >= ch->end )
{
if( ch->autosound && ch->use_loop )
{ // autolooping sounds always go back to start
{
// autolooping sounds always go back to start
ch->pos = 0;
ch->end = ltime + sc->length;
ch->end = ltime + sc->samples;
}
else if( sc->loopstart >= 0 && ch->use_loop )
else if( sc->loopStart >= 0 && ch->use_loop )
{
ch->pos = sc->loopstart;
ch->end = ltime + sc->length - ch->pos;
ch->pos = sc->loopStart;
ch->end = ltime + sc->samples - ch->pos;
}
else ch->sfx = NULL; // channel just stopped
}

View File

@ -114,7 +114,7 @@ SOURCE="$(InputPath)"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\s_direct.c
SOURCE=.\s_backend.c
# End Source File
# Begin Source File

View File

@ -23,20 +23,10 @@ typedef struct
int right;
} portable_samplepair_t;
typedef struct
{
int length;
int loopstart;
int speed; // not needed, because converted on load?
int width;
int stereo;
byte data[1]; // variable sized
} sfxcache_t;
typedef struct sfx_s
{
string name;
sfxcache_t *cache;
wavdata_t *cache;
int touchFrame;
bool default_sound;
@ -178,7 +168,7 @@ extern cvar_t *s_primary;
extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
void S_InitScaletable( void );
sfxcache_t *S_LoadSound( sfx_t *sfx );
wavdata_t *S_LoadSound( sfx_t *sfx );
void S_IssuePlaysound( playsound_t *ps );
void S_PaintChannels( int endtime );
float S_GetMasterVolume( void );

View File

@ -35,4 +35,5 @@ Xash 0.71 Beta 05.05.10
11.rewrite EntitiesInPVS check OK
12.revision MOVETYPE_BOUNCE physic OK
13.revision MOVETYPE_COMPOUND physic OK
14.re-design sound library
14.re-design sound library
15. move loding sounds into launch.dll OK