diff --git a/src/client/sound/header/local.h b/src/client/sound/header/local.h index 5192428a..59e3c44d 100644 --- a/src/client/sound/header/local.h +++ b/src/client/sound/header/local.h @@ -27,89 +27,97 @@ #ifndef CL_SOUND_LOCAL_H #define CL_SOUND_LOCAL_H -typedef struct { - int left; - int right; +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; +typedef struct +{ + int length; + int loopstart; + int speed; /* not needed, because converted on load? */ + int width; #if USE_OPENAL - int size; - int bufnum; + int size; + int bufnum; #endif - int stereo; - byte data[1]; /* variable sized */ + int stereo; + byte data[1]; /* variable sized */ } sfxcache_t; -typedef struct sfx_s { - char name[MAX_QPATH]; - int registration_sequence; - sfxcache_t *cache; - char *truename; +typedef struct sfx_s +{ + char name[MAX_QPATH]; + int registration_sequence; + sfxcache_t *cache; + 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 */ -typedef struct playsound_s { - struct playsound_s *prev, *next; - sfx_t *sfx; - float volume; - float attenuation; - int entnum; - int entchannel; - qboolean fixed_origin; /* use origin field instead of entnum's origin */ - vec3_t origin; - unsigned begin; /* begin on this sample */ + * 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; + qboolean fixed_origin; /* use origin field instead of entnum's origin */ + vec3_t origin; + unsigned 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; +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 looping; /* where to loop, -1 = no looping */ - int entnum; /* to allow overriding a specific sound */ - 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 */ - qboolean fixed_origin; /* use origin instead of fetching entnum's origin */ - qboolean autosound; /* from an entity->sound, cleared each frame */ +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 looping; /* where to loop, -1 = no looping */ + int entnum; /* to allow overriding a specific sound */ + 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 */ + qboolean fixed_origin; /* use origin instead of fetching entnum's origin */ + qboolean autosound; /* from an entity->sound, cleared each frame */ #if USE_OPENAL - int autoframe; - int srcnum; + int autoframe; + int srcnum; #endif } channel_t; -typedef struct { - int rate; - int width; - int channels; - int loopstart; - int samples; - int dataofs; /* chunk starts this many bytes from file start */ +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 enum { - SS_NOT = 0, // soundsystem not started - SS_DMA, // soundsystem started, using DMA/SDL - SS_OAL // soundsystem started, using OpenAL +typedef enum +{ + SS_NOT = 0, /* soundsystem not started */ + SS_DMA, /* soundsystem started, using DMA/SDL */ + SS_OAL /* soundsystem started, using OpenAL */ } sndstarted_t; extern sndstarted_t sound_started; @@ -119,42 +127,42 @@ extern sndstarted_t sound_started; qboolean SNDDMA_Init(void); /* gets the current DMA position */ -int SNDDMA_GetDMAPos(void); +int SNDDMA_GetDMAPos(void); /* shutdown the DMA xfer. */ -void SNDDMA_Shutdown(void); -void SNDDMA_BeginPainting (void); -void SNDDMA_Submit(void); +void SNDDMA_Shutdown(void); +void SNDDMA_BeginPainting(void); +void SNDDMA_Submit(void); -#define MAX_CHANNELS 32 -extern channel_t channels[MAX_CHANNELS]; -extern int s_numchannels; +#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 dma_t dma; -extern playsound_t s_pendingplays; +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 dma_t dma; +extern playsound_t s_pendingplays; -#define MAX_RAW_SAMPLES 8192 -extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES]; +#define MAX_RAW_SAMPLES 8192 +extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES]; -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_ambient; +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_ambient; -wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength); -void S_InitScaletable (void); -sfxcache_t *S_LoadSound (sfx_t *s); -void S_IssuePlaysound (playsound_t *ps); +wavinfo_t GetWavinfo(char *name, byte *wav, int wavlength); +void S_InitScaletable(void); +sfxcache_t *S_LoadSound(sfx_t *s); +void S_IssuePlaysound(playsound_t *ps); void S_PaintChannels(int endtime); /* picks a channel based on priorities, empty slots, number of channels */ @@ -163,28 +171,30 @@ channel_t *S_PickChannel(int entnum, int entchannel); /* spatializes a channel */ void S_Spatialize(channel_t *ch); -void S_BuildSoundList( int *sounds ); +void S_BuildSoundList(int *sounds); #if USE_OPENAL -// this stuff was taken from Q2Pro -// only begin attenuating sound volumes when outside the FULLVOLUME range -#define SOUND_FULLVOLUME 80 -#define SOUND_LOOPATTENUATE 0.003 + /* Only begin attenuating sound volumes + when outside the FULLVOLUME range */ + #define SOUND_FULLVOLUME 80 + #define SOUND_LOOPATTENUATE 0.003 -// number of buffers in flight (needed for ogg) +/* number of buffers in flight (needed for ogg) */ extern int active_buffers; -// for snd_al.c - copied from Q2Pro and adapted -void AL_SoundInfo( void ); -qboolean AL_Init( void ); -void AL_Shutdown( void ); -sfxcache_t *AL_UploadSfx( sfx_t *s, wavinfo_t *s_info, byte *data ); -void AL_DeleteSfx( sfx_t *s ); -void AL_StopChannel( channel_t *ch ); -void AL_PlayChannel( channel_t *ch ); -void AL_StopAllChannels( void ); -void AL_Update( void ); -void AL_RawSamples( int samples, int rate, int width, int channels, byte *data, float volume ); -#endif +/* for snd_al.c - copied from Q2Pro and adapted */ +void AL_SoundInfo(void); +qboolean AL_Init(void); +void AL_Shutdown(void); +sfxcache_t *AL_UploadSfx(sfx_t *s, wavinfo_t *s_info, byte *data); +void AL_DeleteSfx(sfx_t *s); +void AL_StopChannel(channel_t *ch); +void AL_PlayChannel(channel_t *ch); +void AL_StopAllChannels(void); +void AL_Update(void); +void AL_RawSamples(int samples, int rate, int width, + int channels, byte *data, float volume); #endif +#endif + diff --git a/src/client/sound/header/sound.h b/src/client/sound/header/sound.h index 2b6a841f..b8f820c5 100644 --- a/src/client/sound/header/sound.h +++ b/src/client/sound/header/sound.h @@ -30,24 +30,29 @@ struct sfx_s; -void S_Init (void); -void S_Shutdown (void); +void S_Init(void); +void S_Shutdown(void); -/* if origin is NULL, the sound will be dynamically sourced from the entity */ -void S_StartSound (vec3_t origin, int entnum, int entchannel, struct sfx_s *sfx, float fvol, float attenuation, float timeofs); +/* if origin is NULL, the sound will be + dynamically sourced from the entity */ +void S_StartSound(vec3_t origin, int entnum, int entchannel, + struct sfx_s *sfx, float fvol, float attenuation, + float timeofs); -void S_StartLocalSound (char *s); -void S_RawSamples (int samples, int rate, int width, int channels, byte *data, float volume); +void S_StartLocalSound(char *s); +void S_RawSamples(int samples, int rate, int width, int channels, + byte *data, float volume); void S_StopAllSounds(void); -void S_Update (vec3_t origin, vec3_t v_forward, vec3_t v_right, vec3_t v_up); -void S_Activate (qboolean active); -void S_BeginRegistration (void); -struct sfx_s *S_RegisterSound (char *sample); -void S_EndRegistration (void); -struct sfx_s *S_FindName (char *name, qboolean create); +void S_Update(vec3_t origin, vec3_t v_forward, vec3_t v_right, vec3_t v_up); +void S_Activate(qboolean active); +void S_BeginRegistration(void); +struct sfx_s *S_RegisterSound(char *sample); +void S_EndRegistration(void); +struct sfx_s *S_FindName(char *name, qboolean create); -/* the sound code makes callbacks to the client for entitiy position - information, so entities can be dynamically re-spatialized */ -void CL_GetEntitySoundOrigin (int ent, vec3_t org); +/* the sound code makes callbacks to the client for + entitiy position information, so entities can be + dynamically re-spatialized */ +void CL_GetEntitySoundOrigin(int ent, vec3_t org); #endif diff --git a/src/client/sound/header/vorbis.h b/src/client/sound/header/vorbis.h index eeec5b06..9b1fd070 100644 --- a/src/client/sound/header/vorbis.h +++ b/src/client/sound/header/vorbis.h @@ -25,49 +25,51 @@ #ifdef OGG #ifndef CL_SOUND_VORBIS_H -#define CL_SOUND_VORBIS_H + #define CL_SOUND_VORBIS_H /* The OGG codec can return the samples in a number - of different formats, we use the standard signed - short format. */ -#define OGG_SAMPLEWIDTH 2 + * of different formats, we use the standard signed + * short format. */ + #define OGG_SAMPLEWIDTH 2 + #define OGG_DIR "music" -#define OGG_DIR "music" - -typedef enum { +typedef enum +{ PLAY, PAUSE, STOP } ogg_status_t; -typedef enum { +typedef enum +{ ABS, REL } ogg_seek_t; -void OGG_Init (void); -void OGG_Shutdown(void); -void OGG_Reinit(void); -qboolean OGG_Check(char *name); -void OGG_Seek (ogg_seek_t type, double offset); -void OGG_LoadFileList(void); -void OGG_LoadPlaylist(char *name); -qboolean OGG_Open(ogg_seek_t type, int offset); -qboolean OGG_OpenName(char *filename); -int OGG_Read (void); -void OGG_Sequence(void); -void OGG_Stop (void); -void OGG_Stream(void); -void S_RawSamplesVol(int samples, int rate, int width, int channels, byte * data, float volume); +void OGG_Init(void); +void OGG_Shutdown(void); +void OGG_Reinit(void); +qboolean OGG_Check(char *name); +void OGG_Seek(ogg_seek_t type, double offset); +void OGG_LoadFileList(void); +void OGG_LoadPlaylist(char *name); +qboolean OGG_Open(ogg_seek_t type, int offset); +qboolean OGG_OpenName(char *filename); +int OGG_Read(void); +void OGG_Sequence(void); +void OGG_Stop(void); +void OGG_Stream(void); +void S_RawSamplesVol(int samples, int rate, int width, + int channels, byte *data, float volume); /* Console commands. */ -void OGG_ListCmd(void); -void OGG_ParseCmd(char *arg); -void OGG_PauseCmd(void); -void OGG_PlayCmd(void); -void OGG_ResumeCmd(void); -void OGG_SeekCmd(void); -void OGG_StatusCmd(void); +void OGG_ListCmd(void); +void OGG_ParseCmd(char *arg); +void OGG_PauseCmd(void); +void OGG_PlayCmd(void); +void OGG_ResumeCmd(void); +void OGG_SeekCmd(void); +void OGG_StatusCmd(void); #endif #endif diff --git a/src/client/sound/snd_al.c b/src/client/sound/snd_al.c index d397e503..167d511a 100644 --- a/src/client/sound/snd_al.c +++ b/src/client/sound/snd_al.c @@ -21,10 +21,9 @@ * * ======================================================================= * - * Most of these functions are from the Q2Pro project, and some are from - * zeq2. We adapted them to work with Yamagi Quake II - * - * This is an OpenAL backend for the Quake II Soundsystem. + * This is an OpenAL backend for the Quake II Soundsystem. Most of these + * functions are from the Q2Pro project, and some are from zeq2. We + * adapted them to work with Yamagi Quake II. * * ======================================================================= */ @@ -36,11 +35,12 @@ #include "header/local.h" #include "header/vorbis.h" -// translates from AL coordinate system to quake -#define AL_UnpackVector(v) -v[1],v[2],-v[0] -#define AL_CopyVector(a,b) ((b)[0]=-(a)[1],(b)[1]=(a)[2],(b)[2]=-(a)[0]) +/* translates from AL coordinate system to quake */ +#define AL_UnpackVector(v) - v[1], v[2], -v[0] +#define AL_CopyVector(a, b) ((b)[0] = -(a)[1], (b)[1] = (a)[2], (b)[2] = \ + -(a)[0]) -// OpenAL implementation should support at least this number of sources +/* OpenAL implementation should support at least this number of sources */ #define MIN_CHANNELS 16 qboolean streamPlaying; @@ -49,27 +49,31 @@ int active_buffers; static ALuint streamSource; static ALuint underwaterFilter; -static ALuint s_srcnums[MAX_CHANNELS-1]; +static ALuint s_srcnums[MAX_CHANNELS - 1]; static int s_framecount; -// Forward Declarations -static void S_AL_StreamUpdate( void ); -static void S_AL_StreamDie( void ); -// /Forward Declarations +/* Forward Declarations */ +static void S_AL_StreamUpdate(void); +static void S_AL_StreamDie(void); -static void AL_InitStreamSource() { - qalSourcei (streamSource, AL_BUFFER, 0 ); - qalSourcei (streamSource, AL_LOOPING, AL_FALSE ); - qalSource3f(streamSource, AL_POSITION, 0.0, 0.0, 0.0); - qalSource3f(streamSource, AL_VELOCITY, 0.0, 0.0, 0.0); - qalSource3f(streamSource, AL_DIRECTION, 0.0, 0.0, 0.0); - qalSourcef (streamSource, AL_ROLLOFF_FACTOR, 0.0 ); - qalSourcei (streamSource, AL_SOURCE_RELATIVE, AL_TRUE ); +/* /Forward Declarations */ + +static void +AL_InitStreamSource() +{ + qalSourcei(streamSource, AL_BUFFER, 0); + qalSourcei(streamSource, AL_LOOPING, AL_FALSE); + qalSource3f(streamSource, AL_POSITION, 0.0, 0.0, 0.0); + qalSource3f(streamSource, AL_VELOCITY, 0.0, 0.0, 0.0); + qalSource3f(streamSource, AL_DIRECTION, 0.0, 0.0, 0.0); + qalSourcef(streamSource, AL_ROLLOFF_FACTOR, 0.0); + qalSourcei(streamSource, AL_SOURCE_RELATIVE, AL_TRUE); } -static void AL_InitUnderwaterFilter() +static void +AL_InitUnderwaterFilter() { - // Generate a filter + /* Generate a filter */ qalGenFilters(1, &underwaterFilter); if (qalGetError() != AL_NO_ERROR) @@ -78,7 +82,7 @@ static void AL_InitUnderwaterFilter() return; } - // Low pass filter for underwater effect + /* Low pass filter for underwater effect */ qalFilteri(underwaterFilter, AL_FILTER_TYPE, AL_FILTER_LOWPASS); if (qalGetError() != AL_NO_ERROR) @@ -87,44 +91,55 @@ static void AL_InitUnderwaterFilter() return; } - // The effect + /* The effect */ qalFilterf(underwaterFilter, AL_LOWPASS_GAIN, 1.5); qalFilterf(underwaterFilter, AL_LOWPASS_GAINHF, 0.25); } -qboolean AL_Init( void ) { +qboolean +AL_Init(void) +{ int i; - if( !QAL_Init() ) { - Com_Printf( "ERROR: OpenAL failed to initialize.\n" ); + if (!QAL_Init()) + { + Com_Printf("ERROR: OpenAL failed to initialize.\n"); return false; } - // check for linear distance extension - if( !qalIsExtensionPresent( "AL_EXT_LINEAR_DISTANCE" ) ) { - Com_Printf( "ERROR: Required AL_EXT_LINEAR_DISTANCE extension is missing.\n" ); + /* check for linear distance extension */ + if (!qalIsExtensionPresent("AL_EXT_LINEAR_DISTANCE")) + { + Com_Printf("ERROR: Required AL_EXT_LINEAR_DISTANCE extension is missing.\n"); goto fail; } - // generate source names + /* generate source names */ qalGetError(); - qalGenSources( 1, &streamSource ); - if( qalGetError() != AL_NO_ERROR ) - { - Com_Printf( "ERROR: Couldn't get a single Source.\n" ); - goto fail; + qalGenSources(1, &streamSource); - } else { - // -1 because we already got one channel for streaming - for( i = 0; i < MAX_CHANNELS - 1; i++ ) { - qalGenSources( 1, &s_srcnums[i] ); - if( qalGetError() != AL_NO_ERROR ) { + if (qalGetError() != AL_NO_ERROR) + { + Com_Printf("ERROR: Couldn't get a single Source.\n"); + goto fail; + } + else + { + /* -1 because we already got one channel for streaming */ + for (i = 0; i < MAX_CHANNELS - 1; i++) + { + qalGenSources(1, &s_srcnums[i]); + + if (qalGetError() != AL_NO_ERROR) + { break; } } - if( i < MIN_CHANNELS - 1 ) { - Com_Printf( "ERROR: Required at least %d sources, but got %d.\n", MIN_CHANNELS, i+1 ); + if (i < MIN_CHANNELS - 1) + { + Com_Printf("ERROR: Required at least %d sources, but got %d.\n", + MIN_CHANNELS, i + 1); goto fail; } } @@ -142,44 +157,53 @@ fail: return false; } -void AL_Shutdown( void ) { - Com_Printf( "Shutting down OpenAL.\n" ); +void +AL_Shutdown(void) +{ + Com_Printf("Shutting down OpenAL.\n"); S_AL_StreamDie(); qalDeleteSources(1, &streamSource); qalDeleteFilters(1, &underwaterFilter); - if( s_numchannels ) { - // delete source names - qalDeleteSources( s_numchannels, s_srcnums ); - memset( s_srcnums, 0, sizeof( s_srcnums ) ); + if (s_numchannels) + { + /* delete source names */ + qalDeleteSources(s_numchannels, s_srcnums); + memset(s_srcnums, 0, sizeof(s_srcnums)); s_numchannels = 0; } + QAL_Shutdown(); } -sfxcache_t *AL_UploadSfx( sfx_t *s, wavinfo_t *s_info, byte *data ) { +sfxcache_t * +AL_UploadSfx(sfx_t *s, wavinfo_t *s_info, byte *data) +{ sfxcache_t *sc; ALsizei size = s_info->samples * s_info->width; ALenum format = s_info->width == 2 ? AL_FORMAT_MONO16 : AL_FORMAT_MONO8; ALuint name; - if( !size ) { + if (!size) + { return NULL; } qalGetError(); - qalGenBuffers( 1, &name ); - qalBufferData( name, format, data, size, s_info->rate ); + qalGenBuffers(1, &name); + qalBufferData(name, format, data, size, s_info->rate); active_buffers++; - if( qalGetError() != AL_NO_ERROR ) { + + if (qalGetError() != AL_NO_ERROR) + { return NULL; } - // allocate placeholder sfxcache + /* allocate placeholder sfxcache */ sc = s->cache = Z_TagMalloc(sizeof(*sc), 0); - sc->length = s_info->samples * 1000 / s_info->rate; // in msec + sc->length = s_info->samples * 1000 / s_info->rate; /* in msec */ sc->loopstart = s_info->loopstart; sc->width = s_info->width; sc->size = size; @@ -188,147 +212,212 @@ sfxcache_t *AL_UploadSfx( sfx_t *s, wavinfo_t *s_info, byte *data ) { return sc; } -void AL_DeleteSfx( sfx_t *s ) { +void +AL_DeleteSfx(sfx_t *s) +{ sfxcache_t *sc; ALuint name; sc = s->cache; - if( !sc ) { + + if (!sc) + { return; } name = sc->bufnum; - qalDeleteBuffers( 1, &name ); + qalDeleteBuffers(1, &name); active_buffers--; } -void AL_StopChannel( channel_t *ch ) { - +void +AL_StopChannel(channel_t *ch) +{ if (s_show->value > 1) - Com_Printf("%s: %s\n", __func__, ch->sfx->name ); - - // stop it - qalSourceStop( ch->srcnum ); - qalSourcei( ch->srcnum, AL_BUFFER, AL_NONE ); - memset (ch, 0, sizeof(*ch)); -} - -static void AL_Spatialize( channel_t *ch ) { - vec3_t origin; - - // anything coming from the view entity will always be full volume - // no attenuation = no spatialization - if( ch->entnum == -1 || ch->entnum == cl.playernum + 1 || !ch->dist_mult ) { - VectorCopy( listener_origin, origin ); - } else if( ch->fixed_origin ) { - VectorCopy( ch->origin, origin ); - } else { - CL_GetEntitySoundOrigin( ch->entnum, origin ); + { + Com_Printf("%s: %s\n", __func__, ch->sfx->name); } - qalSource3f( ch->srcnum, AL_POSITION, AL_UnpackVector( origin ) ); + /* stop it */ + qalSourceStop(ch->srcnum); + qalSourcei(ch->srcnum, AL_BUFFER, AL_NONE); + memset(ch, 0, sizeof(*ch)); } -void AL_PlayChannel( channel_t *ch ) { +static void +AL_Spatialize(channel_t *ch) +{ + vec3_t origin; + + /* anything coming from the view entity + will always be full volume. no + attenuation = no spatialization */ + if ((ch->entnum == -1) || (ch->entnum == cl.playernum + 1) || + !ch->dist_mult) + { + VectorCopy(listener_origin, origin); + } + else if (ch->fixed_origin) + { + VectorCopy(ch->origin, origin); + } + else + { + CL_GetEntitySoundOrigin(ch->entnum, origin); + } + + qalSource3f(ch->srcnum, AL_POSITION, AL_UnpackVector(origin)); +} + +void +AL_PlayChannel(channel_t *ch) +{ sfxcache_t *sc = ch->sfx->cache; if (s_show->value > 1) - Com_Printf("%s: %s\n", __func__, ch->sfx->name ); + { + Com_Printf("%s: %s\n", __func__, ch->sfx->name); + } ch->srcnum = s_srcnums[ch - channels]; qalGetError(); - qalSourcei( ch->srcnum, AL_BUFFER, sc->bufnum ); - qalSourcei( ch->srcnum, AL_LOOPING, ch->autosound ? AL_TRUE : AL_FALSE ); - qalSourcef( ch->srcnum, AL_GAIN, ch->master_vol ); - qalSourcef( ch->srcnum, AL_REFERENCE_DISTANCE, SOUND_FULLVOLUME ); - qalSourcef( ch->srcnum, AL_MAX_DISTANCE, 8192 ); - qalSourcef( ch->srcnum, AL_ROLLOFF_FACTOR, ch->dist_mult * ( 8192 - SOUND_FULLVOLUME ) ); + qalSourcei(ch->srcnum, AL_BUFFER, sc->bufnum); + qalSourcei(ch->srcnum, AL_LOOPING, ch->autosound ? AL_TRUE : AL_FALSE); + qalSourcef(ch->srcnum, AL_GAIN, ch->master_vol); + qalSourcef(ch->srcnum, AL_REFERENCE_DISTANCE, SOUND_FULLVOLUME); + qalSourcef(ch->srcnum, AL_MAX_DISTANCE, 8192); + qalSourcef(ch->srcnum, AL_ROLLOFF_FACTOR, ch->dist_mult * + (8192 - SOUND_FULLVOLUME)); - AL_Spatialize( ch ); + AL_Spatialize(ch); - // play it - qalSourcePlay( ch->srcnum ); - if( qalGetError() != AL_NO_ERROR ) { - AL_StopChannel( ch ); + /* play it */ + qalSourcePlay(ch->srcnum); + + if (qalGetError() != AL_NO_ERROR) + { + AL_StopChannel(ch); } } -void AL_StopAllChannels( void ) { - int i; - channel_t *ch; +void +AL_StopAllChannels(void) +{ + int i; + channel_t *ch; ch = channels; - for( i = 0; i < s_numchannels; i++, ch++ ) { + + for (i = 0; i < s_numchannels; i++, ch++) + { if (!ch->sfx) + { continue; - AL_StopChannel( ch ); + } + + AL_StopChannel(ch); } + s_rawend = 0; S_AL_StreamDie(); } -static channel_t *AL_FindLoopingSound( int entnum, sfx_t *sfx ) { - int i; - channel_t *ch; +static channel_t * +AL_FindLoopingSound(int entnum, sfx_t *sfx) +{ + int i; + channel_t *ch; ch = channels; - for( i = 0; i < s_numchannels; i++, ch++ ) { - if( !ch->sfx ) + + for (i = 0; i < s_numchannels; i++, ch++) + { + if (!ch->sfx) + { continue; - if( !ch->autosound ) + } + + if (!ch->autosound) + { continue; - if( ch->entnum != entnum ) + } + + if (ch->entnum != entnum) + { continue; - if( ch->sfx != sfx ) + } + + if (ch->sfx != sfx) + { continue; + } + return ch; } return NULL; } -static void AL_AddLoopSounds( void ) { - int i; - int sounds[MAX_EDICTS]; - channel_t *ch; - sfx_t *sfx; - sfxcache_t *sc; - int num; - entity_state_t *ent; +static void +AL_AddLoopSounds(void) +{ + int i; + int sounds[MAX_EDICTS]; + channel_t *ch; + sfx_t *sfx; + sfxcache_t *sc; + int num; + entity_state_t *ent; - if( cls.state != ca_active || cl_paused->value || !s_ambient->value ) { + if ((cls.state != ca_active) || cl_paused->value || !s_ambient->value) + { return; } - S_BuildSoundList( sounds ); + S_BuildSoundList(sounds); - for( i = 0; i < cl.frame.num_entities; i++ ) { + for (i = 0; i < cl.frame.num_entities; i++) + { if (!sounds[i]) + { continue; + } sfx = cl.sound_precache[sounds[i]]; + if (!sfx) - continue; // bad sound effect + { + continue; /* bad sound effect */ + } + sc = sfx->cache; + if (!sc) + { continue; + } - num = ( cl.frame.parse_entities + i ) & ( MAX_PARSE_ENTITIES - 1 ); - ent = &cl_parse_entities [ num ]; + num = (cl.frame.parse_entities + i) & (MAX_PARSE_ENTITIES - 1); + ent = &cl_parse_entities[num]; - ch = AL_FindLoopingSound( ent->number, sfx ); - if( ch ) { + ch = AL_FindLoopingSound(ent->number, sfx); + + if (ch) + { ch->autoframe = s_framecount; ch->end = paintedtime + sc->length; continue; } - // allocate a channel + /* allocate a channel */ ch = S_PickChannel(0, 0); - if (!ch) - continue; - ch->autosound = true; // remove next frame + if (!ch) + { + continue; + } + + ch->autosound = true; /* remove next frame */ ch->autoframe = s_framecount; ch->sfx = sfx; ch->entnum = ent->number; @@ -336,116 +425,145 @@ static void AL_AddLoopSounds( void ) { ch->dist_mult = SOUND_LOOPATTENUATE; ch->end = paintedtime + sc->length; - AL_PlayChannel( ch ); + AL_PlayChannel(ch); } } -static void AL_IssuePlaysounds( void ) { +static void +AL_IssuePlaysounds(void) +{ playsound_t *ps; - // start any playsounds - while (1) { + /* start any playsounds */ + while (1) + { ps = s_pendingplays.next; + if (ps == &s_pendingplays) - break; // no more pending sounds + { + break; /* no more pending sounds */ + } + if (ps->begin > paintedtime) + { break; - S_IssuePlaysound (ps); + } + + S_IssuePlaysound(ps); } } -void AL_Update( void ) { - int i; - channel_t *ch; - vec_t orientation[6]; +void +AL_Update(void) +{ + int i; + channel_t *ch; + vec_t orientation[6]; paintedtime = cl.time; - // set listener parameters - qalListener3f( AL_POSITION, AL_UnpackVector( listener_origin ) ); - AL_CopyVector( listener_forward, orientation ); - AL_CopyVector( listener_up, orientation + 3 ); - qalListenerfv( AL_ORIENTATION, orientation ); - qalListenerf( AL_GAIN, s_volume->value ); - qalDistanceModel( AL_LINEAR_DISTANCE_CLAMPED ); + /* set listener parameters */ + qalListener3f(AL_POSITION, AL_UnpackVector(listener_origin)); + AL_CopyVector(listener_forward, orientation); + AL_CopyVector(listener_up, orientation + 3); + qalListenerfv(AL_ORIENTATION, orientation); + qalListenerf(AL_GAIN, s_volume->value); + qalDistanceModel(AL_LINEAR_DISTANCE_CLAMPED); - // update spatialization for dynamic sounds + /* update spatialization for dynamic sounds */ ch = channels; - for( i = 0; i < s_numchannels; i++, ch++ ) { - if( !ch->sfx ) - continue; - if( ch->autosound ) { - // autosounds are regenerated fresh each frame - if( ch->autoframe != s_framecount ) { - AL_StopChannel( ch ); + for (i = 0; i < s_numchannels; i++, ch++) + { + if (!ch->sfx) + { + continue; + } + + if (ch->autosound) + { + /* autosounds are regenerated fresh each frame */ + if (ch->autoframe != s_framecount) + { + AL_StopChannel(ch); continue; } - } else { + } + else + { ALenum state; qalGetError(); - qalGetSourcei( ch->srcnum, AL_SOURCE_STATE, &state ); - if( qalGetError() != AL_NO_ERROR || state == AL_STOPPED ) { - AL_StopChannel( ch ); + qalGetSourcei(ch->srcnum, AL_SOURCE_STATE, &state); + + if ((qalGetError() != AL_NO_ERROR) || (state == AL_STOPPED)) + { + AL_StopChannel(ch); continue; } } - if (s_show->value) { - Com_Printf ("%3i %s\n", ch->master_vol, ch->sfx->name); + if (s_show->value) + { + Com_Printf("%3i %s\n", ch->master_vol, ch->sfx->name); } - AL_Spatialize(ch); // respatialize channel + AL_Spatialize(ch); /* respatialize channel */ } s_framecount++; - // add loopsounds - AL_AddLoopSounds (); + /* add loopsounds */ + AL_AddLoopSounds(); - // add music + /* add music */ OGG_Stream(); S_AL_StreamUpdate(); AL_IssuePlaysounds(); } -void AL_Underwater() +void +AL_Underwater() { int i; - if(sound_started != SS_OAL) { + + if (sound_started != SS_OAL) + { return; } - // Apply to all sources + /* Apply to all sources */ for (i = 0; i < s_numchannels; i++) { qalSourcei(s_srcnums[i], AL_DIRECT_FILTER, underwaterFilter); } } -void AL_Overwater() +void +AL_Overwater() { int i; - // Apply to all sources + /* Apply to all sources */ for (i = 0; i < s_numchannels; i++) { qalSourcei(s_srcnums[i], AL_DIRECT_FILTER, 0); } } -static void S_AL_StreamDie( void ) +static void +S_AL_StreamDie(void) { - int numBuffers; + int numBuffers; streamPlaying = false; qalSourceStop(streamSource); - // Un-queue any buffers, and delete them - qalGetSourcei( streamSource, AL_BUFFERS_QUEUED, &numBuffers ); - while( numBuffers-- ) + /* Un-queue any buffers, and delete them */ + qalGetSourcei(streamSource, AL_BUFFERS_QUEUED, &numBuffers); + + while (numBuffers--) { ALuint buffer; qalSourceUnqueueBuffers(streamSource, 1, &buffer); @@ -454,14 +572,16 @@ static void S_AL_StreamDie( void ) } } -static void S_AL_StreamUpdate( void ) +static void +S_AL_StreamUpdate(void) { - int numBuffers; - ALint state; + int numBuffers; + ALint state; - // Un-queue any buffers, and delete them - qalGetSourcei( streamSource, AL_BUFFERS_PROCESSED, &numBuffers ); - while( numBuffers-- ) + /* Un-queue any buffers, and delete them */ + qalGetSourcei(streamSource, AL_BUFFERS_PROCESSED, &numBuffers); + + while (numBuffers--) { ALuint buffer; qalSourceUnqueueBuffers(streamSource, 1, &buffer); @@ -469,70 +589,84 @@ static void S_AL_StreamUpdate( void ) active_buffers--; } - // Start the streamSource playing if necessary - qalGetSourcei( streamSource, AL_BUFFERS_QUEUED, &numBuffers ); + /* Start the streamSource playing if necessary */ + qalGetSourcei(streamSource, AL_BUFFERS_QUEUED, &numBuffers); qalGetSourcei(streamSource, AL_SOURCE_STATE, &state); - if(state == AL_STOPPED) + + if (state == AL_STOPPED) { streamPlaying = false; } - if( !streamPlaying && numBuffers ) + if (!streamPlaying && numBuffers) { - qalSourcePlay( streamSource ); + qalSourcePlay(streamSource); streamPlaying = true; } } -static ALuint S_AL_Format(int width, int channels) +static ALuint +S_AL_Format(int width, int channels) { ALuint format = AL_FORMAT_MONO16; - // Work out format - if(width == 1) + /* Work out format */ + if (width == 1) { - if(channels == 1) + if (channels == 1) + { format = AL_FORMAT_MONO8; - else if(channels == 2) + } + else if (channels == 2) + { format = AL_FORMAT_STEREO8; + } } - else if(width == 2) + else if (width == 2) { - if(channels == 1) + if (channels == 1) + { format = AL_FORMAT_MONO16; - else if(channels == 2) + } + else if (channels == 2) + { format = AL_FORMAT_STEREO16; + } } return format; } -void AL_RawSamples( int samples, int rate, int width, int channels, byte *data, float volume ) +void +AL_RawSamples(int samples, int rate, int width, int channels, + byte *data, float volume) { ALuint buffer; ALuint format; - format = S_AL_Format( width, channels ); + format = S_AL_Format(width, channels); - // Create a buffer, and stuff the data into it + /* Create a buffer, and stuff the data into it */ qalGenBuffers(1, &buffer); - qalBufferData(buffer, format, (ALvoid *)data, (samples * width * channels), rate); + qalBufferData(buffer, format, (ALvoid *)data, + (samples * width * channels), rate); active_buffers++; - // set volume - qalSourcef( streamSource, AL_GAIN, volume ); + /* set volume */ + qalSourcef(streamSource, AL_GAIN, volume); - // Shove the data onto the streamSource + /* Shove the data onto the streamSource */ qalSourceQueueBuffers(streamSource, 1, &buffer); - // emulate behavior of S_RawSamples for s_rawend + /* emulate behavior of S_RawSamples for s_rawend */ s_rawend += samples; } -void AL_UnqueueRawSamples() +void +AL_UnqueueRawSamples() { S_AL_StreamDie(); } -#endif // USE_OPENAL +#endif /* USE_OPENAL */ diff --git a/src/client/sound/snd_dma.c b/src/client/sound/snd_dma.c index f7d2c8e2..f7701328 100644 --- a/src/client/sound/snd_dma.c +++ b/src/client/sound/snd_dma.c @@ -31,17 +31,17 @@ #include "header/local.h" #include "header/vorbis.h" -void S_Play ( void ); -void S_SoundList ( void ); -void S_StopAllSounds ( void ); +void S_Play(void); +void S_SoundList(void); +void S_StopAllSounds(void); /* only begin attenuating sound volumes when outside the FULLVOLUME range */ -#define SOUND_FULLVOLUME 80 +#define SOUND_FULLVOLUME 80 #define SOUND_LOOPATTENUATE 0.003 int s_registration_sequence; -channel_t channels [ MAX_CHANNELS ]; +channel_t channels[MAX_CHANNELS]; int s_numchannels; qboolean snd_initialized = false; @@ -63,110 +63,117 @@ int paintedtime; * than could actually be referenced during gameplay, * because we don't want to free anything until we are * sure we won't need it. */ -#define MAX_SFX ( MAX_SOUNDS * 2 ) -sfx_t known_sfx [ MAX_SFX ]; +#define MAX_SFX (MAX_SOUNDS * 2) +sfx_t known_sfx[MAX_SFX]; int num_sfx; -#define MAX_PLAYSOUNDS 128 -playsound_t s_playsounds [ MAX_PLAYSOUNDS ]; +#define MAX_PLAYSOUNDS 128 +playsound_t s_playsounds[MAX_PLAYSOUNDS]; playsound_t s_freeplays; playsound_t s_pendingplays; int s_beginofs; -cvar_t *s_volume; -cvar_t *s_testsound; -cvar_t *s_loadas8bit; -cvar_t *s_khz; -cvar_t *s_mixahead; -cvar_t *s_show; -cvar_t *s_ambient; +cvar_t *s_volume; +cvar_t *s_testsound; +cvar_t *s_loadas8bit; +cvar_t *s_khz; +cvar_t *s_mixahead; +cvar_t *s_show; +cvar_t *s_ambient; int s_rawend; -portable_samplepair_t s_rawsamples [ MAX_RAW_SAMPLES ]; +portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES]; /* * User-setable variables */ - -static void DMA_SoundInfo (void) { - Com_Printf( "%5d stereo\n", dma.channels - 1 ); - Com_Printf( "%5d samples\n", dma.samples ); - Com_Printf( "%5d samplepos\n", dma.samplepos ); - Com_Printf( "%5d samplebits\n", dma.samplebits ); - Com_Printf( "%5d submission_chunk\n", dma.submission_chunk ); - Com_Printf( "%5d speed\n", dma.speed ); - Com_Printf( "%p dma buffer\n", dma.buffer ); +static void +DMA_SoundInfo(void) +{ + Com_Printf("%5d stereo\n", dma.channels - 1); + Com_Printf("%5d samples\n", dma.samples); + Com_Printf("%5d samplepos\n", dma.samplepos); + Com_Printf("%5d samplebits\n", dma.samplebits); + Com_Printf("%5d submission_chunk\n", dma.submission_chunk); + Com_Printf("%5d speed\n", dma.speed); + Com_Printf("%p dma buffer\n", dma.buffer); } void -S_SoundInfo_f ( void ) +S_SoundInfo_f(void) { - if ( !sound_started ) + if (!sound_started) { - Com_Printf( "sound system not started\n" ); + Com_Printf("sound system not started\n"); return; } + #if USE_OPENAL - if(sound_started == SS_OAL) { + if (sound_started == SS_OAL) + { QAL_SoundInfo(); Com_Printf("\nNumber of sources: %d\n", s_numchannels); - } else + } + else #endif + { DMA_SoundInfo(); - + } } - - void -S_Init ( void ) +S_Init(void) { - cvar_t *cv; + cvar_t *cv; - Com_Printf( "\n------- sound initialization -------\n" ); + Com_Printf("\n------- sound initialization -------\n"); - cv = Cvar_Get( "s_initsound", "1", 0 ); + cv = Cvar_Get("s_initsound", "1", 0); - if ( !cv->value ) + if (!cv->value) { - Com_Printf( "not initializing.\n" ); - } else { + Com_Printf("not initializing.\n"); + } + else + { + s_volume = Cvar_Get("s_volume", "0.7", CVAR_ARCHIVE); + s_khz = Cvar_Get("s_khz", "44", CVAR_ARCHIVE); + s_loadas8bit = Cvar_Get("s_loadas8bit", "0", CVAR_ARCHIVE); + s_mixahead = Cvar_Get("s_mixahead", "0.14", CVAR_ARCHIVE); + s_show = Cvar_Get("s_show", "0", 0); + s_testsound = Cvar_Get("s_testsound", "0", 0); + s_ambient = Cvar_Get("s_ambient", "1", 0); - s_volume = Cvar_Get( "s_volume", "0.7", CVAR_ARCHIVE ); - s_khz = Cvar_Get( "s_khz", "44", CVAR_ARCHIVE ); - s_loadas8bit = Cvar_Get( "s_loadas8bit", "0", CVAR_ARCHIVE ); - s_mixahead = Cvar_Get( "s_mixahead", "0.14", CVAR_ARCHIVE ); - s_show = Cvar_Get( "s_show", "0", 0 ); - s_testsound = Cvar_Get( "s_testsound", "0", 0 ); - s_ambient = Cvar_Get( "s_ambient", "1", 0); - - Cmd_AddCommand( "play", S_Play ); - Cmd_AddCommand( "stopsound", S_StopAllSounds ); - Cmd_AddCommand( "soundlist", S_SoundList ); - Cmd_AddCommand( "soundinfo", S_SoundInfo_f ); + Cmd_AddCommand("play", S_Play); + Cmd_AddCommand("stopsound", S_StopAllSounds); + Cmd_AddCommand("soundlist", S_SoundList); + Cmd_AddCommand("soundinfo", S_SoundInfo_f); #ifdef OGG - Cmd_AddCommand( "ogg_init", OGG_Init ); - Cmd_AddCommand( "ogg_shutdown", OGG_Shutdown ); + Cmd_AddCommand("ogg_init", OGG_Init); + Cmd_AddCommand("ogg_shutdown", OGG_Shutdown); #endif #if USE_OPENAL - cv = Cvar_Get( "s_openal", "1", CVAR_ARCHIVE); - if( cv->value && AL_Init() ) { + cv = Cvar_Get("s_openal", "1", CVAR_ARCHIVE); + + if (cv->value && AL_Init()) + { sound_started = SS_OAL; } - else { + else #endif - if ( SNDDMA_Init() ) + { + if (SNDDMA_Init()) { sound_started = SS_DMA; - } else { + } + else + { sound_started = SS_NOT; return; } -#if USE_OPENAL - } /* this is a bit ugly but prevents dangling else problems */ -#endif + } num_sfx = 0; @@ -174,33 +181,34 @@ S_Init ( void ) paintedtime = 0; #if USE_OPENAL - if(sound_started == SS_DMA) + if (sound_started == SS_DMA) { - Com_Printf( "Sound sampling rate: %i\n", dma.speed ); + Com_Printf("Sound sampling rate: %i\n", dma.speed); } #else - Com_Printf( "Sound sampling rate: %i\n", dma.speed ); + Com_Printf("Sound sampling rate: %i\n", dma.speed); #endif S_StopAllSounds(); + #ifdef OGG OGG_Init(); #endif } - Com_Printf( "------------------------------------\n\n" ); + Com_Printf("------------------------------------\n\n"); } /* * Shutdown sound engine */ void -S_Shutdown ( void ) +S_Shutdown(void) { int i; - sfx_t *sfx; + sfx_t *sfx; - if ( !sound_started ) + if (!sound_started) { return; } @@ -208,29 +216,32 @@ S_Shutdown ( void ) S_StopAllSounds(); /* free all sounds */ - for ( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) + for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) { - if ( !sfx->name [ 0 ] ) + if (!sfx->name[0]) { continue; } + #if USE_OPENAL - if ( sound_started == SS_OAL ) + if (sound_started == SS_OAL) { - AL_DeleteSfx( sfx ); + AL_DeleteSfx(sfx); } #endif - if ( sfx->cache ) + + if (sfx->cache) { - Z_Free( sfx->cache ); + Z_Free(sfx->cache); } - if ( sfx->truename ) + + if (sfx->truename) { - Z_Free( sfx-> truename ); + Z_Free(sfx->truename); } } - memset( known_sfx, 0, sizeof ( known_sfx ) ); + memset(known_sfx, 0, sizeof(known_sfx)); num_sfx = 0; @@ -239,23 +250,26 @@ S_Shutdown ( void ) #endif #if USE_OPENAL - if( sound_started == SS_OAL ) + if (sound_started == SS_OAL) { AL_Shutdown(); - } else + } + else #endif + { SNDDMA_Shutdown(); + } sound_started = SS_NOT; s_numchannels = 0; - Cmd_RemoveCommand( "soundlist" ); - Cmd_RemoveCommand( "soundinfo" ); - Cmd_RemoveCommand( "play" ); - Cmd_RemoveCommand( "stopsound" ); + Cmd_RemoveCommand("soundlist"); + Cmd_RemoveCommand("soundinfo"); + Cmd_RemoveCommand("play"); + Cmd_RemoveCommand("stopsound"); #ifdef OGG - Cmd_RemoveCommand( "ogg_init" ); - Cmd_RemoveCommand( "ogg_shutdown" ); + Cmd_RemoveCommand("ogg_init"); + Cmd_RemoveCommand("ogg_shutdown"); #endif } @@ -263,207 +277,207 @@ S_Shutdown ( void ) * Returns the name of a sound */ sfx_t * -S_FindName ( char *name, qboolean create ) +S_FindName(char *name, qboolean create) { int i; - sfx_t *sfx; + sfx_t *sfx; - if ( !name ) + if (!name) { - Com_Error( ERR_FATAL, "S_FindName: NULL\n" ); + Com_Error(ERR_FATAL, "S_FindName: NULL\n"); } - if ( !name [ 0 ] ) + if (!name[0]) { - Com_Error( ERR_FATAL, "S_FindName: empty name\n" ); + Com_Error(ERR_FATAL, "S_FindName: empty name\n"); } - if ( strlen( name ) >= MAX_QPATH ) + if (strlen(name) >= MAX_QPATH) { - Com_Error( ERR_FATAL, "Sound name too long: %s", name ); + Com_Error(ERR_FATAL, "Sound name too long: %s", name); } /* see if already loaded */ - for ( i = 0; i < num_sfx; i++ ) + for (i = 0; i < num_sfx; i++) { - if ( !strcmp( known_sfx [ i ].name, name ) ) + if (!strcmp(known_sfx[i].name, name)) { - return ( &known_sfx [ i ] ); + return &known_sfx[i]; } } - if ( !create ) + if (!create) { - return ( NULL ); + return NULL; } /* find a free sfx */ - for ( i = 0; i < num_sfx; i++ ) + for (i = 0; i < num_sfx; i++) { - if ( !known_sfx [ i ].name [ 0 ] ) + if (!known_sfx[i].name[0]) { break; } } - if ( i == num_sfx ) + if (i == num_sfx) { - if ( num_sfx == MAX_SFX ) + if (num_sfx == MAX_SFX) { - Com_Error( ERR_FATAL, "S_FindName: out of sfx_t" ); + Com_Error(ERR_FATAL, "S_FindName: out of sfx_t"); } num_sfx++; } - if ( strlen( name ) >= MAX_QPATH - 1 ) + if (strlen(name) >= MAX_QPATH - 1) { - Com_Error( ERR_FATAL, "Sound name too long: %s", name ); + Com_Error(ERR_FATAL, "Sound name too long: %s", name); } - sfx = &known_sfx [ i ]; + sfx = &known_sfx[i]; sfx->truename = NULL; - strcpy( sfx->name, name ); + strcpy(sfx->name, name); sfx->registration_sequence = s_registration_sequence; - return ( sfx ); + return sfx; } sfx_t * -S_AliasName ( char *aliasname, char *truename ) +S_AliasName(char *aliasname, char *truename) { - sfx_t *sfx; - char *s; + sfx_t *sfx; + char *s; int i; - s = Z_Malloc( MAX_QPATH ); - strcpy( s, truename ); + s = Z_Malloc(MAX_QPATH); + strcpy(s, truename); /* find a free sfx */ - for ( i = 0; i < num_sfx; i++ ) + for (i = 0; i < num_sfx; i++) { - if ( !known_sfx [ i ].name [ 0 ] ) + if (!known_sfx[i].name[0]) { break; } } - if ( i == num_sfx ) + if (i == num_sfx) { - if ( num_sfx == MAX_SFX ) + if (num_sfx == MAX_SFX) { - Com_Error( ERR_FATAL, "S_FindName: out of sfx_t" ); + Com_Error(ERR_FATAL, "S_FindName: out of sfx_t"); } num_sfx++; } - sfx = &known_sfx [ i ]; + sfx = &known_sfx[i]; sfx->cache = NULL; - strcpy( sfx->name, aliasname ); + strcpy(sfx->name, aliasname); sfx->registration_sequence = s_registration_sequence; sfx->truename = s; - return ( sfx ); + return sfx; } void -S_BeginRegistration ( void ) +S_BeginRegistration(void) { s_registration_sequence++; s_registering = true; } sfx_t * -S_RegisterSound ( char *name ) +S_RegisterSound(char *name) { - sfx_t *sfx; + sfx_t *sfx; - if ( !sound_started ) + if (!sound_started) { - return ( NULL ); + return NULL; } - sfx = S_FindName( name, true ); + sfx = S_FindName(name, true); sfx->registration_sequence = s_registration_sequence; - if ( !s_registering ) + if (!s_registering) { - S_LoadSound( sfx ); + S_LoadSound(sfx); } - return ( sfx ); + return sfx; } void -S_EndRegistration ( void ) +S_EndRegistration(void) { int i; - sfx_t *sfx; + sfx_t *sfx; /* free any sounds not from this registration sequence */ - for ( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) + for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) { - if ( !sfx->name [ 0 ] ) + if (!sfx->name[0]) { continue; } - if ( sfx->registration_sequence != s_registration_sequence ) + if (sfx->registration_sequence != s_registration_sequence) { /* it is possible to have a leftover */ - if ( sfx->cache ) + if (sfx->cache) { - Z_Free( sfx->cache ); /* from a server that didn't finish loading */ + Z_Free(sfx->cache); /* from a server that didn't finish loading */ } - if ( sfx->truename ) + if (sfx->truename) { - Z_Free( sfx->truename ); /* memleak fix from echon */ + Z_Free(sfx->truename); /* memleak fix from echon */ } sfx->cache = NULL; - sfx->name [ 0 ] = 0; + sfx->name[0] = 0; } } /* load everything in */ - for ( i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++ ) + for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++) { - if ( !sfx->name [ 0 ] ) + if (!sfx->name[0]) { continue; } - S_LoadSound( sfx ); + S_LoadSound(sfx); } s_registering = false; } channel_t * -S_PickChannel ( int entnum, int entchannel ) +S_PickChannel(int entnum, int entchannel) { int ch_idx; int first_to_die; int life_left; - channel_t *ch; + channel_t *ch; - if ( entchannel < 0 ) + if (entchannel < 0) { - Com_Error( ERR_DROP, "S_PickChannel: entchannel<0" ); + Com_Error(ERR_DROP, "S_PickChannel: entchannel<0"); } /* Check for replacement sound, or find the best one to replace */ first_to_die = -1; life_left = 0x7fffffff; - for ( ch_idx = 0; ch_idx < s_numchannels; ch_idx++ ) + for (ch_idx = 0; ch_idx < s_numchannels; ch_idx++) { /* channel 0 never overrides */ - if ( ( entchannel != 0 ) && - ( channels [ ch_idx ].entnum == entnum ) && - ( channels [ ch_idx ].entchannel == entchannel ) ) + if ((entchannel != 0) && + (channels[ch_idx].entnum == entnum) && + (channels[ch_idx].entchannel == entchannel)) { /* always override sound from same entity */ first_to_die = ch_idx; @@ -471,69 +485,72 @@ S_PickChannel ( int entnum, int entchannel ) } /* don't let monster sounds override player sounds */ - if ( ( channels [ ch_idx ].entnum == cl.playernum + 1 ) && ( entnum != cl.playernum + 1 ) && channels [ ch_idx ].sfx ) + if ((channels[ch_idx].entnum == cl.playernum + 1) && + (entnum != cl.playernum + 1) && channels[ch_idx].sfx) { continue; } - if ( channels [ ch_idx ].end - paintedtime < life_left ) + if (channels[ch_idx].end - paintedtime < life_left) { - life_left = channels [ ch_idx ].end - paintedtime; + life_left = channels[ch_idx].end - paintedtime; first_to_die = ch_idx; } } - if ( first_to_die == -1 ) + if (first_to_die == -1) { - return ( NULL ); + return NULL; } - ch = &channels [ first_to_die ]; + ch = &channels[first_to_die]; #if USE_OPENAL - if( sound_started == SS_OAL && ch->sfx ) + if ((sound_started == SS_OAL) && ch->sfx) { - AL_StopChannel( ch ); + AL_StopChannel(ch); } #endif - memset( ch, 0, sizeof ( *ch ) ); - return ( ch ); + memset(ch, 0, sizeof(*ch)); + + return ch; } /* * Used for spatializing channels and autosounds */ void -S_SpatializeOrigin ( vec3_t origin, float master_vol, float dist_mult, int *left_vol, int *right_vol ) +S_SpatializeOrigin(vec3_t origin, float master_vol, float dist_mult, + int *left_vol, int *right_vol) { vec_t dot; vec_t dist; vec_t lscale, rscale, scale; vec3_t source_vec; - if ( cls.state != ca_active ) + if (cls.state != ca_active) { *left_vol = *right_vol = 255; return; } /* calculate stereo seperation and distance attenuation */ - VectorSubtract( origin, listener_origin, source_vec ); + VectorSubtract(origin, listener_origin, source_vec); - dist = VectorNormalize( source_vec ); + dist = VectorNormalize(source_vec); dist -= SOUND_FULLVOLUME; - if ( dist < 0 ) + if (dist < 0) { dist = 0; /* close enough to be at full volume */ } dist *= dist_mult; /* different attenuation levels */ - dot = DotProduct( listener_right, source_vec ); + dot = DotProduct(listener_right, source_vec); - if ( ( dma.channels == 1 ) || !dist_mult ) + if ((dma.channels == 1) || !dist_mult) { /* no attenuation = no spatialization */ rscale = 1.0f; @@ -541,74 +558,75 @@ S_SpatializeOrigin ( vec3_t origin, float master_vol, float dist_mult, int *left } else { - rscale = 0.5f * ( 1.0f + dot ); - lscale = 0.5f * ( 1.0f - dot ); + rscale = 0.5f * (1.0f + dot); + lscale = 0.5f * (1.0f - dot); } /* add in distance effect */ - scale = ( 1.0f - dist ) * rscale; - *right_vol = (int) ( master_vol * scale ); + scale = (1.0f - dist) * rscale; + *right_vol = (int)(master_vol * scale); - if ( *right_vol < 0 ) + if (*right_vol < 0) { *right_vol = 0; } - scale = ( 1.0 - dist ) * lscale; - *left_vol = (int) ( master_vol * scale ); + scale = (1.0 - dist) * lscale; + *left_vol = (int)(master_vol * scale); - if ( *left_vol < 0 ) + if (*left_vol < 0) { *left_vol = 0; } } void -S_Spatialize ( channel_t *ch ) +S_Spatialize(channel_t *ch) { vec3_t origin; /* anything coming from the view entity will always be full volume */ - if ( ch->entnum == cl.playernum + 1 ) + if (ch->entnum == cl.playernum + 1) { ch->leftvol = ch->master_vol; ch->rightvol = ch->master_vol; return; } - if ( ch->fixed_origin ) + if (ch->fixed_origin) { - VectorCopy( ch->origin, origin ); + VectorCopy(ch->origin, origin); } else { - CL_GetEntitySoundOrigin( ch->entnum, origin ); + CL_GetEntitySoundOrigin(ch->entnum, origin); } - S_SpatializeOrigin( origin, (float) ch->master_vol, ch->dist_mult, &ch->leftvol, &ch->rightvol ); + S_SpatializeOrigin(origin, (float)ch->master_vol, ch->dist_mult, + &ch->leftvol, &ch->rightvol); } playsound_t * -S_AllocPlaysound ( void ) +S_AllocPlaysound(void) { playsound_t *ps; ps = s_freeplays.next; - if ( ps == &s_freeplays ) + if (ps == &s_freeplays) { - return ( NULL ); /* no free playsounds, this results in stuttering an cracking */ + return NULL; /* no free playsounds, this results in stuttering an cracking */ } /* unlink from freelist */ ps->prev->next = ps->next; ps->next->prev = ps->prev; - return ( ps ); + return ps; } void -S_FreePlaysound ( playsound_t *ps ) +S_FreePlaysound(playsound_t *ps) { /* unlink from channel */ ps->prev->next = ps->next; @@ -627,39 +645,41 @@ S_FreePlaysound ( playsound_t *ps ) * by the update loop. */ void -S_IssuePlaysound ( playsound_t *ps ) +S_IssuePlaysound(playsound_t *ps) { - channel_t *ch; - sfxcache_t *sc; + channel_t *ch; + sfxcache_t *sc; - if ( !ps ) + if (!ps) { return; } - if ( s_show->value ) + if (s_show->value) { - Com_Printf( "Issue %i\n", ps->begin ); + Com_Printf("Issue %i\n", ps->begin); } /* pick a channel to play on */ - ch = S_PickChannel( ps->entnum, ps->entchannel ); + ch = S_PickChannel(ps->entnum, ps->entchannel); - if ( !ch ) + if (!ch) { - S_FreePlaysound( ps ); + S_FreePlaysound(ps); return; } - sc = S_LoadSound( ps->sfx ); - if( !sc ) { - Com_Printf( "S_IssuePlaysound: couldn't load %s\n", ps->sfx->name ); - S_FreePlaysound( ps ); - return; - } + sc = S_LoadSound(ps->sfx); + + if (!sc) + { + Com_Printf("S_IssuePlaysound: couldn't load %s\n", ps->sfx->name); + S_FreePlaysound(ps); + return; + } /* spatialize */ - if ( ps->attenuation == ATTN_STATIC ) + if (ps->attenuation == ATTN_STATIC) { ch->dist_mult = ps->attenuation * 0.001f; } @@ -669,104 +689,111 @@ S_IssuePlaysound ( playsound_t *ps ) ch->dist_mult = ps->attenuation * 0.0005f; } - ch->master_vol = (int) ps->volume; + ch->master_vol = (int)ps->volume; ch->entnum = ps->entnum; ch->entchannel = ps->entchannel; ch->sfx = ps->sfx; - VectorCopy( ps->origin, ch->origin ); + VectorCopy(ps->origin, ch->origin); ch->fixed_origin = ps->fixed_origin; #if USE_OPENAL - if( sound_started == SS_OAL) + if (sound_started == SS_OAL) { - AL_PlayChannel( ch ); - } else + AL_PlayChannel(ch); + } + else #endif - S_Spatialize( ch ); + { + S_Spatialize(ch); + } ch->pos = 0; ch->end = paintedtime + sc->length; /* free the playsound */ - S_FreePlaysound( ps ); + S_FreePlaysound(ps); } struct sfx_s * -S_RegisterSexedSound ( entity_state_t *ent, char *base ) +S_RegisterSexedSound(entity_state_t *ent, char *base) { - int n; - char *p; - int len; - struct sfx_s *sfx; - char model [ MAX_QPATH ]; - char sexedFilename [ MAX_QPATH ]; - char maleFilename [ MAX_QPATH ]; + int n; + char *p; + int len; + struct sfx_s *sfx; + char model[MAX_QPATH]; + char sexedFilename[MAX_QPATH]; + char maleFilename[MAX_QPATH]; /* determine what model the client is using */ - model [ 0 ] = 0; + model[0] = 0; n = CS_PLAYERSKINS + ent->number - 1; - if ( cl.configstrings [ n ] [ 0 ] ) + if (cl.configstrings[n][0]) { - p = strchr( cl.configstrings [ n ], '\\' ); + p = strchr(cl.configstrings[n], '\\'); - if ( p ) + if (p) { p += 1; - strcpy( model, p ); - p = strchr( model, '/' ); + strcpy(model, p); + p = strchr(model, '/'); - if ( p ) + if (p) { - p [ 0 ] = 0; + p[0] = 0; } } } /* if we can't figure it out, they're male */ - if ( !model [ 0 ] ) + if (!model[0]) { - strcpy( model, "male" ); + strcpy(model, "male"); } /* see if we already know of the model specific sound */ - Com_sprintf( sexedFilename, sizeof ( sexedFilename ), "#players/%s/%s", model, base + 1 ); - sfx = S_FindName( sexedFilename, false ); + Com_sprintf(sexedFilename, sizeof(sexedFilename), + "#players/%s/%s", model, base + 1); + sfx = S_FindName(sexedFilename, false); - if ( !sfx ) + if (!sfx) { /* no, so see if it exists */ - len = FS_LoadFile( &sexedFilename [ 1 ], NULL ); + len = FS_LoadFile(&sexedFilename[1], NULL); - if ( len != -1 ) + if (len != -1) { /* yes, close the file and register it */ - sfx = S_RegisterSound( sexedFilename ); + sfx = S_RegisterSound(sexedFilename); } else { /* no, revert to the male sound in the pak0.pak */ - Com_sprintf( maleFilename, sizeof ( maleFilename ), "player/male/%s", base + 1 ); - sfx = S_AliasName( sexedFilename, maleFilename ); + Com_sprintf(maleFilename, sizeof(maleFilename), + "player/male/%s", base + 1); + sfx = S_AliasName(sexedFilename, maleFilename); } } - return ( sfx ); + return sfx; } -static int DMA_DriftBeginofs( float timeofs ) { +static int +DMA_DriftBeginofs(float timeofs) +{ /* drift s_beginofs */ - int start = (int) ( cl.frame.servertime * 0.001f * dma.speed + s_beginofs ); + int start = (int)(cl.frame.servertime * 0.001f * dma.speed + s_beginofs); - if ( start < paintedtime ) + if (start < paintedtime) { start = paintedtime; - s_beginofs = (int) ( start - ( cl.frame.servertime * 0.001f * dma.speed ) ); + s_beginofs = (int)(start - (cl.frame.servertime * 0.001f * dma.speed)); } - else if ( start > paintedtime + 0.3f * dma.speed ) + else if (start > paintedtime + 0.3f * dma.speed) { - start = (int) ( paintedtime + 0.1f * dma.speed ); - s_beginofs = (int) ( start - ( cl.frame.servertime * 0.001f * dma.speed ) ); + start = (int)(paintedtime + 0.1f * dma.speed); + s_beginofs = (int)(start - (cl.frame.servertime * 0.001f * dma.speed)); } else { @@ -782,33 +809,36 @@ static int DMA_DriftBeginofs( float timeofs ) { * override a playing sound */ void -S_StartSound ( vec3_t origin, int entnum, int entchannel, sfx_t *sfx, float fvol, float attenuation, float timeofs ) +S_StartSound(vec3_t origin, int entnum, int entchannel, sfx_t *sfx, + float fvol, float attenuation, float timeofs) { - sfxcache_t *sc; + sfxcache_t *sc; playsound_t *ps, *sort; - if ( !sound_started ) + if (!sound_started) { return; } - if ( !sfx ) + if (!sfx) { return; } - if ( sfx->name [ 0 ] == '*' ) + if (sfx->name[0] == '*') { - sfx = S_RegisterSexedSound( &cl_entities [ entnum ].current, sfx->name ); - if( !sfx ) { + sfx = S_RegisterSexedSound(&cl_entities[entnum].current, sfx->name); + + if (!sfx) + { return; } } /* make sure the sound is loaded */ - sc = S_LoadSound( sfx ); + sc = S_LoadSound(sfx); - if ( !sc ) + if (!sc) { return; /* couldn't load the sound's data */ } @@ -816,14 +846,14 @@ S_StartSound ( vec3_t origin, int entnum, int entchannel, sfx_t *sfx, float fvol /* make the playsound_t */ ps = S_AllocPlaysound(); - if ( !ps ) + if (!ps) { return; } - if ( origin ) + if (origin) { - VectorCopy( origin, ps->origin ); + VectorCopy(origin, ps->origin); ps->fixed_origin = true; } else @@ -837,7 +867,7 @@ S_StartSound ( vec3_t origin, int entnum, int entchannel, sfx_t *sfx, float fvol ps->sfx = sfx; #if USE_OPENAL - if( sound_started == SS_OAL ) + if (sound_started == SS_OAL) { ps->begin = paintedtime + timeofs * 1000; ps->volume = fvol * 384; @@ -850,9 +880,9 @@ S_StartSound ( vec3_t origin, int entnum, int entchannel, sfx_t *sfx, float fvol } /* sort into the pending sound list */ - for ( sort = s_pendingplays.next; - sort != &s_pendingplays && sort->begin < ps->begin; - sort = sort->next ) + for (sort = s_pendingplays.next; + sort != &s_pendingplays && sort->begin < ps->begin; + sort = sort->next) { } @@ -864,39 +894,39 @@ S_StartSound ( vec3_t origin, int entnum, int entchannel, sfx_t *sfx, float fvol } void -S_StartLocalSound ( char *sound ) +S_StartLocalSound(char *sound) { - sfx_t *sfx; + sfx_t *sfx; - if ( !sound_started ) + if (!sound_started) { return; } - sfx = S_RegisterSound( sound ); + sfx = S_RegisterSound(sound); - if ( !sfx ) + if (!sfx) { - Com_Printf( "S_StartLocalSound: can't cache %s\n", sound ); + Com_Printf("S_StartLocalSound: can't cache %s\n", sound); return; } - S_StartSound( NULL, cl.playernum + 1, 0, sfx, 1, 1, 0 ); + S_StartSound(NULL, cl.playernum + 1, 0, sfx, 1, 1, 0); } void -S_ClearBuffer ( void ) +S_ClearBuffer(void) { int clear; - if ( !sound_started ) + if (!sound_started) { return; } s_rawend = 0; - if ( dma.samplebits == 8 ) + if (dma.samplebits == 8) { clear = 0x80; } @@ -907,14 +937,14 @@ S_ClearBuffer ( void ) SNDDMA_BeginPainting(); - if ( dma.buffer ) + if (dma.buffer) { int i; - unsigned char *ptr = (unsigned char *) dma.buffer; + unsigned char *ptr = (unsigned char *)dma.buffer; i = dma.samples * dma.samplebits / 8; - while ( i-- ) + while (i--) { *ptr = clear; ptr++; @@ -925,57 +955,70 @@ S_ClearBuffer ( void ) } void -S_StopAllSounds ( void ) +S_StopAllSounds(void) { int i; - if ( !sound_started ) + if (!sound_started) { return; } /* clear all the playsounds */ - memset( s_playsounds, 0, sizeof ( s_playsounds ) ); + memset(s_playsounds, 0, sizeof(s_playsounds)); s_freeplays.next = s_freeplays.prev = &s_freeplays; s_pendingplays.next = s_pendingplays.prev = &s_pendingplays; - for ( i = 0; i < MAX_PLAYSOUNDS; i++ ) + for (i = 0; i < MAX_PLAYSOUNDS; i++) { - s_playsounds [ i ].prev = &s_freeplays; - s_playsounds [ i ].next = s_freeplays.next; - s_playsounds [ i ].prev->next = &s_playsounds [ i ]; - s_playsounds [ i ].next->prev = &s_playsounds [ i ]; + s_playsounds[i].prev = &s_freeplays; + s_playsounds[i].next = s_freeplays.next; + s_playsounds[i].prev->next = &s_playsounds[i]; + s_playsounds[i].next->prev = &s_playsounds[i]; } #if USE_OPENAL - if( sound_started == SS_OAL ) { + if (sound_started == SS_OAL) + { AL_StopAllChannels(); - } else + } + else #endif + { S_ClearBuffer(); + } /* clear all the channels */ - memset( channels, 0, sizeof ( channels ) ); + memset(channels, 0, sizeof(channels)); } -void S_BuildSoundList( int *sounds ) { - int i; - int num; - entity_state_t *ent; +void +S_BuildSoundList(int *sounds) +{ + int i; + int num; + entity_state_t *ent; - for ( i = 0; i < cl.frame.num_entities; i++ ) + for (i = 0; i < cl.frame.num_entities; i++) { - if (i >= MAX_EDICTS) { + if (i >= MAX_EDICTS) + { break; } - num = ( cl.frame.parse_entities + i ) & ( MAX_PARSE_ENTITIES - 1 ); - ent = &cl_parse_entities [ num ]; - if( s_ambient->value == 2 && !ent->modelindex ) { + num = (cl.frame.parse_entities + i) & (MAX_PARSE_ENTITIES - 1); + ent = &cl_parse_entities[num]; + + if ((s_ambient->value == 2) && !ent->modelindex) + { sounds[i] = 0; - } else if( s_ambient->value == 3 && ent->number != cl.playernum + 1) { + } + else if ((s_ambient->value == 3) && (ent->number != cl.playernum + 1)) + { sounds[i] = 0; - } else { + } + else + { sounds[i] = ent->sound; } } @@ -987,102 +1030,103 @@ void S_BuildSoundList( int *sounds ) { * as the entities are sent to the client */ void -S_AddLoopSounds ( void ) +S_AddLoopSounds(void) { int i, j; - int sounds [ MAX_EDICTS ]; + int sounds[MAX_EDICTS]; int left, right, left_total, right_total; - channel_t *ch; - sfx_t *sfx; - sfxcache_t *sc; + channel_t *ch; + sfx_t *sfx; + sfxcache_t *sc; int num; - entity_state_t *ent; + entity_state_t *ent; vec3_t origin; - if ( cl_paused->value ) + if (cl_paused->value) { return; } - if ( cls.state != ca_active ) + if (cls.state != ca_active) { return; } - if ( !cl.sound_prepped || !s_ambient->value ) + if (!cl.sound_prepped || !s_ambient->value) { return; } - memset(&sounds, 0, sizeof(int) * MAX_EDICTS); - S_BuildSoundList( sounds ); + memset(&sounds, 0, sizeof(int) * MAX_EDICTS); + S_BuildSoundList(sounds); - for ( i = 0; i < cl.frame.num_entities; i++ ) + for (i = 0; i < cl.frame.num_entities; i++) { - if ( !sounds [ i ] ) + if (!sounds[i]) { continue; } - sfx = cl.sound_precache [ sounds [ i ] ]; + sfx = cl.sound_precache[sounds[i]]; - if ( !sfx ) + if (!sfx) { continue; /* bad sound effect */ } sc = sfx->cache; - if ( !sc ) + if (!sc) { continue; } - num = ( cl.frame.parse_entities + i ) & ( MAX_PARSE_ENTITIES - 1 ); - ent = &cl_parse_entities [ num ]; + num = (cl.frame.parse_entities + i) & (MAX_PARSE_ENTITIES - 1); + ent = &cl_parse_entities[num]; - CL_GetEntitySoundOrigin( ent->number, origin ); + CL_GetEntitySoundOrigin(ent->number, origin); /* find the total contribution of all sounds of this type */ - S_SpatializeOrigin( ent->origin, 255.0f, SOUND_LOOPATTENUATE, &left_total, &right_total ); + S_SpatializeOrigin(ent->origin, 255.0f, SOUND_LOOPATTENUATE, + &left_total, &right_total); - for ( j = i + 1; j < cl.frame.num_entities; j++ ) + for (j = i + 1; j < cl.frame.num_entities; j++) { - if ( sounds [ j ] != sounds [ i ] ) + if (sounds[j] != sounds[i]) { continue; } - sounds [ j ] = 0; /* don't check this again later */ + sounds[j] = 0; /* don't check this again later */ - num = ( cl.frame.parse_entities + j ) & ( MAX_PARSE_ENTITIES - 1 ); - ent = &cl_parse_entities [ num ]; + num = (cl.frame.parse_entities + j) & (MAX_PARSE_ENTITIES - 1); + ent = &cl_parse_entities[num]; - S_SpatializeOrigin( ent->origin, 255.0f, SOUND_LOOPATTENUATE, - &left, &right ); + S_SpatializeOrigin(ent->origin, 255.0f, SOUND_LOOPATTENUATE, + &left, &right); left_total += left; right_total += right; } - if ( ( left_total == 0 ) && ( right_total == 0 ) ) + if ((left_total == 0) && (right_total == 0)) { continue; /* not audible */ } /* allocate a channel */ - ch = S_PickChannel( 0, 0 ); + ch = S_PickChannel(0, 0); - if ( !ch ) + if (!ch) { return; } - if ( left_total > 255 ) + if (left_total > 255) { left_total = 255; } - if ( right_total > 255 ) + if (right_total > 255) { right_total = 255; } @@ -1097,7 +1141,7 @@ S_AddLoopSounds ( void ) modulo operation. The workaround checks for this situation and in that case, sets the pos and end parameters to 0. */ - if ( sc->length == 0 ) + if (sc->length == 0) { ch->pos = 0; ch->end = 0; @@ -1116,110 +1160,113 @@ S_AddLoopSounds ( void ) * would be terrible slow. */ void -S_RawSamples ( int samples, int rate, int width, int channels, byte *data, float volume ) +S_RawSamples(int samples, int rate, int width, + int channels, byte *data, float volume) { int i; int src, dst; float scale; int intVolume; - if ( !sound_started ) + if (!sound_started) { return; } - if ( s_rawend < paintedtime ) + if (s_rawend < paintedtime) { s_rawend = paintedtime; } #if USE_OPENAL - if( sound_started == SS_OAL ) + if (sound_started == SS_OAL) { AL_RawSamples(samples, rate, width, channels, data, volume); return; } #endif - scale = (float) rate / dma.speed; - intVolume = (int) (256 * volume); + scale = (float)rate / dma.speed; + intVolume = (int)(256 * volume); - if ( ( channels == 2 ) && ( width == 2 ) ) + if ((channels == 2) && (width == 2)) { - for ( i = 0; ; i++ ) + for (i = 0; ; i++) { - src = (int) ( i * scale ); + src = (int)(i * scale); - if ( src >= samples ) + if (src >= samples) { break; } - dst = s_rawend & ( MAX_RAW_SAMPLES - 1 ); + dst = s_rawend & (MAX_RAW_SAMPLES - 1); s_rawend++; - s_rawsamples [dst].left = ((short *) data)[src * 2] * intVolume; - s_rawsamples [dst].right = ((short *) data)[src * 2 + 1] * intVolume; + s_rawsamples[dst].left = ((short *)data)[src * 2] * intVolume; + s_rawsamples[dst].right = ((short *)data)[src * 2 + 1] * intVolume; } } - else if ( ( channels == 1 ) && ( width == 2 ) ) + else if ((channels == 1) && (width == 2)) { - for ( i = 0; ; i++ ) + for (i = 0; ; i++) { - src = (int) ( i * scale ); + src = (int)(i * scale); - if ( src >= samples ) + if (src >= samples) { break; } - dst = s_rawend & ( MAX_RAW_SAMPLES - 1 ); + dst = s_rawend & (MAX_RAW_SAMPLES - 1); s_rawend++; - s_rawsamples [dst].left = ((short *) data)[src] * intVolume; - s_rawsamples [dst].right = ((short *) data)[src] * intVolume; + s_rawsamples[dst].left = ((short *)data)[src] * intVolume; + s_rawsamples[dst].right = ((short *)data)[src] * intVolume; } } - else if ( ( channels == 2 ) && ( width == 1 ) ) + else if ((channels == 2) && (width == 1)) { intVolume *= 256; - for ( i = 0; ; i++ ) + for (i = 0; ; i++) { - src = (int) ( i * scale ); + src = (int)(i * scale); - if ( src >= samples ) + if (src >= samples) { break; } - dst = s_rawend & ( MAX_RAW_SAMPLES - 1 ); + dst = s_rawend & (MAX_RAW_SAMPLES - 1); s_rawend++; - s_rawsamples [dst].left = (((byte *) data)[src * 2] - 128) * intVolume; - s_rawsamples [dst].right = (((byte *) data)[src * 2 + 1] - 128) * intVolume; + s_rawsamples[dst].left = + (((byte *)data)[src * 2] - 128) * intVolume; + s_rawsamples[dst].right = + (((byte *)data)[src * 2 + 1] - 128) * intVolume; } } - else if ( ( channels == 1 ) && ( width == 1 ) ) + else if ((channels == 1) && (width == 1)) { intVolume *= 256; - for ( i = 0; ; i++ ) + for (i = 0; ; i++) { - src = (int) ( i * scale ); + src = (int)(i * scale); - if ( src >= samples ) + if (src >= samples) { break; } - dst = s_rawend & ( MAX_RAW_SAMPLES - 1 ); + dst = s_rawend & (MAX_RAW_SAMPLES - 1); s_rawend++; - s_rawsamples [dst].left = (((byte *) data)[src] - 128) * intVolume; - s_rawsamples [dst].right = (((byte *) data)[src] - 128) * intVolume; + s_rawsamples[dst].left = (((byte *)data)[src] - 128) * intVolume; + s_rawsamples[dst].right = (((byte *)data)[src] - 128) * intVolume; } } } void -GetSoundtime ( void ) +GetSoundtime(void) { int samplepos; static int buffers; @@ -1232,11 +1279,11 @@ GetSoundtime ( void ) calls to S_Update. Oh well. This a hack around that. */ samplepos = SNDDMA_GetDMAPos(); - if ( samplepos < oldsamplepos ) + if (samplepos < oldsamplepos) { buffers++; /* buffer wrapped */ - if ( paintedtime > 0x40000000 ) + if (paintedtime > 0x40000000) { /* time to chop things off to avoid 32 bit limits */ buffers = 0; @@ -1253,45 +1300,47 @@ GetSoundtime ( void ) * Called once each time through the main loop */ void -S_Update ( vec3_t origin, vec3_t forward, vec3_t right, vec3_t up ) +S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up) { int i; int total; - channel_t *ch; - unsigned endtime; + channel_t *ch; + unsigned endtime; int samps; - if ( !sound_started ) + if (!sound_started) { return; } - /* if the laoding plaque is up, clear everything - * out to make sure we aren't looping a dirty - * dma buffer while loading */ - if ( cls.disable_screen ) + /* if the loading plaque is up, clear everything + out to make sure we aren't looping a dirty + dma buffer while loading */ + if (cls.disable_screen) { - if (sound_started == SS_DMA ) { + if (sound_started == SS_DMA) + { S_ClearBuffer(); } + return; } - VectorCopy( origin, listener_origin ); - VectorCopy( forward, listener_forward ); - VectorCopy( right, listener_right ); - VectorCopy( up, listener_up ); - + VectorCopy(origin, listener_origin); + VectorCopy(forward, listener_forward); + VectorCopy(right, listener_right); + VectorCopy(up, listener_up); #if USE_OPENAL - if( sound_started == SS_OAL ) { - AL_Update(); - return; - } + if (sound_started == SS_OAL) + { + AL_Update(); + return; + } #endif - /* rebuild scale tables if volume is modified */ - if ( s_volume->modified ) + /* rebuild scale tables if volume is modified */ + if (s_volume->modified) { S_InitScaletable(); } @@ -1299,25 +1348,25 @@ S_Update ( vec3_t origin, vec3_t forward, vec3_t right, vec3_t up ) /* update spatialization for dynamic sounds */ ch = channels; - for ( i = 0; i < s_numchannels; i++, ch++ ) + for (i = 0; i < s_numchannels; i++, ch++) { - if ( !ch->sfx ) + if (!ch->sfx) { continue; } - if ( ch->autosound ) + if (ch->autosound) { /* autosounds are regenerated fresh each frame */ - memset( ch, 0, sizeof ( *ch ) ); + memset(ch, 0, sizeof(*ch)); continue; } - S_Spatialize( ch ); /* respatialize channel */ + S_Spatialize(ch); /* respatialize channel */ - if ( !ch->leftvol && !ch->rightvol ) + if (!ch->leftvol && !ch->rightvol) { - memset( ch, 0, sizeof ( *ch ) ); + memset(ch, 0, sizeof(*ch)); continue; } } @@ -1326,21 +1375,22 @@ S_Update ( vec3_t origin, vec3_t forward, vec3_t right, vec3_t up ) S_AddLoopSounds(); /* debugging output */ - if ( s_show->value ) + if (s_show->value) { total = 0; ch = channels; - for ( i = 0; i < s_numchannels; i++, ch++ ) + for (i = 0; i < s_numchannels; i++, ch++) { - if ( ch->sfx && ( ch->leftvol || ch->rightvol ) ) + if (ch->sfx && (ch->leftvol || ch->rightvol)) { - Com_Printf( "%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name ); + Com_Printf("%3i %3i %s\n", ch->leftvol, + ch->rightvol, ch->sfx->name); total++; } } - Com_Printf( "----(%i)---- painted: %i\n", total, paintedtime ); + Com_Printf("----(%i)---- painted: %i\n", total, paintedtime); } #ifdef OGG @@ -1349,14 +1399,14 @@ S_Update ( vec3_t origin, vec3_t forward, vec3_t right, vec3_t up ) #endif /* mix some sound */ - if ( !sound_started ) + if (!sound_started) { return; } SNDDMA_BeginPainting(); - if ( !dma.buffer ) + if (!dma.buffer) { return; } @@ -1364,111 +1414,113 @@ S_Update ( vec3_t origin, vec3_t forward, vec3_t right, vec3_t up ) /* Updates DMA time */ GetSoundtime(); - if ( !soundtime ) + if (!soundtime) { return; } /* check to make sure that we haven't overshot */ - if ( paintedtime < soundtime ) + if (paintedtime < soundtime) { - Com_DPrintf( "S_Update_ : overflow\n" ); + Com_DPrintf("S_Update_ : overflow\n"); paintedtime = soundtime; } /* mix ahead of current position */ - endtime = (int) ( soundtime + s_mixahead->value * dma.speed ); + endtime = (int)(soundtime + s_mixahead->value * dma.speed); /* mix to an even submission block size */ - endtime = ( endtime + dma.submission_chunk - 1 ) & ~( dma.submission_chunk - 1 ); - samps = dma.samples >> ( dma.channels - 1 ); + endtime = (endtime + dma.submission_chunk - 1) & ~(dma.submission_chunk - 1); + samps = dma.samples >> (dma.channels - 1); - if ( endtime - soundtime > samps ) + if (endtime - soundtime > samps) { endtime = soundtime + samps; } - S_PaintChannels( endtime ); + S_PaintChannels(endtime); SNDDMA_Submit(); } void -S_Play ( void ) +S_Play(void) { int i; - char name [ 256 ]; - sfx_t *sfx; + char name[256]; + sfx_t *sfx; i = 1; - while ( i < Cmd_Argc() ) + while (i < Cmd_Argc()) { - if ( !strrchr( Cmd_Argv( i ), '.' ) ) + if (!strrchr(Cmd_Argv(i), '.')) { - strncpy( name, Cmd_Argv( i ), sizeof ( name ) - 5 ); - strcat( name, ".wav" ); + strncpy(name, Cmd_Argv(i), sizeof(name) - 5); + strcat(name, ".wav"); } else { - strncpy( name, Cmd_Argv( i ), sizeof ( name ) - 1 ); + strncpy(name, Cmd_Argv(i), sizeof(name) - 1); } - if ( strstr( name, ".." ) || ( name [ 0 ] == '/' ) || ( name [ 0 ] == '\\' ) ) + if (strstr(name, "..") || (name[0] == '/') || (name[0] == '\\')) { - Com_Printf( "Bad filename %s\n", name ); + Com_Printf("Bad filename %s\n", name); return; } - sfx = S_RegisterSound( name ); - { - S_StartSound( NULL, cl.playernum + 1, 0, sfx, 1.0, 1.0, 0 ); - } + sfx = S_RegisterSound(name); + S_StartSound(NULL, cl.playernum + 1, 0, sfx, 1.0, 1.0, 0); i++; } } void -S_SoundList ( void ) +S_SoundList(void) { int i; - sfx_t *sfx; - sfxcache_t *sc; + sfx_t *sfx; + sfxcache_t *sc; int size, total; int numsounds; total = 0; numsounds = 0; - for ( sfx = known_sfx, i = 0; i < num_sfx; i++, sfx++ ) + for (sfx = known_sfx, i = 0; i < num_sfx; i++, sfx++) { - if ( !sfx->name [ 0 ] ) + if (!sfx->name[0]) { continue; } sc = sfx->cache; - if ( sc ) + if (sc) { - size = sc->length * sc->width * ( sc->stereo + 1 ); + size = sc->length * sc->width * (sc->stereo + 1); total += size; - Com_Printf( "%s(%2db) %8i : %s\n", sc->loopstart != -1 ? "L" : " ", sc->width * 8, size, sfx->name ); + Com_Printf("%s(%2db) %8i : %s\n", + sc->loopstart != -1 ? "L" : " ", + sc->width * 8, size, sfx->name); } else { - if ( sfx->name [ 0 ] == '*' ) + if (sfx->name[0] == '*') { - Com_Printf( " placeholder : %s\n", sfx->name ); + Com_Printf(" placeholder : %s\n", sfx->name); } else { - Com_Printf( " not loaded : %s\n", sfx->name ); + Com_Printf(" not loaded : %s\n", sfx->name); } } numsounds++; } - Com_Printf( "Total resident: %i bytes (%.2f MB) in %d sounds\n", total, (float) total / 1024 / 1024, numsounds ); + Com_Printf("Total resident: %i bytes (%.2f MB) in %d sounds\n", total, + (float)total / 1024 / 1024, numsounds); } + diff --git a/src/client/sound/snd_mem.c b/src/client/sound/snd_mem.c index b414d867..e3c2d1bf 100644 --- a/src/client/sound/snd_mem.c +++ b/src/client/sound/snd_mem.c @@ -19,8 +19,9 @@ * * ======================================================================= * - * The sound caching. This file contains support functions for loading - * the sound samples into the memory. + * The sound caching. This file contains support functions for + * processing the soundsamples, load them into the memory and + * provide them to the SDL or OpenAL sound backend. * * ======================================================================= */ @@ -29,7 +30,7 @@ #include "header/local.h" void -ResampleSfx ( sfx_t *sfx, int inrate, int inwidth, byte *data ) +ResampleSfx(sfx_t *sfx, int inrate, int inwidth, byte *data) { int outcount; int srcsample; @@ -37,37 +38,38 @@ ResampleSfx ( sfx_t *sfx, int inrate, int inwidth, byte *data ) int i; int sample; unsigned int samplefrac, fracstep; - sfxcache_t *sc; + sfxcache_t *sc; sc = sfx->cache; - if ( !sc ) + if (!sc) { return; } - stepscale = (float) inrate / dma.speed; /* this is usually 0.5, 1, or 2 */ + stepscale = (float)inrate / dma.speed; /* this is usually 0.5, 1, or 2 */ - outcount = (int) ( sc->length / stepscale ); + outcount = (int)(sc->length / stepscale); - if ( outcount == 0 ) + if (outcount == 0) { - Com_Printf( "ResampleSfx: Invalid sound file '%s' (zero length)\n", sfx->name ); - Z_Free( sfx->cache ); + Com_Printf("ResampleSfx: Invalid sound file '%s' (zero length)\n", + sfx->name); + Z_Free(sfx->cache); sfx->cache = NULL; return; } sc->length = outcount; - if ( sc->loopstart != -1 ) + if (sc->loopstart != -1) { - sc->loopstart = (int) ( sc->loopstart / stepscale ); + sc->loopstart = (int)(sc->loopstart / stepscale); } sc->speed = dma.speed; - if ( s_loadas8bit->value ) + if (s_loadas8bit->value) { sc->width = 1; } @@ -81,62 +83,62 @@ ResampleSfx ( sfx_t *sfx, int inrate, int inwidth, byte *data ) /* resample / decimate to the current source rate */ samplefrac = 0; - fracstep = (int) ( stepscale * 256 ); + fracstep = (int)(stepscale * 256); - for ( i = 0; i < outcount; i++ ) + for (i = 0; i < outcount; i++) { srcsample = samplefrac >> 8; samplefrac += fracstep; - if ( inwidth == 2 ) + if (inwidth == 2) { - sample = LittleShort( ( (short *) data ) [ srcsample ] ); + sample = LittleShort(((short *)data)[srcsample]); } else { - sample = (int) ( (unsigned char) ( data [ srcsample ] ) - 128 ) << 8; + sample = (int)((unsigned char)(data[srcsample]) - 128) << 8; } - if ( sc->width == 2 ) + if (sc->width == 2) { - ( (short *) sc->data ) [ i ] = sample; + ((short *)sc->data)[i] = sample; } else { - ( (signed char *) sc->data ) [ i ] = sample >> 8; + ((signed char *)sc->data)[i] = sample >> 8; } } } sfxcache_t * -S_LoadSound ( sfx_t *s ) +S_LoadSound(sfx_t *s) { - char namebuffer [ MAX_QPATH ]; - byte *data; + char namebuffer[MAX_QPATH]; + byte *data; wavinfo_t info; int len; float stepscale; - sfxcache_t *sc; + sfxcache_t *sc; int size; - char *name; + char *name; - if ( s->name [ 0 ] == '*' ) + if (s->name[0] == '*') { - return ( NULL ); + return NULL; } /* see if still in memory */ sc = s->cache; - if ( sc ) + if (sc) { - return ( sc ); + return sc; } /* load it in */ - if ( s->truename ) + if (s->truename) { name = s->truename; } @@ -146,48 +148,52 @@ S_LoadSound ( sfx_t *s ) name = s->name; } - if ( name [ 0 ] == '#' ) + if (name[0] == '#') { - strcpy( namebuffer, &name [ 1 ] ); - } else { - Com_sprintf( namebuffer, sizeof ( namebuffer ), "sound/%s", name ); + strcpy(namebuffer, &name[1]); + } + else + { + Com_sprintf(namebuffer, sizeof(namebuffer), "sound/%s", name); } - size = FS_LoadFile( namebuffer, (void **) &data ); + size = FS_LoadFile(namebuffer, (void **)&data); - if ( !data ) + if (!data) { s->cache = NULL; - Com_DPrintf( "Couldn't load %s\n", namebuffer ); - return ( NULL ); + Com_DPrintf("Couldn't load %s\n", namebuffer); + return NULL; } - info = GetWavinfo( s->name, data, size ); + info = GetWavinfo(s->name, data, size); - if ( info.channels != 1 ) + if (info.channels != 1) { - Com_Printf( "%s is a stereo sample\n", s->name ); - FS_FreeFile( data ); - return ( NULL ); + Com_Printf("%s is a stereo sample\n", s->name); + FS_FreeFile(data); + return NULL; } - if (sound_started != SS_OAL) { - stepscale = (float) info.rate / dma.speed; - len = (int) ( info.samples / stepscale ); - if ( ( info.samples == 0 ) || ( len == 0 ) ) + if (sound_started != SS_OAL) + { + stepscale = (float)info.rate / dma.speed; + len = (int)(info.samples / stepscale); + + if ((info.samples == 0) || (len == 0)) { - Com_Printf( "WARNING: Zero length sound encountered: %s\n", s->name ); - FS_FreeFile( data ); - return ( NULL ); + Com_Printf("WARNING: Zero length sound encountered: %s\n", s->name); + FS_FreeFile(data); + return NULL; } len = len * info.width * info.channels; - sc = s->cache = Z_Malloc( len + sizeof ( sfxcache_t ) ); + sc = s->cache = Z_Malloc(len + sizeof(sfxcache_t)); - if ( !sc ) + if (!sc) { - FS_FreeFile( data ); - return ( NULL ); + FS_FreeFile(data); + return NULL; } sc->length = info.samples; @@ -199,12 +205,17 @@ S_LoadSound ( sfx_t *s ) #if USE_OPENAL if (sound_started == SS_OAL) + { sc = AL_UploadSfx(s, &info, data + info.dataofs); + } else #endif - ResampleSfx( s, sc->speed, sc->width, data + info.dataofs ); + { + ResampleSfx(s, sc->speed, sc->width, data + info.dataofs); + } - FS_FreeFile( data ); + FS_FreeFile(data); - return ( sc ); + return sc; } + diff --git a/src/client/sound/snd_vorbis.c b/src/client/sound/snd_vorbis.c index 99a49bbe..1a8a83ee 100644 --- a/src/client/sound/snd_vorbis.c +++ b/src/client/sound/snd_vorbis.c @@ -29,10 +29,10 @@ #ifdef OGG +#define OV_EXCLUDE_STATIC_CALLBACKS + #include #include - -#define OV_EXCLUDE_STATIC_CALLBACKS #include #include "../header/client.h" @@ -43,46 +43,46 @@ void AL_UnqueueRawSamples(); #endif -qboolean ogg_first_init = true; /* First initialization flag. */ -qboolean ogg_started = false; /* Initialization flag. */ -int ogg_bigendian = 0; -byte *ogg_buffer; /* File buffer. */ -char **ogg_filelist; /* List of Ogg Vorbis files. */ -char ovBuf [ 4096 ]; /* Buffer for sound. */ -int ogg_curfile; /* Index of currently played file. */ -int ogg_numfiles; /* Number of Ogg Vorbis files. */ -int ovSection; /* Position in Ogg Vorbis file. */ -ogg_status_t ogg_status; /* Status indicator. */ -cvar_t *ogg_autoplay; /* Play this song when started. */ -cvar_t *ogg_check; /* Check Ogg files or not. */ -cvar_t *ogg_playlist; /* Playlist. */ -cvar_t *ogg_sequence; /* Sequence play indicator. */ -cvar_t *ogg_volume; /* Music volume. */ -OggVorbis_File ovFile; /* Ogg Vorbis file. */ -vorbis_info *ogg_info; /* Ogg Vorbis file information */ -int ogg_numbufs; /* Number of buffers for OpenAL */ +qboolean ogg_first_init = true; /* First initialization flag. */ +qboolean ogg_started = false; /* Initialization flag. */ +int ogg_bigendian = 0; +byte *ogg_buffer; /* File buffer. */ +char **ogg_filelist; /* List of Ogg Vorbis files. */ +char ovBuf[4096]; /* Buffer for sound. */ +int ogg_curfile; /* Index of currently played file. */ +int ogg_numfiles; /* Number of Ogg Vorbis files. */ +int ovSection; /* Position in Ogg Vorbis file. */ +ogg_status_t ogg_status; /* Status indicator. */ +cvar_t *ogg_autoplay; /* Play this song when started. */ +cvar_t *ogg_check; /* Check Ogg files or not. */ +cvar_t *ogg_playlist; /* Playlist. */ +cvar_t *ogg_sequence; /* Sequence play indicator. */ +cvar_t *ogg_volume; /* Music volume. */ +OggVorbis_File ovFile; /* Ogg Vorbis file. */ +vorbis_info *ogg_info; /* Ogg Vorbis file information */ +int ogg_numbufs; /* Number of buffers for OpenAL */ /* * Initialize the Ogg Vorbis subsystem. */ void -OGG_Init ( void ) +OGG_Init(void) { - cvar_t *cv; /* Cvar pointer. */ + cvar_t *cv; /* Cvar pointer. */ - if ( ogg_started ) + if (ogg_started) { return; } - Com_Printf( "Starting Ogg Vorbis.\n" ); + Com_Printf("Starting Ogg Vorbis.\n"); /* Skip initialization if disabled. */ - cv = Cvar_Get( "ogg_enable", "0", CVAR_ARCHIVE ); + cv = Cvar_Get("ogg_enable", "0", CVAR_ARCHIVE); - if ( cv->value != 1 ) + if (cv->value != 1) { - Com_Printf( "Ogg Vorbis not initializing.\n" ); + Com_Printf("Ogg Vorbis not initializing.\n"); return; } @@ -92,46 +92,46 @@ OGG_Init ( void ) } /* Cvars. */ - ogg_autoplay = Cvar_Get( "ogg_autoplay", "?", CVAR_ARCHIVE ); - ogg_check = Cvar_Get( "ogg_check", "0", CVAR_ARCHIVE ); - ogg_playlist = Cvar_Get( "ogg_playlist", "playlist", CVAR_ARCHIVE ); - ogg_sequence = Cvar_Get( "ogg_sequence", "loop", CVAR_ARCHIVE ); - ogg_volume = Cvar_Get( "ogg_volume", "0.7", CVAR_ARCHIVE ); + ogg_autoplay = Cvar_Get("ogg_autoplay", "?", CVAR_ARCHIVE); + ogg_check = Cvar_Get("ogg_check", "0", CVAR_ARCHIVE); + ogg_playlist = Cvar_Get("ogg_playlist", "playlist", CVAR_ARCHIVE); + ogg_sequence = Cvar_Get("ogg_sequence", "loop", CVAR_ARCHIVE); + ogg_volume = Cvar_Get("ogg_volume", "0.7", CVAR_ARCHIVE); /* Console commands. */ - Cmd_AddCommand( "ogg_list", OGG_ListCmd ); - Cmd_AddCommand( "ogg_pause", OGG_PauseCmd ); - Cmd_AddCommand( "ogg_play", OGG_PlayCmd ); - Cmd_AddCommand( "ogg_reinit", OGG_Reinit ); - Cmd_AddCommand( "ogg_resume", OGG_ResumeCmd ); - Cmd_AddCommand( "ogg_seek", OGG_SeekCmd ); - Cmd_AddCommand( "ogg_status", OGG_StatusCmd ); - Cmd_AddCommand( "ogg_stop", OGG_Stop ); + Cmd_AddCommand("ogg_list", OGG_ListCmd); + Cmd_AddCommand("ogg_pause", OGG_PauseCmd); + Cmd_AddCommand("ogg_play", OGG_PlayCmd); + Cmd_AddCommand("ogg_reinit", OGG_Reinit); + Cmd_AddCommand("ogg_resume", OGG_ResumeCmd); + Cmd_AddCommand("ogg_seek", OGG_SeekCmd); + Cmd_AddCommand("ogg_status", OGG_StatusCmd); + Cmd_AddCommand("ogg_stop", OGG_Stop); /* Build list of files. */ ogg_numfiles = 0; - if ( ogg_playlist->string [ 0 ] != '\0' ) + if (ogg_playlist->string[0] != '\0') { - OGG_LoadPlaylist( ogg_playlist->string ); + OGG_LoadPlaylist(ogg_playlist->string); } - if ( ogg_numfiles == 0 ) + if (ogg_numfiles == 0) { OGG_LoadFileList(); } /* Check if we have Ogg Vorbis files. */ - if ( ogg_numfiles <= 0 ) + if (ogg_numfiles <= 0) { - Com_Printf( "No Ogg Vorbis files found.\n" ); + Com_Printf("No Ogg Vorbis files found.\n"); ogg_started = true; /* For OGG_Shutdown(). */ OGG_Shutdown(); return; } /* Initialize variables. */ - if ( ogg_first_init ) + if (ogg_first_init) { ogg_buffer = NULL; ogg_curfile = -1; @@ -142,12 +142,12 @@ OGG_Init ( void ) ogg_started = true; - Com_Printf( "%d Ogg Vorbis files found.\n", ogg_numfiles ); + Com_Printf("%d Ogg Vorbis files found.\n", ogg_numfiles); /* Autoplay support. */ - if ( ogg_autoplay->string [ 0 ] != '\0' ) + if (ogg_autoplay->string[0] != '\0') { - OGG_ParseCmd( ogg_autoplay->string ); + OGG_ParseCmd(ogg_autoplay->string); } } @@ -155,29 +155,29 @@ OGG_Init ( void ) * Shutdown the Ogg Vorbis subsystem. */ void -OGG_Shutdown ( void ) +OGG_Shutdown(void) { - if ( !ogg_started ) + if (!ogg_started) { return; } - Com_Printf( "Shutting down Ogg Vorbis.\n" ); + Com_Printf("Shutting down Ogg Vorbis.\n"); OGG_Stop(); /* Free the list of files. */ - FS_FreeList( ogg_filelist, ogg_numfiles + 1 ); + FS_FreeList(ogg_filelist, ogg_numfiles + 1); /* Remove console commands. */ - Cmd_RemoveCommand( "ogg_list" ); - Cmd_RemoveCommand( "ogg_pause" ); - Cmd_RemoveCommand( "ogg_play" ); - Cmd_RemoveCommand( "ogg_reinit" ); - Cmd_RemoveCommand( "ogg_resume" ); - Cmd_RemoveCommand( "ogg_seek" ); - Cmd_RemoveCommand( "ogg_status" ); - Cmd_RemoveCommand( "ogg_stop" ); + Cmd_RemoveCommand("ogg_list"); + Cmd_RemoveCommand("ogg_pause"); + Cmd_RemoveCommand("ogg_play"); + Cmd_RemoveCommand("ogg_reinit"); + Cmd_RemoveCommand("ogg_resume"); + Cmd_RemoveCommand("ogg_seek"); + Cmd_RemoveCommand("ogg_status"); + Cmd_RemoveCommand("ogg_stop"); ogg_started = false; } @@ -186,7 +186,7 @@ OGG_Shutdown ( void ) * Reinitialize the Ogg Vorbis subsystem. */ void -OGG_Reinit ( void ) +OGG_Reinit(void) { OGG_Shutdown(); OGG_Init(); @@ -196,93 +196,94 @@ OGG_Reinit ( void ) * Check if the file is a valid Ogg Vorbis file. */ qboolean -OGG_Check ( char *name ) +OGG_Check(char *name) { qboolean res; /* Return value. */ - byte *buffer; /* File buffer. */ + byte *buffer; /* File buffer. */ int size; /* File size. */ OggVorbis_File ovf; /* Ogg Vorbis file. */ - if ( ogg_check->value == 0 ) + if (ogg_check->value == 0) { - return ( true ); + return true; } res = false; - if ( ( size = FS_LoadFile( name, (void **) &buffer ) ) > 0 ) + if ((size = FS_LoadFile(name, (void **)&buffer)) > 0) { - if ( ov_test( NULL, &ovf, (char *) buffer, size ) == 0 ) + if (ov_test(NULL, &ovf, (char *)buffer, size) == 0) { res = true; - ov_clear( &ovf ); + ov_clear(&ovf); } - FS_FreeFile( buffer ); + FS_FreeFile(buffer); } - return ( res ); + return res; } /* * Change position in the file. */ void -OGG_Seek ( ogg_seek_t type, double offset ) +OGG_Seek(ogg_seek_t type, double offset) { double pos; /* Position in file (in seconds). */ double total; /* Length of file (in seconds). */ /* Check if the file is seekable. */ - if ( ov_seekable( &ovFile ) == 0 ) + if (ov_seekable(&ovFile) == 0) { - Com_Printf( "OGG_Seek: file is not seekable.\n" ); + Com_Printf("OGG_Seek: file is not seekable.\n"); return; } /* Get file information. */ - pos = ov_time_tell( &ovFile ); - total = ov_time_total( &ovFile, -1 ); + pos = ov_time_tell(&ovFile); + total = ov_time_total(&ovFile, -1); - switch ( type ) + switch (type) { case ABS: - if ( ( offset >= 0 ) && ( offset <= total ) ) + if ((offset >= 0) && (offset <= total)) { - if ( ov_time_seek( &ovFile, offset ) != 0 ) + if (ov_time_seek(&ovFile, offset) != 0) { - Com_Printf( "OGG_Seek: could not seek.\n" ); + Com_Printf("OGG_Seek: could not seek.\n"); } else { - Com_Printf( "%0.2f -> %0.2f of %0.2f.\n", pos, offset, total ); + Com_Printf("%0.2f -> %0.2f of %0.2f.\n", pos, offset, total); } } else { - Com_Printf( "OGG_Seek: invalid offset.\n" ); + Com_Printf("OGG_Seek: invalid offset.\n"); } break; case REL: - if ( ( pos + offset >= 0 ) && ( pos + offset <= total ) ) + if ((pos + offset >= 0) && (pos + offset <= total)) { - if ( ov_time_seek( &ovFile, pos + offset ) != 0 ) + if (ov_time_seek(&ovFile, pos + offset) != 0) { - Com_Printf( "OGG_Seek: could not seek.\n" ); + Com_Printf("OGG_Seek: could not seek.\n"); } else { - Com_Printf( "%0.2f -> %0.2f of %0.2f.\n", pos, pos + offset, total ); + Com_Printf("%0.2f -> %0.2f of %0.2f.\n", + pos, pos + offset, total); } } else { - Com_Printf( "OGG_Seek: invalid offset.\n" ); + Com_Printf("OGG_Seek: invalid offset.\n"); } break; @@ -293,115 +294,122 @@ OGG_Seek ( ogg_seek_t type, double offset ) * Load list of Ogg Vorbis files in "music". */ void -OGG_LoadFileList ( void ) +OGG_LoadFileList(void) { - char **list; /* List of .ogg files. */ - int i; /* Loop counter. */ - int j; /* Real position in list. */ + char **list; /* List of .ogg files. */ + int i; /* Loop counter. */ + int j; /* Real position in list. */ /* Get file list. */ - list = FS_ListFiles2( va( "%s/*.ogg", OGG_DIR ), &ogg_numfiles, 0, SFF_SUBDIR | SFF_HIDDEN | SFF_SYSTEM ); + list = FS_ListFiles2(va("%s/*.ogg", OGG_DIR), + &ogg_numfiles, 0, SFF_SUBDIR | SFF_HIDDEN | + SFF_SYSTEM); ogg_numfiles--; /* Check if there are posible Ogg files. */ - if ( list == NULL ) + if (list == NULL) { return; } /* Allocate list of files. */ - ogg_filelist = malloc( sizeof ( char * ) * ogg_numfiles ); + ogg_filelist = malloc(sizeof(char *) * ogg_numfiles); /* Add valid Ogg Vorbis file to the list. */ - for ( i = 0, j = 0; i < ogg_numfiles; i++ ) + for (i = 0, j = 0; i < ogg_numfiles; i++) { - if ( !OGG_Check( list [ i ] ) ) + if (!OGG_Check(list[i])) { - free( list [ i ] ); + free(list[i]); continue; } - ogg_filelist [ j++ ] = list [ i ]; + ogg_filelist[j++] = list[i]; } /* Free the file list. */ - free( list ); + free(list); - /* Adjust the list size (remove space for invalid music files). */ + /* Adjust the list size (remove + space for invalid music files). */ ogg_numfiles = j; - ogg_filelist = realloc( ogg_filelist, sizeof ( char * ) * ogg_numfiles ); + ogg_filelist = realloc(ogg_filelist, sizeof(char *) * ogg_numfiles); } /* * Load playlist. */ void -OGG_LoadPlaylist ( char *playlist ) +OGG_LoadPlaylist(char *playlist) { - byte *buffer; /* Buffer to read the file. */ - char *ptr; /* Pointer for parsing the file. */ - int i; /* Loop counter. */ + byte *buffer; /* Buffer to read the file. */ + char *ptr; /* Pointer for parsing the file. */ + int i; /* Loop counter. */ int size; /* Length of buffer and strings. */ /* Open playlist. */ - if ( ( size = FS_LoadFile( va( "%s/%s.lst", OGG_DIR, ogg_playlist->string ), (void **) &buffer ) ) < 0 ) + if ((size = FS_LoadFile(va("%s/%s.lst", OGG_DIR, + ogg_playlist->string), (void **)&buffer)) < 0) { - Com_Printf( "OGG_LoadPlaylist: could not open playlist: %s.\n", strerror( errno ) ); + Com_Printf("OGG_LoadPlaylist: could not open playlist: %s.\n", + strerror(errno)); return; } /* Count the files in playlist. */ - for ( ptr = strtok( (char *)buffer, "\n" ); ptr != NULL; ptr = strtok( NULL, "\n" ) ) + for (ptr = strtok((char *)buffer, "\n"); + ptr != NULL; + ptr = strtok(NULL, "\n")) { - if ( (byte *) ptr != buffer ) + if ((byte *)ptr != buffer) { - ptr [ -1 ] = '\n'; + ptr[-1] = '\n'; } - if ( OGG_Check( va( "%s/%s", OGG_DIR, ptr ) ) ) + if (OGG_Check(va("%s/%s", OGG_DIR, ptr))) { ogg_numfiles++; } } /* Allocate file list. */ - ogg_filelist = malloc( sizeof ( char * ) * ogg_numfiles ); + ogg_filelist = malloc(sizeof(char *) * ogg_numfiles); i = 0; - for ( ptr = strtok( (char *) buffer, "\n" ); - ptr != NULL; - ptr = strtok( NULL, "\n" ) ) + for (ptr = strtok((char *)buffer, "\n"); + ptr != NULL; + ptr = strtok(NULL, "\n")) { - if ( OGG_Check( va( "%s/%s", OGG_DIR, ptr ) ) ) + if (OGG_Check(va("%s/%s", OGG_DIR, ptr))) { - ogg_filelist [ i++ ] = strdup( va( "%s/%s", OGG_DIR, ptr ) ); + ogg_filelist[i++] = strdup(va("%s/%s", OGG_DIR, ptr)); } } /* Free file buffer. */ - FS_FreeFile( buffer ); + FS_FreeFile(buffer); } /* * Play Ogg Vorbis file (with absolute or relative index). */ qboolean -OGG_Open ( ogg_seek_t type, int offset ) +OGG_Open(ogg_seek_t type, int offset) { int size; /* File size. */ - int pos = -1; /* Absolute position. */ + int pos = -1; /* Absolute position. */ int res; /* Error indicator. */ - switch ( type ) + switch (type) { case ABS: /* Absolute index. */ - if ( ( offset < 0 ) || ( offset >= ogg_numfiles ) ) + if ((offset < 0) || (offset >= ogg_numfiles)) { - Com_Printf( "OGG_Open: %d out of range.\n", offset + 1 ); - return ( false ); + Com_Printf("OGG_Open: %d out of range.\n", offset + 1); + return false; } else { @@ -412,17 +420,17 @@ OGG_Open ( ogg_seek_t type, int offset ) case REL: /* Simulate a loopback. */ - if ( ( ogg_curfile == -1 ) && ( offset < 0 ) ) + if ((ogg_curfile == -1) && (offset < 0)) { offset++; } - while ( ogg_curfile + offset < 0 ) + while (ogg_curfile + offset < 0) { offset += ogg_numfiles; } - while ( ogg_curfile + offset >= ogg_numfiles ) + while (ogg_curfile + offset >= ogg_numfiles) { offset -= ogg_numfiles; } @@ -432,11 +440,11 @@ OGG_Open ( ogg_seek_t type, int offset ) } /* Check running music. */ - if ( ogg_status == PLAY ) + if (ogg_status == PLAY) { - if ( ogg_curfile == pos ) + if (ogg_curfile == pos) { - return ( true ); + return true; } else @@ -446,29 +454,32 @@ OGG_Open ( ogg_seek_t type, int offset ) } /* Find file. */ - if ( ( size = FS_LoadFile( ogg_filelist [ pos ], (void **) &ogg_buffer ) ) == -1 ) + if ((size = FS_LoadFile(ogg_filelist[pos], (void **)&ogg_buffer)) == -1) { - Com_Printf( "OGG_Open: could not open %d (%s): %s.\n", pos, ogg_filelist [ pos ], strerror( errno ) ); - return ( false ); + Com_Printf("OGG_Open: could not open %d (%s): %s.\n", + pos, ogg_filelist[pos], strerror(errno)); + return false; } /* Open ogg vorbis file. */ - if ( ( res = ov_open( NULL, &ovFile, (char *) ogg_buffer, size ) ) < 0 ) + if ((res = ov_open(NULL, &ovFile, (char *)ogg_buffer, size)) < 0) { - Com_Printf( "OGG_Open: '%s' is not a valid Ogg Vorbis file (error %i).\n", ogg_filelist [ pos ], res ); - FS_FreeFile( ogg_buffer ); + Com_Printf("OGG_Open: '%s' is not a valid Ogg Vorbis file (error %i).\n", + ogg_filelist[pos], res); FS_FreeFile(ogg_buffer); ogg_buffer = NULL; - return ( false ); + return false; } ogg_info = ov_info(&ovFile, 0); + if (!ogg_info) { - Com_Printf( "OGG_Open: Unable to get stream information for %s.\n", ogg_filelist [ pos ] ); - ov_clear( &ovFile ); - FS_FreeFile( ogg_buffer ); + Com_Printf("OGG_Open: Unable to get stream information for %s.\n", + ogg_filelist[pos]); + ov_clear(&ovFile); + FS_FreeFile(ogg_buffer); ogg_buffer = NULL; - return ( false ); + return false; } /* Play file. */ @@ -476,44 +487,44 @@ OGG_Open ( ogg_seek_t type, int offset ) ogg_curfile = pos; ogg_status = PLAY; - return ( true ); + return true; } /* * Play Ogg Vorbis file (with name only). */ qboolean -OGG_OpenName ( char *filename ) +OGG_OpenName(char *filename) { - char *name; /* File name. */ - int i; /* Loop counter. */ + char *name; /* File name. */ + int i; /* Loop counter. */ - /* If the track name is '00' stop playback */ + /* If the track name is '00', stop playback */ if (!strncmp(filename, "00", sizeof(char) * 3)) { OGG_PauseCmd(); - return ( false ); + return false; } - name = va( "%s/%s.ogg", OGG_DIR, filename ); + name = va("%s/%s.ogg", OGG_DIR, filename); - for ( i = 0; i < ogg_numfiles; i++ ) + for (i = 0; i < ogg_numfiles; i++) { - if ( strcmp( name, ogg_filelist [ i ] ) == 0 ) + if (strcmp(name, ogg_filelist[i]) == 0) { break; } } - if ( i < ogg_numfiles ) + if (i < ogg_numfiles) { - return ( OGG_Open( ABS, i ) ); + return OGG_Open(ABS, i); } else { - Com_Printf( "OGG_OpenName: '%s' not in the list.\n", filename ); - return ( false ); + Com_Printf("OGG_OpenName: '%s' not in the list.\n", filename); + return false; } } @@ -521,55 +532,58 @@ OGG_OpenName ( char *filename ) * Play a portion of the currently opened file. */ int -OGG_Read ( void ) +OGG_Read(void) { - int res; /* Number of bytes read. */ + int res; /* Number of bytes read. */ /* Read and resample. */ - res = ov_read( &ovFile, ovBuf, sizeof ( ovBuf ), ogg_bigendian, OGG_SAMPLEWIDTH, 1, &ovSection ); - S_RawSamples( res / (OGG_SAMPLEWIDTH * ogg_info->channels), - ogg_info->rate, OGG_SAMPLEWIDTH, ogg_info->channels, (byte *) ovBuf, ogg_volume->value ); + res = ov_read(&ovFile, ovBuf, sizeof(ovBuf), + ogg_bigendian, OGG_SAMPLEWIDTH, 1, + &ovSection); + S_RawSamples(res / (OGG_SAMPLEWIDTH * ogg_info->channels), + ogg_info->rate, OGG_SAMPLEWIDTH, ogg_info->channels, + (byte *)ovBuf, ogg_volume->value); /* Check for end of file. */ - if ( res == 0 ) + if (res == 0) { OGG_Stop(); OGG_Sequence(); } - return ( res ); + return res; } /* * Play files in sequence. */ void -OGG_Sequence ( void ) +OGG_Sequence(void) { - if ( strcmp( ogg_sequence->string, "next" ) == 0 ) + if (strcmp(ogg_sequence->string, "next") == 0) { - OGG_Open( REL, 1 ); + OGG_Open(REL, 1); } - else if ( strcmp( ogg_sequence->string, "prev" ) == 0 ) + else if (strcmp(ogg_sequence->string, "prev") == 0) { - OGG_Open( REL, -1 ); + OGG_Open(REL, -1); } - else if ( strcmp( ogg_sequence->string, "random" ) == 0 ) + else if (strcmp(ogg_sequence->string, "random") == 0) { - OGG_Open( ABS, randk() % ogg_numfiles ); + OGG_Open(ABS, randk() % ogg_numfiles); } - else if ( strcmp( ogg_sequence->string, "loop" ) == 0 ) + else if (strcmp(ogg_sequence->string, "loop") == 0) { - OGG_Open( REL, 0 ); + OGG_Open(REL, 0); } - else if ( strcmp( ogg_sequence->string, "none" ) != 0 ) + else if (strcmp(ogg_sequence->string, "none") != 0) { - Com_Printf( "Invalid value of ogg_sequence: %s\n", ogg_sequence->string ); - Cvar_Set( "ogg_sequence", "none" ); + Com_Printf("Invalid value of ogg_sequence: %s\n", ogg_sequence->string); + Cvar_Set("ogg_sequence", "none"); } } @@ -577,27 +591,28 @@ OGG_Sequence ( void ) * Stop playing the current file. */ void -OGG_Stop ( void ) +OGG_Stop(void) { - if ( ogg_status == STOP ) + if (ogg_status == STOP) { return; } #ifdef USE_OPENAL - if(sound_started == SS_OAL) { + if (sound_started == SS_OAL) + { AL_UnqueueRawSamples(); } #endif - ov_clear( &ovFile ); + ov_clear(&ovFile); ogg_status = STOP; ogg_info = NULL; ogg_numbufs = 0; - if ( ogg_buffer != NULL ) + if (ogg_buffer != NULL) { - FS_FreeFile( ogg_buffer ); + FS_FreeFile(ogg_buffer); ogg_buffer = NULL; } } @@ -606,18 +621,17 @@ OGG_Stop ( void ) * Stream music. */ void -OGG_Stream ( void ) +OGG_Stream(void) { - if ( !ogg_started ) + if (!ogg_started) { return; } - - if ( ogg_status == PLAY ) + if (ogg_status == PLAY) { #ifdef USE_OPENAL - if ( sound_started == SS_OAL ) + if (sound_started == SS_OAL) { /* Calculate the number of buffers used for storing decoded OGG/Vorbis data. @@ -631,101 +645,100 @@ OGG_Stream ( void ) seconds playback. The music won't stutter as long as the framerate stayes over 1 FPS. */ - if ( ogg_numbufs == 0 ) + if (ogg_numbufs == 0) { ogg_numbufs = active_buffers + 64; } /* active_buffers are all active OpenAL buffers, buffering normal sfx _and_ ogg/vorbis samples. */ - while ( active_buffers <= ogg_numbufs ) + while (active_buffers <= ogg_numbufs) { OGG_Read(); } - } else { /* using DMA/SDL */ + } + else /* using SDL */ #endif + { /* Read that number samples into the buffer, that were played since the last call to this function. This keeps the buffer at all times at an "optimal" fill level. */ - while ( paintedtime + MAX_RAW_SAMPLES - 2048 > s_rawend ) + while (paintedtime + MAX_RAW_SAMPLES - 2048 > s_rawend) { OGG_Read(); } -#ifdef USE_OPENAL - } /* using DMA/SDL */ -#endif + } /* using SDL */ } /* ogg_status == PLAY */ - } /* * List Ogg Vorbis files. */ void -OGG_ListCmd ( void ) +OGG_ListCmd(void) { int i; - for ( i = 0; i < ogg_numfiles; i++ ) + for (i = 0; i < ogg_numfiles; i++) { - Com_Printf( "%d %s\n", i + 1, ogg_filelist [ i ] ); + Com_Printf("%d %s\n", i + 1, ogg_filelist[i]); } - Com_Printf( "%d Ogg Vorbis files.\n", ogg_numfiles ); + Com_Printf("%d Ogg Vorbis files.\n", ogg_numfiles); } /* * Parse play controls. */ void -OGG_ParseCmd ( char *arg ) +OGG_ParseCmd(char *arg) { int n; cvar_t *ogg_enable; - ogg_enable = Cvar_Get( "ogg_enable", "0", CVAR_ARCHIVE ); + ogg_enable = Cvar_Get("ogg_enable", "0", CVAR_ARCHIVE); - switch ( arg [ 0 ] ) + switch (arg[0]) { case '#': - n = (int)strtol( arg + 1, (char **)NULL, 10) - 1; - OGG_Open( ABS, n ); + n = (int)strtol(arg + 1, (char **)NULL, 10) - 1; + OGG_Open(ABS, n); break; case '?': - OGG_Open( ABS, randk() % ogg_numfiles ); + OGG_Open(ABS, randk() % ogg_numfiles); break; case '>': - if ( strlen( arg ) > 1 ) + if (strlen(arg) > 1) { - OGG_Open( REL, (int)strtol( arg + 1, (char **)NULL, 10 ) ); + OGG_Open(REL, (int)strtol(arg + 1, (char **)NULL, 10)); } else { - OGG_Open( REL, 1 ); + OGG_Open(REL, 1); } break; case '<': - if ( strlen( arg ) > 1 ) + if (strlen(arg) > 1) { - OGG_Open( REL, -(int)strtol( arg + 1, (char **)NULL, 10 ) ); + OGG_Open(REL, -(int)strtol(arg + 1, (char **)NULL, 10)); } else { - OGG_Open( REL, -1 ); + OGG_Open(REL, -1); } break; default: - if ( ogg_enable->value != 0 ) + if (ogg_enable->value != 0) { - OGG_OpenName( arg ); + OGG_OpenName(arg); } break; @@ -736,9 +749,9 @@ OGG_ParseCmd ( char *arg ) * Pause current song. */ void -OGG_PauseCmd ( void ) +OGG_PauseCmd(void) { - if ( ogg_status == PLAY ) + if (ogg_status == PLAY) { ogg_status = PAUSE; ogg_numbufs = 0; @@ -749,24 +762,24 @@ OGG_PauseCmd ( void ) * Play control. */ void -OGG_PlayCmd ( void ) +OGG_PlayCmd(void) { - if ( Cmd_Argc() < 2 ) + if (Cmd_Argc() < 2) { - Com_Printf( "Usage: ogg_play {filename | #n | ? | >n | n | n}\n" ); + Com_Printf("Usage: ogg_seek {n | n}\n"); return; } - switch ( Cmd_Argv( 1 ) [ 0 ] ) + switch (Cmd_Argv(1)[0]) { case '>': - OGG_Seek( REL, strtod( Cmd_Argv( 1 ) + 1 , (char **)NULL ) ); + OGG_Seek(REL, strtod(Cmd_Argv(1) + 1, (char **)NULL)); break; case '<': - OGG_Seek( REL, -strtod( Cmd_Argv( 1 ) + 1, (char **)NULL ) ); + OGG_Seek(REL, -strtod(Cmd_Argv(1) + 1, (char **)NULL)); break; default: - OGG_Seek( ABS, strtod( Cmd_Argv( 1 ), (char **)NULL ) ); + OGG_Seek(ABS, strtod(Cmd_Argv(1), (char **)NULL)); break; } } @@ -807,33 +820,36 @@ OGG_SeekCmd ( void ) * Display status. */ void -OGG_StatusCmd ( void ) +OGG_StatusCmd(void) { - switch ( ogg_status ) + switch (ogg_status) { case PLAY: - Com_Printf( "Playing file %d (%s) at %0.2f seconds.\n", - ogg_curfile + 1, ogg_filelist [ ogg_curfile ], ov_time_tell( &ovFile ) ); + Com_Printf("Playing file %d (%s) at %0.2f seconds.\n", + ogg_curfile + 1, ogg_filelist[ogg_curfile], + ov_time_tell(&ovFile)); break; case PAUSE: - Com_Printf( "Paused file %d (%s) at %0.2f seconds.\n", - ogg_curfile + 1, ogg_filelist [ ogg_curfile ], ov_time_tell( &ovFile ) ); + Com_Printf("Paused file %d (%s) at %0.2f seconds.\n", + ogg_curfile + 1, ogg_filelist[ogg_curfile], + ov_time_tell(&ovFile)); break; case STOP: - if ( ogg_curfile == -1 ) + if (ogg_curfile == -1) { - Com_Printf( "Stopped.\n" ); + Com_Printf("Stopped.\n"); } else { - Com_Printf( "Stopped file %d (%s).\n", - ogg_curfile + 1, ogg_filelist [ ogg_curfile ] ); + Com_Printf("Stopped file %d (%s).\n", + ogg_curfile + 1, ogg_filelist[ogg_curfile]); } break; } } -# endif /* OGG */ +#endif /* OGG */ + diff --git a/src/client/sound/snd_wav.c b/src/client/sound/snd_wav.c index 081fcd86..d5f6344b 100644 --- a/src/client/sound/snd_wav.c +++ b/src/client/sound/snd_wav.c @@ -19,7 +19,7 @@ * * ======================================================================= * - * This file implements a subset of the WAVE audio file format + * This file implements a subset of the WAVE audio file format. * * ======================================================================= */ @@ -27,48 +27,45 @@ #include "../header/client.h" #include "header/local.h" -// FIXME: this code is really fucked up, those global variables make me sick. -// someone should clean this up one day.. - -byte *data_p; -byte *iff_end; -byte *last_chunk; -byte *iff_data; -int iff_chunk_len; +byte *data_p; +byte *iff_end; +byte *last_chunk; +byte *iff_data; +int iff_chunk_len; short -GetLittleShort ( void ) +GetLittleShort(void) { short val = 0; val = *data_p; - val = val + ( *( data_p + 1 ) << 8 ); + val = val + (*(data_p + 1) << 8); data_p += 2; - return ( val ); + return val; } int -GetLittleLong ( void ) +GetLittleLong(void) { int val = 0; val = *data_p; - val = val + ( *( data_p + 1 ) << 8 ); - val = val + ( *( data_p + 2 ) << 16 ); - val = val + ( *( data_p + 3 ) << 24 ); + val = val + (*(data_p + 1) << 8); + val = val + (*(data_p + 2) << 16); + val = val + (*(data_p + 3) << 24); data_p += 4; - return ( val ); + return val; } void -FindNextChunk ( char *name ) +FindNextChunk(char *name) { - while ( 1 ) + while (1) { data_p = last_chunk; data_p += 4; - if ( data_p >= iff_end ) + if (data_p >= iff_end) { data_p = NULL; return; @@ -76,16 +73,16 @@ FindNextChunk ( char *name ) iff_chunk_len = GetLittleLong(); - if ( iff_chunk_len < 0 ) + if (iff_chunk_len < 0) { data_p = NULL; return; } data_p -= 8; - last_chunk = data_p + 8 + ( ( iff_chunk_len + 1 ) & ~1 ); + last_chunk = data_p + 8 + ((iff_chunk_len + 1) & ~1); - if ( !strncmp( (const char *) data_p, name, 4 ) ) + if (!strncmp((const char *)data_p, name, 4)) { return; } @@ -93,57 +90,57 @@ FindNextChunk ( char *name ) } void -FindChunk ( char *name ) +FindChunk(char *name) { last_chunk = iff_data; - FindNextChunk( name ); + FindNextChunk(name); } wavinfo_t -GetWavinfo ( char *name, byte *wav, int wavlength ) +GetWavinfo(char *name, byte *wav, int wavlength) { wavinfo_t info; int i; int format; int samples; - memset( &info, 0, sizeof ( info ) ); + memset(&info, 0, sizeof(info)); - if ( !wav ) + if (!wav) { - return ( info ); + return info; } iff_data = wav; iff_end = wav + wavlength; /* find "RIFF" chunk */ - FindChunk( "RIFF" ); + FindChunk("RIFF"); - if ( !( data_p && !strncmp( (const char *) data_p + 8, "WAVE", 4 ) ) ) + if (!(data_p && !strncmp((const char *)data_p + 8, "WAVE", 4))) { - Com_Printf( "Missing RIFF/WAVE chunks\n" ); - return ( info ); + Com_Printf("Missing RIFF/WAVE chunks\n"); + return info; } /* get "fmt " chunk */ iff_data = data_p + 12; - FindChunk( "fmt " ); + FindChunk("fmt "); - if ( !data_p ) + if (!data_p) { - Com_Printf( "Missing fmt chunk\n" ); - return ( info ); + Com_Printf("Missing fmt chunk\n"); + return info; } data_p += 8; format = GetLittleShort(); - if ( format != 1 ) + if (format != 1) { - Com_Printf( "Microsoft PCM format only\n" ); - return ( info ); + Com_Printf("Microsoft PCM format only\n"); + return info; } info.channels = GetLittleShort(); @@ -152,21 +149,24 @@ GetWavinfo ( char *name, byte *wav, int wavlength ) info.width = GetLittleShort() / 8; /* get cue chunk */ - FindChunk( "cue " ); + FindChunk("cue "); - if ( data_p ) + if (data_p) { data_p += 32; info.loopstart = GetLittleLong(); - /* if the next chunk is a LIST chunk, look for a cue length marker */ - FindNextChunk( "LIST" ); + /* if the next chunk is a LIST chunk, + look for a cue length marker */ + FindNextChunk("LIST"); - if ( data_p ) + if (data_p) { - if ( ( ( data_p - wav ) + 32 <= wavlength ) && !strncmp( (const char *) data_p + 28, "mark", 4 ) ) + if (((data_p - wav) + 32 <= wavlength) && + !strncmp((const char *)data_p + 28, "mark", 4)) { - /* this is not a proper parse, but it works with cooledit... */ + /* this is not a proper parse, + but it works with cooledit... */ data_p += 24; i = GetLittleLong(); /* samples in loop */ info.samples = info.loopstart + i; @@ -179,22 +179,22 @@ GetWavinfo ( char *name, byte *wav, int wavlength ) } /* find data chunk */ - FindChunk( "data" ); + FindChunk("data"); - if ( !data_p ) + if (!data_p) { - Com_Printf( "Missing data chunk\n" ); - return ( info ); + Com_Printf("Missing data chunk\n"); + return info; } data_p += 4; samples = GetLittleLong() / info.width; - if ( info.samples ) + if (info.samples) { - if ( samples < info.samples ) + if (samples < info.samples) { - Com_Error( ERR_DROP, "Sound %s has a bad loop length", name ); + Com_Error(ERR_DROP, "Sound %s has a bad loop length", name); } } else @@ -202,7 +202,8 @@ GetWavinfo ( char *name, byte *wav, int wavlength ) info.samples = samples; } - info.dataofs = (int) ( data_p - wav ); + info.dataofs = (int)(data_p - wav); - return ( info ); + return info; } +