OpenAL support code, slightly cleaner.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3675 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2010-11-28 19:14:21 +00:00
parent 6553fbe917
commit 7b06062137
3 changed files with 52 additions and 75 deletions

View file

@ -42,9 +42,9 @@ qboolean snd_initialized = false;
int snd_speed;
vec3_t listener_origin;
vec3_t listener_forward;
vec3_t listener_right;
vec3_t listener_up;
vec3_t listener_forward = {1, 0, 0};
vec3_t listener_right = {0, 1, 0};
vec3_t listener_up = {0, 0, 1};
vec_t sound_nominal_clip_dist=1000.0;
int soundtime; // sample PAIRS
@ -605,7 +605,7 @@ typedef struct {
} sdriver_t;
sdriver_t drivers[] = {
//in order of preference
{"OpenAL", &pOPENAL_InitCard}, //yay, get someone else to sort out sound support, woot
{"DSound", &pDSOUND_InitCard}, //prefered on windows
{"MacOS", &pMacOS_InitCard}, //prefered on mac
{"AHI", &pAHI_InitCard}, //prefered on morphos
@ -614,6 +614,7 @@ sdriver_t drivers[] = {
{"ALSA", &pALSA_InitCard}, //pure shite
{"OSS", &pOSS_InitCard}, //good, but not likely to work any more
{"OpenAL", &pOPENAL_InitCard}, //yay, get someone else to sort out sound support, woot
{"WaveOut", &pWAV_InitCard}, //doesn't work properly in vista, etc.
{NULL, NULL}
};
@ -1045,6 +1046,7 @@ void S_Init (void)
snd_initialized = true;
if (!known_sfx)
known_sfx = Hunk_AllocName (MAX_SFX*sizeof(sfx_t), "sfx_t");
num_sfx = 0;
@ -1311,14 +1313,18 @@ void S_StartSoundCard(soundcardinfo_t *sc, int entnum, int entchannel, sfx_t *sf
if (nosound.ival)
return;
if (!pitchadj)
pitchadj = 100;
#ifdef AVAIL_OPENAL
if (sc->openal)
OpenAL_StartSound(entnum, entchannel, sfx, origin, fvol, attenuation);
{
OpenAL_StartSound(entnum, entchannel, sfx, origin, fvol, attenuation, pitchadj / 100.0f);
return;
}
#endif
vol = fvol*255;
if (!pitchadj)
pitchadj = 100;
// pick a channel to play on
target_chan = SND_PickChannel(sc, entnum, entchannel);

View file

@ -542,34 +542,44 @@ void SND_ResampleStream (void *in, int inrate, int inwidth, int inchannels, int
ResampleSfx
================
*/
void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, qbyte *data)
void ResampleSfx (sfx_t *sfx, int inrate, int inchannels, int inwidth, int insamps, int inloopstart, qbyte *data)
{
extern cvar_t snd_linearresample;
double scale;
sfxcache_t *sc;
int insamps, outsamps;
int outsamps;
int len;
int outwidth;
sc = Cache_Check (&sfx->cache);
if (!sc)
return;
insamps = sc->length;
scale = snd_speed / (double)inrate;
outsamps = insamps * scale;
sc->length = outsamps;
if (sc->loopstart != -1)
sc->loopstart = sc->loopstart * scale;
sc->speed = snd_speed;
if (loadas8bit.ival)
sc->width = 1;
if (loadas8bit.ival < 0)
outwidth = 2;
else if (loadas8bit.ival)
outwidth = 1;
else
sc->width = inwidth;
outwidth = inwidth;
len = outsamps * outwidth * inchannels;
sc = Cache_Alloc (&sfx->cache, len + sizeof(sfxcache_t), sfx->name);
if (!sc)
{
return;
}
sc->numchannels = inchannels;
sc->width = outwidth;
sc->speed = snd_speed;
sc->length = outsamps;
if (inloopstart == -1)
sc->loopstart = inloopstart;
else
sc->loopstart = inloopstart * scale;
SND_ResampleStream (data,
inrate,
inwidth,
sc->numchannels,
inchannels,
insamps,
sc->data,
sc->speed,
@ -663,8 +673,6 @@ sfxcache_t *S_LoadDoomSpeakerSound (sfx_t *s, qbyte *data, int datalen, int snds
sfxcache_t *S_LoadDoomSound (sfx_t *s, qbyte *data, int datalen, int sndspeed)
{
sfxcache_t *sc;
// format data from Unofficial Doom Specs v1.6
unsigned short *dataus;
int samples, rate, len;
@ -686,36 +694,17 @@ sfxcache_t *S_LoadDoomSound (sfx_t *s, qbyte *data, int datalen, int sndspeed)
if (datalen != samples)
return NULL;
len = (int)((double)samples * (double)snd_speed / (double)rate);
sc = Cache_Alloc (&s->cache, len + sizeof(sfxcache_t), s->name);
if (!sc)
{
return NULL;
}
sc->length = samples;
sc->loopstart = -1;
sc->numchannels = 1;
sc->width = 1;
sc->speed = rate;
if (sc->width == 1)
COM_CharBias(data, sc->length);
else if (sc->width == 2)
COM_SwapLittleShortBlock((short *)data, sc->length);
ResampleSfx (s, sc->speed, sc->width, data);
ResampleSfx (s, rate, 1, 1, samples, -1, data);
return sc;
return Cache_Check(&s->cache);
}
#endif
sfxcache_t *S_LoadWavSound (sfx_t *s, qbyte *data, int datalen, int sndspeed)
{
wavinfo_t info;
int len;
sfxcache_t *sc;
if (datalen < 4 || strncmp(data, "RIFF", 4))
return NULL;
@ -728,29 +717,14 @@ sfxcache_t *S_LoadWavSound (sfx_t *s, qbyte *data, int datalen, int sndspeed)
return NULL;
}
len = (int) ((double) info.samples * (double) snd_speed / (double) info.rate);
len = len * info.width * info.numchannels;
if (info.width == 1)
COM_CharBias(data + info.dataofs, info.samples*info.numchannels);
else if (info.width == 2)
COM_SwapLittleShortBlock((short *)(data + info.dataofs), info.samples*info.numchannels);
sc = Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
if (!sc)
{
return NULL;
}
ResampleSfx (s, info.rate, info.numchannels, info.width, info.samples, info.loopstart, data + info.dataofs);
sc->length = info.samples;
sc->loopstart = info.loopstart;
sc->speed = info.rate;
sc->width = info.width;
sc->numchannels = info.numchannels;
if (sc->width == 1)
COM_CharBias(data + info.dataofs, sc->length*sc->numchannels);
else if (sc->width == 2)
COM_SwapLittleShortBlock((short *)(data + info.dataofs), sc->length*sc->numchannels);
ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);
return sc;
return Cache_Check(&s->cache);
}
sfxcache_t *S_LoadOVSound (sfx_t *s, qbyte *data, int datalen, int sndspeed);
@ -890,9 +864,6 @@ sfxcache_t *S_LoadSound (sfx_t *s)
s->failedload = false;
#ifdef AVAIL_OPENAL
OpenAL_LoadSound(s, sc, com_filesize, data);
#endif
for (i = sizeof(AudioInputPlugins)/sizeof(AudioInputPlugins[0])-1; i >= 0; i--)
{
if (AudioInputPlugins[i])

View file

@ -160,7 +160,7 @@ qboolean S_Voip_Speaking(unsigned int plno);
#endif
qboolean S_IsPlayingSomewhere(sfx_t *s);
void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, qbyte *data);
void ResampleSfx (sfx_t *sfx, int inrate, int inchannels, int inwidth, int insamps, int inloopstart, qbyte *data);
// picks a channel based on priorities, empty slots, number of channels
channel_t *SND_PickChannel(soundcardinfo_t *sc, int entnum, int entchannel);
@ -185,8 +185,8 @@ void SNDVC_MicInput(qbyte *buffer, int samples, int freq, int width);
#ifdef AVAIL_OPENAL
void OpenAL_LoadSound (sfx_t *s, sfxcache_t *sc, size_t size, void *data);
void OpenAL_StartSound(int entnum, int entchannel, sfx_t * sfx, vec3_t origin, float fvol, float attenuation);
void OpenAL_LoadCache(sfx_t *s, sfxcache_t *sc);
void OpenAL_StartSound(int entnum, int entchannel, sfx_t * sfx, vec3_t origin, float fvol, float attenuation, float pitchscale);
void OpenAL_Update_Listener(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up);
void OpenAL_CvarInit(void);
#endif