Doom sound support for both digital and PC speaker samples (might need changes with VFS)

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2251 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
TimeServ 2006-05-08 02:03:41 +00:00
parent 913e26b1ae
commit 9d9b74c274
1 changed files with 123 additions and 2 deletions

View File

@ -147,6 +147,123 @@ void ResampleSfx (sfx_t *sfx, int inrate, int inwidth, qbyte *data)
}
//=============================================================================
#ifdef DOOMWADS
#define DSPK_RATE 140
#define DSPK_FREQ 30
sfxcache_t *S_LoadDoomSpeakerSound (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, len, timeraccum, inrate, inaccum;
qbyte *outdata;
qbyte towrite;
if (datalen < 4)
return NULL;
dataus = (unsigned short*)data;
if (LittleShort(dataus[0]) != 0)
return NULL;
samples = LittleShort(dataus[1]);
data += 4;
datalen -= 4;
if (datalen != samples)
return NULL;
len = (int)((double)samples * (double)snd_speed / DSPK_RATE);
sc = Cache_Alloc (&s->cache, len + sizeof(sfxcache_t), s->name);
if (!sc)
{
return NULL;
}
sc->length = len;
sc->loopstart = -1;
sc->numchannels = 1;
sc->width = 1;
sc->speed = snd_speed;
timeraccum = 0;
outdata = sc->data;
towrite = 0x40;
inrate = (int)((double)snd_speed / DSPK_RATE);
inaccum = inrate;
while (len > 0)
{
timeraccum += *data * DSPK_FREQ;
if (timeraccum > snd_speed)
{
towrite ^= 0xFF; // swap speaker component
timeraccum -= snd_speed;
}
inaccum--;
if (!inaccum)
{
data++;
inaccum = inrate;
}
*outdata = towrite;
outdata++;
len--;
}
return sc;
}
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;
if (datalen < 8)
return NULL;
dataus = (unsigned short*)data;
if (LittleShort(dataus[0]) != 3)
return NULL;
rate = LittleShort(dataus[1]);
samples = LittleShort(dataus[2]);
data += 8;
datalen -= 8;
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;
ResampleSfx (s, sc->speed, sc->width, data);
return sc;
}
#endif
sfxcache_t *S_LoadWavSound (sfx_t *s, qbyte *data, int datalen, int sndspeed)
{
@ -183,12 +300,16 @@ sfxcache_t *S_LoadWavSound (sfx_t *s, qbyte *data, int datalen, int sndspeed)
sfxcache_t *S_LoadOVSound (sfx_t *s, qbyte *data, int datalen, int sndspeed);
S_LoadSound_t AudioInputPlugins[8] =
S_LoadSound_t AudioInputPlugins[10] =
{
#ifdef AVAIL_OGGVORBIS
S_LoadOVSound,
#endif
S_LoadWavSound
S_LoadWavSound,
#ifdef DOOMWADS
S_LoadDoomSound,
S_LoadDoomSpeakerSound
#endif
};
qboolean S_RegisterSoundInputPlugin(S_LoadSound_t loadfnc)