git-svn-id: https://svn.eduke32.com/eduke32@637 1a8010ca-5511-0410-912e-c29ae57300e0

This commit is contained in:
terminx 2008-03-08 07:46:30 +00:00
parent bc0f8369e6
commit 6b956dfe2a
12 changed files with 1037 additions and 1037 deletions

View file

@ -53,16 +53,12 @@ ifeq ($(PLATFORM),LINUX)
OBJ=obj
EOBJ=eobj
NASMFLAGS+= -f elf
ifeq ($(USE_OPENAL),1)
LIBS+= -lvorbisfile -lvorbis -logg
endif
LIBS+= -lvorbisfile -lvorbis -logg
else
ifeq ($(PLATFORM),WINDOWS)
OBJ=obj_win
EOBJ=eobj_win
ifeq ($(USE_OPENAL),1)
LIBS+= -L$(ALROOT)/lib -lvorbisfile -lvorbis -logg
endif
LIBS+= -L$(ALROOT)/lib -lvorbisfile -lvorbis -logg
else
OBJ=obj
EOBJ=eobj

View file

@ -8720,8 +8720,10 @@ static int parsegroupfiles(scriptfile *script)
initprintf("Error: missing ID for music definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,tinttokptr));
break;
}
#ifdef USE_OPENAL
if (AL_DefineMusic(ID,ext))
initprintf("Error: invalid music ID on line %s:%d\n", script->filename, scriptfile_getlinum(script,tinttokptr));
#endif
}
break;

View file

@ -88,9 +88,7 @@ typedef enum
VOC,
DemandFeed,
WAV,
#ifdef USE_OPENAL
OGG
#endif
} wavedata;
typedef enum
@ -134,11 +132,11 @@ typedef struct VoiceNode
int priority;
void ( *DemandFeed )( char **ptr, unsigned int *length );
#ifdef USE_OPENAL
struct sounddef OGGstream;
char *bufsnd;
int downsample;
#endif
short *LeftVolume;
short *RightVolume;

View file

@ -705,7 +705,6 @@ int FX_PlayWAV
Begin playback of sound data with the given volume and priority.
---------------------------------------------------------------------*/
#ifdef USE_OPENAL
int FX_PlayOGG
(
char *ptr,
@ -730,7 +729,6 @@ int FX_PlayOGG
return(handle);
}
#endif
/*---------------------------------------------------------------------
Function: FX_PlayWAV
@ -766,7 +764,7 @@ int FX_PlayLoopedWAV
return(handle);
}
#ifdef USE_OPENAL
int FX_PlayLoopedOGG
(
char *ptr,
@ -795,7 +793,7 @@ int FX_PlayLoopedOGG
return(handle);
}
#endif
/*---------------------------------------------------------------------
Function: FX_PlayVOC3D
@ -826,7 +824,7 @@ int FX_PlayVOC3D
return(handle);
}
#ifdef USE_OPENAL
int FX_PlayOGG3D
(
char *ptr,
@ -850,7 +848,6 @@ int FX_PlayOGG3D
return(handle);
}
#endif
/*---------------------------------------------------------------------
Function: FX_PlayWAV3D

View file

@ -206,11 +206,9 @@ char *MV_ErrorString(int ErrorNumber)
case MV_InvalidWAVFile :
ErrorString = "Invalid WAV file passed in to Multivoc.";
break;
#ifdef USE_OPENAL
case MV_InvalidOGGFile :
ErrorString = "Invalid OGG file passed in to Multivoc.";
break;
#endif
case MV_InvalidMixMode :
ErrorString = "Invalid mix mode request in Multivoc.";
break;
@ -918,7 +916,7 @@ playbackstatus MV_GetNextWAVBlock(VoiceNode *voice)
Controls playback of demand fed data.
---------------------------------------------------------------------*/
#ifdef USE_OPENAL
void downsample(char *ptr,int size,int factor)
{
short *pti=(short *)ptr;int i,j,sum;
@ -982,7 +980,7 @@ playbackstatus MV_GetNextOGGBlock(VoiceNode *voice)
return(KeepPlaying);
}
#endif
/*---------------------------------------------------------------------
Function: MV_ServiceRecord
@ -2406,7 +2404,7 @@ int MV_PlayLoopedVOC(char *ptr, int loopstart, int loopend, int pitchoffset, int
priority.
---------------------------------------------------------------------*/
VoiceNode *voice;
#ifdef USE_OPENAL
int MV_PlayLoopedOGG(char *ptr, int loopstart, int loopend, int pitchoffset, int vol, int left, int right, int priority, unsigned int callbackval)
{
vorbis_info *vorbisInfo;
@ -2546,7 +2544,7 @@ int MV_PlayOGG3D(char *ptr, int pitchoffset, int angle, int distance, int priori
return(status);
}
#endif
/*---------------------------------------------------------------------
Function: MV_CreateVolumeTable
@ -2886,11 +2884,11 @@ int MV_Init(int soundcard, int MixRate, int Voices, int numchannels, int sampleb
Bfree(map[i].musicfn1);
}
for (i=MAXSOUNDS-1;i>=0;i--)
/* for (i=MAXSOUNDS-1;i>=0;i--)
{
if (g_sounds[i].filename1 != NULL)
Bfree(g_sounds[i].filename1);
}
} */
}
#endif
#if defined(_WIN32)

View file

@ -50,9 +50,7 @@ enum MV_Errors
MV_DPMI_Error,
MV_InvalidVOCFile,
MV_InvalidWAVFile,
#ifdef USE_OPENAL
MV_InvalidOGGFile,
#endif
MV_InvalidMixMode,
MV_IrqFailure,
MV_DMAFailure,

File diff suppressed because it is too large Load diff

View file

@ -1,36 +1,36 @@
#ifdef _WIN32
#include "dsound.h"
#endif
#include "baselayer.h"
#include "compat.h"
#include <AL/al.h>
#include <AL/alc.h>
#include <vorbis/vorbisfile.h>
#include "_multivc.h"
ALCdevice * device=NULL;
ALCcontext * context=NULL;
char *ALdoing="";
int AL_Error;
int bufsize;
int openal_disabled = 0;
typedef struct SD
{
ALuint buffers[16];
ALuint source;
ALenum format;
char loop;
char type;
int rate;
sounddef def;
}sounddef1;
sounddef1 sounds1[2];
#ifdef _WIN32
#include "dsound.h"
#endif
#include "baselayer.h"
#include "compat.h"
#include <AL/al.h>
#include <AL/alc.h>
#include <vorbis/vorbisfile.h>
#include "_multivc.h"
ALCdevice * device=NULL;
ALCcontext * context=NULL;
char *ALdoing="";
int AL_Error;
int bufsize;
int openal_disabled = 0;
typedef struct SD
{
ALuint buffers[16];
ALuint source;
ALenum format;
char loop;
char type;
int rate;
sounddef def;
}sounddef1;
sounddef1 sounds1[2];
#ifdef _WIN32
// Windows
static HANDLE hALDLL;
@ -38,33 +38,33 @@ static HANDLE hALDLL;
#include <dlfcn.h>
static void *alhandle = NULL;
#endif
char *aldriver = NULL;
void (AL_APIENTRY * balGetSourcei)( ALuint sid, ALenum param, ALint* value );
void (AL_APIENTRY * balSourcef)( ALuint sid, ALenum param, ALfloat value );
void (AL_APIENTRY * balSourcePlay)( ALuint sid );
void (AL_APIENTRY * balSourcePause)( ALuint sid );
ALCenum (ALC_APIENTRY * balcGetError)( ALCdevice *device );
ALenum (AL_APIENTRY * balGetError)( void );
void (AL_APIENTRY * balBufferData)( ALuint bid, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq );
void (AL_APIENTRY * balGenBuffers)( ALsizei n, ALuint* buffers );
void (AL_APIENTRY * balGenSources)( ALsizei n, ALuint* sources );
void (AL_APIENTRY * balSourcei)( ALuint sid, ALenum param, ALint value );
void (AL_APIENTRY * balSourceQueueBuffers)( ALuint sid, ALsizei numEntries, const ALuint *bids );
void (AL_APIENTRY * balSourceStop)( ALuint sid );
void (AL_APIENTRY * balSourceUnqueueBuffers)( ALuint sid, ALsizei numEntries, ALuint *bids );
void (AL_APIENTRY * bbalDeleteSources)( ALsizei n, const ALuint* sources );
ALCboolean (ALC_APIENTRY * balcMakeContextCurrent)( ALCcontext *context );
void (AL_APIENTRY * balDeleteSources)( ALsizei n, const ALuint* sources );
void (AL_APIENTRY * balDeleteBuffers)( ALsizei n, const ALuint* buffers );
void (ALC_APIENTRY * balcDestroyContext)( ALCcontext *context );
ALCboolean (ALC_APIENTRY * balcCloseDevice)( ALCdevice *device );
ALCdevice *(ALC_APIENTRY * balcOpenDevice)( const ALCchar *devicename );
ALCcontext *(ALC_APIENTRY * balcCreateContext)( ALCdevice *device, const ALCint* attrlist );
const ALchar* (AL_APIENTRY * balGetString)( ALenum param );
#endif
char *aldriver = NULL;
void (AL_APIENTRY * balGetSourcei)( ALuint sid, ALenum param, ALint* value );
void (AL_APIENTRY * balSourcef)( ALuint sid, ALenum param, ALfloat value );
void (AL_APIENTRY * balSourcePlay)( ALuint sid );
void (AL_APIENTRY * balSourcePause)( ALuint sid );
ALCenum (ALC_APIENTRY * balcGetError)( ALCdevice *device );
ALenum (AL_APIENTRY * balGetError)( void );
void (AL_APIENTRY * balBufferData)( ALuint bid, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq );
void (AL_APIENTRY * balGenBuffers)( ALsizei n, ALuint* buffers );
void (AL_APIENTRY * balGenSources)( ALsizei n, ALuint* sources );
void (AL_APIENTRY * balSourcei)( ALuint sid, ALenum param, ALint value );
void (AL_APIENTRY * balSourceQueueBuffers)( ALuint sid, ALsizei numEntries, const ALuint *bids );
void (AL_APIENTRY * balSourceStop)( ALuint sid );
void (AL_APIENTRY * balSourceUnqueueBuffers)( ALuint sid, ALsizei numEntries, ALuint *bids );
void (AL_APIENTRY * bbalDeleteSources)( ALsizei n, const ALuint* sources );
ALCboolean (ALC_APIENTRY * balcMakeContextCurrent)( ALCcontext *context );
void (AL_APIENTRY * balDeleteSources)( ALsizei n, const ALuint* sources );
void (AL_APIENTRY * balDeleteBuffers)( ALsizei n, const ALuint* buffers );
void (ALC_APIENTRY * balcDestroyContext)( ALCcontext *context );
ALCboolean (ALC_APIENTRY * balcCloseDevice)( ALCdevice *device );
ALCdevice *(ALC_APIENTRY * balcOpenDevice)( const ALCchar *devicename );
ALCcontext *(ALC_APIENTRY * balcCreateContext)( ALCdevice *device, const ALCint* attrlist );
const ALchar* (AL_APIENTRY * balGetString)( ALenum param );
static void * algetproc_(const char *s, int *err, int fatal)
{
void *t;
@ -101,26 +101,26 @@ int unloadaldriver(void)
#endif
balGetSourcei = NULL;
balSourcef = NULL;
balSourcePlay = NULL;
balSourcePause = NULL;
balcGetError = NULL;
balGetError = NULL;
balBufferData = NULL;
balGenBuffers = NULL;
balGenSources = NULL;
balSourcei = NULL;
balSourceQueueBuffers = NULL;
balSourceStop = NULL;
balSourceUnqueueBuffers = NULL;
bbalDeleteSources = NULL;
balcMakeContextCurrent = NULL;
balDeleteSources = NULL;
balDeleteBuffers = NULL;
balcDestroyContext = NULL;
balcCloseDevice = NULL;
balcOpenDevice = NULL;
balcCreateContext = NULL;
balSourcef = NULL;
balSourcePlay = NULL;
balSourcePause = NULL;
balcGetError = NULL;
balGetError = NULL;
balBufferData = NULL;
balGenBuffers = NULL;
balGenSources = NULL;
balSourcei = NULL;
balSourceQueueBuffers = NULL;
balSourceStop = NULL;
balSourceUnqueueBuffers = NULL;
bbalDeleteSources = NULL;
balcMakeContextCurrent = NULL;
balDeleteSources = NULL;
balDeleteBuffers = NULL;
balcDestroyContext = NULL;
balcCloseDevice = NULL;
balcOpenDevice = NULL;
balcCreateContext = NULL;
balGetString = NULL;
return 0;
@ -159,309 +159,309 @@ int loadaldriver(void)
aldriver = strdup(driver);
balGetSourcei = ALGETPROC("alGetSourcei");
balSourcef = ALGETPROC("alSourcef");
balSourcePlay = ALGETPROC("alSourcePlay");
balSourcePause = ALGETPROC("alSourcePause");
balcGetError = ALGETPROC("alcGetError");
balGetError = ALGETPROC("alGetError");
balBufferData = ALGETPROC("alBufferData");
balGenBuffers = ALGETPROC("alGenBuffers");
balGenSources = ALGETPROC("alGenSources");
balSourcei = ALGETPROC("alSourcei");
balSourceQueueBuffers = ALGETPROC("alSourceQueueBuffers");
balSourceStop = ALGETPROC("alSourceStop");
balSourceUnqueueBuffers = ALGETPROC("alSourceUnqueueBuffers");
balDeleteSources = ALGETPROC("alDeleteSources");
balcMakeContextCurrent = ALGETPROC("alcMakeContextCurrent");
balDeleteSources = ALGETPROC("alDeleteSources");
balDeleteBuffers = ALGETPROC("alDeleteBuffers");
balcDestroyContext = ALGETPROC("alcDestroyContext");
balcCloseDevice = ALGETPROC("alcCloseDevice");
balcOpenDevice = ALGETPROC("alcOpenDevice");
balcCreateContext = ALGETPROC("alcCreateContext");
balSourcef = ALGETPROC("alSourcef");
balSourcePlay = ALGETPROC("alSourcePlay");
balSourcePause = ALGETPROC("alSourcePause");
balcGetError = ALGETPROC("alcGetError");
balGetError = ALGETPROC("alGetError");
balBufferData = ALGETPROC("alBufferData");
balGenBuffers = ALGETPROC("alGenBuffers");
balGenSources = ALGETPROC("alGenSources");
balSourcei = ALGETPROC("alSourcei");
balSourceQueueBuffers = ALGETPROC("alSourceQueueBuffers");
balSourceStop = ALGETPROC("alSourceStop");
balSourceUnqueueBuffers = ALGETPROC("alSourceUnqueueBuffers");
balDeleteSources = ALGETPROC("alDeleteSources");
balcMakeContextCurrent = ALGETPROC("alcMakeContextCurrent");
balDeleteSources = ALGETPROC("alDeleteSources");
balDeleteBuffers = ALGETPROC("alDeleteBuffers");
balcDestroyContext = ALGETPROC("alcDestroyContext");
balcCloseDevice = ALGETPROC("alcCloseDevice");
balcOpenDevice = ALGETPROC("alcOpenDevice");
balcCreateContext = ALGETPROC("alcCreateContext");
balGetString = ALGETPROC("alGetString");
if (err) unloadaldriver();
return err;
}
char *ALC_ErrorString(int code)
{
switch(code)
{
case ALC_NO_ERROR:
return "OpenAL error: There is no current error.";
case ALC_INVALID_DEVICE:
return "OpenAL error: No device.";
case ALC_INVALID_CONTEXT:
return "OpenAL error: Invalid context ID.";
case ALC_INVALID_ENUM:
return "OpenAL error: Invalid parameter.";
case ALC_INVALID_VALUE:
return "OpenAL error: Invalid enum parameter value.";
case ALC_OUT_OF_MEMORY:
return "OpenAL error: Unable to allocate memory.";
default:
return "OpenAL error: Unknown error.";
}
}
char *AL_ErrorString(int code)
{
switch(code)
{
case AL_NO_ERROR:
return "OpenAL error: There is no current error.";
case AL_INVALID_NAME:
return "OpenAL error: Invalid name parameter.";
case AL_INVALID_ENUM:
return "OpenAL error: Invalid parameter.";
case AL_INVALID_VALUE:
return "OpenAL error: Invalid enum parameter value.";
case AL_INVALID_OPERATION:
return "OpenAL error: Illegal call.";
case AL_OUT_OF_MEMORY:
return "OpenAL error: Unable to allocate memory.";
case OV_EFAULT:
return "Internal logic fault (bug or heap/stack corruption.";
case OV_EREAD:
return "Read from media.";
case OV_EIMPL:
return "The bitstream makes use of a feature not implemented in this library version.";
case OV_EINVAL:
return "Invalid argument value.";
case OV_ENOTVORBIS:
return "Not Vorbis data.";
case OV_EBADHEADER:
return "Invalid Vorbis header.";
case OV_EVERSION:
return "Vorbis version mismatch.";
case OV_ENOTAUDIO:
return "Packet data submitted to vorbis_synthesis is not audio data.";
case OV_EBADPACKET:
return "Invalid packet submitted to vorbis_synthesis.";
case OV_EBADLINK:
return "Invalid stream section supplied to libvorbis/libvorbisfile, or the requested link is corrupt.";
case OV_ENOSEEK:
return "Bitstream is not seekable.";
default:
return "Unknown OpenAL/Ogg error.";
}
}
void check(int show)
{
AL_Error=balcGetError(device);
if(AL_Error!=ALC_NO_ERROR&&show)initprintf("%s(%s)\n",ALC_ErrorString(AL_Error),ALdoing);
AL_Error=balGetError();
if(AL_Error!= AL_NO_ERROR&&show)initprintf("%s(%s)\n", AL_ErrorString(AL_Error),ALdoing);
}
extern ov_callbacks cb;
int AL_Init()
{
if (loadaldriver())
{
initprintf("Failed loading OpenAL driver.\n");
openal_disabled = 1;
return 1;
}
ALdoing="Init";
// device=alcOpenDevice(ud.config.HardwareAL?"Generic Hardware":"Generic Software");
device=balcOpenDevice(NULL);
check(1);
if(device)
{
context=balcCreateContext(device,NULL);
check(1);
}
if(context)
{
balcMakeContextCurrent(context);check(1);
initprintf("OpenAL Information:\n"
" Version: %s\n"
" Vendor: %s\n\n",balGetString(AL_VERSION),balGetString(AL_VENDOR));
} else initprintf("OpenAL initialisation failed. Try http://www.openal.org/\n");
ALdoing="Open";
balGenBuffers(16, sounds1[1].buffers);
check(1);
balGenSources(1,&sounds1[1].source);
check(1);
return 0;
}
void AL_Shutdown()
{
ALdoing="Delete source";
balDeleteSources(1,&sounds1[1].source);
check(1);
ALdoing="Delete buffers";
balDeleteBuffers(16, sounds1[1].buffers);
check(1);
ALdoing="Shut";
balcMakeContextCurrent(NULL);
check(1);
balcDestroyContext(context);
check(1);
balcCloseDevice(device);
unloadaldriver();
}
#define BUFFER_SIZE (4096 * 4*8*8)
int AL_MusicVolume;
sounddef1 music;
extern int Musicsize;
void AL_stop();
int update();
int stream(ALuint buffer);
void open1(char *ptr,int sizef,char loop);
void AL_Pause() {if(music.def.size)balSourcePause(music.source);}
void AL_Continue() {if(music.def.size)balSourcePlay(music.source);}
void AL_Update() {if(music.def.size&&!update(0))AL_stop();}
int AL_isntALmusic() {return !music.def.size;}
void AL_SetMusicVolume(int volume)
{
AL_MusicVolume=volume;
if(music.def.size)balSourcef(music.source,AL_GAIN,volume/(255.));
}
int isplaying()
{
ALenum state;
balGetSourcei(music.source,AL_SOURCE_STATE,&state);
return state==AL_PLAYING;
}
int update()
{
int processed=0;
int active=1;
ALuint buffer;
ALdoing="update";
balGetSourcei(music.source,AL_BUFFERS_PROCESSED,&processed);
check(1);
if(processed)
switch(music.type)
{
case 1:
while(processed--)
{
balSourceUnqueueBuffers(music.source,1,&buffer);
check(1);
active=stream(buffer);
if(active)
{
balSourceQueueBuffers(music.source,1,&buffer);
check(1);
}
}
break;
}
return active;
}
void AL_stop()
{
int queued=0;ALuint buffer;
if(!music.def.size)return;
balSourceStop(music.source);
balGetSourcei(music.source,AL_BUFFERS_QUEUED,&queued);
ALdoing="release";
while(queued--)
{
balSourceUnqueueBuffers(music.source,1,&buffer);
check(1);
}
balDeleteSources(1,&music.source);check(1);
balDeleteBuffers(2, music.buffers);check(1);
if(music.type==1)ov_clear(&music.def.oggStream);
Bmemset(&music,0,sizeof(sounddef1));
}
int stream(ALuint buffer)
{
char pcm[BUFFER_SIZE];
ALsizei size=0;
int section,result;
while(size<BUFFER_SIZE)
{
result=ov_read(&music.def.oggStream,pcm+size,BUFFER_SIZE-size,0,2,1,&section);
if(result==0&&music.loop)ov_pcm_seek(&music.def.oggStream,0);else
if(result> 0)size+=result;else break;
}
if(!size)return 0;
ALdoing="stream";
balBufferData(buffer,music.format,pcm,size,music.rate);
check(1);
return 1;
}
void AL_PlaySong(char *ptr,int loop)
{
vorbis_info* vorbisInfo;
int bf=2,i;
ALenum format;ALsizei size;ALsizei freq;ALvoid* data;
if(!context)return;
Bmemset(&music,0,sizeof(sounddef1));
switch(*ptr)
{
case 'O':music.type=1;break;
default: return;
}
music.def.size=Musicsize;
music.loop=loop;
music.def.ptrsnd=ptr;
switch(music.type)
{
case 1:
if((i=ov_open_callbacks(&music.def,&music.def.oggStream,0,0,cb))<0)
{
Bmemset(&music,0,sizeof(sounddef1));
initprintf("Music error: %s\n",AL_ErrorString(i));
return;
}
vorbisInfo=ov_info(&music.def.oggStream,-1);
if(!vorbisInfo)
{
initprintf("Music error: vorbisInfo\n");
Bmemset(&music,0,sizeof(sounddef1));
return;
}
music.rate=vorbisInfo->rate;
music.format=(vorbisInfo->channels==1)?AL_FORMAT_MONO16:AL_FORMAT_STEREO16;break;
}
ALdoing="Open";
balGenBuffers(2, music.buffers);check(1);
balGenSources(1,&music.source);check(1);
balSourcei(music.source,AL_SOURCE_RELATIVE,AL_TRUE);
switch(music.type)
{
case 1: stream(music.buffers[0]);
if(!stream(music.buffers[1]))bf=1;
balSourceQueueBuffers(music.source,bf,music.buffers);
break;
}
AL_SetMusicVolume(AL_MusicVolume);
AL_Continue();
}
char *ALC_ErrorString(int code)
{
switch(code)
{
case ALC_NO_ERROR:
return "OpenAL error: There is no current error.";
case ALC_INVALID_DEVICE:
return "OpenAL error: No device.";
case ALC_INVALID_CONTEXT:
return "OpenAL error: Invalid context ID.";
case ALC_INVALID_ENUM:
return "OpenAL error: Invalid parameter.";
case ALC_INVALID_VALUE:
return "OpenAL error: Invalid enum parameter value.";
case ALC_OUT_OF_MEMORY:
return "OpenAL error: Unable to allocate memory.";
default:
return "OpenAL error: Unknown error.";
}
}
char *AL_ErrorString(int code)
{
switch(code)
{
case AL_NO_ERROR:
return "OpenAL error: There is no current error.";
case AL_INVALID_NAME:
return "OpenAL error: Invalid name parameter.";
case AL_INVALID_ENUM:
return "OpenAL error: Invalid parameter.";
case AL_INVALID_VALUE:
return "OpenAL error: Invalid enum parameter value.";
case AL_INVALID_OPERATION:
return "OpenAL error: Illegal call.";
case AL_OUT_OF_MEMORY:
return "OpenAL error: Unable to allocate memory.";
case OV_EFAULT:
return "Internal logic fault (bug or heap/stack corruption.";
case OV_EREAD:
return "Read from media.";
case OV_EIMPL:
return "The bitstream makes use of a feature not implemented in this library version.";
case OV_EINVAL:
return "Invalid argument value.";
case OV_ENOTVORBIS:
return "Not Vorbis data.";
case OV_EBADHEADER:
return "Invalid Vorbis header.";
case OV_EVERSION:
return "Vorbis version mismatch.";
case OV_ENOTAUDIO:
return "Packet data submitted to vorbis_synthesis is not audio data.";
case OV_EBADPACKET:
return "Invalid packet submitted to vorbis_synthesis.";
case OV_EBADLINK:
return "Invalid stream section supplied to libvorbis/libvorbisfile, or the requested link is corrupt.";
case OV_ENOSEEK:
return "Bitstream is not seekable.";
default:
return "Unknown OpenAL/Ogg error.";
}
}
void check(int show)
{
AL_Error=balcGetError(device);
if(AL_Error!=ALC_NO_ERROR&&show)initprintf("%s(%s)\n",ALC_ErrorString(AL_Error),ALdoing);
AL_Error=balGetError();
if(AL_Error!= AL_NO_ERROR&&show)initprintf("%s(%s)\n", AL_ErrorString(AL_Error),ALdoing);
}
extern ov_callbacks cb;
int AL_Init()
{
if (loadaldriver())
{
initprintf("Failed loading OpenAL driver.\nDownload OpenAL 1.1 or greater from http://www.openal.org/downloads.html.");
openal_disabled = 1;
return 1;
}
ALdoing="Init";
// device=alcOpenDevice(ud.config.HardwareAL?"Generic Hardware":"Generic Software");
device=balcOpenDevice(NULL);
check(1);
if(device)
{
context=balcCreateContext(device,NULL);
check(1);
}
if(context)
{
balcMakeContextCurrent(context);check(1);
initprintf("OpenAL Information:\n"
" Version: %s\n"
" Vendor: %s\n\n",balGetString(AL_VERSION),balGetString(AL_VENDOR));
} else initprintf("OpenAL initialization failed.\n");
ALdoing="Open";
balGenBuffers(16, sounds1[1].buffers);
check(1);
balGenSources(1,&sounds1[1].source);
check(1);
return 0;
}
void AL_Shutdown()
{
ALdoing="Delete source";
balDeleteSources(1,&sounds1[1].source);
check(1);
ALdoing="Delete buffers";
balDeleteBuffers(16, sounds1[1].buffers);
check(1);
ALdoing="Shut";
balcMakeContextCurrent(NULL);
check(1);
balcDestroyContext(context);
check(1);
balcCloseDevice(device);
unloadaldriver();
}
#define BUFFER_SIZE (4096 * 4*8*8)
int AL_MusicVolume;
sounddef1 music;
extern int Musicsize;
void AL_Stop();
int update();
int stream(ALuint buffer);
void open1(char *ptr,int sizef,char loop);
void AL_Pause() {if(music.def.size)balSourcePause(music.source);}
void AL_Continue() {if(music.def.size)balSourcePlay(music.source);}
void AL_Update() {if(music.def.size&&!update(0))AL_Stop();}
int AL_isntALmusic() {return !music.def.size;}
void AL_SetMusicVolume(int volume)
{
AL_MusicVolume=volume;
if(music.def.size)balSourcef(music.source,AL_GAIN,volume/(255.));
}
int isplaying()
{
ALenum state;
balGetSourcei(music.source,AL_SOURCE_STATE,&state);
return state==AL_PLAYING;
}
int update()
{
int processed=0;
int active=1;
ALuint buffer;
ALdoing="update";
balGetSourcei(music.source,AL_BUFFERS_PROCESSED,&processed);
check(1);
if(processed)
switch(music.type)
{
case 1:
while(processed--)
{
balSourceUnqueueBuffers(music.source,1,&buffer);
check(1);
active=stream(buffer);
if(active)
{
balSourceQueueBuffers(music.source,1,&buffer);
check(1);
}
}
break;
}
return active;
}
void AL_Stop()
{
int queued=0;ALuint buffer;
if(!music.def.size)return;
balSourceStop(music.source);
balGetSourcei(music.source,AL_BUFFERS_QUEUED,&queued);
ALdoing="release";
while(queued--)
{
balSourceUnqueueBuffers(music.source,1,&buffer);
check(1);
}
balDeleteSources(1,&music.source);check(1);
balDeleteBuffers(2, music.buffers);check(1);
if(music.type==1)ov_clear(&music.def.oggStream);
Bmemset(&music,0,sizeof(sounddef1));
}
int stream(ALuint buffer)
{
char pcm[BUFFER_SIZE];
ALsizei size=0;
int section,result;
while(size<BUFFER_SIZE)
{
result=ov_read(&music.def.oggStream,pcm+size,BUFFER_SIZE-size,0,2,1,&section);
if(result==0&&music.loop)ov_pcm_seek(&music.def.oggStream,0);else
if(result> 0)size+=result;else break;
}
if(!size)return 0;
ALdoing="stream";
balBufferData(buffer,music.format,pcm,size,music.rate);
check(1);
return 1;
}
void AL_PlaySong(char *ptr,int loop)
{
vorbis_info* vorbisInfo;
int bf=2,i;
ALenum format;ALsizei size;ALsizei freq;ALvoid* data;
if(!context)return;
Bmemset(&music,0,sizeof(sounddef1));
switch(*ptr)
{
case 'O':music.type=1;break;
default: return;
}
music.def.size=Musicsize;
music.loop=loop;
music.def.ptrsnd=ptr;
switch(music.type)
{
case 1:
if((i=ov_open_callbacks(&music.def,&music.def.oggStream,0,0,cb))<0)
{
Bmemset(&music,0,sizeof(sounddef1));
initprintf("Music error: %s\n",AL_ErrorString(i));
return;
}
vorbisInfo=ov_info(&music.def.oggStream,-1);
if(!vorbisInfo)
{
initprintf("Music error: vorbisInfo\n");
Bmemset(&music,0,sizeof(sounddef1));
return;
}
music.rate=vorbisInfo->rate;
music.format=(vorbisInfo->channels==1)?AL_FORMAT_MONO16:AL_FORMAT_STEREO16;break;
}
ALdoing="Open";
balGenBuffers(2, music.buffers);check(1);
balGenSources(1,&music.source);check(1);
balSourcei(music.source,AL_SOURCE_RELATIVE,AL_TRUE);
switch(music.type)
{
case 1: stream(music.buffers[0]);
if(!stream(music.buffers[1]))bf=1;
balSourceQueueBuffers(music.source,bf,music.buffers);
break;
}
AL_SetMusicVolume(AL_MusicVolume);
AL_Continue();
}

View file

@ -9,7 +9,7 @@ void AL_Update();
char *AL_ErrorString(int code);
char *ALC_ErrorString(int code);
void AL_stop();
void AL_Stop();
int AL_isntALmusic();
void AL_PlaySong(char *song,int loopflag);
void AL_Pause();

View file

@ -54,6 +54,10 @@ Adapted to work with JonoF's port by James Bentler (bentler@cs.umn.edu)
#include <SDL_mixer.h>
#include "music.h"
#ifdef USE_OPENAL
#include "openal.h"
#endif
#define __FX_TRUE (1 == 1)
#define __FX_FALSE (!__FX_TRUE)
@ -376,6 +380,11 @@ void MUSIC_SetVolume(int volume)
volume = max(0, volume);
volume = min(volume, 255);
#ifdef USE_OPENAL
if (!openal_disabled)
AL_SetMusicVolume(volume);
#endif
Mix_VolumeMusic(volume >> 1); // convert 0-255 to 0-128.
} // MUSIC_SetVolume
@ -412,6 +421,10 @@ int MUSIC_SongPlaying(void)
void MUSIC_Continue(void)
{
#ifdef USE_OPENAL
if (!openal_disabled)
AL_Continue();
#endif
if (Mix_PausedMusic())
Mix_ResumeMusic();
else if (music_songdata)
@ -421,12 +434,20 @@ void MUSIC_Continue(void)
void MUSIC_Pause(void)
{
#ifdef USE_OPENAL
if (!openal_disabled)
AL_Pause();
#endif
Mix_PauseMusic();
} // MUSIC_Pause
int MUSIC_StopSong(void)
{
#ifdef USE_OPENAL
if (!openal_disabled)
AL_Stop();
#endif
//if (!fx_initialized)
if (!Mix_QuerySpec(NULL, NULL, NULL))
{
@ -450,7 +471,12 @@ int MUSIC_StopSong(void)
int MUSIC_PlaySong(unsigned char *song, int loopflag)
{
//SDL_RWops *rw;
#ifdef USE_OPENAL
if (!openal_disabled)
AL_PlaySong((char *)song,loopflag);
if(openal_disabled || AL_isntALmusic())
#endif
{
MUSIC_StopSong();
music_songdata = (char *)song;
@ -468,7 +494,7 @@ int MUSIC_PlaySong(unsigned char *song, int loopflag)
music_musicchunk = Mix_LoadMUS_RW(rw);
Mix_PlayMusic(music_musicchunk, (loopflag == MUSIC_PlayOnce) ? 0 : -1);
*/
}
return(MUSIC_Ok);
} // MUSIC_PlaySong

View file

@ -1605,7 +1605,8 @@ int enterlevel(int g)
FX_StopAllSounds();
clearsoundlocks();
FX_SetReverb(0);
playmusicMAP(&env_music_fn[1][0],MAXVOLUMES*MAXLEVELS+2); // loadmus
MUSIC_StopSong();
playmusicMAP(&env_music_fn[2][0],MAXVOLUMES*MAXLEVELS+2); // loadmus
if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
{

View file

@ -392,14 +392,10 @@ int xyzsound(int num,int i,int x,int y,int z)
if (*g_sounds[num].ptr == 'C')
voice = FX_PlayLoopedVOC(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz,
pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,num);
#ifdef USE_OPENAL
else if (!openal_disabled)
{
else
if (*g_sounds[num].ptr == 'O')
voice = FX_PlayLoopedOGG(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz,
pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,num);
}
#endif
else
voice = FX_PlayLoopedWAV(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz,
pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,num);
@ -408,13 +404,9 @@ int xyzsound(int num,int i,int x,int y,int z)
{
if (*g_sounds[num].ptr == 'C')
voice = FX_PlayVOC3D(g_sounds[ num ].ptr,pitch,sndang>>6,sndist>>6, g_sounds[num].pr, num);
#ifdef USE_OPENAL
else if (!openal_disabled)
{
else
if (*g_sounds[num].ptr == 'O')
voice = FX_PlayOGG3D(g_sounds[ num ].ptr,pitch,sndang>>6,sndist>>6, g_sounds[num].pr, num);
}
#endif
else
voice = FX_PlayWAV3D(g_sounds[ num ].ptr,pitch,sndang>>6,sndist>>6, g_sounds[num].pr, num);
}
@ -477,17 +469,13 @@ void sound(int num)
voice = FX_PlayLoopedVOC(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz,
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].pr,num);
}
#ifdef USE_OPENAL
else if (!openal_disabled)
{
else
if (*g_sounds[num].ptr == 'O')
{
start = (int)*(unsigned short *)(g_sounds[num].ptr + 0x14);
voice = FX_PlayLoopedOGG(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz,
pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].pr,num);
}
}
#endif
else
{
start = (int)*(unsigned short *)(g_sounds[num].ptr + 0x14);
@ -499,13 +487,9 @@ void sound(int num)
{
if (*g_sounds[num].ptr == 'C')
voice = FX_PlayVOC3D(g_sounds[ num ].ptr, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num);
#ifdef USE_OPENAL
else if (!openal_disabled)
{
else
if (*g_sounds[num].ptr == 'O')
voice = FX_PlayOGG3D(g_sounds[ num ].ptr, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num);
}
#endif
else
voice = FX_PlayWAV3D(g_sounds[ num ].ptr, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num);
}