sync several sound-related files with uhexen2 a little: move

DEFAULT_SOUND_PACKET_VOLUME and DEFAULT_SOUND_PACKET_ATTENUATION
from sound.h to protocol.h. remove unused gamealive, soundalive
and splitbuffer members from the dma_t structure. make SNDDMA_Init()
to take a dma_t* parameter and make sn static to snd_dma.c. copy
over LordHavoc's S_StartSound skip calculation fixes from uhexen2.
make many functions/data static to their respective files. many
whitespace/formatting clean-ups.


git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@356 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Ozkan Sezer 2010-12-30 21:10:26 +00:00
parent bcef8e85f0
commit f157f088d1
7 changed files with 167 additions and 185 deletions

View file

@ -22,13 +22,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef __CDAUDIO_H #ifndef __CDAUDIO_H
#define __CDAUDIO_H #define __CDAUDIO_H
int CDAudio_Init(void); int CDAudio_Init (void);
void CDAudio_Play(byte track, qboolean looping); void CDAudio_Play (byte track, qboolean looping);
void CDAudio_Stop(void); void CDAudio_Stop (void);
void CDAudio_Pause(void); void CDAudio_Pause (void);
void CDAudio_Resume(void); void CDAudio_Resume (void);
void CDAudio_Shutdown(void); void CDAudio_Shutdown (void);
void CDAudio_Update(void); void CDAudio_Update (void);
#endif /* __CDAUDIO_H */ #endif /* __CDAUDIO_H */

View file

@ -98,8 +98,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// a sound with no channel is a local only sound // a sound with no channel is a local only sound
#define SND_VOLUME (1<<0) // a byte #define SND_VOLUME (1<<0) // a byte
#define SND_ATTENUATION (1<<1) // a byte #define SND_ATTENUATION (1<<1) // a byte
#define SND_LOOPING (1<<2) // a long #define SND_LOOPING (1<<2) // a long
#define DEFAULT_SOUND_PACKET_VOLUME 255
#define DEFAULT_SOUND_PACKET_ATTENUATION 1.0
//johnfitz -- PROTOCOL_FITZQUAKE -- new bits //johnfitz -- PROTOCOL_FITZQUAKE -- new bits
#define SND_LARGEENTITY (1<<3) // a short + byte (instead of just a short) #define SND_LARGEENTITY (1<<3) // a short + byte (instead of just a short)
#define SND_LARGESOUND (1<<4) // a short soundindex (instead of a byte) #define SND_LARGESOUND (1<<4) // a short soundindex (instead of a byte)

View file

@ -24,10 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef __QUAKE_SOUND__ #ifndef __QUAKE_SOUND__
#define __QUAKE_SOUND__ #define __QUAKE_SOUND__
#define DEFAULT_SOUND_PACKET_VOLUME 255 /* !!! if this is changed, it must be changed in asm_i386.h too !!! */
#define DEFAULT_SOUND_PACKET_ATTENUATION 1.0
// !!! if this is changed, it much be changed in asm_i386.h too !!!
typedef struct typedef struct
{ {
int left; int left;
@ -36,72 +33,69 @@ typedef struct
typedef struct sfx_s typedef struct sfx_s
{ {
char name[MAX_QPATH]; char name[MAX_QPATH];
cache_user_t cache; cache_user_t cache;
} sfx_t; } sfx_t;
// !!! if this is changed, it much be changed in asm_i386.h too !!! /* !!! if this is changed, it must be changed in asm_i386.h too !!! */
typedef struct typedef struct
{ {
int length; int length;
int loopstart; int loopstart;
int speed; int speed;
int width; int width;
int stereo; int stereo;
byte data[1]; // variable sized byte data[1]; /* variable sized */
} sfxcache_t; } sfxcache_t;
typedef struct typedef struct
{ {
qboolean gamealive; int channels;
qboolean soundalive; int samples; /* mono samples in buffer */
qboolean splitbuffer; int submission_chunk; /* don't mix less than this # */
int channels; int samplepos; /* in mono samples */
int samples; // mono samples in buffer int samplebits;
int submission_chunk; // don't mix less than this # int speed;
int samplepos; // in mono samples
int samplebits;
int speed;
unsigned char *buffer; unsigned char *buffer;
} dma_t; } dma_t;
// !!! if this is changed, it much be changed in asm_i386.h too !!! /* !!! if this is changed, it must be changed in asm_i386.h too !!! */
typedef struct typedef struct
{ {
sfx_t *sfx; // sfx number sfx_t *sfx; /* sfx number */
int leftvol; // 0-255 volume int leftvol; /* 0-255 volume */
int rightvol; // 0-255 volume int rightvol; /* 0-255 volume */
int end; // end time in global paintsamples int end; /* end time in global paintsamples */
int pos; // sample position in sfx int pos; /* sample position in sfx */
int looping; // where to loop, -1 = no looping int looping; /* where to loop, -1 = no looping */
int entnum; // to allow overriding a specific sound int entnum; /* to allow overriding a specific sound */
int entchannel; // int entchannel;
vec3_t origin; // origin of sound effect vec3_t origin; /* origin of sound effect */
vec_t dist_mult; // distance multiplier (attenuation/clipK) vec_t dist_mult; /* distance multiplier (attenuation/clipK) */
int master_vol; // 0-255 master volume int master_vol; /* 0-255 master volume */
} channel_t; } channel_t;
#define WAV_FORMAT_PCM 1 #define WAV_FORMAT_PCM 1
typedef struct typedef struct
{ {
int rate; int rate;
int width; int width;
int channels; int channels;
int loopstart; int loopstart;
int samples; int samples;
int dataofs; // chunk starts this many bytes from file start int dataofs; /* chunk starts this many bytes from file start */
} wavinfo_t; } wavinfo_t;
void S_Init (void); void S_Init (void);
void S_Startup (void); void S_Startup (void);
void S_Shutdown (void); void S_Shutdown (void);
void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation); void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation);
void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation); void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation);
void S_StopSound (int entnum, int entchannel); void S_StopSound (int entnum, int entchannel);
void S_StopAllSounds(qboolean clear); void S_StopAllSounds(qboolean clear);
void S_ClearBuffer (void); void S_ClearBuffer (void);
void S_Update (vec3_t origin, vec3_t v_forward, vec3_t v_right, vec3_t v_up); void S_Update (vec3_t origin, vec3_t forward, vec3_t right, vec3_t up);
void S_ExtraUpdate (void); void S_ExtraUpdate (void);
void S_BlockSound (void); void S_BlockSound (void);
@ -112,28 +106,28 @@ void S_TouchSound (const char *sample);
void S_ClearPrecache (void); void S_ClearPrecache (void);
void S_BeginPrecaching (void); void S_BeginPrecaching (void);
void S_EndPrecaching (void); void S_EndPrecaching (void);
void S_PaintChannels(int endtime); void S_PaintChannels (int endtime);
void S_InitPaintChannels (void); void S_InitPaintChannels (void);
// picks a channel based on priorities, empty slots, number of channels /* picks a channel based on priorities, empty slots, number of channels */
channel_t *SND_PickChannel(int entnum, int entchannel); channel_t *SND_PickChannel (int entnum, int entchannel);
// spatializes a channel /* spatializes a channel */
void SND_Spatialize(channel_t *ch); void SND_Spatialize (channel_t *ch);
// music stream support /* music stream support */
void S_RawSamples(int samples, int rate, int width, int channels, byte * data, float volume); void S_RawSamples(int samples, int rate, int width, int channels, byte * data, float volume);
// returns file's extension including the dot, or NULL /* returns file's extension including the dot, or NULL */
const char *S_FileExtension (const char *name); const char *S_FileExtension (const char *name);
// initializes cycling through a DMA buffer and returns information on it /* initializes cycling through a DMA buffer and returns information on it */
qboolean SNDDMA_Init(void); qboolean SNDDMA_Init(dma_t *dma);
// gets the current DMA position /* gets the current DMA position */
int SNDDMA_GetDMAPos(void); int SNDDMA_GetDMAPos(void);
// shutdown the DMA xfer. /* shutdown the DMA xfer. */
void SNDDMA_Shutdown(void); void SNDDMA_Shutdown(void);
/* validates & locks the dma buffer */ /* validates & locks the dma buffer */
@ -148,59 +142,47 @@ void SNDDMA_BlockSound(void);
/* unblocks the output upon window focus gain */ /* unblocks the output upon window focus gain */
void SNDDMA_UnblockSound(void); void SNDDMA_UnblockSound(void);
// ==================================================================== /* ====================================================================
// User-setable variables * User-setable variables
// ==================================================================== * ====================================================================
*/
#define MAX_CHANNELS 512 //johnfitz -- was 128
#define MAX_DYNAMIC_CHANNELS 128 //johnfitz -- was 8
#define MAX_CHANNELS 512 /* johnfitz -- was 128 */
#define MAX_DYNAMIC_CHANNELS 128 /* johnfitz -- was 8 */
extern channel_t snd_channels[MAX_CHANNELS]; extern channel_t snd_channels[MAX_CHANNELS];
// 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds /* 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds
// MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc * MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc
// MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds * MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds
*/
extern int total_channels; extern volatile dma_t *shm;
// extern int total_channels;
// Fake dma is a synchronous faking of the DMA progress used for extern int soundtime;
// isolating performance in the renderer. The fakedma_updates is extern int paintedtime;
// number of times S_Update() is called per second. extern int s_rawend;
//
extern qboolean fakedma; extern vec3_t listener_origin;
extern int fakedma_updates; extern vec3_t listener_forward;
extern int paintedtime; extern vec3_t listener_right;
extern int s_rawend; extern vec3_t listener_up;
extern vec3_t listener_origin;
extern vec3_t listener_forward; extern cvar_t sndspeed;
extern vec3_t listener_right; extern cvar_t sfxvolume;
extern vec3_t listener_up; extern cvar_t loadas8bit;
extern volatile dma_t *shm;
extern volatile dma_t sn;
#define MAX_RAW_SAMPLES 8192 #define MAX_RAW_SAMPLES 8192
extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES]; extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
extern cvar_t loadas8bit; extern cvar_t bgmvolume;
extern cvar_t bgmvolume;
extern cvar_t sfxvolume;
extern cvar_t sndspeed;
extern qboolean snd_initialized; void S_LocalSound (const char *name);
extern int snd_blocked;
void S_LocalSound (const char *s);
sfxcache_t *S_LoadSound (sfx_t *s); sfxcache_t *S_LoadSound (sfx_t *s);
wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength); wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength);
void SND_InitScaletable (void); void SND_InitScaletable (void);
void S_AmbientOff (void);
void S_AmbientOn (void);
#endif /* __QUAKE_SOUND__ */ #endif /* __QUAKE_SOUND__ */

View file

@ -23,12 +23,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h" #include "quakedef.h"
void S_Play(void); static void S_Play (void);
void S_PlayVol(void); static void S_PlayVol (void);
void S_SoundList(void); static void S_SoundList (void);
void S_Update_(); static void S_Update_ (void);
void S_StopAllSounds(qboolean clear); void S_StopAllSounds (qboolean clear);
void S_StopAllSoundsC(void); static void S_StopAllSoundsC (void);
// ======================================================================= // =======================================================================
// Internal sound data & structures // Internal sound data & structures
@ -37,10 +37,10 @@ void S_StopAllSoundsC(void);
channel_t snd_channels[MAX_CHANNELS]; channel_t snd_channels[MAX_CHANNELS];
int total_channels; int total_channels;
int snd_blocked = 0; static int snd_blocked = 0;
qboolean snd_initialized = false; static qboolean snd_initialized = false;
volatile dma_t sn; static dma_t sn;
volatile dma_t *shm = NULL; volatile dma_t *shm = NULL;
vec3_t listener_origin; vec3_t listener_origin;
@ -58,31 +58,32 @@ portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
#define MAX_SFX 512 #define MAX_SFX 512
sfx_t *known_sfx; // hunk allocated [MAX_SFX] static sfx_t *known_sfx = NULL; // hunk allocated [MAX_SFX]
int num_sfx; static int num_sfx;
sfx_t *ambient_sfx[NUM_AMBIENTS]; static sfx_t *ambient_sfx[NUM_AMBIENTS];
qboolean sound_started = false; static qboolean sound_started = false;
static float oldvolume = -1.0; cvar_t bgmvolume = {"bgmvolume", "1", true};
cvar_t sfxvolume = {"volume", "0.7", true};
cvar_t bgmvolume = {"bgmvolume", "1", true}; cvar_t precache = {"precache", "1"};
cvar_t sfxvolume = {"volume", "0.7", true}; cvar_t loadas8bit = {"loadas8bit", "0"};
cvar_t nosound = {"nosound", "0"}; cvar_t sndspeed = {"sndspeed", "11025"};
cvar_t precache = {"precache", "1"};
cvar_t loadas8bit = {"loadas8bit", "0"}; static float oldvolume = -1.0;
cvar_t bgmbuffer = {"bgmbuffer", "4096"};
cvar_t ambient_level = {"ambient_level", "0.3"}; static cvar_t nosound = {"nosound", "0"};
cvar_t ambient_fade = {"ambient_fade", "100"}; static cvar_t ambient_level = {"ambient_level", "0.3"};
cvar_t snd_noextraupdate = {"snd_noextraupdate", "0"}; static cvar_t ambient_fade = {"ambient_fade", "100"};
cvar_t snd_show = {"snd_show", "0"}; static cvar_t snd_noextraupdate = {"snd_noextraupdate", "0"};
cvar_t _snd_mixahead = {"_snd_mixahead", "0.1", true}; static cvar_t snd_show = {"snd_show", "0"};
cvar_t sndspeed = {"sndspeed", "11025"}; static cvar_t _snd_mixahead = {"_snd_mixahead", "0.1", true};
void S_SoundInfo_f(void) static void S_SoundInfo_f (void)
{ {
if (!sound_started || !shm) if (!sound_started || !shm)
{ {
@ -110,7 +111,7 @@ void S_Startup (void)
if (!snd_initialized) if (!snd_initialized)
return; return;
sound_started = SNDDMA_Init(); sound_started = SNDDMA_Init(&sn);
if (!sound_started) if (!sound_started)
{ {
@ -144,7 +145,6 @@ void S_Init (void)
Cvar_RegisterVariable(&precache, NULL); Cvar_RegisterVariable(&precache, NULL);
Cvar_RegisterVariable(&loadas8bit, NULL); Cvar_RegisterVariable(&loadas8bit, NULL);
Cvar_RegisterVariable(&bgmvolume, NULL); Cvar_RegisterVariable(&bgmvolume, NULL);
Cvar_RegisterVariable(&bgmbuffer, NULL);
Cvar_RegisterVariable(&ambient_level, NULL); Cvar_RegisterVariable(&ambient_level, NULL);
Cvar_RegisterVariable(&ambient_fade, NULL); Cvar_RegisterVariable(&ambient_fade, NULL);
Cvar_RegisterVariable(&snd_noextraupdate, NULL); Cvar_RegisterVariable(&snd_noextraupdate, NULL);
@ -155,7 +155,7 @@ void S_Init (void)
if (safemode || COM_CheckParm("-nosound")) if (safemode || COM_CheckParm("-nosound"))
return; return;
Con_Printf("Sound Initialization\n"); Con_Printf("\nSound Initialization\n");
Cmd_AddCommand("play", S_Play); Cmd_AddCommand("play", S_Play);
Cmd_AddCommand("playvol", S_PlayVol); Cmd_AddCommand("playvol", S_PlayVol);
@ -204,8 +204,6 @@ void S_Shutdown (void)
if (!sound_started) if (!sound_started)
return; return;
if (shm)
shm->gamealive = 0;
sound_started = 0; sound_started = 0;
snd_blocked = 0; snd_blocked = 0;
@ -224,7 +222,7 @@ S_FindName
================== ==================
*/ */
sfx_t *S_FindName (const char *name) static sfx_t *S_FindName (const char *name)
{ {
int i; int i;
sfx_t *sfx; sfx_t *sfx;
@ -476,9 +474,17 @@ void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float
continue; continue;
if (check->sfx == sfx && !check->pos) if (check->sfx == sfx && !check->pos)
{ {
skip = rand () % (int)(0.1*shm->speed); /*
skip = rand () % (int)(0.1 * shm->speed);
if (skip >= target_chan->end) if (skip >= target_chan->end)
skip = target_chan->end - 1; skip = target_chan->end - 1;
*/
/* LordHavoc: fixed skip calculations */
skip = 0.1 * shm->speed; /* 0.1 * sc->speed */
if (skip > sc->length)
skip = sc->length;
if (skip > 0)
skip = rand() % skip;
target_chan->pos += skip; target_chan->pos += skip;
target_chan->end -= skip; target_chan->end -= skip;
break; break;
@ -523,7 +529,7 @@ void S_StopAllSounds (qboolean clear)
S_ClearBuffer (); S_ClearBuffer ();
} }
void S_StopAllSoundsC (void) static void S_StopAllSoundsC (void)
{ {
S_StopAllSounds (true); S_StopAllSounds (true);
} }
@ -601,17 +607,15 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
S_UpdateAmbientSounds S_UpdateAmbientSounds
=================== ===================
*/ */
void S_UpdateAmbientSounds (void) static void S_UpdateAmbientSounds (void)
{ {
mleaf_t *l; mleaf_t *l;
int vol, ambient_channel; int vol, ambient_channel;
channel_t *chan; channel_t *chan;
//johnfitz -- no ambients when disconnected // no ambients when disconnected
if (cls.state != ca_connected) if (cls.state != ca_connected)
return; return;
//johnfitz
// calc ambient sound levels // calc ambient sound levels
if (!cl.worldmodel) if (!cl.worldmodel)
return; return;
@ -856,7 +860,7 @@ void S_Update (vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
S_Update_(); S_Update_();
} }
void GetSoundtime (void) static void GetSoundtime (void)
{ {
int samplepos; int samplepos;
static int buffers; static int buffers;
@ -872,7 +876,6 @@ void GetSoundtime (void)
#else #else
samplepos = SNDDMA_GetDMAPos(); samplepos = SNDDMA_GetDMAPos();
if (samplepos < oldsamplepos) if (samplepos < oldsamplepos)
{ {
buffers++; // buffer wrapped buffers++; // buffer wrapped
@ -892,15 +895,13 @@ void GetSoundtime (void)
void S_ExtraUpdate (void) void S_ExtraUpdate (void)
{ {
if (snd_noextraupdate.value) if (snd_noextraupdate.value)
return; // don't pollute timings return; // don't pollute timings
S_Update_(); S_Update_();
} }
void S_Update_(void) static void S_Update_ (void)
{ {
#if 1
unsigned int endtime; unsigned int endtime;
int samps; int samps;
@ -929,7 +930,6 @@ void S_Update_(void)
S_PaintChannels (endtime); S_PaintChannels (endtime);
SNDDMA_Submit (); SNDDMA_Submit ();
#endif
} }
void S_BlockSound (void) void S_BlockSound (void)
@ -966,7 +966,7 @@ console functions
=============================================================================== ===============================================================================
*/ */
void S_Play (void) static void S_Play (void)
{ {
static int hash = 345; static int hash = 345;
int i; int i;
@ -989,7 +989,7 @@ void S_Play (void)
} }
} }
void S_PlayVol (void) static void S_PlayVol (void)
{ {
static int hash = 543; static int hash = 543;
int i; int i;
@ -1010,11 +1010,11 @@ void S_PlayVol (void)
sfx = S_PrecacheSound(name); sfx = S_PrecacheSound(name);
vol = Q_atof(Cmd_Argv(i + 1)); vol = Q_atof(Cmd_Argv(i + 1));
S_StartSound(hash++, 0, sfx, listener_origin, vol, 1.0); S_StartSound(hash++, 0, sfx, listener_origin, vol, 1.0);
i+=2; i += 2;
} }
} }
void S_SoundList (void) static void S_SoundList (void)
{ {
int i; int i;
sfx_t *sfx; sfx_t *sfx;
@ -1033,7 +1033,7 @@ void S_SoundList (void)
Con_SafePrintf ("L"); //johnfitz -- was Con_Printf Con_SafePrintf ("L"); //johnfitz -- was Con_Printf
else else
Con_SafePrintf (" "); //johnfitz -- was Con_Printf Con_SafePrintf (" "); //johnfitz -- was Con_Printf
Con_SafePrintf("(%2db) %6i : %s\n",sc->width*8, size, sfx->name); //johnfitz -- was Con_Printf Con_SafePrintf("(%2db) %6i : %s\n", sc->width*8, size, sfx->name); //johnfitz -- was Con_Printf
} }
Con_Printf ("%i sounds, %i bytes\n", num_sfx, total); //johnfitz -- added count Con_Printf ("%i sounds, %i bytes\n", num_sfx, total); //johnfitz -- added count
} }

View file

@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
ResampleSfx ResampleSfx
================ ================
*/ */
void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, byte *data) static void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, byte *data)
{ {
int outcount; int outcount;
int srcsample; int srcsample;
@ -59,16 +59,15 @@ void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, byte *data)
if (stepscale == 1 && inwidth == 1 && sc->width == 1) if (stepscale == 1 && inwidth == 1 && sc->width == 1)
{ {
// fast special case // fast special case
for (i=0 ; i<outcount ; i++) for (i = 0; i < outcount; i++)
((signed char *)sc->data)[i] ((signed char *)sc->data)[i] = (int)( (unsigned char)(data[i]) - 128);
= (int)( (unsigned char)(data[i]) - 128);
} }
else else
{ {
// general case // general case
samplefrac = 0; samplefrac = 0;
fracstep = stepscale*256; fracstep = stepscale*256;
for (i=0 ; i<outcount ; i++) for (i = 0; i < outcount; i++)
{ {
srcsample = samplefrac >> 8; srcsample = samplefrac >> 8;
samplefrac += fracstep; samplefrac += fracstep;
@ -112,7 +111,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
Q_strcpy(namebuffer, "sound/"); Q_strcpy(namebuffer, "sound/");
Q_strcat(namebuffer, s->name); Q_strcat(namebuffer, s->name);
// Con_Printf ("loading %s\n", namebuffer); // Con_Printf ("loading %s\n",namebuffer);
data = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf)); data = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf));
@ -171,15 +170,13 @@ WAV loading
=============================================================================== ===============================================================================
*/ */
static byte *data_p;
static byte *iff_end;
static byte *last_chunk;
static byte *iff_data;
static int iff_chunk_len;
byte *data_p; static short GetLittleShort (void)
byte *iff_end;
byte *last_chunk;
byte *iff_data;
int iff_chunk_len;
short GetLittleShort(void)
{ {
short val = 0; short val = 0;
val = *data_p; val = *data_p;
@ -188,7 +185,7 @@ short GetLittleShort(void)
return val; return val;
} }
int GetLittleLong(void) static int GetLittleLong (void)
{ {
int val = 0; int val = 0;
val = *data_p; val = *data_p;
@ -199,7 +196,7 @@ int GetLittleLong(void)
return val; return val;
} }
void FindNextChunk(const char *name) static void FindNextChunk (const char *name)
{ {
while (1) while (1)
{ {
@ -225,14 +222,14 @@ void FindNextChunk(const char *name)
} }
} }
void FindChunk(const char *name) static void FindChunk (const char *name)
{ {
last_chunk = iff_data; last_chunk = iff_data;
FindNextChunk (name); FindNextChunk (name);
} }
#if 0 #if 0
void DumpChunks(void) static void DumpChunks (void)
{ {
char str[5]; char str[5];
@ -243,7 +240,7 @@ void DumpChunks(void)
memcpy (str, data_p, 4); memcpy (str, data_p, 4);
data_p += 4; data_p += 4;
iff_chunk_len = GetLittleLong(); iff_chunk_len = GetLittleLong();
Con_Printf ("%p : %s (%d)\n", (data_p - 4), str, iff_chunk_len); Con_Printf ("0x%x : %s (%d)\n", (int)(data_p - 4), str, iff_chunk_len);
data_p += (iff_chunk_len + 1) & ~1; data_p += (iff_chunk_len + 1) & ~1;
} while (data_p < iff_end); } while (data_p < iff_end);
} }
@ -257,9 +254,9 @@ GetWavinfo
wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength) wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength)
{ {
wavinfo_t info; wavinfo_t info;
int i; int i;
int format; int format;
int samples; int samples;
memset (&info, 0, sizeof(info)); memset (&info, 0, sizeof(info));
@ -299,7 +296,7 @@ wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength)
info.channels = GetLittleShort(); info.channels = GetLittleShort();
info.rate = GetLittleLong(); info.rate = GetLittleLong();
data_p += 4+2; data_p += 4 + 2;
info.width = GetLittleShort() / 8; info.width = GetLittleShort() / 8;
// get cue chunk // get cue chunk
@ -308,6 +305,7 @@ wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength)
{ {
data_p += 32; data_p += 32;
info.loopstart = GetLittleLong(); info.loopstart = GetLittleLong();
// Con_Printf("loopstart=%d\n", sfx->loopstart);
// if the next chunk is a LIST chunk, look for a cue length marker // if the next chunk is a LIST chunk, look for a cue length marker
FindNextChunk ("LIST"); FindNextChunk ("LIST");
@ -316,9 +314,9 @@ wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength)
if (!strncmp((char *)data_p + 28, "mark", 4)) if (!strncmp((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; data_p += 24;
i = GetLittleLong (); // samples in loop i = GetLittleLong(); // samples in loop
info.samples = info.loopstart + i; info.samples = info.loopstart + i;
// Con_Printf("looped length: %i\n", i); // Con_Printf("looped length: %i\n", i);
} }
} }
} }
@ -334,7 +332,7 @@ wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength)
} }
data_p += 4; data_p += 4;
samples = GetLittleLong () / info.width; samples = GetLittleLong() / info.width;
if (info.samples) if (info.samples)
{ {

View file

@ -31,9 +31,7 @@ short *snd_out;
static int snd_vol; static int snd_vol;
void Snd_WriteLinearBlastStereo16 (void); static void Snd_WriteLinearBlastStereo16 (void)
void Snd_WriteLinearBlastStereo16 (void)
{ {
int i; int i;
int val; int val;
@ -58,7 +56,7 @@ void Snd_WriteLinearBlastStereo16 (void)
} }
} }
void S_TransferStereo16 (int endtime) static void S_TransferStereo16 (int endtime)
{ {
int lpos; int lpos;
int lpaintedtime; int lpaintedtime;
@ -87,7 +85,7 @@ void S_TransferStereo16 (int endtime)
} }
} }
void S_TransferPaintBuffer(int endtime) static void S_TransferPaintBuffer (int endtime)
{ {
int out_idx, out_mask; int out_idx, out_mask;
int count, step, val; int count, step, val;
@ -146,8 +144,8 @@ CHANNEL MIXING
=============================================================================== ===============================================================================
*/ */
void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int endtime); static void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int endtime);
void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int endtime); static void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int endtime);
void S_PaintChannels (int endtime) void S_PaintChannels (int endtime)
{ {
@ -268,7 +266,7 @@ void SND_InitScaletable (void)
} }
void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count) static void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count)
{ {
int data; int data;
int *lscale, *rscale; int *lscale, *rscale;
@ -294,7 +292,7 @@ void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count)
ch->pos += count; ch->pos += count;
} }
void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count) static void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count)
{ {
int data; int data;
int left, right; int left, right;

View file

@ -71,7 +71,7 @@ static void paint_audio (void *unused, Uint8 *stream, int len)
shm->samplepos = 0; shm->samplepos = 0;
} }
qboolean SNDDMA_Init (void) qboolean SNDDMA_Init (dma_t *dma)
{ {
SDL_AudioSpec desired, obtained; SDL_AudioSpec desired, obtained;
int tmp, val; int tmp, val;
@ -120,8 +120,8 @@ qboolean SNDDMA_Init (void)
return false; return false;
} }
memset ((void *) &sn, 0, sizeof(dma_t)); memset ((void *) dma, 0, sizeof(dma_t));
shm = &sn; shm = dma;
/* Fill the audio DMA information block */ /* Fill the audio DMA information block */
shm->samplebits = (obtained.format & 0xFF); /* first byte of format is bits */ shm->samplebits = (obtained.format & 0xFF); /* first byte of format is bits */