Cleanup local.h of the sound system

This commit is contained in:
Yamagi Burmeister 2013-04-20 14:20:58 +02:00
parent d9cd053461
commit 720db15de9
3 changed files with 195 additions and 68 deletions

View file

@ -56,11 +56,13 @@ cvar_t *s_sdldriver;
int *snd_p;
static sound_t *backend;
static portable_samplepair_t paintbuffer[SDL_PAINTBUFFER_SIZE];
static int beginofs;
static int playpos = 0;
static int samplesize = 0;
static int snd_inited = 0;
static int snd_scaletable[32][256];
static int snd_vol;
static int soundtime;
/* ------------------------------------------------------------------ */
@ -450,21 +452,21 @@ SDL_PaintChannels(int endtime)
int
SDL_DriftBeginofs(float timeofs)
{
int start = (int)(cl.frame.servertime * 0.001f * sound.speed + s_beginofs);
int start = (int)(cl.frame.servertime * 0.001f * sound.speed + beginofs);
if (start < paintedtime)
{
start = paintedtime;
s_beginofs = (int)(start - (cl.frame.servertime * 0.001f * sound.speed));
beginofs = (int)(start - (cl.frame.servertime * 0.001f * sound.speed));
}
else if (start > paintedtime + 0.3f * sound.speed)
{
start = (int)(paintedtime + 0.1f * sound.speed);
s_beginofs = (int)(start - (cl.frame.servertime * 0.001f * sound.speed));
beginofs = (int)(start - (cl.frame.servertime * 0.001f * sound.speed));
}
else
{
s_beginofs -= 10;
beginofs -= 10;
}
return timeofs ? start + timeofs * sound.speed : paintedtime;
@ -1318,7 +1320,10 @@ SDL_BackendInit(void)
SDL_PauseAudio(0);
Com_Printf("SDL audio initialized.\n");
soundtime = 0;
snd_inited = 1;
return 1;
}

View file

@ -19,7 +19,7 @@
*
* =======================================================================
*
* Local defines of the sound system
* Local defines for the sound system.
*
* =======================================================================
*/
@ -27,26 +27,39 @@
#ifndef CL_SOUND_LOCAL_H
#define CL_SOUND_LOCAL_H
#define MAX_CHANNELS 32
#define MAX_RAW_SAMPLES 8192
/*
* Holds one sample with 2 channels
*/
typedef struct
{
int left;
int right;
} portable_samplepair_t;
/*
* Holds a cached SFX and
* it's meta data
*/
typedef struct
{
int length;
int loopstart;
int speed; /* not needed, because converted on load? */
int speed;
int width;
#if USE_OPENAL
int size;
int bufnum;
#endif
int stereo;
byte data[1]; /* variable sized */
byte data[1];
} sfxcache_t;
/*
* Holds a SFX
*/
typedef struct sfx_s
{
char name[MAX_QPATH];
@ -55,9 +68,10 @@ typedef struct sfx_s
char *truename;
} 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 */
/* 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;
@ -66,11 +80,18 @@ typedef struct playsound_s
float attenuation;
int entnum;
int entchannel;
qboolean fixed_origin; /* use origin field instead of entnum's origin */
qboolean fixed_origin;
vec3_t origin;
unsigned begin; /* begin on this sample */
unsigned begin;
} playsound_t;
/*
* Interface to pass data and metadata
* between the frontend and the backends.
* Mainly used by the SDL backend, since
* the OpenAL backend has it's own AL
* based magic.
*/
typedef struct
{
int channels;
@ -82,6 +103,10 @@ typedef struct
unsigned char *buffer;
} sound_t;
/*
* Hold all information for one
* playback channel.
*/
typedef struct
{
sfx_t *sfx; /* sfx number */
@ -104,6 +129,10 @@ typedef struct
#endif
} channel_t;
/*
* Information read from
* wave file header.
*/
typedef struct
{
int rate;
@ -114,50 +143,19 @@ typedef struct
int dataofs; /* chunk starts this many bytes from file start */
} wavinfo_t;
/*
* Type of active sound backend
*/
typedef enum
{
SS_NOT = 0, /* soundsystem not started */
SS_DMA, /* soundsystem started, using DMA/SDL */
SS_SDL, /* soundsystem started, using SDL */
SS_OAL /* soundsystem started, using OpenAL */
} sndstarted_t;
extern sndstarted_t sound_started;
int s_beginofs;
int soundtime;
/* initializes cycling through a DMA
buffer and returns information on it */
qboolean SDL_BackendInit(void);
/* gets the current DMA position */
int SDL_GetPos(void);
/* shutdown the DMA xfer. */
void SDL_BackendShutdown(void);
void SDL_SoundInfo(void);
int SDL_DriftBeginofs(float);
void SDL_ClearBuffer(void);
void SDL_AddLoopSounds(void);
void SDL_UpdateSoundtime(void);
#define MAX_CHANNELS 32
extern channel_t channels[MAX_CHANNELS];
extern int s_numchannels;
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 sound_t sound;
extern playsound_t s_pendingplays;
#define MAX_RAW_SAMPLES 8192
extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
/*
* cvars
*/
extern cvar_t *s_volume;
extern cvar_t *s_nosound;
extern cvar_t *s_loadas8bit;
@ -167,25 +165,110 @@ extern cvar_t *s_mixahead;
extern cvar_t *s_testsound;
extern cvar_t *s_ambient;
wavinfo_t GetWavinfo(char *name, byte *wav, int wavlength);
void SDL_UpdateScaletable(void);
sfxcache_t *S_LoadSound(sfx_t *s);
void S_IssuePlaysound(playsound_t *ps);
void SDL_PaintChannels(int endtime);
qboolean SDL_Cache(sfx_t *sfx, wavinfo_t *info, byte *data);
void SDL_Update(void);
/*
* Globals
*/
extern channel_t channels[MAX_CHANNELS];
extern int paintedtime;
extern int s_numchannels;
extern int s_rawend;
extern playsound_t s_pendingplays;
extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
extern sndstarted_t sound_started;
extern sound_t sound;
extern vec3_t listener_origin;
extern vec3_t listener_forward;
extern vec3_t listener_right;
extern vec3_t listener_up;
/* picks a channel based on priorities, empty slots, number of channels */
/*
* Returns the header infos
* of a wave file
*/
wavinfo_t GetWavinfo(char *name, byte *wav, int wavlength);
/*
* Loads one sample into
* the cache
*/
sfxcache_t *S_LoadSound(sfx_t *s);
/*
* Plays one sound sample
*/
void S_IssuePlaysound(playsound_t *ps);
/*
* picks a channel based on priorities,
* empty slots, number of channels
*/
channel_t *S_PickChannel(int entnum, int entchannel);
/* spatializes a channel */
void SDL_Spatialize(channel_t *ch);
void SDL_RawSamples(int samples, int rate, int width, int channels, byte *data, float volume);
/*
* Builds a list of all
* sound still in flight
*/
void S_BuildSoundList(int *sounds);
/* ----------------------------------------------------------------- */
/*
* Initalizes the SDL backend
*/
qboolean SDL_BackendInit(void);
/*
* Shuts the SDL backend down
*/
void SDL_BackendShutdown(void);
/*
* Print informations about
* the SDL backend
*/
void SDL_SoundInfo(void);
/*
* Alters start position of
* sound playback
*/
int SDL_DriftBeginofs(float);
/*
* Clears all playback buffers
*/
void SDL_ClearBuffer(void);
/*
* Caches an sample for use
* the SDL backend
*/
qboolean SDL_Cache(sfx_t *sfx, wavinfo_t *info, byte *data);
/*
* Performs all sound calculations
* for the SDL backendend and fills
* the buffer
*/
void SDL_Update(void);
/*
* Queues raw samples for
* playback
*/
void SDL_RawSamples(int samples, int rate, int width,
int channels, byte *data, float volume);
/*
* Spartializes a sample
*/
void SDL_Spatialize(channel_t *ch);
/* ----------------------------------------------------------------- */
#if USE_OPENAL
/* Only begin attenuating sound volumes
/* Only begin attenuating sound volumes
when outside the FULLVOLUME range */
#define SOUND_FULLVOLUME 80
#define SOUND_LOOPATTENUATE 0.003
@ -193,19 +276,59 @@ void S_BuildSoundList(int *sounds);
/* number of buffers in flight (needed for ogg) */
extern int active_buffers;
/* for snd_al.c - copied from Q2Pro and adapted */
/*
* Informations about the
* OpenAL backend
*/
void AL_SoundInfo(void);
/* Initializes the OpenAL backend
*/
qboolean AL_Init(void);
/*
* Shuts the OpenAL backend down
*/
void AL_Shutdown(void);
/*
* Upload ("cache") one sample
* into OpenAL
*/
sfxcache_t *AL_UploadSfx(sfx_t *s, wavinfo_t *s_info, byte *data);
/*
* Deletes one sample from OpenAL
*/
void AL_DeleteSfx(sfx_t *s);
/*
* Stops playback of a channel
*/
void AL_StopChannel(channel_t *ch);
/*
* Starts playback of a channel
*/
void AL_PlayChannel(channel_t *ch);
/*
* Stops playback of all channels
*/
void AL_StopAllChannels(void);
/*
* Perform caculations and fill
* OpenALs buffer
*/
void AL_Update(void);
/*
* Plays raw samples
*/
void AL_RawSamples(int samples, int rate, int width,
int channels, byte *data, float volume);
#endif
#endif
#endif /* USE_OPENAL */
#endif /* CL_SOUND_LOCAL_H */

View file

@ -151,7 +151,7 @@ S_Init(void)
{
if (SDL_BackendInit())
{
sound_started = SS_DMA;
sound_started = SS_SDL;
}
else
{
@ -162,7 +162,6 @@ S_Init(void)
num_sfx = 0;
soundtime = 0;
paintedtime = 0;
Com_Printf("Sound sampling rate: %i\n", sound.speed);