This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/engine/client/sound.h

280 lines
8.3 KiB
C
Raw Normal View History

2009-10-02 22:00:00 +02:00
//=======================================================================
// Copyright XashXT Group 2009 <20>
2010-06-27 22:00:00 +02:00
// sound.h - sndlib main header
2009-10-02 22:00:00 +02:00
//=======================================================================
#ifndef SOUND_H
#define SOUND_H
2010-06-27 22:00:00 +02:00
extern byte *sndpool;
2009-10-02 22:00:00 +02:00
2010-06-27 22:00:00 +02:00
#include "mathlib.h"
2009-10-02 22:00:00 +02:00
2010-08-15 22:00:00 +02:00
// local flags (never sending acorss the net)
#define SND_LOCALSOUND (1<<9) // not paused, not looped, for internal use
#define SND_STOP_LOOPING (1<<10) // stop all looping sounds on the entity.
2010-09-16 22:00:00 +02:00
// sound engine rate defines
#define SOUND_DMA_SPEED 44100 // hardware playback rate
#define SOUND_11k 11025 // 11khz sample rate
#define SOUND_22k 22050 // 22khz sample rate
#define SOUND_44k 44100 // 44khz sample rate
2010-09-12 22:00:00 +02:00
// fixed point stuff for real-time resampling
#define FIX_BITS 28
#define FIX_SCALE (1 << FIX_BITS)
#define FIX_MASK ((1 << FIX_BITS)-1)
#define FIX_FLOAT(a) ((int)((a) * FIX_SCALE))
#define FIX(a) (((int)(a)) << FIX_BITS)
#define FIX_INTPART(a) (((int)(a)) >> FIX_BITS)
#define FIX_FRACTION(a,b) (FIX(a)/(b))
#define FIX_FRACPART(a) ((a) & FIX_MASK)
2010-09-16 22:00:00 +02:00
#define CLIP( x ) (( x ) > 32767 ? 32767 : (( x ) < -32767 ? -32767 : ( x )))
#define SWAP( a, b, t ) {(t) = (a); (a) = (b); (b) = (t);}
#define AVG( a, b ) (((a) + (b)) >> 1 )
#define AVG4( a, b, c, d ) (((a) + (b) + (c) + (d)) >> 2 )
#define PAINTBUFFER_SIZE 1024 // 44k: was 512
#define PAINTBUFFER (g_curpaintbuffer)
#define CPAINTBUFFERS 3
2009-10-02 22:00:00 +02:00
typedef struct
{
int left;
int right;
2009-10-11 22:00:00 +02:00
} portable_samplepair_t;
2009-10-02 22:00:00 +02:00
2010-09-16 22:00:00 +02:00
// sound mixing buffer
#define CPAINTFILTERMEM 3
#define CPAINTFILTERS 4 // maximum number of consecutive upsample passes per paintbuffer
typedef struct
{
2010-10-26 22:00:00 +02:00
qboolean factive; // if true, mix to this paintbuffer using flags
2010-09-16 22:00:00 +02:00
portable_samplepair_t *pbuf; // front stereo mix buffer, for 2 or 4 channel mixing
int ifilter; // current filter memory buffer to use for upsampling pass
portable_samplepair_t fltmem[CPAINTFILTERS][CPAINTFILTERMEM];
} paintbuffer_t;
2009-10-02 22:00:00 +02:00
typedef struct sfx_s
{
string name;
2010-04-20 22:00:00 +02:00
wavdata_t *cache;
2009-10-02 22:00:00 +02:00
2009-11-23 22:00:00 +01:00
int touchFrame;
uint hashValue;
struct sfx_s *hashNext;
2009-10-02 22:00:00 +02:00
} sfx_t;
2010-09-16 22:00:00 +02:00
extern portable_samplepair_t drybuffer[];
extern portable_samplepair_t paintbuffer[];
extern portable_samplepair_t roombuffer[];
extern portable_samplepair_t temppaintbuffer[];
extern portable_samplepair_t *g_curpaintbuffer;
extern paintbuffer_t paintbuffers[];
2009-12-06 22:00:00 +01:00
// structure used for fading in and out client sound volume.
typedef struct
{
float initial_percent;
float percent; // how far to adjust client's volume down by.
float starttime; // GetHostTime() when we started adjusting volume
float fadeouttime; // # of seconds to get to faded out state
float holdtime; // # of seconds to hold
float fadeintime; // # of seconds to restore
} soundfade_t;
2009-10-02 22:00:00 +02:00
typedef struct
{
int samples; // mono samples in buffer
int samplepos; // in mono samples
byte *buffer;
2010-11-20 22:00:00 +01:00
qboolean initialized; // sound engine is active
2009-10-02 22:00:00 +02:00
} dma_t;
2010-06-27 22:00:00 +02:00
#include "vox.h"
typedef struct
{
double sample;
wavdata_t *pData;
double forcedEndSample;
2010-10-26 22:00:00 +02:00
qboolean finished;
2010-06-27 22:00:00 +02:00
} mixer_t;
2009-10-11 22:00:00 +02:00
typedef struct
2009-10-02 22:00:00 +02:00
{
sfx_t *sfx; // sfx number
2010-06-27 22:00:00 +02:00
int leftvol; // 0-255 left volume
int rightvol; // 0-255 right volume
int entnum; // entity soundsource
int entchannel; // sound channel (CHAN_STREAM, CHAN_VOICE, etc.)
vec3_t origin; // only use if fixed_origin is set
float dist_mult; // distance multiplier (attenuation/clipK)
2010-04-21 22:00:00 +02:00
int master_vol; // 0-255 master volume
2010-10-26 22:00:00 +02:00
qboolean isSentence; // bit who indicated sentence
2010-06-27 22:00:00 +02:00
int basePitch; // base pitch percent (100% is normal pitch playback)
float pitch; // real-time pitch after any modulation or shift by dynamic data
2010-10-26 22:00:00 +02:00
qboolean use_loop; // don't loop default and local sounds
qboolean staticsound; // use origin instead of fetching entnum's origin
qboolean localsound; // it's a local menu sound (not looped, not paused)
qboolean bdry; // if true, bypass all dsp processing for this sound (ie: music)
2010-09-12 22:00:00 +02:00
mixer_t pMixer;
2010-06-27 22:00:00 +02:00
// sentence mixer
int wordIndex;
2010-09-12 22:00:00 +02:00
mixer_t *currentWord; // NULL if sentence is finished
2010-06-27 22:00:00 +02:00
voxword_t words[CVOXWORDMAX];
2009-10-02 22:00:00 +02:00
} channel_t;
2010-04-21 22:00:00 +02:00
typedef struct
{
2010-09-02 22:00:00 +02:00
vec3_t origin; // simorg + view_ofs
2010-04-21 22:00:00 +02:00
vec3_t velocity;
vec3_t forward;
vec3_t right;
vec3_t up;
int entnum;
int waterlevel;
float frametime; // used for sound fade
2010-10-26 22:00:00 +02:00
qboolean active;
qboolean inmenu; // listener in-menu ?
qboolean paused;
qboolean streaming; // playing AVI-file
2010-11-18 22:00:00 +01:00
qboolean lerping; // lerp stream ?
2010-11-19 22:00:00 +01:00
qboolean stream_paused; // pause only background track
2010-04-21 22:00:00 +02:00
} listener_t;
2009-10-02 22:00:00 +02:00
typedef struct
{
string loopName;
2010-04-27 22:00:00 +02:00
stream_t *stream;
2010-11-22 22:00:00 +01:00
int source; // may be game, menu, etc
2009-10-02 22:00:00 +02:00
} bg_track_t;
/*
====================================================================
SYSTEM SPECIFIC FUNCTIONS
====================================================================
*/
2010-06-27 22:00:00 +02:00
// initializes cycling through a DMA buffer and returns information on it
2010-10-26 22:00:00 +02:00
qboolean SNDDMA_Init( void *hInst );
2010-06-27 22:00:00 +02:00
int SNDDMA_GetSoundtime( void );
void SNDDMA_Shutdown( void );
void SNDDMA_BeginPainting( void );
void SNDDMA_Submit( void );
2009-10-02 22:00:00 +02:00
2010-06-27 22:00:00 +02:00
//====================================================================
2010-10-16 22:00:00 +02:00
#define MAX_DYNAMIC_CHANNELS 28
2010-06-27 22:00:00 +02:00
#define MAX_CHANNELS 128
#define MAX_RAW_SAMPLES 8192
extern channel_t channels[MAX_CHANNELS];
extern int total_channels;
extern int paintedtime;
extern int s_rawend;
extern int soundtime;
extern dma_t dma;
extern listener_t s_listener;
2010-09-16 22:00:00 +02:00
extern int idsp_room;
2009-10-02 22:00:00 +02:00
2010-10-22 22:00:00 +02:00
extern convar_t *s_check_errors;
extern convar_t *s_volume;
extern convar_t *s_musicvolume;
extern convar_t *s_show;
extern convar_t *s_mixahead;
extern convar_t *s_lerping;
extern convar_t *dsp_off;
2009-10-02 22:00:00 +02:00
2010-06-27 22:00:00 +02:00
extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
2009-10-02 22:00:00 +02:00
2010-06-27 22:00:00 +02:00
void S_InitScaletable( void );
wavdata_t *S_LoadSound( sfx_t *sfx );
float S_GetMasterVolume( void );
2010-04-21 22:00:00 +02:00
void S_PrintDeviceName( void );
2009-10-02 22:00:00 +02:00
2010-06-24 22:00:00 +02:00
//
2010-06-27 22:00:00 +02:00
// s_main.c
2010-06-24 22:00:00 +02:00
//
2010-06-27 22:00:00 +02:00
void S_FreeChannel( channel_t *ch );
2010-06-28 22:00:00 +02:00
2010-09-12 22:00:00 +02:00
//
// s_mix.c
//
int S_MixDataToDevice( channel_t *pChannel, int sampleCount, int outputRate, int outputOffset );
2010-10-26 22:00:00 +02:00
void MIX_ClearAllPaintBuffers( int SampleCount, qboolean clearFilters );
2010-09-16 22:00:00 +02:00
void MIX_InitAllPaintbuffers( void );
void MIX_FreeAllPaintbuffers( void );
void MIX_PaintChannels( int endtime );
2010-06-27 22:00:00 +02:00
// s_load.c
2010-10-26 22:00:00 +02:00
qboolean S_TestSoundChar( const char *pch, char c );
2010-06-27 22:00:00 +02:00
char *S_SkipSoundChar( const char *pch );
sfx_t *S_FindName( const char *name, int *pfInCache );
2010-09-12 22:00:00 +02:00
void S_FreeSound( sfx_t *sfx );
2010-06-27 22:00:00 +02:00
// s_dsp.c
2010-10-26 22:00:00 +02:00
qboolean AllocDsps( void );
2010-09-16 22:00:00 +02:00
void FreeDsps( void );
void CheckNewDspPresets( void );
void DSP_Process( int idsp, portable_samplepair_t *pbfront, int sampleCount );
float DSP_GetGain( int idsp );
void DSP_ClearState( void );
2010-12-21 22:00:00 +01:00
qboolean S_Init( void );
2010-06-27 22:00:00 +02:00
void S_Shutdown( void );
2010-10-26 22:00:00 +02:00
void S_Activate( qboolean active, void *hInst );
2010-06-27 22:00:00 +02:00
void S_SoundList_f( void );
void S_SoundInfo_f( void );
channel_t *SND_PickDynamicChannel( int entnum, int channel, sfx_t *sfx );
channel_t *SND_PickStaticChannel( int entnum, sfx_t *sfx );
2010-12-25 22:00:00 +01:00
int S_GetCurrentStaticSounds( soundlist_t *pout, int size );
2010-06-27 22:00:00 +02:00
sfx_t *S_GetSfxByHandle( sound_t handle );
void S_StopSound( int entnum, int channel, const char *soundname );
void S_StopAllSounds( void );
void S_FreeSounds( void );
2009-10-02 22:00:00 +02:00
2010-04-21 22:00:00 +02:00
//
// s_mouth.c
//
void SND_InitMouth( int entnum, int entchannel );
2010-06-27 22:00:00 +02:00
void SND_MoveMouth8( channel_t *ch, wavdata_t *pSource, int count );
2010-04-21 22:00:00 +02:00
void SND_CloseMouth( channel_t *ch );
2010-04-27 22:00:00 +02:00
//
// s_stream.c
//
2010-09-30 22:00:00 +02:00
void S_StreamSoundTrack( void );
2010-04-27 22:00:00 +02:00
void S_StreamBackgroundTrack( void );
2010-06-27 22:00:00 +02:00
//
// s_utils.c
//
int S_ZeroCrossingAfter( wavdata_t *pWaveData, int sample );
int S_ZeroCrossingBefore( wavdata_t *pWaveData, int sample );
2010-10-26 22:00:00 +02:00
int S_GetOutputData( wavdata_t *pSource, void **pData, int samplePosition, int sampleCount, qboolean use_loop );
2010-09-12 22:00:00 +02:00
void S_SetSampleStart( channel_t *pChan, wavdata_t *pSource, int newPosition );
void S_SetSampleEnd( channel_t *pChan, wavdata_t *pSource, int newEndPosition );
2010-11-26 22:00:00 +01:00
float S_SimpleSpline( float value );
2010-06-24 22:00:00 +02:00
2010-06-27 22:00:00 +02:00
//
// s_vox.c
//
void VOX_Init( void );
void VOX_Shutdown( void );
void VOX_SetChanVol( channel_t *ch );
void VOX_LoadSound( channel_t *pchan, const char *psz );
2010-09-12 22:00:00 +02:00
float VOX_ModifyPitch( channel_t *ch, float pitch );
int VOX_MixDataToDevice( channel_t *pChannel, int sampleCount, int outputRate, int outputOffset );
2010-06-24 22:00:00 +02:00
2009-10-02 22:00:00 +02:00
#endif//SOUND_H