mirror of
https://github.com/nzp-team/fteqw.git
synced 2025-02-17 01:11:18 +00:00
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:
parent
6553fbe917
commit
7b06062137
3 changed files with 52 additions and 75 deletions
|
@ -42,9 +42,9 @@ qboolean snd_initialized = false;
|
||||||
int snd_speed;
|
int snd_speed;
|
||||||
|
|
||||||
vec3_t listener_origin;
|
vec3_t listener_origin;
|
||||||
vec3_t listener_forward;
|
vec3_t listener_forward = {1, 0, 0};
|
||||||
vec3_t listener_right;
|
vec3_t listener_right = {0, 1, 0};
|
||||||
vec3_t listener_up;
|
vec3_t listener_up = {0, 0, 1};
|
||||||
vec_t sound_nominal_clip_dist=1000.0;
|
vec_t sound_nominal_clip_dist=1000.0;
|
||||||
|
|
||||||
int soundtime; // sample PAIRS
|
int soundtime; // sample PAIRS
|
||||||
|
@ -605,7 +605,7 @@ typedef struct {
|
||||||
} sdriver_t;
|
} sdriver_t;
|
||||||
sdriver_t drivers[] = {
|
sdriver_t drivers[] = {
|
||||||
//in order of preference
|
//in order of preference
|
||||||
{"OpenAL", &pOPENAL_InitCard}, //yay, get someone else to sort out sound support, woot
|
|
||||||
{"DSound", &pDSOUND_InitCard}, //prefered on windows
|
{"DSound", &pDSOUND_InitCard}, //prefered on windows
|
||||||
{"MacOS", &pMacOS_InitCard}, //prefered on mac
|
{"MacOS", &pMacOS_InitCard}, //prefered on mac
|
||||||
{"AHI", &pAHI_InitCard}, //prefered on morphos
|
{"AHI", &pAHI_InitCard}, //prefered on morphos
|
||||||
|
@ -614,6 +614,7 @@ sdriver_t drivers[] = {
|
||||||
{"ALSA", &pALSA_InitCard}, //pure shite
|
{"ALSA", &pALSA_InitCard}, //pure shite
|
||||||
{"OSS", &pOSS_InitCard}, //good, but not likely to work any more
|
{"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.
|
{"WaveOut", &pWAV_InitCard}, //doesn't work properly in vista, etc.
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
@ -1045,7 +1046,8 @@ void S_Init (void)
|
||||||
|
|
||||||
snd_initialized = true;
|
snd_initialized = true;
|
||||||
|
|
||||||
known_sfx = Hunk_AllocName (MAX_SFX*sizeof(sfx_t), "sfx_t");
|
if (!known_sfx)
|
||||||
|
known_sfx = Hunk_AllocName (MAX_SFX*sizeof(sfx_t), "sfx_t");
|
||||||
num_sfx = 0;
|
num_sfx = 0;
|
||||||
|
|
||||||
// create a piece of DMA memory
|
// create a piece of DMA memory
|
||||||
|
@ -1311,14 +1313,18 @@ void S_StartSoundCard(soundcardinfo_t *sc, int entnum, int entchannel, sfx_t *sf
|
||||||
if (nosound.ival)
|
if (nosound.ival)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!pitchadj)
|
||||||
|
pitchadj = 100;
|
||||||
|
|
||||||
#ifdef AVAIL_OPENAL
|
#ifdef AVAIL_OPENAL
|
||||||
if (sc->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
|
#endif
|
||||||
|
|
||||||
vol = fvol*255;
|
vol = fvol*255;
|
||||||
if (!pitchadj)
|
|
||||||
pitchadj = 100;
|
|
||||||
|
|
||||||
// pick a channel to play on
|
// pick a channel to play on
|
||||||
target_chan = SND_PickChannel(sc, entnum, entchannel);
|
target_chan = SND_PickChannel(sc, entnum, entchannel);
|
||||||
|
|
|
@ -542,34 +542,44 @@ void SND_ResampleStream (void *in, int inrate, int inwidth, int inchannels, int
|
||||||
ResampleSfx
|
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;
|
extern cvar_t snd_linearresample;
|
||||||
double scale;
|
double scale;
|
||||||
sfxcache_t *sc;
|
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;
|
scale = snd_speed / (double)inrate;
|
||||||
outsamps = insamps * scale;
|
outsamps = insamps * scale;
|
||||||
sc->length = outsamps;
|
if (loadas8bit.ival < 0)
|
||||||
if (sc->loopstart != -1)
|
outwidth = 2;
|
||||||
sc->loopstart = sc->loopstart * scale;
|
else if (loadas8bit.ival)
|
||||||
|
outwidth = 1;
|
||||||
sc->speed = snd_speed;
|
|
||||||
if (loadas8bit.ival)
|
|
||||||
sc->width = 1;
|
|
||||||
else
|
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,
|
SND_ResampleStream (data,
|
||||||
inrate,
|
inrate,
|
||||||
inwidth,
|
inwidth,
|
||||||
sc->numchannels,
|
inchannels,
|
||||||
insamps,
|
insamps,
|
||||||
sc->data,
|
sc->data,
|
||||||
sc->speed,
|
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 *S_LoadDoomSound (sfx_t *s, qbyte *data, int datalen, int sndspeed)
|
||||||
{
|
{
|
||||||
sfxcache_t *sc;
|
|
||||||
|
|
||||||
// format data from Unofficial Doom Specs v1.6
|
// format data from Unofficial Doom Specs v1.6
|
||||||
unsigned short *dataus;
|
unsigned short *dataus;
|
||||||
int samples, rate, len;
|
int samples, rate, len;
|
||||||
|
@ -686,36 +694,17 @@ sfxcache_t *S_LoadDoomSound (sfx_t *s, qbyte *data, int datalen, int sndspeed)
|
||||||
if (datalen != samples)
|
if (datalen != samples)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
len = (int)((double)samples * (double)snd_speed / (double)rate);
|
COM_CharBias(data, sc->length);
|
||||||
|
|
||||||
sc = Cache_Alloc (&s->cache, len + sizeof(sfxcache_t), s->name);
|
ResampleSfx (s, rate, 1, 1, samples, -1, data);
|
||||||
if (!sc)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
sc->length = samples;
|
return Cache_Check(&s->cache);
|
||||||
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);
|
|
||||||
|
|
||||||
return sc;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sfxcache_t *S_LoadWavSound (sfx_t *s, qbyte *data, int datalen, int sndspeed)
|
sfxcache_t *S_LoadWavSound (sfx_t *s, qbyte *data, int datalen, int sndspeed)
|
||||||
{
|
{
|
||||||
wavinfo_t info;
|
wavinfo_t info;
|
||||||
int len;
|
|
||||||
sfxcache_t *sc;
|
|
||||||
|
|
||||||
if (datalen < 4 || strncmp(data, "RIFF", 4))
|
if (datalen < 4 || strncmp(data, "RIFF", 4))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -728,29 +717,14 @@ sfxcache_t *S_LoadWavSound (sfx_t *s, qbyte *data, int datalen, int sndspeed)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = (int) ((double) info.samples * (double) snd_speed / (double) info.rate);
|
if (info.width == 1)
|
||||||
len = len * info.width * info.numchannels;
|
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);
|
ResampleSfx (s, info.rate, info.numchannels, info.width, info.samples, info.loopstart, data + info.dataofs);
|
||||||
if (!sc)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
sc->length = info.samples;
|
|
||||||
sc->loopstart = info.loopstart;
|
|
||||||
sc->speed = info.rate;
|
|
||||||
sc->width = info.width;
|
|
||||||
sc->numchannels = info.numchannels;
|
|
||||||
|
|
||||||
if (sc->width == 1)
|
return Cache_Check(&s->cache);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sfxcache_t *S_LoadOVSound (sfx_t *s, qbyte *data, int datalen, int sndspeed);
|
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;
|
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--)
|
for (i = sizeof(AudioInputPlugins)/sizeof(AudioInputPlugins[0])-1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (AudioInputPlugins[i])
|
if (AudioInputPlugins[i])
|
||||||
|
|
|
@ -160,7 +160,7 @@ qboolean S_Voip_Speaking(unsigned int plno);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
qboolean S_IsPlayingSomewhere(sfx_t *s);
|
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
|
// picks a channel based on priorities, empty slots, number of channels
|
||||||
channel_t *SND_PickChannel(soundcardinfo_t *sc, int entnum, int entchannel);
|
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
|
#ifdef AVAIL_OPENAL
|
||||||
void OpenAL_LoadSound (sfx_t *s, sfxcache_t *sc, size_t size, void *data);
|
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);
|
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_Update_Listener(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up);
|
||||||
void OpenAL_CvarInit(void);
|
void OpenAL_CvarInit(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue