Disable sound, not crash, when OpenAL init fails.
This commit is contained in:
parent
aa61006034
commit
aff53cc9ba
1 changed files with 57 additions and 6 deletions
57
src/openal.c
57
src/openal.c
|
@ -31,6 +31,8 @@ ALCdevice *AvpSoundDevice;
|
||||||
ALvoid *AvpSoundContext;
|
ALvoid *AvpSoundContext;
|
||||||
int AvpFrequency = 44100;
|
int AvpFrequency = 44100;
|
||||||
|
|
||||||
|
static int SoundActivated = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
openal.c TODO:
|
openal.c TODO:
|
||||||
1. AL_PITCH code does not work.
|
1. AL_PITCH code does not work.
|
||||||
|
@ -40,6 +42,7 @@ openal.c TODO:
|
||||||
4. Restarting sound system may or may not work.
|
4. Restarting sound system may or may not work.
|
||||||
5. Doppler (if it was originally used) isn't currently used.
|
5. Doppler (if it was originally used) isn't currently used.
|
||||||
Probably also broken in OpenAL (see 1).
|
Probably also broken in OpenAL (see 1).
|
||||||
|
6. Better Error Handling (device not avail, etc).
|
||||||
*/
|
*/
|
||||||
int PlatStartSoundSys()
|
int PlatStartSoundSys()
|
||||||
{
|
{
|
||||||
|
@ -61,12 +64,18 @@ int PlatStartSoundSys()
|
||||||
attrlist[3] = AL_FALSE;
|
attrlist[3] = AL_FALSE;
|
||||||
attrlist[4] = 0;
|
attrlist[4] = 0;
|
||||||
|
|
||||||
|
SoundActivated = 0;
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "'( (sampling-rate %d ))\n", AvpFrequency);
|
snprintf(buf, sizeof(buf), "'( (sampling-rate %d ))\n", AvpFrequency);
|
||||||
|
|
||||||
AvpSoundDevice = alcOpenDevice(buf);
|
AvpSoundDevice = alcOpenDevice(buf);
|
||||||
|
if (AvpSoundDevice == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
AvpSoundContext = alcCreateContext(AvpSoundDevice, attrlist);
|
AvpSoundContext = alcCreateContext(AvpSoundDevice, attrlist);
|
||||||
// AvpSoundDevice = alcOpenDevice(NULL);
|
if (AvpSoundContext == NULL) /* TODO: destroy sound device */
|
||||||
// AvpSoundContext = alcCreateContext(AvpSoundDevice, NULL);
|
return 0;
|
||||||
|
|
||||||
alcMakeContextCurrent(AvpSoundContext);
|
alcMakeContextCurrent(AvpSoundContext);
|
||||||
|
|
||||||
alListenerfv(AL_POSITION, pos);
|
alListenerfv(AL_POSITION, pos);
|
||||||
|
@ -111,6 +120,8 @@ int PlatStartSoundSys()
|
||||||
alSourcef(p, AL_REFERENCE_DISTANCE, 1.0f);
|
alSourcef(p, AL_REFERENCE_DISTANCE, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SoundActivated = 1;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,6 +378,9 @@ int PlatPlaySound(int activeIndex)
|
||||||
{
|
{
|
||||||
int si;
|
int si;
|
||||||
|
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if ((activeIndex < 0) || (activeIndex >= SOUND_MAXACTIVE))
|
if ((activeIndex < 0) || (activeIndex >= SOUND_MAXACTIVE))
|
||||||
return 0;
|
return 0;
|
||||||
si = ActiveSounds[activeIndex].soundIndex;
|
si = ActiveSounds[activeIndex].soundIndex;
|
||||||
|
@ -434,6 +448,9 @@ void PlatStopSound(int activeIndex)
|
||||||
{
|
{
|
||||||
/* printf("PlatStopSound(%d)\n", activeIndex); */
|
/* printf("PlatStopSound(%d)\n", activeIndex); */
|
||||||
|
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
// if (ActiveSounds[activeIndex].paused)
|
// if (ActiveSounds[activeIndex].paused)
|
||||||
// alSourcePause (ActiveSounds[activeIndex].ds3DBufferP);
|
// alSourcePause (ActiveSounds[activeIndex].ds3DBufferP);
|
||||||
// else
|
// else
|
||||||
|
@ -467,6 +484,9 @@ static float vol_to_gain_table[] = {
|
||||||
|
|
||||||
int PlatChangeGlobalVolume(int volume)
|
int PlatChangeGlobalVolume(int volume)
|
||||||
{
|
{
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
alListenerf(AL_GAIN, vol_to_gain_table[volume]);
|
alListenerf(AL_GAIN, vol_to_gain_table[volume]);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -474,6 +494,9 @@ int PlatChangeGlobalVolume(int volume)
|
||||||
|
|
||||||
int PlatChangeSoundVolume(int activeIndex, int volume)
|
int PlatChangeSoundVolume(int activeIndex, int volume)
|
||||||
{
|
{
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
alSourcef(ActiveSounds[activeIndex].ds3DBufferP,
|
alSourcef(ActiveSounds[activeIndex].ds3DBufferP,
|
||||||
AL_GAIN, vol_to_gain_table[volume]);
|
AL_GAIN, vol_to_gain_table[volume]);
|
||||||
|
|
||||||
|
@ -484,6 +507,9 @@ int PlatChangeSoundPitch(int activeIndex, int pitch)
|
||||||
{
|
{
|
||||||
float frequency;
|
float frequency;
|
||||||
|
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if ((pitch < PITCH_MIN) || (pitch >= PITCH_MAX))
|
if ((pitch < PITCH_MIN) || (pitch >= PITCH_MAX))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -508,6 +534,10 @@ int PlatSoundHasStopped(int activeIndex)
|
||||||
/*
|
/*
|
||||||
printf("PlatSoundHasStopped(%d)\n", activeIndex);
|
printf("PlatSoundHasStopped(%d)\n", activeIndex);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
alGetSourceiv (ActiveSounds[activeIndex].ds3DBufferP,
|
alGetSourceiv (ActiveSounds[activeIndex].ds3DBufferP,
|
||||||
AL_SOURCE_STATE, &val);
|
AL_SOURCE_STATE, &val);
|
||||||
|
|
||||||
|
@ -526,6 +556,9 @@ int PlatDo3dSound(int activeIndex)
|
||||||
VECTORCH relativePosn;
|
VECTORCH relativePosn;
|
||||||
int newVolume;
|
int newVolume;
|
||||||
|
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (ActiveSounds[activeIndex].threedee == 0)
|
if (ActiveSounds[activeIndex].threedee == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -622,6 +655,9 @@ void PlatUpdatePlayer()
|
||||||
{
|
{
|
||||||
ALfloat vel[3], or[6], pos[3];
|
ALfloat vel[3], or[6], pos[3];
|
||||||
|
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (Global_VDB_Ptr) {
|
if (Global_VDB_Ptr) {
|
||||||
extern int NormalFrameTime;
|
extern int NormalFrameTime;
|
||||||
extern int DopplerShiftIsOn;
|
extern int DopplerShiftIsOn;
|
||||||
|
@ -673,6 +709,9 @@ void PlatEndGameSound(SOUNDINDEX index)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if((index<0)||(index>=SID_MAXIMUM)) return; /* no such sound */
|
if((index<0)||(index>=SID_MAXIMUM)) return; /* no such sound */
|
||||||
|
|
||||||
for (i = 0; i < SOUND_MAXACTIVE; i++) {
|
for (i = 0; i < SOUND_MAXACTIVE; i++) {
|
||||||
|
@ -740,7 +779,10 @@ void UpdateSoundFrequencies()
|
||||||
|
|
||||||
/* printf("FREQ UpdateSoundFreqncies()\n"); */
|
/* printf("FREQ UpdateSoundFreqncies()\n"); */
|
||||||
|
|
||||||
if (!SoundSwitchedOn)
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!SoundSwitchedOn) /* TODO: maybe I should have used this var.. */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < SOUND_MAXACTIVE; i++) {
|
for (i = 0; i < SOUND_MAXACTIVE; i++) {
|
||||||
|
@ -771,6 +813,10 @@ int LoadWavFile(int soundNum, char * wavFileName)
|
||||||
/*
|
/*
|
||||||
printf("LoadWavFile(%d, %s) - sound\n", soundNum, wavFileName);
|
printf("LoadWavFile(%d, %s) - sound\n", soundNum, wavFileName);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
alutLoadWAV (wavFileName, &data, &format, &size, &bits, &freq);
|
alutLoadWAV (wavFileName, &data, &format, &size, &bits, &freq);
|
||||||
alGenBuffers (1, &(GameSounds[soundNum].dsBufferP));
|
alGenBuffers (1, &(GameSounds[soundNum].dsBufferP));
|
||||||
alBufferData (GameSounds[soundNum].dsBufferP, format, data, size, freq);
|
alBufferData (GameSounds[soundNum].dsBufferP, format, data, size, freq);
|
||||||
|
@ -808,6 +854,8 @@ unsigned char *ExtractWavFile(int soundIndex, unsigned char *bufferPtr)
|
||||||
int slen;
|
int slen;
|
||||||
|
|
||||||
/* printf("ExtractWavFile(%d, %p)\n", soundIndex, bufferPtr); */
|
/* printf("ExtractWavFile(%d, %p)\n", soundIndex, bufferPtr); */
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
slen = strlen (bufferPtr) + 1;
|
slen = strlen (bufferPtr) + 1;
|
||||||
GameSounds[soundIndex].wavName = (char *)AllocateMem (slen);
|
GameSounds[soundIndex].wavName = (char *)AllocateMem (slen);
|
||||||
|
@ -878,6 +926,9 @@ int LoadWavFromFastFile(int soundNum, char * wavFileName)
|
||||||
|
|
||||||
/* printf("LoadWavFromFastFile(%d, %s)\n", soundNum, wavFileName); */
|
/* printf("LoadWavFromFastFile(%d, %s)\n", soundNum, wavFileName); */
|
||||||
|
|
||||||
|
if (!SoundActivated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if ((fp = ffopen (wavFileName, "rb")) != NULL) {
|
if ((fp = ffopen (wavFileName, "rb")) != NULL) {
|
||||||
ffseek (fp, 0, SEEK_END);
|
ffseek (fp, 0, SEEK_END);
|
||||||
len = fftell (fp);
|
len = fftell (fp);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue