2008-03-08 07:46:30 +00:00
|
|
|
#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;
|
|
|
|
|
2008-03-09 08:14:12 +00:00
|
|
|
char *ALdoing = NULL;
|
2008-03-08 07:46:30 +00:00
|
|
|
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;
|
|
|
|
|
2008-03-14 21:04:28 +00:00
|
|
|
sounddef1 music;
|
2008-03-08 07:46:30 +00:00
|
|
|
|
2008-03-08 06:51:53 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
// Windows
|
2008-03-09 08:14:12 +00:00
|
|
|
static HANDLE hALDLL = NULL;
|
2008-03-08 06:51:53 +00:00
|
|
|
#else
|
|
|
|
#include <dlfcn.h>
|
|
|
|
static void *alhandle = NULL;
|
2008-03-08 07:46:30 +00:00
|
|
|
#endif
|
|
|
|
|
2008-03-09 08:14:12 +00:00
|
|
|
static char *aldriver = NULL;
|
|
|
|
|
|
|
|
static void (AL_APIENTRY * balGetSourcei)(ALuint sid, ALenum param, ALint* value);
|
|
|
|
static void (AL_APIENTRY * balSourcef)(ALuint sid, ALenum param, ALfloat value);
|
|
|
|
static void (AL_APIENTRY * balSourcePlay)(ALuint sid);
|
|
|
|
static void (AL_APIENTRY * balSourcePause)(ALuint sid);
|
|
|
|
static ALCenum(ALC_APIENTRY * balcGetError)(ALCdevice *device);
|
|
|
|
static ALenum(AL_APIENTRY * balGetError)(void);
|
|
|
|
static void (AL_APIENTRY * balBufferData)(ALuint bid, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq);
|
|
|
|
static void (AL_APIENTRY * balGenBuffers)(ALsizei n, ALuint* buffers);
|
|
|
|
static void (AL_APIENTRY * balGenSources)(ALsizei n, ALuint* sources);
|
|
|
|
static void (AL_APIENTRY * balSourcei)(ALuint sid, ALenum param, ALint value);
|
|
|
|
static void (AL_APIENTRY * balSourceQueueBuffers)(ALuint sid, ALsizei numEntries, const ALuint *bids);
|
|
|
|
static void (AL_APIENTRY * balSourceStop)(ALuint sid);
|
|
|
|
static void (AL_APIENTRY * balSourceUnqueueBuffers)(ALuint sid, ALsizei numEntries, ALuint *bids);
|
|
|
|
static void (AL_APIENTRY * bbalDeleteSources)(ALsizei n, const ALuint* sources);
|
|
|
|
static ALCboolean(ALC_APIENTRY * balcMakeContextCurrent)(ALCcontext *context);
|
|
|
|
static void (AL_APIENTRY * balDeleteSources)(ALsizei n, const ALuint* sources);
|
|
|
|
static void (AL_APIENTRY * balDeleteBuffers)(ALsizei n, const ALuint* buffers);
|
|
|
|
static void (ALC_APIENTRY * balcDestroyContext)(ALCcontext *context);
|
|
|
|
static ALCboolean(ALC_APIENTRY * balcCloseDevice)(ALCdevice *device);
|
|
|
|
static ALCdevice *(ALC_APIENTRY * balcOpenDevice)(const ALCchar *devicename);
|
|
|
|
static ALCcontext *(ALC_APIENTRY * balcCreateContext)(ALCdevice *device, const ALCint* attrlist);
|
|
|
|
static const ALchar*(AL_APIENTRY * balGetString)(ALenum param);
|
2008-03-08 07:46:30 +00:00
|
|
|
|
2008-03-08 06:51:53 +00:00
|
|
|
static void * algetproc_(const char *s, int *err, int fatal)
|
|
|
|
{
|
|
|
|
void *t;
|
|
|
|
#if defined _WIN32
|
|
|
|
t = (void*)GetProcAddress(hALDLL,s);
|
|
|
|
#else
|
|
|
|
t = (void*)dlsym(alhandle,s);
|
|
|
|
#endif
|
|
|
|
if (!t && fatal)
|
|
|
|
{
|
|
|
|
initprintf("Failed to find %s in %s\n", s, aldriver);
|
|
|
|
*err = 1;
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
#define ALGETPROC(s) algetproc_(s,&err,1)
|
|
|
|
#define ALGETPROCSOFT(s) algetproc_(s,&err,0)
|
|
|
|
|
2008-03-09 08:14:12 +00:00
|
|
|
static int unloadaldriver(void)
|
2008-03-08 06:51:53 +00:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (!hALDLL) return 0;
|
|
|
|
#endif
|
|
|
|
|
2008-03-09 08:14:12 +00:00
|
|
|
if (aldriver)
|
|
|
|
free(aldriver);
|
2008-03-08 06:51:53 +00:00
|
|
|
aldriver = NULL;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2008-03-09 08:14:12 +00:00
|
|
|
if (hALDLL)
|
|
|
|
FreeLibrary(hALDLL);
|
2008-03-08 06:51:53 +00:00
|
|
|
hALDLL = NULL;
|
|
|
|
#else
|
2008-03-09 08:14:12 +00:00
|
|
|
if (alhandle)
|
|
|
|
dlclose(alhandle);
|
2008-03-08 06:51:53 +00:00
|
|
|
alhandle = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
balGetSourcei = NULL;
|
2008-03-08 07:46:30 +00:00
|
|
|
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;
|
2008-03-08 06:51:53 +00:00
|
|
|
balGetString = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-09 08:14:12 +00:00
|
|
|
static int loadaldriver(void)
|
2008-03-08 06:51:53 +00:00
|
|
|
{
|
|
|
|
void *t;
|
|
|
|
int err=0;
|
|
|
|
char *driver;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2008-03-09 08:14:12 +00:00
|
|
|
if (hALDLL)
|
|
|
|
return 0;
|
2008-03-08 06:51:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// if (!driver)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
driver = "OpenAL32.DLL";
|
|
|
|
#elif defined __APPLE__
|
|
|
|
driver = "/System/Library/Frameworks/OpenGL.framework/OpenGL"; // FIXME: like I know anything about Apple. Hah.
|
|
|
|
#else
|
|
|
|
driver = "libopenal.so";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
initprintf("Loading %s\n",driver);
|
|
|
|
|
2008-03-09 08:14:12 +00:00
|
|
|
#ifdef _WIN32
|
2008-03-08 06:51:53 +00:00
|
|
|
hALDLL = LoadLibrary(driver);
|
|
|
|
if (!hALDLL) return -1;
|
|
|
|
#else
|
|
|
|
alhandle = dlopen(driver, RTLD_NOW|RTLD_GLOBAL);
|
|
|
|
if (!alhandle) return -1;
|
|
|
|
#endif
|
|
|
|
aldriver = strdup(driver);
|
|
|
|
|
|
|
|
balGetSourcei = ALGETPROC("alGetSourcei");
|
2008-03-08 07:46:30 +00:00
|
|
|
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");
|
2008-03-08 06:51:53 +00:00
|
|
|
balGetString = ALGETPROC("alGetString");
|
|
|
|
|
|
|
|
if (err) unloadaldriver();
|
|
|
|
return err;
|
|
|
|
}
|
2008-03-08 07:46:30 +00:00
|
|
|
|
|
|
|
char *ALC_ErrorString(int code)
|
|
|
|
{
|
2008-03-08 19:45:48 +00:00
|
|
|
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.";
|
|
|
|
}
|
2008-03-08 07:46:30 +00:00
|
|
|
}
|
|
|
|
char *AL_ErrorString(int code)
|
|
|
|
{
|
2008-03-08 19:45:48 +00:00
|
|
|
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.";
|
|
|
|
}
|
2008-03-08 07:46:30 +00:00
|
|
|
}
|
|
|
|
void check(int show)
|
|
|
|
{
|
|
|
|
AL_Error=balcGetError(device);
|
2008-03-08 19:45:48 +00:00
|
|
|
if (AL_Error!=ALC_NO_ERROR&&show)initprintf("%s(%s)\n",ALC_ErrorString(AL_Error),ALdoing);
|
2008-03-08 07:46:30 +00:00
|
|
|
AL_Error=balGetError();
|
2008-03-08 19:45:48 +00:00
|
|
|
if (AL_Error!= AL_NO_ERROR&&show)initprintf("%s(%s)\n", AL_ErrorString(AL_Error),ALdoing);
|
2008-03-08 07:46:30 +00:00
|
|
|
}
|
|
|
|
extern ov_callbacks cb;
|
|
|
|
|
|
|
|
|
|
|
|
int AL_Init()
|
|
|
|
{
|
2008-03-14 21:04:28 +00:00
|
|
|
Bmemset(&music,0,sizeof(music)); // "music.def.size=0" means music not playing
|
2008-03-08 07:46:30 +00:00
|
|
|
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);
|
2008-03-08 19:45:48 +00:00
|
|
|
|
|
|
|
if (device)
|
2008-03-08 07:46:30 +00:00
|
|
|
{
|
|
|
|
context=balcCreateContext(device,NULL);
|
|
|
|
check(1);
|
|
|
|
}
|
2008-03-08 19:45:48 +00:00
|
|
|
|
|
|
|
if (context)
|
2008-03-08 07:46:30 +00:00
|
|
|
{
|
2008-03-09 08:14:12 +00:00
|
|
|
// char *s,*t,*u,i;
|
2008-03-08 19:45:48 +00:00
|
|
|
|
|
|
|
balcMakeContextCurrent(context);check(1);
|
|
|
|
initprintf("OpenAL Information:\n"
|
|
|
|
" Version: %s\n"
|
|
|
|
" Vendor: %s\n"
|
|
|
|
" Renderer: %s\n"
|
2008-03-09 08:14:12 +00:00
|
|
|
// " Extensions:\n"
|
2008-03-08 19:45:48 +00:00
|
|
|
,balGetString(AL_VERSION),balGetString(AL_VENDOR),balGetString(AL_RENDERER));
|
|
|
|
|
2008-03-09 08:14:12 +00:00
|
|
|
/* s = Bstrdup(balGetString(AL_EXTENSIONS));
|
|
|
|
if (!s) initprintf(balGetString(AL_EXTENSIONS));
|
|
|
|
else
|
2008-03-08 19:45:48 +00:00
|
|
|
{
|
2008-03-09 08:14:12 +00:00
|
|
|
i = 0; t = u = s;
|
|
|
|
while (*t)
|
2008-03-08 19:45:48 +00:00
|
|
|
{
|
2008-03-09 08:14:12 +00:00
|
|
|
if (*t == ' ')
|
|
|
|
{
|
|
|
|
if (i&1)
|
|
|
|
{
|
|
|
|
*t = 0;
|
|
|
|
initprintf(" %s\n",u);
|
|
|
|
u = t+1;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
t++;
|
2008-03-08 19:45:48 +00:00
|
|
|
}
|
2008-03-09 08:14:12 +00:00
|
|
|
if (i&1) initprintf(" %s\n",u);
|
|
|
|
Bfree(s);
|
2008-03-08 19:45:48 +00:00
|
|
|
}
|
2008-03-09 08:14:12 +00:00
|
|
|
*/
|
2008-03-08 19:45:48 +00:00
|
|
|
}
|
|
|
|
else initprintf("OpenAL initialization failed.\n");
|
2008-03-08 07:46:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AL_Shutdown()
|
|
|
|
{
|
2008-03-14 21:04:28 +00:00
|
|
|
if (openal_disabled)return;
|
2008-03-08 07:46:30 +00:00
|
|
|
|
|
|
|
ALdoing="Shut";
|
|
|
|
balcMakeContextCurrent(NULL);
|
|
|
|
check(1);
|
|
|
|
balcDestroyContext(context);
|
|
|
|
check(1);
|
|
|
|
balcCloseDevice(device);
|
|
|
|
unloadaldriver();
|
|
|
|
}
|
|
|
|
|
2008-03-14 21:04:28 +00:00
|
|
|
#define BUFFER_SIZE 65536 // (4096 * 4*8*8)
|
2008-03-08 07:46:30 +00:00
|
|
|
int AL_MusicVolume;
|
|
|
|
extern int Musicsize;
|
|
|
|
|
|
|
|
|
|
|
|
void AL_Stop();
|
|
|
|
int update();
|
|
|
|
int stream(ALuint buffer);
|
|
|
|
void open1(char *ptr,int sizef,char loop);
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-08 19:45:48 +00:00
|
|
|
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();}
|
2008-03-08 07:46:30 +00:00
|
|
|
int AL_isntALmusic() {return !music.def.size;}
|
|
|
|
|
|
|
|
void AL_SetMusicVolume(int volume)
|
|
|
|
{
|
|
|
|
AL_MusicVolume=volume;
|
2008-03-08 19:45:48 +00:00
|
|
|
if (music.def.size)balSourcef(music.source,AL_GAIN,volume/(255.));
|
2008-03-08 07:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2008-03-08 19:45:48 +00:00
|
|
|
if (processed)
|
|
|
|
switch (music.type)
|
|
|
|
{
|
2008-03-08 07:46:30 +00:00
|
|
|
case 1:
|
2008-03-08 19:45:48 +00:00
|
|
|
while (processed--)
|
2008-03-08 07:46:30 +00:00
|
|
|
{
|
|
|
|
balSourceUnqueueBuffers(music.source,1,&buffer);
|
|
|
|
check(1);
|
|
|
|
active=stream(buffer);
|
2008-03-08 19:45:48 +00:00
|
|
|
if (active)
|
2008-03-08 07:46:30 +00:00
|
|
|
{
|
|
|
|
balSourceQueueBuffers(music.source,1,&buffer);
|
|
|
|
check(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-03-08 19:45:48 +00:00
|
|
|
}
|
2008-03-08 07:46:30 +00:00
|
|
|
return active;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AL_Stop()
|
|
|
|
{
|
|
|
|
int queued=0;ALuint buffer;
|
|
|
|
|
2008-03-08 19:45:48 +00:00
|
|
|
if (!music.def.size)return;
|
2008-03-08 07:46:30 +00:00
|
|
|
|
|
|
|
balSourceStop(music.source);
|
|
|
|
balGetSourcei(music.source,AL_BUFFERS_QUEUED,&queued);
|
|
|
|
|
|
|
|
ALdoing="release";
|
2008-03-08 19:45:48 +00:00
|
|
|
while (queued--)
|
2008-03-08 07:46:30 +00:00
|
|
|
{
|
|
|
|
balSourceUnqueueBuffers(music.source,1,&buffer);
|
|
|
|
check(1);
|
|
|
|
}
|
|
|
|
balDeleteSources(1,&music.source);check(1);
|
|
|
|
balDeleteBuffers(2, music.buffers);check(1);
|
|
|
|
|
2008-03-08 19:45:48 +00:00
|
|
|
if (music.type==1)ov_clear(&music.def.oggStream);
|
2008-03-08 07:46:30 +00:00
|
|
|
Bmemset(&music,0,sizeof(sounddef1));
|
|
|
|
}
|
|
|
|
|
|
|
|
int stream(ALuint buffer)
|
|
|
|
{
|
|
|
|
ALsizei size=0;
|
|
|
|
int section,result;
|
2008-03-14 21:04:28 +00:00
|
|
|
static char pcm[BUFFER_SIZE];
|
2008-03-08 07:46:30 +00:00
|
|
|
|
2008-03-08 19:45:48 +00:00
|
|
|
while (size<BUFFER_SIZE)
|
2008-03-08 07:46:30 +00:00
|
|
|
{
|
|
|
|
result=ov_read(&music.def.oggStream,pcm+size,BUFFER_SIZE-size,0,2,1,§ion);
|
2008-03-08 19:45:48 +00:00
|
|
|
if (result==0&&music.loop)ov_pcm_seek(&music.def.oggStream,0);else
|
|
|
|
if (result> 0)size+=result;else break;
|
2008-03-08 07:46:30 +00:00
|
|
|
}
|
2008-03-09 08:14:12 +00:00
|
|
|
if (!size)
|
|
|
|
return 0;
|
2008-03-08 07:46:30 +00:00
|
|
|
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;
|
2008-03-09 08:14:12 +00:00
|
|
|
ALenum format;
|
|
|
|
ALsizei size;
|
|
|
|
ALsizei freq;
|
|
|
|
ALvoid* data;
|
2008-03-08 07:46:30 +00:00
|
|
|
|
2008-03-09 08:14:12 +00:00
|
|
|
if (!context)
|
|
|
|
return;
|
2008-03-08 07:46:30 +00:00
|
|
|
Bmemset(&music,0,sizeof(sounddef1));
|
2008-03-08 19:45:48 +00:00
|
|
|
switch (*ptr)
|
2008-03-08 07:46:30 +00:00
|
|
|
{
|
2008-03-09 08:14:12 +00:00
|
|
|
case 'O':
|
|
|
|
music.type=1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2008-03-08 07:46:30 +00:00
|
|
|
}
|
|
|
|
music.def.size=Musicsize;
|
|
|
|
music.loop=loop;
|
|
|
|
music.def.ptrsnd=ptr;
|
|
|
|
|
2008-03-08 19:45:48 +00:00
|
|
|
switch (music.type)
|
2008-03-08 07:46:30 +00:00
|
|
|
{
|
2008-03-08 19:45:48 +00:00
|
|
|
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;
|
2008-03-09 08:14:12 +00:00
|
|
|
music.format=(vorbisInfo->channels==1)?AL_FORMAT_MONO16:AL_FORMAT_STEREO16;
|
|
|
|
break;
|
2008-03-08 07:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ALdoing="Open";
|
|
|
|
balGenBuffers(2, music.buffers);check(1);
|
|
|
|
balGenSources(1,&music.source);check(1);
|
|
|
|
balSourcei(music.source,AL_SOURCE_RELATIVE,AL_TRUE);
|
|
|
|
|
2008-03-08 19:45:48 +00:00
|
|
|
switch (music.type)
|
2008-03-08 07:46:30 +00:00
|
|
|
{
|
2008-03-09 08:14:12 +00:00
|
|
|
case 1:
|
|
|
|
stream(music.buffers[0]);
|
|
|
|
if (!stream(music.buffers[1]))
|
|
|
|
bf=1;
|
2008-03-08 19:45:48 +00:00
|
|
|
balSourceQueueBuffers(music.source,bf,music.buffers);
|
|
|
|
break;
|
2008-03-08 07:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AL_SetMusicVolume(AL_MusicVolume);
|
|
|
|
AL_Continue();
|
|
|
|
}
|