mirror of
https://bitbucket.org/CPMADevs/cnq3
synced 2024-11-10 06:31:48 +00:00
audio interface clean-up and Sys_* documentation
This commit is contained in:
parent
c60d47e93f
commit
caaa8e4e47
5 changed files with 67 additions and 85 deletions
|
@ -476,12 +476,12 @@ static void S_Base_ClearSoundBuffer()
|
||||||
|
|
||||||
s_rawend = 0;
|
s_rawend = 0;
|
||||||
|
|
||||||
SNDDMA_BeginPainting();
|
Sys_S_BeginPainting();
|
||||||
if (dma.buffer) {
|
if (dma.buffer) {
|
||||||
int clear = (dma.samplebits == 8) ? 0x80 : 0x00;
|
int clear = (dma.samplebits == 8) ? 0x80 : 0x00;
|
||||||
Com_Memset( dma.buffer, clear, dma.samples * dma.samplebits/8 );
|
Com_Memset( dma.buffer, clear, dma.samples * dma.samplebits/8 );
|
||||||
}
|
}
|
||||||
SNDDMA_Submit();
|
Sys_S_Submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -844,7 +844,7 @@ static void S_GetSoundtime()
|
||||||
|
|
||||||
// it is possible to miscount buffers if it has wrapped twice between
|
// it is possible to miscount buffers if it has wrapped twice between
|
||||||
// calls to S_Update. Oh well.
|
// calls to S_Update. Oh well.
|
||||||
int samplepos = SNDDMA_GetDMAPos();
|
int samplepos = Sys_S_GetDMAPos();
|
||||||
if (samplepos < oldsamplepos) {
|
if (samplepos < oldsamplepos) {
|
||||||
buffers++; // buffer wrapped
|
buffers++; // buffer wrapped
|
||||||
if (s_paintedtime > 0x40000000) {
|
if (s_paintedtime > 0x40000000) {
|
||||||
|
@ -913,11 +913,11 @@ static void S_Update_DMA()
|
||||||
if (endtime - s_soundtime > samps)
|
if (endtime - s_soundtime > samps)
|
||||||
endtime = s_soundtime + samps;
|
endtime = s_soundtime + samps;
|
||||||
|
|
||||||
SNDDMA_BeginPainting();
|
Sys_S_BeginPainting();
|
||||||
|
|
||||||
S_PaintChannels( endtime );
|
S_PaintChannels( endtime );
|
||||||
|
|
||||||
SNDDMA_Submit();
|
Sys_S_Submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1090,7 +1090,7 @@ static void S_Base_Shutdown()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNDDMA_Shutdown();
|
Sys_S_Shutdown();
|
||||||
|
|
||||||
s_soundStarted = qfalse;
|
s_soundStarted = qfalse;
|
||||||
|
|
||||||
|
@ -1113,7 +1113,7 @@ qbool S_Base_Init( soundInterface_t *si )
|
||||||
|
|
||||||
Cvar_RegisterArray( cl_cvars, MODULE_SOUND );
|
Cvar_RegisterArray( cl_cvars, MODULE_SOUND );
|
||||||
|
|
||||||
if (!SNDDMA_Init())
|
if (!Sys_S_Init())
|
||||||
return qfalse;
|
return qfalse;
|
||||||
|
|
||||||
s_soundStarted = qtrue;
|
s_soundStarted = qtrue;
|
||||||
|
|
|
@ -119,11 +119,23 @@ typedef struct
|
||||||
====================================================================
|
====================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
qbool SNDDMA_Init();
|
qbool Sys_S_Init();
|
||||||
int SNDDMA_GetDMAPos();
|
void Sys_S_Shutdown();
|
||||||
void SNDDMA_Shutdown();
|
|
||||||
void SNDDMA_BeginPainting();
|
// Returns the current sample position (in mono samples read)
|
||||||
void SNDDMA_Submit();
|
// inside the DMA ring buffer so the mixing code knows
|
||||||
|
// how many sample are required to fill it up.
|
||||||
|
int Sys_S_GetDMAPos();
|
||||||
|
|
||||||
|
// Makes sure dma.buffer is valid and accessible.
|
||||||
|
// If necessary, acquires a lock.
|
||||||
|
void Sys_S_BeginPainting();
|
||||||
|
|
||||||
|
// Sends sound to device if dma.buffer isn't really the DMA buffer.
|
||||||
|
// If a lock was acquired by Sys_S_BeginPainting,
|
||||||
|
// Sys_S_Submit will release it.
|
||||||
|
void Sys_S_Submit();
|
||||||
|
|
||||||
|
|
||||||
#define MAX_CHANNELS 96
|
#define MAX_CHANNELS 96
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ static void FillAudioBufferCallback( void* userData, Uint8* sdlBuffer, int sdlBy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
qbool SNDDMA_Init()
|
qbool Sys_S_Init()
|
||||||
{
|
{
|
||||||
if (audio.valid)
|
if (audio.valid)
|
||||||
return qtrue;
|
return qtrue;
|
||||||
|
@ -86,7 +86,7 @@ qbool SNDDMA_Init()
|
||||||
audio.device = SDL_OpenAudioDevice(NULL, 0, &desired, &obtained, 0);
|
audio.device = SDL_OpenAudioDevice(NULL, 0, &desired, &obtained, 0);
|
||||||
if (audio.device == 0) {
|
if (audio.device == 0) {
|
||||||
Com_Printf("SDL_OpenAudioDevice failed: %s\n", SDL_GetError());
|
Com_Printf("SDL_OpenAudioDevice failed: %s\n", SDL_GetError());
|
||||||
SNDDMA_Shutdown();
|
Sys_S_Shutdown();
|
||||||
return qfalse;
|
return qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ qbool SNDDMA_Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int SNDDMA_GetDMAPos()
|
int Sys_S_GetDMAPos()
|
||||||
{
|
{
|
||||||
if (!audio.valid)
|
if (!audio.valid)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -118,7 +118,7 @@ int SNDDMA_GetDMAPos()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SNDDMA_Shutdown()
|
void Sys_S_Shutdown()
|
||||||
{
|
{
|
||||||
if (audio.device != 0) {
|
if (audio.device != 0) {
|
||||||
SDL_PauseAudioDevice(audio.device, 1);
|
SDL_PauseAudioDevice(audio.device, 1);
|
||||||
|
@ -135,7 +135,7 @@ void SNDDMA_Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SNDDMA_Submit()
|
void Sys_S_Submit()
|
||||||
{
|
{
|
||||||
if (!audio.valid)
|
if (!audio.valid)
|
||||||
return;
|
return;
|
||||||
|
@ -145,7 +145,7 @@ void SNDDMA_Submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SNDDMA_BeginPainting()
|
void Sys_S_BeginPainting()
|
||||||
{
|
{
|
||||||
if (!audio.valid)
|
if (!audio.valid)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1060,21 +1060,26 @@ typedef struct {
|
||||||
void *evPtr; // this must be manually freed if not NULL
|
void *evPtr; // this must be manually freed if not NULL
|
||||||
} sysEvent_t;
|
} sysEvent_t;
|
||||||
|
|
||||||
sysEvent_t Sys_GetEvent();
|
sysEvent_t Sys_GetEvent();
|
||||||
|
|
||||||
void Sys_Init();
|
void Sys_Init();
|
||||||
void Sys_Quit( int status ); // status is the engine's exit code
|
void Sys_Quit( int status ); // status is the engine's exit code
|
||||||
|
|
||||||
// both of these must handle duplicate calls correctly
|
// both of these must handle duplicate calls correctly
|
||||||
void Sys_InitInput();
|
// and are only called in a full input subsystem restart (i.e. in_restart)
|
||||||
void Sys_ShutdownInput();
|
void Sys_InitInput();
|
||||||
|
void Sys_ShutdownInput();
|
||||||
|
|
||||||
// general development dll loading for virtual machine testing
|
// general development dll loading for virtual machine testing
|
||||||
void* QDECL Sys_LoadDll( const char* name, dllSyscall_t *entryPoint, dllSyscall_t systemcalls );
|
void* QDECL Sys_LoadDll( const char* name, dllSyscall_t *entryPoint, dllSyscall_t systemcalls );
|
||||||
void Sys_UnloadDll( void* dllHandle );
|
void Sys_UnloadDll( void* dllHandle );
|
||||||
|
|
||||||
void QDECL Sys_Error( const char *error, ...);
|
void QDECL Sys_Error( const char *error, ...);
|
||||||
char *Sys_GetClipboardData( void ); // note that this isn't journaled...
|
|
||||||
|
// allowed to fail and return NULL
|
||||||
|
// if it succeeds, returns memory allocated by Z_Malloc
|
||||||
|
// note that this isn't journaled
|
||||||
|
char *Sys_GetClipboardData( void );
|
||||||
|
|
||||||
void Sys_Print( const char *msg );
|
void Sys_Print( const char *msg );
|
||||||
|
|
||||||
|
@ -1083,30 +1088,28 @@ void Sys_Print( const char *msg );
|
||||||
int Sys_Milliseconds();
|
int Sys_Milliseconds();
|
||||||
|
|
||||||
// the system console is shown when a dedicated server is running
|
// the system console is shown when a dedicated server is running
|
||||||
void Sys_DisplaySystemConsole( qbool show );
|
|
||||||
|
|
||||||
void Sys_ShowConsole( int level, qbool quitOnClose );
|
void Sys_ShowConsole( int level, qbool quitOnClose );
|
||||||
|
|
||||||
void Sys_SetErrorText( const char *text );
|
void Sys_SetErrorText( const char *text );
|
||||||
|
|
||||||
|
// net_ip.cpp
|
||||||
|
// system-specific but not implemented in the platform layer
|
||||||
qbool Sys_GetPacket( netadr_t* net_from, msg_t* net_message );
|
qbool Sys_GetPacket( netadr_t* net_from, msg_t* net_message );
|
||||||
void Sys_SendPacket( int length, const void *data, netadr_t to );
|
void Sys_SendPacket( int length, const void *data, netadr_t to );
|
||||||
|
qbool Sys_StringToAdr( const char *s, netadr_t *a ); // does NOT parse port numbers, only base addresses
|
||||||
qbool Sys_StringToAdr( const char *s, netadr_t *a );
|
|
||||||
//Does NOT parse port numbers, only base addresses.
|
|
||||||
|
|
||||||
qbool Sys_IsLANAddress( const netadr_t& adr );
|
qbool Sys_IsLANAddress( const netadr_t& adr );
|
||||||
void Sys_ShowIP();
|
void Sys_ShowIP();
|
||||||
|
|
||||||
void Sys_Mkdir( const char* path );
|
void Sys_Mkdir( const char* path );
|
||||||
const char* Sys_Cwd();
|
const char* Sys_Cwd();
|
||||||
const char* Sys_DefaultHomePath();
|
const char* Sys_DefaultHomePath();
|
||||||
|
|
||||||
char** Sys_ListFiles( const char *directory, const char *extension, const char *filter, int *numfiles, qbool wantsubs );
|
char** Sys_ListFiles( const char *directory, const char *extension, const char *filter, int *numfiles, qbool wantsubs );
|
||||||
void Sys_FreeFileList( char **list );
|
void Sys_FreeFileList( char **list );
|
||||||
|
|
||||||
qbool Sys_LowPhysicalMemory( void );
|
qbool Sys_LowPhysicalMemory( void );
|
||||||
|
|
||||||
qbool Sys_HardReboot(); // qtrue when the server can restart itself
|
qbool Sys_HardReboot(); // qtrue when the server can restart itself
|
||||||
|
|
||||||
qbool Sys_HasCNQ3Parent(); // qtrue if a child of CNQ3
|
qbool Sys_HasCNQ3Parent(); // qtrue if a child of CNQ3
|
||||||
int Sys_GetUptimeSeconds( qbool parent ); // negative if not available
|
int Sys_GetUptimeSeconds( qbool parent ); // negative if not available
|
||||||
|
|
|
@ -55,12 +55,8 @@ static const char *DSoundError( int error ) {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
==================
|
void Sys_S_Shutdown( void ) {
|
||||||
SNDDMA_Shutdown
|
|
||||||
==================
|
|
||||||
*/
|
|
||||||
void SNDDMA_Shutdown( void ) {
|
|
||||||
Com_DPrintf( "Shutting down sound system\n" );
|
Com_DPrintf( "Shutting down sound system\n" );
|
||||||
|
|
||||||
if ( pDS ) {
|
if ( pDS ) {
|
||||||
|
@ -124,7 +120,7 @@ static qbool SNDDMA_InitDS()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Com_Printf("failed\n");
|
Com_Printf("failed\n");
|
||||||
SNDDMA_Shutdown();
|
Sys_S_Shutdown();
|
||||||
return qfalse;
|
return qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +130,7 @@ static qbool SNDDMA_InitDS()
|
||||||
|
|
||||||
if ( DS_OK != pDS->SetCooperativeLevel( g_wv.hWnd, DSSCL_PRIORITY ) ) {
|
if ( DS_OK != pDS->SetCooperativeLevel( g_wv.hWnd, DSSCL_PRIORITY ) ) {
|
||||||
Com_Printf ("failed\n");
|
Com_Printf ("failed\n");
|
||||||
SNDDMA_Shutdown();
|
Sys_S_Shutdown();
|
||||||
return qfalse;
|
return qfalse;
|
||||||
}
|
}
|
||||||
Com_DPrintf("ok\n" );
|
Com_DPrintf("ok\n" );
|
||||||
|
@ -173,7 +169,7 @@ static qbool SNDDMA_InitDS()
|
||||||
dsbuf.dwFlags = DSBCAPS_LOCSOFTWARE | DSBCAPS_GETCURRENTPOSITION2;
|
dsbuf.dwFlags = DSBCAPS_LOCSOFTWARE | DSBCAPS_GETCURRENTPOSITION2;
|
||||||
if (DS_OK != pDS->CreateSoundBuffer( &dsbuf, &pDSBuf, NULL )) {
|
if (DS_OK != pDS->CreateSoundBuffer( &dsbuf, &pDSBuf, NULL )) {
|
||||||
Com_Printf( "failed\n" );
|
Com_Printf( "failed\n" );
|
||||||
SNDDMA_Shutdown();
|
Sys_S_Shutdown();
|
||||||
return qfalse;
|
return qfalse;
|
||||||
}
|
}
|
||||||
Com_DPrintf( "forced to software. ok\n" );
|
Com_DPrintf( "forced to software. ok\n" );
|
||||||
|
@ -182,14 +178,14 @@ static qbool SNDDMA_InitDS()
|
||||||
// Make sure mixer is active
|
// Make sure mixer is active
|
||||||
if ( DS_OK != pDSBuf->Play( 0, 0, DSBPLAY_LOOPING ) ) {
|
if ( DS_OK != pDSBuf->Play( 0, 0, DSBPLAY_LOOPING ) ) {
|
||||||
Com_Printf ("*** Looped sound play failed ***\n");
|
Com_Printf ("*** Looped sound play failed ***\n");
|
||||||
SNDDMA_Shutdown ();
|
Sys_S_Shutdown ();
|
||||||
return qfalse;
|
return qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the returned buffer size
|
// get the returned buffer size
|
||||||
if ( DS_OK != pDSBuf->GetCaps(&dsbcaps) ) {
|
if ( DS_OK != pDSBuf->GetCaps(&dsbcaps) ) {
|
||||||
Com_Printf ("*** GetCaps failed ***\n");
|
Com_Printf ("*** GetCaps failed ***\n");
|
||||||
SNDDMA_Shutdown ();
|
Sys_S_Shutdown ();
|
||||||
return qfalse;
|
return qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,16 +200,16 @@ static qbool SNDDMA_InitDS()
|
||||||
|
|
||||||
sample16 = (dma.samplebits/8) - 1;
|
sample16 = (dma.samplebits/8) - 1;
|
||||||
|
|
||||||
SNDDMA_BeginPainting();
|
Sys_S_BeginPainting();
|
||||||
if (dma.buffer)
|
if (dma.buffer)
|
||||||
memset(dma.buffer, 0, dma.samples * dma.samplebits/8);
|
memset(dma.buffer, 0, dma.samples * dma.samplebits/8);
|
||||||
SNDDMA_Submit();
|
Sys_S_Submit();
|
||||||
|
|
||||||
return qtrue;
|
return qtrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
qbool SNDDMA_Init(void)
|
qbool Sys_S_Init(void)
|
||||||
{
|
{
|
||||||
CoInitialize(NULL);
|
CoInitialize(NULL);
|
||||||
|
|
||||||
|
@ -230,16 +226,7 @@ qbool SNDDMA_Init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
int Sys_S_GetDMAPos( void ) {
|
||||||
==============
|
|
||||||
SNDDMA_GetDMAPos
|
|
||||||
|
|
||||||
return the current sample position (in mono samples read)
|
|
||||||
inside the recirculating dma buffer, so the mixing code will know
|
|
||||||
how many sample are required to fill it up.
|
|
||||||
===============
|
|
||||||
*/
|
|
||||||
int SNDDMA_GetDMAPos( void ) {
|
|
||||||
MMTIME mmtime;
|
MMTIME mmtime;
|
||||||
int s;
|
int s;
|
||||||
DWORD dwWrite;
|
DWORD dwWrite;
|
||||||
|
@ -256,14 +243,8 @@ int SNDDMA_GetDMAPos( void ) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
==============
|
|
||||||
SNDDMA_BeginPainting
|
|
||||||
|
|
||||||
Makes sure dma.buffer is valid
|
void Sys_S_BeginPainting( void ) {
|
||||||
===============
|
|
||||||
*/
|
|
||||||
void SNDDMA_BeginPainting( void ) {
|
|
||||||
int reps;
|
int reps;
|
||||||
DWORD dwSize2;
|
DWORD dwSize2;
|
||||||
DWORD *pbuf, *pbuf2;
|
DWORD *pbuf, *pbuf2;
|
||||||
|
@ -309,15 +290,8 @@ void SNDDMA_BeginPainting( void ) {
|
||||||
dma.buffer = (unsigned char *)pbuf;
|
dma.buffer = (unsigned char *)pbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
==============
|
|
||||||
SNDDMA_Submit
|
|
||||||
|
|
||||||
Send sound to device if buffer isn't really the dma buffer
|
void Sys_S_Submit( void )
|
||||||
Also unlocks the dsound buffer
|
|
||||||
===============
|
|
||||||
*/
|
|
||||||
void SNDDMA_Submit( void )
|
|
||||||
{
|
{
|
||||||
if ( pDSBuf ) {
|
if ( pDSBuf ) {
|
||||||
pDSBuf->Unlock( dma.buffer, locksize, NULL, 0 );
|
pDSBuf->Unlock( dma.buffer, locksize, NULL, 0 );
|
||||||
|
@ -325,13 +299,7 @@ void SNDDMA_Submit( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
// Called in reaction to WM_ACTIVATE
|
||||||
=================
|
|
||||||
WIN_S_WindowActivate
|
|
||||||
|
|
||||||
Called in reaction to WM_ACTIVATE
|
|
||||||
=================
|
|
||||||
*/
|
|
||||||
void WIN_S_WindowActivate()
|
void WIN_S_WindowActivate()
|
||||||
{
|
{
|
||||||
if ( !pDS ) {
|
if ( !pDS ) {
|
||||||
|
@ -340,7 +308,6 @@ void WIN_S_WindowActivate()
|
||||||
|
|
||||||
if ( DS_OK != pDS->SetCooperativeLevel( g_wv.hWnd, DSSCL_PRIORITY ) ) {
|
if ( DS_OK != pDS->SetCooperativeLevel( g_wv.hWnd, DSSCL_PRIORITY ) ) {
|
||||||
Com_Printf ("sound SetCooperativeLevel failed\n");
|
Com_Printf ("sound SetCooperativeLevel failed\n");
|
||||||
SNDDMA_Shutdown();
|
Sys_S_Shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue