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/snd_dx/sound.h

244 lines
6.6 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
#include <windows.h>
#include "launch_api.h"
#include "qfiles_ref.h"
2010-04-21 22:00:00 +02:00
#include "engine_api.h" // trace_t declaration
2009-10-02 22:00:00 +02:00
#include "vsound_api.h"
2010-08-07 22:00:00 +02:00
#include "cl_entity.h"
2009-10-02 22:00:00 +02:00
2010-06-27 22:00:00 +02:00
extern stdlib_api_t com;
2009-10-02 22:00:00 +02:00
extern vsound_imp_t si;
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
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
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;
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 channels;
int samples; // mono samples in buffer
int submission_chunk; // don't mix less than this #
int samplepos; // in mono samples
int samplebits;
int speed;
byte *buffer;
} dma_t;
2010-06-27 22:00:00 +02:00
#include "vox.h"
typedef struct
{
double sample;
wavdata_t *pData;
double forcedEndSample;
bool m_finished;
int delaySamples;
} 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
int end; // end time in global paintsamples
int pos; // sample position in sfx
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-06-27 22:00:00 +02:00
bool isSentence; // bit who indicated sentence
int basePitch; // base pitch percent (100% is normal pitch playback)
float pitch; // real-time pitch after any modulation or shift by dynamic data
bool use_loop; // don't loop default and local sounds
bool staticsound; // use origin instead of fetching entnum's origin
2010-06-28 22:00:00 +02:00
bool localsound; // it's a local menu sound (not looped, not paused)
2010-06-27 22:00:00 +02:00
// sentence mixer
int wordIndex;
mixer_t currentWord;
voxword_t words[CVOXWORDMAX];
2009-10-02 22:00:00 +02:00
} channel_t;
2010-04-21 22:00:00 +02:00
typedef struct
{
vec3_t origin; // simorg
vec3_t vieworg; // simorg + view_ofs
vec3_t velocity;
vec3_t forward;
vec3_t right;
vec3_t up;
int entnum;
int waterlevel;
float frametime; // used for sound fade
2010-07-24 22:00:00 +02:00
bool active;
bool inmenu; // listener in-menu ?
2010-04-24 22:00:00 +02:00
bool paused;
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;
2009-10-02 22:00:00 +02:00
} bg_track_t;
/*
====================================================================
SYSTEM SPECIFIC FUNCTIONS
====================================================================
*/
2010-04-21 22:00:00 +02:00
#define Host_Error com.error
2009-10-02 22:00:00 +02:00
#define Z_Malloc( size ) Mem_Alloc( sndpool, size )
2010-06-27 22:00:00 +02:00
// initializes cycling through a DMA buffer and returns information on it
bool SNDDMA_Init( void *hInst );
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
//====================================================================
#define MAX_DYNAMIC_CHANNELS 24
#define MAX_CHANNELS 128
#define MAX_RAW_SAMPLES 8192
extern portable_samplepair_t paintbuffer[];
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;
2009-10-02 22:00:00 +02:00
2010-06-27 22:00:00 +02:00
extern cvar_t *s_check_errors;
extern cvar_t *s_volume;
extern cvar_t *s_musicvolume;
extern cvar_t *s_khz;
extern cvar_t *s_show;
extern cvar_t *s_mixahead;
extern cvar_t *s_primary;
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 );
void S_PaintChannels( int endtime );
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
void S_BeginFrame( void );
2010-06-27 22:00:00 +02:00
// s_load.c
bool S_TestSoundChar( const char *pch, char c );
char *S_SkipSoundChar( const char *pch );
sfx_t *S_FindName( const char *name, int *pfInCache );
// s_dsp.c
2009-10-10 22:00:00 +02:00
void SX_Init( void );
void SX_Free( void );
void SX_RoomFX( int endtime, int fFilter, int fTimefx );
2010-06-24 22:00:00 +02:00
bool S_Init( void *hInst );
2010-06-27 22:00:00 +02:00
void S_Shutdown( void );
2010-07-01 22:00:00 +02:00
void S_Activate( bool active, void *hInst );
2010-06-27 22:00:00 +02:00
void S_SoundList_f( void );
void S_SoundInfo_f( void );
// if origin is NULL, the sound will be dynamically sourced from the entity
void S_StartSound( const vec3_t pos, int ent, int chan, sound_t sfx, float vol, float attn, int pitch, int flags );
void S_StaticSound( const vec3_t pos, int ent, int chan, sound_t handle, float fvol, float attn, int pitch, int flags );
channel_t *SND_PickDynamicChannel( int entnum, int channel, sfx_t *sfx );
channel_t *SND_PickStaticChannel( int entnum, sfx_t *sfx );
2009-11-25 22:00:00 +01:00
void S_FadeClientVolume( float fadePercent, float fadeOutSeconds, float holdTime, float fadeInSeconds );
2010-06-28 22:00:00 +02:00
void S_StartLocalSound( const char *name );
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 );
2010-08-12 22:00:00 +02:00
void S_RenderFrame( struct ref_params_s *fd );
2010-06-27 22:00:00 +02:00
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
//
void S_StartStreaming( void );
void S_StopStreaming( void );
void S_StreamRawSamples( int samples, int rate, int width, int channels, const byte *data );
void S_StartBackgroundTrack( const char *intro, const char *loop );
void S_StreamBackgroundTrack( void );
void S_StopBackgroundTrack( 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 );
int S_GetOutputData( wavdata_t *pSource, void **pData, int samplePosition, int sampleCount );
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-06-28 22:00:00 +02:00
wavdata_t *VOX_LoadNextWord( channel_t *pchan );
2010-06-24 22:00:00 +02:00
2010-06-27 22:00:00 +02:00
void S_BeginRegistration( void );
sound_t S_RegisterSound( const char *sample );
void S_EndRegistration( void );
2009-10-02 22:00:00 +02:00
#endif//SOUND_H