220 lines
6.2 KiB
C
220 lines
6.2 KiB
C
//=======================================================================
|
|
// Copyright XashXT Group 2009 ©
|
|
// sound.h - sndlib main header
|
|
//=======================================================================
|
|
|
|
#ifndef SOUND_H
|
|
#define SOUND_H
|
|
|
|
#include <windows.h>
|
|
#include "launch_api.h"
|
|
#include "qfiles_ref.h"
|
|
#include "vsound_api.h"
|
|
|
|
extern stdlib_api_t com;
|
|
extern vsound_imp_t si;
|
|
extern byte *sndpool;
|
|
|
|
#include "mathlib.h"
|
|
|
|
typedef struct
|
|
{
|
|
int left;
|
|
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;
|
|
|
|
int touchFrame;
|
|
bool default_sound;
|
|
uint hashValue;
|
|
struct sfx_s *hashNext;
|
|
} sfx_t;
|
|
|
|
// a playsound_t will be generated by each call to S_StartSound,
|
|
// when the mixer reaches playsound->begin, the playsound will
|
|
// be assigned to a channel
|
|
typedef struct playsound_s
|
|
{
|
|
struct playsound_s *prev, *next;
|
|
sfx_t *sfx;
|
|
float volume;
|
|
float attenuation;
|
|
int entnum;
|
|
int entchannel;
|
|
bool fixed_origin; // use origin field instead of entnum's origin
|
|
bool use_loop;
|
|
vec3_t origin;
|
|
uint begin; // begin on this sample
|
|
} playsound_t;
|
|
|
|
// structure used for fading in and out client sound volume.
|
|
typedef struct
|
|
{
|
|
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;
|
|
|
|
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;
|
|
|
|
typedef struct
|
|
{
|
|
sfx_t *sfx; // sfx number
|
|
int leftvol; // 0-255 volume
|
|
int rightvol; // 0-255 volume
|
|
int end; // end time in global paintsamples
|
|
int pos; // sample position in sfx
|
|
int basePitch; // base pitch percent (100% is normal pitch playback)
|
|
float pitch; // real-time pitch after any modulation or shift by dynamic data
|
|
int looping; // where to loop, -1 = no looping OBSOLETE?
|
|
int entnum; // to allow overriding a specific sound
|
|
int loopnum; // entity num that playing autosound
|
|
int loopframe; // for stopping looping sounds
|
|
int entchannel; //
|
|
vec3_t origin; // only use if fixed_origin is set
|
|
vec_t dist_mult; // distance multiplier (attenuation/clipK)
|
|
int master_vol; // 0-255 master volume
|
|
bool fixed_origin; // use origin instead of fetching entnum's origin
|
|
bool autosound; // from an entity->sound, cleared each frame
|
|
bool use_loop; // don't loop default and local sounds
|
|
bool fsentence; // bit who indicated sentence
|
|
bool use_delay; // delayed start
|
|
} channel_t;
|
|
|
|
typedef struct
|
|
{
|
|
int rate;
|
|
int width;
|
|
int channels;
|
|
int loopstart;
|
|
int samples;
|
|
int dataofs; // chunk starts this many bytes from file start
|
|
} wavinfo_t;
|
|
|
|
typedef struct
|
|
{
|
|
string introName;
|
|
string loopName;
|
|
bool looping;
|
|
file_t *file;
|
|
int start;
|
|
int rate;
|
|
uint format;
|
|
void *vorbisFile;
|
|
} bg_track_t;
|
|
|
|
/*
|
|
====================================================================
|
|
|
|
SYSTEM SPECIFIC FUNCTIONS
|
|
|
|
====================================================================
|
|
*/
|
|
#define Host_Error com.error
|
|
#define Z_Malloc( size ) Mem_Alloc( sndpool, size )
|
|
|
|
// initializes cycling through a DMA buffer and returns information on it
|
|
bool SNDDMA_Init( void *hInst );
|
|
int SNDDMA_GetDMAPos( void );
|
|
void SNDDMA_Shutdown( void );
|
|
void SNDDMA_BeginPainting( void );
|
|
void SNDDMA_Submit( void );
|
|
|
|
//====================================================================
|
|
|
|
#define MAX_CHANNELS 64
|
|
#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 vec3_t listener_origin;
|
|
extern vec3_t listener_forward;
|
|
extern vec3_t listener_right;
|
|
extern vec3_t listener_up;
|
|
extern int listener_waterlevel;
|
|
extern dma_t dma;
|
|
extern playsound_t s_pendingplays;
|
|
extern bool sound_started;
|
|
|
|
extern cvar_t *s_check_errors;
|
|
extern cvar_t *s_volume;
|
|
extern cvar_t *s_nosound;
|
|
extern cvar_t *s_loadas8bit;
|
|
extern cvar_t *s_khz;
|
|
extern cvar_t *s_show;
|
|
extern cvar_t *s_mixahead;
|
|
extern cvar_t *s_testsound;
|
|
extern cvar_t *s_primary;
|
|
|
|
extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
|
|
|
|
void S_InitScaletable( void );
|
|
sfxcache_t *S_LoadSound( sfx_t *sfx );
|
|
void S_IssuePlaysound( playsound_t *ps );
|
|
void S_PaintChannels( int endtime );
|
|
float S_GetMasterVolume( void );
|
|
|
|
// s_load.c
|
|
bool S_TestSoundChar( const char *pch, char c );
|
|
|
|
// s_dsp.c
|
|
void SX_Init( void );
|
|
void SX_Free( void );
|
|
void SX_RoomFX( int endtime, int fFilter, int fTimefx );
|
|
|
|
bool S_Init( void *hInst );
|
|
void S_Shutdown( void );
|
|
void S_Activate( bool active );
|
|
void S_SoundList_f( void );
|
|
void S_SoundInfo_f( void );
|
|
|
|
// if origin is NULL, the sound will be dynamically sourced from the entity
|
|
void S_StartSound( const vec3_t pos, int ent, int chan, sound_t sfx, float vol, float attn, float pitch, int flags );
|
|
void S_StreamRawSamples( int samples, int rate, int width, int channels, const byte *data );
|
|
bool S_AddLoopingSound( int entnum, sound_t handle, float volume, float attn );
|
|
void S_StartBackgroundTrack( const char *intro, const char *loop );
|
|
channel_t *S_PickChannel( int entNum, int entChannel );
|
|
void S_FadeClientVolume( float fadePercent, float fadeOutSeconds, float holdTime, float fadeInSeconds );
|
|
int S_StartLocalSound( const char *name, float volume, float pitch, const float *org );
|
|
sfx_t *S_GetSfxByHandle( sound_t handle );
|
|
void S_StopBackgroundTrack( void );
|
|
void S_Update( ref_params_t *fd );
|
|
void S_StartStreaming( void );
|
|
void S_StopStreaming( void );
|
|
void S_StopAllSounds( void );
|
|
void S_FreeSounds( void );
|
|
|
|
void S_BeginRegistration( void );
|
|
sound_t S_RegisterSound( const char *sample );
|
|
void S_EndRegistration( void );
|
|
|
|
#endif//SOUND_H
|