OpenAL WIP.
This commit is contained in:
parent
2e7aec7855
commit
68a0572d13
1 changed files with 29 additions and 20 deletions
49
src/openal.c
49
src/openal.c
|
@ -159,24 +159,32 @@ int PlatStartSoundSys()
|
||||||
};
|
};
|
||||||
|
|
||||||
SoundActivated = 0;
|
SoundActivated = 0;
|
||||||
if (WantSound == 0)
|
if (WantSound == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
attrlist[0] = ALC_FREQUENCY;
|
attrlist[0] = ALC_FREQUENCY;
|
||||||
attrlist[1] = AvpFrequency;
|
attrlist[1] = AvpFrequency;
|
||||||
attrlist[2] = ALC_SYNC;
|
attrlist[2] = ALC_SYNC;
|
||||||
attrlist[3] = AL_FALSE;
|
attrlist[3] = AL_FALSE;
|
||||||
attrlist[4] = 0;
|
attrlist[4] = 0;
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
buf[0] = 0;
|
||||||
|
#else
|
||||||
_snprintf(buf, sizeof(buf), "'( (sampling-rate %d ))\n", AvpFrequency);
|
_snprintf(buf, sizeof(buf), "'( (sampling-rate %d ))\n", AvpFrequency);
|
||||||
|
#endif
|
||||||
|
|
||||||
AvpSoundDevice = alcOpenDevice(buf);
|
AvpSoundDevice = alcOpenDevice(buf);
|
||||||
if (AvpSoundDevice == NULL)
|
if (AvpSoundDevice == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
AvpSoundContext = alcCreateContext(AvpSoundDevice, attrlist);
|
AvpSoundContext = alcCreateContext(AvpSoundDevice, attrlist);
|
||||||
if (AvpSoundContext == NULL) /* TODO: destroy sound device */
|
if (AvpSoundContext == NULL) {
|
||||||
|
/* TODO: destroy sound device */
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
alcMakeContextCurrent(AvpSoundContext);
|
alcMakeContextCurrent(AvpSoundContext);
|
||||||
|
|
||||||
|
@ -191,13 +199,17 @@ int PlatStartSoundSys()
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset( ActiveSounds, 0, sizeof(ActiveSounds) );
|
||||||
|
|
||||||
for (i = 0; i < SOUND_MAXACTIVE; i++) {
|
for (i = 0; i < SOUND_MAXACTIVE; i++) {
|
||||||
ALuint p;
|
ALuint p;
|
||||||
|
|
||||||
alGenSources (1, &p);
|
alGenSources (1, &p);
|
||||||
if (alGetError () != AL_NO_ERROR) {
|
if (alGetError () != AL_NO_ERROR) {
|
||||||
fprintf (stderr, "alGenSources () error = ...");
|
// TODO - need to figure out how many sources we are allowed to make
|
||||||
return -1;
|
//fprintf (stderr, "alGenSources () error = ...");
|
||||||
|
//return -1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActiveSounds[i].ds3DBufferP = p;
|
ActiveSounds[i].ds3DBufferP = p;
|
||||||
|
@ -214,9 +226,6 @@ int PlatStartSoundSys()
|
||||||
alSourcefv(p, AL_POSITION, ActiveSounds[i].PropSetP_pos);
|
alSourcefv(p, AL_POSITION, ActiveSounds[i].PropSetP_pos);
|
||||||
alSourcefv(p, AL_VELOCITY, ActiveSounds[i].PropSetP_vel);
|
alSourcefv(p, AL_VELOCITY, ActiveSounds[i].PropSetP_vel);
|
||||||
|
|
||||||
/*
|
|
||||||
alSourcef(p, AL_ROLLOFF_FACTOR, 0.0f);
|
|
||||||
*/
|
|
||||||
alSourcef(p, AL_ROLLOFF_FACTOR, 0.01f);
|
alSourcef(p, AL_ROLLOFF_FACTOR, 0.01f);
|
||||||
alSourcef(p, AL_REFERENCE_DISTANCE, 1.0f);
|
alSourcef(p, AL_REFERENCE_DISTANCE, 1.0f);
|
||||||
}
|
}
|
||||||
|
@ -859,7 +868,8 @@ unsigned int PlatMaxHWSounds()
|
||||||
#ifdef OPENAL_DEBUG
|
#ifdef OPENAL_DEBUG
|
||||||
fprintf(stderr, "OPENAL: PlatMaxHWSounds()\n");
|
fprintf(stderr, "OPENAL: PlatMaxHWSounds()\n");
|
||||||
#endif
|
#endif
|
||||||
return 32;
|
// TODO - need to implement this for real?
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitialiseBaseFrequency(SOUNDINDEX soundNum)
|
void InitialiseBaseFrequency(SOUNDINDEX soundNum)
|
||||||
|
@ -974,8 +984,7 @@ printf("WAV DEBUG: bad bit setup\n");
|
||||||
|
|
||||||
int LoadWavFile(int soundNum, char * wavFileName)
|
int LoadWavFile(int soundNum, char * wavFileName)
|
||||||
{
|
{
|
||||||
ALuint size;
|
ALushort freq, format;
|
||||||
ALushort freq, chan, format;
|
|
||||||
ALvoid *data, *bufferPtr;
|
ALvoid *data, *bufferPtr;
|
||||||
int len, seclen;
|
int len, seclen;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
@ -1030,9 +1039,8 @@ unsigned char *ExtractWavFile(int soundIndex, unsigned char *bufferPtr)
|
||||||
{
|
{
|
||||||
ALint len, seclen = 0;
|
ALint len, seclen = 0;
|
||||||
void *udata;
|
void *udata;
|
||||||
ALushort rfmt, rchan, rfreq;
|
ALushort rfmt, rfreq;
|
||||||
ALuint rsize;
|
size_t slen;
|
||||||
int slen;
|
|
||||||
|
|
||||||
#ifdef OPENAL_DEBUG
|
#ifdef OPENAL_DEBUG
|
||||||
fprintf(stderr, "OPENAL: ExtractWavFile(%d, %p)\n", soundIndex, bufferPtr);
|
fprintf(stderr, "OPENAL: ExtractWavFile(%d, %p)\n", soundIndex, bufferPtr);
|
||||||
|
@ -1073,7 +1081,8 @@ int LoadWavFromFastFile(int soundNum, char * wavFileName)
|
||||||
{
|
{
|
||||||
FFILE *fp;
|
FFILE *fp;
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
unsigned int len = 0;
|
size_t len;
|
||||||
|
int ok = 0;
|
||||||
|
|
||||||
#ifdef OPENAL_DEBUG
|
#ifdef OPENAL_DEBUG
|
||||||
fprintf(stderr, "OPENAL: LoadWavFromFastFile(%d, %s)\n", soundNum, wavFileName);
|
fprintf(stderr, "OPENAL: LoadWavFromFastFile(%d, %s)\n", soundNum, wavFileName);
|
||||||
|
@ -1087,9 +1096,9 @@ int LoadWavFromFastFile(int soundNum, char * wavFileName)
|
||||||
strcpy (buf, wavFileName);
|
strcpy (buf, wavFileName);
|
||||||
ffread (&buf[strlen(wavFileName)+1], len, 1, fp);
|
ffread (&buf[strlen(wavFileName)+1], len, 1, fp);
|
||||||
ffclose (fp);
|
ffclose (fp);
|
||||||
len = (int)ExtractWavFile (soundNum, buf);
|
ok = ( ExtractWavFile (soundNum, buf) != NULL );
|
||||||
free (buf);
|
free (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue