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

208 lines
5.8 KiB
C
Raw Normal View History

2009-10-02 22:00:00 +02:00
//=======================================================================
// Copyright XashXT Group 2009 <20>
// 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;
2009-10-11 22:00:00 +02:00
} portable_samplepair_t;
2009-10-02 22:00:00 +02:00
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;
2009-11-23 22:00:00 +01:00
int touchFrame;
2009-10-02 22:00:00 +02:00
bool default_sound;
2009-11-23 22:00:00 +01:00
uint hashValue;
struct sfx_s *hashNext;
2009-10-02 22:00:00 +02:00
} 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;
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;
2009-10-11 22:00:00 +02:00
typedef struct
2009-10-02 22:00:00 +02:00
{
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
2009-10-11 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
2009-10-02 22:00:00 +02:00
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
2009-10-11 22:00:00 +02:00
bool fsentence; // bit who indicated sentence
bool use_delay; // delayed start
2009-10-02 22:00:00 +02:00
} 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
2009-10-11 22:00:00 +02:00
extern portable_samplepair_t paintbuffer[];
2009-10-02 22:00:00 +02:00
extern channel_t channels[MAX_CHANNELS];
2009-10-11 22:00:00 +02:00
extern int total_channels;
2009-10-02 22:00:00 +02:00
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;
2009-10-11 22:00:00 +02:00
extern int listener_waterlevel;
2009-10-02 22:00:00 +02:00
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;
2009-10-11 22:00:00 +02:00
extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
2009-10-02 22:00:00 +02:00
void S_InitScaletable( void );
2009-10-11 22:00:00 +02:00
sfxcache_t *S_LoadSound( sfx_t *sfx );
2009-10-02 22:00:00 +02:00
void S_IssuePlaysound( playsound_t *ps );
void S_PaintChannels( int endtime );
2009-10-11 22:00:00 +02:00
// s_load.c
bool S_TestSoundChar( const char *pch, char c );
2009-10-10 22:00:00 +02:00
// s_dsp.c
void SX_Init( void );
void SX_Free( void );
void SX_RoomFX( int endtime, int fFilter, int fTimefx );
2009-10-02 22:00:00 +02:00
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
2009-10-11 22:00:00 +02:00
void S_StartSound( const vec3_t pos, int ent, int chan, sound_t sfx, float vol, float attn, float pitch, int flags );
2009-10-02 22:00:00 +02:00
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 );
2009-11-25 22:00:00 +01:00
void S_FadeClientVolume( float fadePercent, float fadeOutSeconds, float holdTime, float fadeInSeconds );
2009-10-02 22:00:00 +02:00
int S_StartLocalSound( const char *name, float volume, float pitch, const float *org );
sfx_t *S_GetSfxByHandle( sound_t handle );
void S_StopBackgroundTrack( void );
2009-10-06 22:00:00 +02:00
void S_Update( ref_params_t *fd );
2009-10-02 22:00:00 +02:00
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