From bb03e645391434b4d3db1064157fb0089e4fd2ea Mon Sep 17 00:00:00 2001 From: waltje Date: Sun, 18 Jun 2017 22:31:49 -0400 Subject: [PATCH] Small fixes for openal and some dynamic linking stuff. Bug in libopenal.a makes this not work, so we're still on openall.dll ... --- src/Makefile.mingw | 13 ++- src/SOUND/openal.c | 273 +++++++++++++++++++++++---------------------- 2 files changed, 147 insertions(+), 139 deletions(-) diff --git a/src/Makefile.mingw b/src/Makefile.mingw index d92d2d175..f143c592a 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -62,7 +62,7 @@ endif ######################################################################### # Nothing should need changing from here on.. # ######################################################################### -VPATH = . cpu sound sound/resid-fp video lzf network network/slirp win +VPATH = . cpu sound sound/resid-fp sound/openal video lzf network network/slirp win PLAT = win/ ifeq ($(X64), y) CPP = g++.exe -m64 @@ -170,12 +170,13 @@ NETOBJ = network.o \ net_ne2000.o SCSIOBJ = scsi.o scsi_disk.o scsi_buslogic.o scsi_aha154x.o SNDOBJ = sound.o \ + openal.o \ + dbopl.o nukedopl.o \ convolve.o convolve-sse.o envelope.o extfilt.o \ filter.o pot.o sid.o voice.o wave6581__ST.o \ wave6581_P_T.o wave6581_PS_.o wave6581_PST.o \ wave8580__ST.o wave8580_P_T.o wave8580_PS_.o \ wave8580_PST.o wave.o \ - dbopl.o nukedopl.o openal.o \ snd_speaker.o snd_ps1.o snd_pssj.o \ snd_adlib.o snd_adlibgold.o snd_ad1848.o \ snd_sb.o snd_sb_dsp.o snd_cms.o snd_dbopl.o \ @@ -220,9 +221,11 @@ OBJ = $(MAINOBJ) $(CPUOBJ) $(SYSOBJ) $(DEVOBJ) $(USBOBJ) \ LZFOBJ = lzf_c.o lzf_d.o -LIBS = -lddraw -ldinput8 -ldxguid -ld3d9 -ld3dx9 -lopenal.dll \ - -mwindows -lcomctl32 -lwinmm -lwsock32 -liphlpapi -lpsapi \ - -static-libstdc++ -static -lstdc++ -static-libgcc -static -lgcc +LIBS = -mwindows \ + -lopenal.dll \ + -lddraw -ldinput8 -ldxguid -ld3d9 -ld3dx9 \ + -lcomctl32 -lkernel32 -lwsock32 -lwinmm -liphlpapi -lpsapi \ + -static -lstdc++ -lgcc # Build rules. diff --git a/src/SOUND/openal.c b/src/SOUND/openal.c index b044c0e5a..bda40f44e 100644 --- a/src/SOUND/openal.c +++ b/src/SOUND/openal.c @@ -3,6 +3,10 @@ #include #include #ifdef USE_OPENAL +# undef AL_API +# undef ALC_API +# define AL_LIBTYPE_STATIC +# define ALC_LIBTYPE_STATIC # include # include # include @@ -11,219 +15,220 @@ #include "sound.h" -FILE *allog; +#define FREQ 48000 +#define BUFLEN SOUNDBUFLEN + + #ifdef USE_OPENAL ALuint buffers[4]; /* front and back buffers */ ALuint buffers_cd[4]; /* front and back buffers */ static ALuint source[2]; /* audio source */ #endif -#define FREQ 48000 -#define BUFLEN SOUNDBUFLEN -void closeal(void); -ALvoid alutInit(ALint *argc,ALbyte **argv) +ALvoid alutInit(ALint *argc,ALbyte **argv) { - ALCcontext *Context; - ALCdevice *Device; + ALCcontext *Context; + ALCdevice *Device; - /* Open device */ - Device=alcOpenDevice((ALCchar *)""); + /* Open device */ + Device = alcOpenDevice((ALCchar *)""); + if (Device != NULL) { /* Create context(s) */ - Context=alcCreateContext(Device,NULL); - /* Set active context */ - alcMakeContextCurrent(Context); - /* Register extensions */ + Context = alcCreateContext(Device, NULL); + if (Context != NULL) { + /* Set active context */ + alcMakeContextCurrent(Context); + } + } } -ALvoid alutExit(ALvoid) + +ALvoid alutExit(ALvoid) { - ALCcontext *Context; - ALCdevice *Device; + ALCcontext *Context; + ALCdevice *Device; - /* Unregister extensions */ - - /* Get active context */ - Context=alcGetCurrentContext(); + /* Get active context */ + Context = alcGetCurrentContext(); + if (Context != NULL) { /* Get device for active context */ - Device=alcGetContextsDevice(Context); - /* Disable context */ - alcMakeContextCurrent(NULL); + Device = alcGetContextsDevice(Context); + if (Device != NULL) { + /* Disable context */ + alcMakeContextCurrent(NULL); + + /* Close device */ + alcCloseDevice(Device); + } + /* Release context(s) */ alcDestroyContext(Context); - /* Close device */ - alcCloseDevice(Device); -} -void initalmain(int argc, char *argv[]) -{ -#ifdef USE_OPENAL - alutInit(0,0); - atexit(closeal); -#endif + } } + void closeal(void) { #ifdef USE_OPENAL - alutExit(); + alutExit(); #endif } + +void initalmain(int argc, char *argv[]) +{ +#ifdef USE_OPENAL + alutInit(0,0); + atexit(closeal); +#endif +} + + void inital(ALvoid) { #ifdef USE_OPENAL - int c; + float buf[BUFLEN*2]; + float cd_buf[CD_BUFLEN*2]; + int16_t buf_int16[BUFLEN*2]; + int16_t cd_buf_int16[CD_BUFLEN*2]; + int c; - float buf[BUFLEN*2]; - - float cd_buf[CD_BUFLEN*2]; - - int16_t buf_int16[BUFLEN*2]; - - int16_t cd_buf_int16[CD_BUFLEN*2]; - - alGenBuffers(4, buffers); - alGenBuffers(4, buffers_cd); + alGenBuffers(4, buffers); + alGenBuffers(4, buffers_cd); - alGenSources(2, source); + alGenSources(2, source); - alSource3f(source[0], AL_POSITION, 0.0, 0.0, 0.0); - alSource3f(source[0], AL_VELOCITY, 0.0, 0.0, 0.0); - alSource3f(source[0], AL_DIRECTION, 0.0, 0.0, 0.0); - alSourcef (source[0], AL_ROLLOFF_FACTOR, 0.0 ); - alSourcei (source[0], AL_SOURCE_RELATIVE, AL_TRUE ); - alSource3f(source[1], AL_POSITION, 0.0, 0.0, 0.0); - alSource3f(source[1], AL_VELOCITY, 0.0, 0.0, 0.0); - alSource3f(source[1], AL_DIRECTION, 0.0, 0.0, 0.0); - alSourcef (source[1], AL_ROLLOFF_FACTOR, 0.0 ); - alSourcei (source[1], AL_SOURCE_RELATIVE, AL_TRUE ); + alSource3f(source[0], AL_POSITION, 0.0, 0.0, 0.0); + alSource3f(source[0], AL_VELOCITY, 0.0, 0.0, 0.0); + alSource3f(source[0], AL_DIRECTION, 0.0, 0.0, 0.0); + alSourcef (source[0], AL_ROLLOFF_FACTOR, 0.0 ); + alSourcei (source[0], AL_SOURCE_RELATIVE, AL_TRUE ); - memset(buf,0,BUFLEN*2*sizeof(float)); - memset(cd_buf,0,BUFLEN*2*sizeof(float)); + alSource3f(source[1], AL_POSITION, 0.0, 0.0, 0.0); + alSource3f(source[1], AL_VELOCITY, 0.0, 0.0, 0.0); + alSource3f(source[1], AL_DIRECTION, 0.0, 0.0, 0.0); + alSourcef (source[1], AL_ROLLOFF_FACTOR, 0.0 ); + alSourcei (source[1], AL_SOURCE_RELATIVE, AL_TRUE ); - for (c = 0; c < 4; c++) - { - if (sound_is_float) - { - alBufferData(buffers[c], AL_FORMAT_STEREO_FLOAT32, buf, BUFLEN*2*sizeof(float), FREQ); - alBufferData(buffers_cd[c], AL_FORMAT_STEREO_FLOAT32, cd_buf, CD_BUFLEN*2*sizeof(float), CD_FREQ); - } - else - { - alBufferData(buffers[c], AL_FORMAT_STEREO16, buf_int16, BUFLEN*2*sizeof(int16_t), FREQ); - alBufferData(buffers_cd[c], AL_FORMAT_STEREO16, cd_buf_int16, CD_BUFLEN*2*sizeof(int16_t), CD_FREQ); - } - } + memset(buf,0,BUFLEN*2*sizeof(float)); + memset(cd_buf,0,BUFLEN*2*sizeof(float)); - alSourceQueueBuffers(source[0], 4, buffers); - alSourceQueueBuffers(source[1], 4, buffers_cd); - alSourcePlay(source[0]); - alSourcePlay(source[1]); + for (c = 0; c < 4; c++) { + if (sound_is_float) { + alBufferData(buffers[c], AL_FORMAT_STEREO_FLOAT32, buf, BUFLEN*2*sizeof(float), FREQ); + alBufferData(buffers_cd[c], AL_FORMAT_STEREO_FLOAT32, cd_buf, CD_BUFLEN*2*sizeof(float), CD_FREQ); + } else { + alBufferData(buffers[c], AL_FORMAT_STEREO16, buf_int16, BUFLEN*2*sizeof(int16_t), FREQ); + alBufferData(buffers_cd[c], AL_FORMAT_STEREO16, cd_buf_int16, CD_BUFLEN*2*sizeof(int16_t), CD_FREQ); + } + } + + alSourceQueueBuffers(source[0], 4, buffers); + alSourceQueueBuffers(source[1], 4, buffers_cd); + alSourcePlay(source[0]); + alSourcePlay(source[1]); #endif } + void givealbuffer(float *buf) { #ifdef USE_OPENAL - int processed; - int state; - ALuint buffer; + int processed; + int state; + ALuint buffer; - alGetSourcei(source[0], AL_SOURCE_STATE, &state); + alGetSourcei(source[0], AL_SOURCE_STATE, &state); - if (state==0x1014) - { - alSourcePlay(source[0]); - } - alGetSourcei(source[0], AL_BUFFERS_PROCESSED, &processed); + if (state==0x1014) { + alSourcePlay(source[0]); + } + alGetSourcei(source[0], AL_BUFFERS_PROCESSED, &processed); - if (processed>=1) - { - alSourceUnqueueBuffers(source[0], 1, &buffer); + if (processed>=1) { + alSourceUnqueueBuffers(source[0], 1, &buffer); - alBufferData(buffer, AL_FORMAT_STEREO_FLOAT32, buf, BUFLEN*2*sizeof(float), FREQ); + alBufferData(buffer, AL_FORMAT_STEREO_FLOAT32, buf, BUFLEN*2*sizeof(float), FREQ); - alSourceQueueBuffers(source[0], 1, &buffer); - } + alSourceQueueBuffers(source[0], 1, &buffer); + } #endif } + void givealbuffer_int16(int16_t *buf) { #ifdef USE_OPENAL - int processed; - int state; - ALuint buffer; + int processed; + int state; + ALuint buffer; - alGetSourcei(source[0], AL_SOURCE_STATE, &state); + alGetSourcei(source[0], AL_SOURCE_STATE, &state); - if (state==0x1014) - { - alSourcePlay(source[0]); - } - alGetSourcei(source[0], AL_BUFFERS_PROCESSED, &processed); + if (state==0x1014) { + alSourcePlay(source[0]); + } + alGetSourcei(source[0], AL_BUFFERS_PROCESSED, &processed); - if (processed>=1) - { - alSourceUnqueueBuffers(source[0], 1, &buffer); + if (processed>=1) { + alSourceUnqueueBuffers(source[0], 1, &buffer); - alBufferData(buffer, AL_FORMAT_STEREO16, buf, BUFLEN*2*sizeof(int16_t), FREQ); + alBufferData(buffer, AL_FORMAT_STEREO16, buf, BUFLEN*2*sizeof(int16_t), FREQ); - alSourceQueueBuffers(source[0], 1, &buffer); - } + alSourceQueueBuffers(source[0], 1, &buffer); + } #endif } + void givealbuffer_cd(float *buf) { #ifdef USE_OPENAL - int processed; - int state; + int processed; + int state; - alGetSourcei(source[1], AL_SOURCE_STATE, &state); + alGetSourcei(source[1], AL_SOURCE_STATE, &state); - if (state==0x1014) - { - alSourcePlay(source[1]); - } - alGetSourcei(source[1], AL_BUFFERS_PROCESSED, &processed); + if (state==0x1014) { + alSourcePlay(source[1]); + } + alGetSourcei(source[1], AL_BUFFERS_PROCESSED, &processed); - if (processed>=1) - { - ALuint buffer; + if (processed>=1) { + ALuint buffer; - alSourceUnqueueBuffers(source[1], 1, &buffer); + alSourceUnqueueBuffers(source[1], 1, &buffer); - alBufferData(buffer, AL_FORMAT_STEREO_FLOAT32, buf, CD_BUFLEN*2*sizeof(float), CD_FREQ); + alBufferData(buffer, AL_FORMAT_STEREO_FLOAT32, buf, CD_BUFLEN*2*sizeof(float), CD_FREQ); - alSourceQueueBuffers(source[1], 1, &buffer); - } + alSourceQueueBuffers(source[1], 1, &buffer); + } #endif } + void givealbuffer_cd_int16(int16_t *buf) { #ifdef USE_OPENAL - int processed; - int state; + int processed; + int state; - alGetSourcei(source[1], AL_SOURCE_STATE, &state); + alGetSourcei(source[1], AL_SOURCE_STATE, &state); - if (state==0x1014) - { - alSourcePlay(source[1]); - } - alGetSourcei(source[1], AL_BUFFERS_PROCESSED, &processed); + if (state==0x1014) { + alSourcePlay(source[1]); + } + alGetSourcei(source[1], AL_BUFFERS_PROCESSED, &processed); - if (processed>=1) - { - ALuint buffer; + if (processed>=1) { + ALuint buffer; - alSourceUnqueueBuffers(source[1], 1, &buffer); + alSourceUnqueueBuffers(source[1], 1, &buffer); - alBufferData(buffer, AL_FORMAT_STEREO16, buf, CD_BUFLEN*2*sizeof(int16_t), CD_FREQ); + alBufferData(buffer, AL_FORMAT_STEREO16, buf, CD_BUFLEN*2*sizeof(int16_t), CD_FREQ); - alSourceQueueBuffers(source[1], 1, &buffer); - } + alSourceQueueBuffers(source[1], 1, &buffer); + } #endif }