More OpenAL changes (Chuck Mason).

This commit is contained in:
Steven Fuller 2001-08-14 18:23:13 +00:00 committed by Patryk Obara
parent 0200ee9777
commit c7d772650f
2 changed files with 47 additions and 37 deletions

View file

@ -570,7 +570,7 @@ int main(int argc, char *argv[])
AvP.CurrentEnv = AvP.StartingEnv = 0; /* are these even used? */ AvP.CurrentEnv = AvP.StartingEnv = 0; /* are these even used? */
AvP.PlayerType = I_Alien; AvP.PlayerType = I_Alien;
SetLevelToLoad(AVP_ENVIRONMENT_FERARCO); /* starting alien level */ SetLevelToLoad(AVP_ENVIRONMENT_TEMPLE); /* starting alien level */
// AvP.PlayerType = I_Marine; // AvP.PlayerType = I_Marine;
// SetLevelToLoad(AVP_ENVIRONMENT_DERELICT); /* starting marine level */ // SetLevelToLoad(AVP_ENVIRONMENT_DERELICT); /* starting marine level */

View file

@ -186,15 +186,15 @@ void PlatStopSound(int activeIndex)
int PlatChangeSoundVolume(int activeIndex, int volume) int PlatChangeSoundVolume(int activeIndex, int volume)
{ {
float nv = 127.0f / (float) volume; // float nv = 127.0f / (float) volume;
fprintf(stderr, "PlatChangeSoundVolume(%d, %d) - %f\n", activeIndex, volume, nv); fprintf(stderr, "PlatChangeSoundVolume(%d, %d)\n", activeIndex, volume);
if (nv > 1.0) // if (nv > 1.0)
nv = 1.0; // nv = 1.0;
alSourcef (ActiveSounds[activeIndex].ds3DBufferP, // alSourcef (ActiveSounds[activeIndex].ds3DBufferP,
AL_MAX_GAIN, nv); // AL_MAX_GAIN, nv);
return 1; return 1;
} }
@ -211,15 +211,15 @@ int PlatChangeSoundPitch(int activeIndex, int pitch)
if (pitch == PITCH_DEFAULTPLAT) if (pitch == PITCH_DEFAULTPLAT)
frequency = 0; frequency = 0;
else { else {
SOUNDINDEX gsi = ActiveSounds[activeIndex].soundIndex; // SOUNDINDEX gsi = ActiveSounds[activeIndex].soundIndex;
frequency = ToneToFrequency (GameSounds[gsi].dsFrequency, // frequency = ToneToFrequency (GameSounds[gsi].dsFrequency,
GameSounds[gameSoundIndex].pitch, pitch); // GameSounds[gameSoundIndex].pitch, pitch);
frequency = (128.0f / ((float)pitch + 127.0)); frequency = (128.0f / ((float)pitch + 127.0));
} }
ActiveSounds[activeIndex].pitch = pitch; ActiveSounds[activeIndex].pitch = pitch;
// alSourcei (ActiveSounds[activeIndex].ds3DBufferP, AL_PITCH, frequency); alSourcei (ActiveSounds[activeIndex].ds3DBufferP, AL_PITCH, frequency);
return 1; return 1;
} }
@ -318,8 +318,9 @@ int PlatDo3dSound(int activeIndex)
relativePosn.vz; relativePosn.vz;
alSourcefv (ActiveSounds[activeIndex].ds3DBufferP, alSourcefv (ActiveSounds[activeIndex].ds3DBufferP,
AL_POSITION, ActiveSounds[activeIndex].PropSetP_pos); AL_POSITION, ActiveSounds[activeIndex].PropSetP_pos);
#if 1 /* The c++ code had this stuff marked out b/c there was no "Doppler" shifting */
#if 0
ActiveSounds[activeIndex].PropSetP_vel[0] = ActiveSounds[activeIndex].PropSetP_vel[0] =
ActiveSounds[activeIndex].threedeedata.velocity.vx; ActiveSounds[activeIndex].threedeedata.velocity.vx;
ActiveSounds[activeIndex].PropSetP_vel[1] = ActiveSounds[activeIndex].PropSetP_vel[1] =
@ -396,6 +397,23 @@ int LoadWavFile(int soundNum, char * wavFileName)
return 0; return 0;
} }
unsigned char *Force8to16 (unsigned char *buf, int *len)
{
unsigned char *nbuf;
unsigned int i;
nbuf = (unsigned char *) AllocateMem (*len * 2);
for (i = 0; i < *len; i++) {
short int x = ((buf[i] << 8) | buf[i]) ^ 0x8000;
nbuf[i*2+0] = (x & 0x00ff);
nbuf[i*2+1] = (x >> 8) & 0xff;
}
*len *= 2;
return nbuf;
}
// In libopenal // In libopenal
extern void *acLoadWAV (void *data, ALuint *size, void **udata, extern void *acLoadWAV (void *data, ALuint *size, void **udata,
ALushort *fmt, ALushort *chan, ALushort *freq); ALushort *fmt, ALushort *chan, ALushort *freq);
@ -403,6 +421,7 @@ extern void *acLoadWAV (void *data, ALuint *size, void **udata,
unsigned char *ExtractWavFile(int soundIndex, unsigned char *bufferPtr) unsigned char *ExtractWavFile(int soundIndex, unsigned char *bufferPtr)
{ {
ALint len, seclen = 0; ALint len, seclen = 0;
unsigned char *nb;
void *udata; void *udata;
ALushort rfmt, rchan, rfreq, rsize; ALushort rfmt, rchan, rfreq, rsize;
@ -421,18 +440,16 @@ fprintf (stderr, "Loaded %s\n", GameSounds[soundIndex].wavName);
fprintf (stderr, "Unable to convert data\n"); fprintf (stderr, "Unable to convert data\n");
return (unsigned char *)0; return (unsigned char *)0;
} }
printf("rfmt = %d, rchan = %d, rfreq = %d, len = %d\n", rfmt, rchan, rfreq, len);
if ((rfmt == AUDIO_U8)) { if ((rfmt == AUDIO_U8)) {
if (rchan == 2) { nb = Force8to16 (udata, &len);
rfmt = AL_FORMAT_STEREO8; rfmt = AUDIO_S16LSB;
seclen = len / (rfreq * 1 * 2);
} else if (rchan == 1) { free (udata);
rfmt = AL_FORMAT_MONO8; udata = nb;
seclen = len / rfreq; }
}
} else if ((rfmt == AUDIO_S16LSB) || (rfmt == AUDIO_S16MSB)) { if ((rfmt == AUDIO_S16LSB) || (rfmt == AUDIO_S16MSB)) {
if (rchan == 2) { if (rchan == 2) {
rfmt = AL_FORMAT_STEREO16; rfmt = AL_FORMAT_STEREO16;
seclen = len / (rfreq * 2 * 2); seclen = len / (rfreq * 2 * 2);
@ -448,19 +465,7 @@ printf("rfmt = %d, rchan = %d, rfreq = %d, len = %d\n", rfmt, rchan, rfreq, len)
alGenBuffers (1, &(GameSounds[soundIndex].dsBufferP)); alGenBuffers (1, &(GameSounds[soundIndex].dsBufferP));
alBufferData (GameSounds[soundIndex].dsBufferP, alBufferData (GameSounds[soundIndex].dsBufferP,
rfmt, udata, rsize, rfreq); rfmt, udata, rsize, rfreq);
{
ALint t, val;
alGenSources(1, &t);
alSourcei(t, AL_BUFFER, GameSounds[soundIndex].dsBufferP);
alSourcePlay(t);
do {
sleep(1);
alGetSourceiv(t, AL_SOURCE_STATE, &val);
} while (val == AL_PLAYING);
}
GameSounds[soundIndex].loaded = 1; GameSounds[soundIndex].loaded = 1;
GameSounds[soundIndex].flags = SAMPLE_IN_HW; GameSounds[soundIndex].flags = SAMPLE_IN_HW;
GameSounds[soundIndex].length = (seclen != 0) ? seclen : 1; GameSounds[soundIndex].length = (seclen != 0) ? seclen : 1;
@ -533,12 +538,17 @@ void PlatUpdatePlayer()
vel[2] = 0.0; vel[2] = 0.0;
} }
#if 1 /* again, no doppler crap. */
#if 0
{ {
pos[0] = Global_VDB_Ptr->VDB_World.vx; pos[0] = Global_VDB_Ptr->VDB_World.vx;
pos[1] = Global_VDB_Ptr->VDB_World.vy; pos[1] = Global_VDB_Ptr->VDB_World.vy;
pos[2] = Global_VDB_Ptr->VDB_World.vz; pos[2] = Global_VDB_Ptr->VDB_World.vz;
} }
#else
{
pos[0] = pos[1] = pos[2] = 0.0;
}
#endif #endif
} }