Add OpenAL-Soft 1.15.1.

This commit is contained in:
rude
2013-09-25 20:36:51 +02:00
parent 4c59d385ef
commit 00c0af3b7c
85 changed files with 43429 additions and 0 deletions
@@ -0,0 +1,61 @@
#ifndef _AL_AUXEFFECTSLOT_H_
#define _AL_AUXEFFECTSLOT_H_
#include "alMain.h"
#include "alEffect.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ALeffectState {
ALvoid (*Destroy)(struct ALeffectState *State);
ALboolean (*DeviceUpdate)(struct ALeffectState *State, ALCdevice *Device);
ALvoid (*Update)(struct ALeffectState *State, ALCdevice *Device, const struct ALeffectslot *Slot);
ALvoid (*Process)(struct ALeffectState *State, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]);
} ALeffectState;
typedef struct ALeffectslot
{
ALeffect effect;
volatile ALfloat Gain;
volatile ALboolean AuxSendAuto;
volatile ALenum NeedsUpdate;
ALeffectState *EffectState;
ALIGN(16) ALfloat WetBuffer[1][BUFFERSIZE];
ALfloat ClickRemoval[1];
ALfloat PendingClicks[1];
RefCount ref;
/* Self ID */
ALuint id;
} ALeffectslot;
ALenum InitEffectSlot(ALeffectslot *slot);
ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context);
ALeffectState *NoneCreate(void);
ALeffectState *ReverbCreate(void);
ALeffectState *EchoCreate(void);
ALeffectState *ModulatorCreate(void);
ALeffectState *DedicatedCreate(void);
#define ALeffectState_Destroy(a) ((a)->Destroy((a)))
#define ALeffectState_DeviceUpdate(a,b) ((a)->DeviceUpdate((a),(b)))
#define ALeffectState_Update(a,b,c) ((a)->Update((a),(b),(c)))
#define ALeffectState_Process(a,b,c,d) ((a)->Process((a),(b),(c),(d)))
ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,102 @@
#ifndef _AL_BUFFER_H_
#define _AL_BUFFER_H_
#include "alMain.h"
#ifdef __cplusplus
extern "C" {
#endif
/* User formats */
enum UserFmtType {
UserFmtByte = AL_BYTE_SOFT,
UserFmtUByte = AL_UNSIGNED_BYTE_SOFT,
UserFmtShort = AL_SHORT_SOFT,
UserFmtUShort = AL_UNSIGNED_SHORT_SOFT,
UserFmtInt = AL_INT_SOFT,
UserFmtUInt = AL_UNSIGNED_INT_SOFT,
UserFmtFloat = AL_FLOAT_SOFT,
UserFmtDouble = AL_DOUBLE_SOFT,
UserFmtByte3 = AL_BYTE3_SOFT,
UserFmtUByte3 = AL_UNSIGNED_BYTE3_SOFT,
UserFmtMulaw,
UserFmtAlaw,
UserFmtIMA4,
};
enum UserFmtChannels {
UserFmtMono = AL_MONO_SOFT,
UserFmtStereo = AL_STEREO_SOFT,
UserFmtRear = AL_REAR_SOFT,
UserFmtQuad = AL_QUAD_SOFT,
UserFmtX51 = AL_5POINT1_SOFT, /* (WFX order) */
UserFmtX61 = AL_6POINT1_SOFT, /* (WFX order) */
UserFmtX71 = AL_7POINT1_SOFT, /* (WFX order) */
};
ALuint BytesFromUserFmt(enum UserFmtType type);
ALuint ChannelsFromUserFmt(enum UserFmtChannels chans);
static __inline ALuint FrameSizeFromUserFmt(enum UserFmtChannels chans,
enum UserFmtType type)
{
return ChannelsFromUserFmt(chans) * BytesFromUserFmt(type);
}
/* Storable formats */
enum FmtType {
FmtByte = UserFmtByte,
FmtShort = UserFmtShort,
FmtFloat = UserFmtFloat,
};
enum FmtChannels {
FmtMono = UserFmtMono,
FmtStereo = UserFmtStereo,
FmtRear = UserFmtRear,
FmtQuad = UserFmtQuad,
FmtX51 = UserFmtX51,
FmtX61 = UserFmtX61,
FmtX71 = UserFmtX71,
};
ALuint BytesFromFmt(enum FmtType type);
ALuint ChannelsFromFmt(enum FmtChannels chans);
static __inline ALuint FrameSizeFromFmt(enum FmtChannels chans, enum FmtType type)
{
return ChannelsFromFmt(chans) * BytesFromFmt(type);
}
typedef struct ALbuffer
{
ALvoid *data;
ALsizei Frequency;
ALenum Format;
ALsizei SampleLen;
enum FmtChannels FmtChannels;
enum FmtType FmtType;
enum UserFmtChannels OriginalChannels;
enum UserFmtType OriginalType;
ALsizei OriginalSize;
ALsizei LoopStart;
ALsizei LoopEnd;
/* Number of times buffer was attached to a source (deletion can only occur when 0) */
RefCount ref;
RWLock lock;
/* Self ID */
ALuint id;
} ALbuffer;
ALvoid ReleaseALBuffers(ALCdevice *device);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,114 @@
#ifndef _AL_EFFECT_H_
#define _AL_EFFECT_H_
#include "alMain.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
EAXREVERB = 0,
REVERB,
ECHO,
MODULATOR,
DEDICATED,
MAX_EFFECTS
};
extern ALboolean DisabledEffects[MAX_EFFECTS];
extern ALfloat ReverbBoost;
extern ALboolean EmulateEAXReverb;
typedef struct ALeffect
{
// Effect type (AL_EFFECT_NULL, ...)
ALenum type;
struct {
// Shared Reverb Properties
ALfloat Density;
ALfloat Diffusion;
ALfloat Gain;
ALfloat GainHF;
ALfloat DecayTime;
ALfloat DecayHFRatio;
ALfloat ReflectionsGain;
ALfloat ReflectionsDelay;
ALfloat LateReverbGain;
ALfloat LateReverbDelay;
ALfloat AirAbsorptionGainHF;
ALfloat RoomRolloffFactor;
ALboolean DecayHFLimit;
// Additional EAX Reverb Properties
ALfloat GainLF;
ALfloat DecayLFRatio;
ALfloat ReflectionsPan[3];
ALfloat LateReverbPan[3];
ALfloat EchoTime;
ALfloat EchoDepth;
ALfloat ModulationTime;
ALfloat ModulationDepth;
ALfloat HFReference;
ALfloat LFReference;
} Reverb;
struct {
ALfloat Delay;
ALfloat LRDelay;
ALfloat Damping;
ALfloat Feedback;
ALfloat Spread;
} Echo;
struct {
ALfloat Frequency;
ALfloat HighPassCutoff;
ALint Waveform;
} Modulator;
struct {
ALfloat Gain;
} Dedicated;
void (*SetParami)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALint val);
void (*SetParamiv)(struct ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals);
void (*SetParamf)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val);
void (*SetParamfv)(struct ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals);
void (*GetParami)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALint *val);
void (*GetParamiv)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals);
void (*GetParamf)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val);
void (*GetParamfv)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals);
/* Self ID */
ALuint id;
} ALeffect;
#define ALeffect_SetParami(x, c, p, v) ((x)->SetParami((x),(c),(p),(v)))
#define ALeffect_SetParamiv(x, c, p, v) ((x)->SetParamiv((x),(c),(p),(v)))
#define ALeffect_SetParamf(x, c, p, v) ((x)->SetParamf((x),(c),(p),(v)))
#define ALeffect_SetParamfv(x, c, p, v) ((x)->SetParamfv((x),(c),(p),(v)))
#define ALeffect_GetParami(x, c, p, v) ((x)->GetParami((x),(c),(p),(v)))
#define ALeffect_GetParamiv(x, c, p, v) ((x)->GetParamiv((x),(c),(p),(v)))
#define ALeffect_GetParamf(x, c, p, v) ((x)->GetParamf((x),(c),(p),(v)))
#define ALeffect_GetParamfv(x, c, p, v) ((x)->GetParamfv((x),(c),(p),(v)))
static __inline ALboolean IsReverbEffect(ALenum type)
{ return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; }
ALenum InitEffect(ALeffect *effect);
ALvoid ReleaseALEffects(ALCdevice *device);
ALvoid LoadReverbPreset(const char *name, ALeffect *effect);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,18 @@
#ifndef _AL_ERROR_H_
#define _AL_ERROR_H_
#include "alMain.h"
#ifdef __cplusplus
extern "C" {
#endif
extern ALboolean TrapALError;
ALvoid alSetError(ALCcontext *Context, ALenum errorCode);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,90 @@
#ifndef _AL_FILTER_H_
#define _AL_FILTER_H_
#include "alMain.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LOWPASSFREQREF (5000)
typedef struct {
ALfloat coeff;
#ifndef _MSC_VER
ALfloat history[0];
#else
ALfloat history[1];
#endif
} FILTER;
static __inline ALfloat lpFilter2P(FILTER *iir, ALuint offset, ALfloat input)
{
ALfloat *history = &iir->history[offset*2];
ALfloat a = iir->coeff;
ALfloat output = input;
output = output + (history[0]-output)*a;
history[0] = output;
output = output + (history[1]-output)*a;
history[1] = output;
return output;
}
static __inline ALfloat lpFilter2PC(const FILTER *iir, ALuint offset, ALfloat input)
{
const ALfloat *history = &iir->history[offset*2];
ALfloat a = iir->coeff;
ALfloat output = input;
output = output + (history[0]-output)*a;
output = output + (history[1]-output)*a;
return output;
}
/* Calculates the low-pass filter coefficient given the pre-scaled gain and
* cos(w) value. Note that g should be pre-scaled (sqr(gain) for one-pole,
* sqrt(gain) for four-pole, etc) */
ALfloat lpCoeffCalc(ALfloat g, ALfloat cw);
typedef struct ALfilter {
// Filter type (AL_FILTER_NULL, ...)
ALenum type;
ALfloat Gain;
ALfloat GainHF;
void (*SetParami)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALint val);
void (*SetParamiv)(struct ALfilter *filter, ALCcontext *context, ALenum param, const ALint *vals);
void (*SetParamf)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val);
void (*SetParamfv)(struct ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals);
void (*GetParami)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALint *val);
void (*GetParamiv)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALint *vals);
void (*GetParamf)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val);
void (*GetParamfv)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals);
/* Self ID */
ALuint id;
} ALfilter;
#define ALfilter_SetParami(x, c, p, v) ((x)->SetParami((x),(c),(p),(v)))
#define ALfilter_SetParamiv(x, c, p, v) ((x)->SetParamiv((x),(c),(p),(v)))
#define ALfilter_SetParamf(x, c, p, v) ((x)->SetParamf((x),(c),(p),(v)))
#define ALfilter_SetParamfv(x, c, p, v) ((x)->SetParamfv((x),(c),(p),(v)))
#define ALfilter_GetParami(x, c, p, v) ((x)->GetParami((x),(c),(p),(v)))
#define ALfilter_GetParamiv(x, c, p, v) ((x)->GetParamiv((x),(c),(p),(v)))
#define ALfilter_GetParamf(x, c, p, v) ((x)->GetParamf((x),(c),(p),(v)))
#define ALfilter_GetParamfv(x, c, p, v) ((x)->GetParamfv((x),(c),(p),(v)))
ALvoid ReleaseALFilters(ALCdevice *device);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,28 @@
#ifndef _AL_LISTENER_H_
#define _AL_LISTENER_H_
#include "alMain.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ALlistener {
volatile ALfloat Position[3];
volatile ALfloat Velocity[3];
volatile ALfloat Forward[3];
volatile ALfloat Up[3];
volatile ALfloat Gain;
volatile ALfloat MetersPerUnit;
struct {
ALfloat Matrix[4][4];
ALfloat Velocity[3];
} Params;
} ALlistener;
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,884 @@
#ifndef AL_MAIN_H
#define AL_MAIN_H
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
#include <math.h>
#ifdef HAVE_FENV_H
#include <fenv.h>
#endif
#include "AL/al.h"
#include "AL/alc.h"
#include "AL/alext.h"
#ifndef AL_SOFT_deferred_updates
#define AL_SOFT_deferred_updates 1
#define AL_DEFERRED_UPDATES_SOFT 0xC002
typedef ALvoid (AL_APIENTRY*LPALDEFERUPDATESSOFT)(void);
typedef ALvoid (AL_APIENTRY*LPALPROCESSUPDATESSOFT)(void);
#ifdef AL_ALEXT_PROTOTYPES
AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void);
AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void);
#endif
#endif
#if defined(HAVE_STDINT_H)
#include <stdint.h>
typedef int64_t ALint64;
typedef uint64_t ALuint64;
#elif defined(HAVE___INT64)
typedef __int64 ALint64;
typedef unsigned __int64 ALuint64;
#elif (SIZEOF_LONG == 8)
typedef long ALint64;
typedef unsigned long ALuint64;
#elif (SIZEOF_LONG_LONG == 8)
typedef long long ALint64;
typedef unsigned long long ALuint64;
#endif
typedef ptrdiff_t ALintptrEXT;
typedef ptrdiff_t ALsizeiptrEXT;
#define MAKEU64(x,y) (((ALuint64)(x)<<32)|(ALuint64)(y))
#ifdef HAVE_GCC_FORMAT
#define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
#else
#define PRINTF_STYLE(x, y)
#endif
static const union {
ALuint u;
ALubyte b[sizeof(ALuint)];
} EndianTest = { 1 };
#define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
#define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
typedef DWORD pthread_key_t;
int pthread_key_create(pthread_key_t *key, void (*callback)(void*));
int pthread_key_delete(pthread_key_t key);
void *pthread_getspecific(pthread_key_t key);
int pthread_setspecific(pthread_key_t key, void *val);
#define HAVE_DYNLOAD 1
void *LoadLib(const char *name);
void CloseLib(void *handle);
void *GetSymbol(void *handle, const char *name);
WCHAR *strdupW(const WCHAR *str);
typedef LONG pthread_once_t;
#define PTHREAD_ONCE_INIT 0
void pthread_once(pthread_once_t *once, void (*callback)(void));
static __inline int sched_yield(void)
{ SwitchToThread(); return 0; }
#else
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <sys/time.h>
#include <time.h>
#include <errno.h>
#define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
typedef pthread_mutex_t CRITICAL_SECTION;
void InitializeCriticalSection(CRITICAL_SECTION *cs);
void DeleteCriticalSection(CRITICAL_SECTION *cs);
void EnterCriticalSection(CRITICAL_SECTION *cs);
void LeaveCriticalSection(CRITICAL_SECTION *cs);
ALuint timeGetTime(void);
void Sleep(ALuint t);
#if defined(HAVE_DLFCN_H)
#define HAVE_DYNLOAD 1
void *LoadLib(const char *name);
void CloseLib(void *handle);
void *GetSymbol(void *handle, const char *name);
#endif
#endif
typedef void *volatile XchgPtr;
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
typedef ALuint RefCount;
static __inline RefCount IncrementRef(volatile RefCount *ptr)
{ return __sync_add_and_fetch(ptr, 1); }
static __inline RefCount DecrementRef(volatile RefCount *ptr)
{ return __sync_sub_and_fetch(ptr, 1); }
static __inline int ExchangeInt(volatile int *ptr, int newval)
{
return __sync_lock_test_and_set(ptr, newval);
}
static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
{
return __sync_lock_test_and_set(ptr, newval);
}
static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
{
return __sync_bool_compare_and_swap(ptr, oldval, newval);
}
static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
{
return __sync_bool_compare_and_swap(ptr, oldval, newval);
}
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
static __inline int xaddl(volatile int *dest, int incr)
{
int ret;
__asm__ __volatile__("lock; xaddl %0,(%1)"
: "=r" (ret)
: "r" (dest), "0" (incr)
: "memory");
return ret;
}
typedef int RefCount;
static __inline RefCount IncrementRef(volatile RefCount *ptr)
{ return xaddl(ptr, 1)+1; }
static __inline RefCount DecrementRef(volatile RefCount *ptr)
{ return xaddl(ptr, -1)-1; }
static __inline int ExchangeInt(volatile int *dest, int newval)
{
int ret;
__asm__ __volatile__("lock; xchgl %0,(%1)"
: "=r" (ret)
: "r" (dest), "0" (newval)
: "memory");
return ret;
}
static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
{
int ret;
__asm__ __volatile__("lock; cmpxchgl %2,(%1)"
: "=a" (ret)
: "r" (dest), "r" (newval), "0" (oldval)
: "memory");
return ret == oldval;
}
static __inline void *ExchangePtr(XchgPtr *dest, void *newval)
{
void *ret;
__asm__ __volatile__(
#ifdef __i386__
"lock; xchgl %0,(%1)"
#else
"lock; xchgq %0,(%1)"
#endif
: "=r" (ret)
: "r" (dest), "0" (newval)
: "memory"
);
return ret;
}
static __inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
{
void *ret;
__asm__ __volatile__(
#ifdef __i386__
"lock; cmpxchgl %2,(%1)"
#else
"lock; cmpxchgq %2,(%1)"
#endif
: "=a" (ret)
: "r" (dest), "r" (newval), "0" (oldval)
: "memory"
);
return ret == oldval;
}
#elif defined(_WIN32)
typedef LONG RefCount;
static __inline RefCount IncrementRef(volatile RefCount *ptr)
{ return InterlockedIncrement(ptr); }
static __inline RefCount DecrementRef(volatile RefCount *ptr)
{ return InterlockedDecrement(ptr); }
extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
static __inline int ExchangeInt(volatile int *ptr, int newval)
{
union {
volatile int *i;
volatile LONG *l;
} u = { ptr };
return InterlockedExchange(u.l, newval);
}
static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
{
return InterlockedExchangePointer(ptr, newval);
}
static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
{
union {
volatile int *i;
volatile LONG *l;
} u = { ptr };
return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
}
static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
{
return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
}
#elif defined(__APPLE__)
#include <libkern/OSAtomic.h>
typedef int32_t RefCount;
static __inline RefCount IncrementRef(volatile RefCount *ptr)
{ return OSAtomicIncrement32Barrier(ptr); }
static __inline RefCount DecrementRef(volatile RefCount *ptr)
{ return OSAtomicDecrement32Barrier(ptr); }
static __inline int ExchangeInt(volatile int *ptr, int newval)
{
/* Really? No regular old atomic swap? */
int oldval;
do {
oldval = *ptr;
} while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
return oldval;
}
static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
{
void *oldval;
do {
oldval = *ptr;
} while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
return oldval;
}
static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
{
return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
}
static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
{
return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
}
#else
#error "No atomic functions available on this platform!"
typedef ALuint RefCount;
#endif
typedef struct {
volatile RefCount read_count;
volatile RefCount write_count;
volatile ALenum read_lock;
volatile ALenum read_entry_lock;
volatile ALenum write_lock;
} RWLock;
void RWLockInit(RWLock *lock);
void ReadLock(RWLock *lock);
void ReadUnlock(RWLock *lock);
void WriteLock(RWLock *lock);
void WriteUnlock(RWLock *lock);
typedef struct UIntMap {
struct {
ALuint key;
ALvoid *value;
} *array;
ALsizei size;
ALsizei maxsize;
ALsizei limit;
RWLock lock;
} UIntMap;
extern UIntMap TlsDestructor;
void InitUIntMap(UIntMap *map, ALsizei limit);
void ResetUIntMap(UIntMap *map);
ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
static __inline void LockUIntMapRead(UIntMap *map)
{ ReadLock(&map->lock); }
static __inline void UnlockUIntMapRead(UIntMap *map)
{ ReadUnlock(&map->lock); }
static __inline void LockUIntMapWrite(UIntMap *map)
{ WriteLock(&map->lock); }
static __inline void UnlockUIntMapWrite(UIntMap *map)
{ WriteUnlock(&map->lock); }
#ifdef __cplusplus
extern "C" {
#endif
struct Hrtf;
#define DEFAULT_OUTPUT_RATE (44100)
#define MIN_OUTPUT_RATE (8000)
// Find the next power-of-2 for non-power-of-2 numbers.
static __inline ALuint NextPowerOf2(ALuint value)
{
if(value > 0)
{
value--;
value |= value>>1;
value |= value>>2;
value |= value>>4;
value |= value>>8;
value |= value>>16;
}
return value+1;
}
/* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
* mode. */
static __inline ALint fastf2i(ALfloat f)
{
#ifdef HAVE_LRINTF
return lrintf(f);
#elif defined(_MSC_VER) && defined(_M_IX86)
ALint i;
__asm fld f
__asm fistp i
return i;
#else
return (ALint)f;
#endif
}
/* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
* mode. */
static __inline ALuint fastf2u(ALfloat f)
{ return fastf2i(f); }
enum DevProbe {
ALL_DEVICE_PROBE,
CAPTURE_DEVICE_PROBE
};
typedef struct {
ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
void (*ClosePlayback)(ALCdevice*);
ALCboolean (*ResetPlayback)(ALCdevice*);
ALCboolean (*StartPlayback)(ALCdevice*);
void (*StopPlayback)(ALCdevice*);
ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
void (*CloseCapture)(ALCdevice*);
void (*StartCapture)(ALCdevice*);
void (*StopCapture)(ALCdevice*);
ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
ALCuint (*AvailableSamples)(ALCdevice*);
void (*Lock)(ALCdevice*);
void (*Unlock)(ALCdevice*);
ALint64 (*GetLatency)(ALCdevice*);
} BackendFuncs;
struct BackendInfo {
const char *name;
ALCboolean (*Init)(BackendFuncs*);
void (*Deinit)(void);
void (*Probe)(enum DevProbe);
BackendFuncs Funcs;
};
ALCboolean alc_alsa_init(BackendFuncs *func_list);
void alc_alsa_deinit(void);
void alc_alsa_probe(enum DevProbe type);
ALCboolean alc_oss_init(BackendFuncs *func_list);
void alc_oss_deinit(void);
void alc_oss_probe(enum DevProbe type);
ALCboolean alc_solaris_init(BackendFuncs *func_list);
void alc_solaris_deinit(void);
void alc_solaris_probe(enum DevProbe type);
ALCboolean alc_sndio_init(BackendFuncs *func_list);
void alc_sndio_deinit(void);
void alc_sndio_probe(enum DevProbe type);
ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
void alcMMDevApiDeinit(void);
void alcMMDevApiProbe(enum DevProbe type);
ALCboolean alcDSoundInit(BackendFuncs *func_list);
void alcDSoundDeinit(void);
void alcDSoundProbe(enum DevProbe type);
ALCboolean alcWinMMInit(BackendFuncs *FuncList);
void alcWinMMDeinit(void);
void alcWinMMProbe(enum DevProbe type);
ALCboolean alc_pa_init(BackendFuncs *func_list);
void alc_pa_deinit(void);
void alc_pa_probe(enum DevProbe type);
ALCboolean alc_wave_init(BackendFuncs *func_list);
void alc_wave_deinit(void);
void alc_wave_probe(enum DevProbe type);
ALCboolean alc_pulse_init(BackendFuncs *func_list);
void alc_pulse_deinit(void);
void alc_pulse_probe(enum DevProbe type);
ALCboolean alc_ca_init(BackendFuncs *func_list);
void alc_ca_deinit(void);
void alc_ca_probe(enum DevProbe type);
ALCboolean alc_opensl_init(BackendFuncs *func_list);
void alc_opensl_deinit(void);
void alc_opensl_probe(enum DevProbe type);
ALCboolean alc_null_init(BackendFuncs *func_list);
void alc_null_deinit(void);
void alc_null_probe(enum DevProbe type);
ALCboolean alc_loopback_init(BackendFuncs *func_list);
void alc_loopback_deinit(void);
void alc_loopback_probe(enum DevProbe type);
enum DistanceModel {
InverseDistanceClamped = AL_INVERSE_DISTANCE_CLAMPED,
LinearDistanceClamped = AL_LINEAR_DISTANCE_CLAMPED,
ExponentDistanceClamped = AL_EXPONENT_DISTANCE_CLAMPED,
InverseDistance = AL_INVERSE_DISTANCE,
LinearDistance = AL_LINEAR_DISTANCE,
ExponentDistance = AL_EXPONENT_DISTANCE,
DisableDistance = AL_NONE,
DefaultDistanceModel = InverseDistanceClamped
};
enum Resampler {
PointResampler,
LinearResampler,
CubicResampler,
ResamplerMax,
};
enum Channel {
FrontLeft = 0,
FrontRight,
FrontCenter,
LFE,
BackLeft,
BackRight,
BackCenter,
SideLeft,
SideRight,
MaxChannels,
};
/* Device formats */
enum DevFmtType {
DevFmtByte = ALC_BYTE_SOFT,
DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
DevFmtShort = ALC_SHORT_SOFT,
DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
DevFmtInt = ALC_INT_SOFT,
DevFmtUInt = ALC_UNSIGNED_INT_SOFT,
DevFmtFloat = ALC_FLOAT_SOFT,
DevFmtTypeDefault = DevFmtFloat
};
enum DevFmtChannels {
DevFmtMono = ALC_MONO_SOFT,
DevFmtStereo = ALC_STEREO_SOFT,
DevFmtQuad = ALC_QUAD_SOFT,
DevFmtX51 = ALC_5POINT1_SOFT,
DevFmtX61 = ALC_6POINT1_SOFT,
DevFmtX71 = ALC_7POINT1_SOFT,
/* Similar to 5.1, except using the side channels instead of back */
DevFmtX51Side = 0x80000000,
DevFmtChannelsDefault = DevFmtStereo
};
ALuint BytesFromDevFmt(enum DevFmtType type);
ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
enum DevFmtType type)
{
return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
}
extern const struct EffectList {
const char *name;
int type;
const char *ename;
ALenum val;
} EffectList[];
enum DeviceType {
Playback,
Capture,
Loopback
};
/* Size for temporary storage of buffer data, in ALfloats. Larger values need
* more memory, while smaller values may need more iterations. The value needs
* to be a sensible size, however, as it constrains the max stepping value used
* for mixing, as well as the maximum number of samples per mixing iteration.
*
* The mixer requires being able to do two samplings per mixing loop. With the
* cubic resampler (which requires 3 padding samples), this limits a 2048
* buffer size to about 2044. This means that buffer_freq*source_pitch cannot
* exceed device_freq*2044 for a 32-bit buffer.
*/
#ifndef BUFFERSIZE
#define BUFFERSIZE 2048
#endif
struct ALCdevice_struct
{
volatile RefCount ref;
ALCboolean Connected;
enum DeviceType Type;
CRITICAL_SECTION Mutex;
ALuint Frequency;
ALuint UpdateSize;
ALuint NumUpdates;
enum DevFmtChannels FmtChans;
enum DevFmtType FmtType;
ALCchar *DeviceName;
volatile ALCenum LastError;
// Maximum number of sources that can be created
ALuint MaxNoOfSources;
// Maximum number of slots that can be created
ALuint AuxiliaryEffectSlotMax;
ALCuint NumMonoSources;
ALCuint NumStereoSources;
ALuint NumAuxSends;
// Map of Buffers for this device
UIntMap BufferMap;
// Map of Effects for this device
UIntMap EffectMap;
// Map of Filters for this device
UIntMap FilterMap;
/* HRTF filter tables */
const struct Hrtf *Hrtf;
// Stereo-to-binaural filter
struct bs2b *Bs2b;
ALCint Bs2bLevel;
// Device flags
ALuint Flags;
ALuint ChannelOffsets[MaxChannels];
enum Channel Speaker2Chan[MaxChannels];
ALfloat SpeakerAngle[MaxChannels];
ALuint NumChan;
/* Temp storage used for mixing. +1 for the predictive sample. */
ALIGN(16) ALfloat SampleData1[BUFFERSIZE+1];
ALIGN(16) ALfloat SampleData2[BUFFERSIZE+1];
// Dry path buffer mix
ALIGN(16) ALfloat DryBuffer[MaxChannels][BUFFERSIZE];
ALIGN(16) ALfloat ClickRemoval[MaxChannels];
ALIGN(16) ALfloat PendingClicks[MaxChannels];
/* Default effect slot */
struct ALeffectslot *DefaultSlot;
// Contexts created on this device
ALCcontext *volatile ContextList;
BackendFuncs *Funcs;
void *ExtraData; // For the backend's use
ALCdevice *volatile next;
};
#define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
#define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
#define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
#define ALCdevice_StartPlayback(a) ((a)->Funcs->StartPlayback((a)))
#define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
#define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
#define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
#define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
#define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
#define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
#define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
#define ALCdevice_Lock(a) ((a)->Funcs->Lock((a)))
#define ALCdevice_Unlock(a) ((a)->Funcs->Unlock((a)))
#define ALCdevice_GetLatency(a) ((a)->Funcs->GetLatency((a)))
// Frequency was requested by the app or config file
#define DEVICE_FREQUENCY_REQUEST (1<<1)
// Channel configuration was requested by the config file
#define DEVICE_CHANNELS_REQUEST (1<<2)
// Sample type was requested by the config file
#define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
// Stereo sources cover 120-degree angles around +/-90
#define DEVICE_WIDE_STEREO (1<<16)
// Specifies if the device is currently running
#define DEVICE_RUNNING (1<<31)
/* Invalid channel offset */
#define INVALID_OFFSET (~0u)
#define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
#define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
#define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
#define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
#define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
#define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
struct ALCcontext_struct
{
volatile RefCount ref;
struct ALlistener *Listener;
UIntMap SourceMap;
UIntMap EffectSlotMap;
ALenum LastError;
volatile ALenum UpdateSources;
volatile enum DistanceModel DistanceModel;
volatile ALboolean SourceDistanceModel;
volatile ALfloat DopplerFactor;
volatile ALfloat DopplerVelocity;
volatile ALfloat SpeedOfSound;
volatile ALenum DeferUpdates;
struct ALsource **ActiveSources;
ALsizei ActiveSourceCount;
ALsizei MaxActiveSources;
struct ALeffectslot **ActiveEffectSlots;
ALsizei ActiveEffectSlotCount;
ALsizei MaxActiveEffectSlots;
ALCdevice *Device;
const ALCchar *ExtensionList;
ALCcontext *volatile next;
};
#define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
#define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
#define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
#define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
ALCcontext *GetContextRef(void);
void ALCcontext_IncRef(ALCcontext *context);
void ALCcontext_DecRef(ALCcontext *context);
void AppendAllDevicesList(const ALCchar *name);
void AppendCaptureDeviceList(const ALCchar *name);
void ALCdevice_LockDefault(ALCdevice *device);
void ALCdevice_UnlockDefault(ALCdevice *device);
ALint64 ALCdevice_GetLatencyDefault(ALCdevice *device);
static __inline void LockContext(ALCcontext *context)
{ ALCdevice_Lock(context->Device); }
static __inline void UnlockContext(ALCcontext *context)
{ ALCdevice_Unlock(context->Device); }
void *al_malloc(size_t alignment, size_t size);
void *al_calloc(size_t alignment, size_t size);
void al_free(void *ptr);
typedef struct {
int state;
#ifdef HAVE_SSE
int sse_state;
#endif
} FPUCtl;
void SetMixerFPUMode(FPUCtl *ctl);
void RestoreFPUMode(const FPUCtl *ctl);
ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
ALuint StopThread(ALvoid *thread);
typedef struct RingBuffer RingBuffer;
RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
void DestroyRingBuffer(RingBuffer *ring);
ALsizei RingBufferSize(RingBuffer *ring);
void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
void ReadALConfig(void);
void FreeALConfig(void);
int ConfigValueExists(const char *blockName, const char *keyName);
const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
int GetConfigValueBool(const char *blockName, const char *keyName, int def);
int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
void SetRTPriority(void);
void SetDefaultChannelOrder(ALCdevice *device);
void SetDefaultWFXChannelOrder(ALCdevice *device);
const ALCchar *DevFmtTypeString(enum DevFmtType type);
const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
#define HRIR_BITS (7)
#define HRIR_LENGTH (1<<HRIR_BITS)
#define HRIR_MASK (HRIR_LENGTH-1)
#define HRTFDELAY_BITS (20)
#define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
#define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1)
const struct Hrtf *GetHrtf(ALCdevice *device);
void FreeHrtfs(void);
ALuint GetHrtfIrSize (const struct Hrtf *Hrtf);
ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
ALuint GetMovingHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat delta, ALint counter, ALfloat (*coeffs)[2], ALuint *delays, ALfloat (*coeffStep)[2], ALint *delayStep);
void al_print(const char *type, const char *func, const char *fmt, ...) PRINTF_STYLE(3,4);
#define AL_PRINT(T, ...) al_print((T), __FUNCTION__, __VA_ARGS__)
extern FILE *LogFile;
enum LogLevel {
NoLog,
LogError,
LogWarning,
LogTrace,
LogRef
};
extern enum LogLevel LogLevel;
#define TRACEREF(...) do { \
if(LogLevel >= LogRef) \
AL_PRINT("(--)", __VA_ARGS__); \
} while(0)
#define TRACE(...) do { \
if(LogLevel >= LogTrace) \
AL_PRINT("(II)", __VA_ARGS__); \
} while(0)
#define WARN(...) do { \
if(LogLevel >= LogWarning) \
AL_PRINT("(WW)", __VA_ARGS__); \
} while(0)
#define ERR(...) do { \
if(LogLevel >= LogError) \
AL_PRINT("(EE)", __VA_ARGS__); \
} while(0)
extern ALint RTPrioLevel;
extern ALuint CPUCapFlags;
enum {
CPU_CAP_SSE = 1<<0,
CPU_CAP_NEON = 1<<1,
};
void FillCPUCaps(ALuint capfilter);
/**
* Starts a try block. Must not be nested within another try block within the
* same function.
*/
#define al_try do { \
int _al_err=0; \
_al_try_label: \
if(_al_err == 0)
/**
* After a try or another catch block, runs the next block if the given value
* was thrown.
*/
#define al_catch(val) else if(_al_err == (val))
/**
* After a try or catch block, runs the next block for any value thrown and not
* caught.
*/
#define al_catchany() else
/** Marks the end of the final catch (or the try) block. */
#define al_endtry } while(0)
/**
* The given integer value is "thrown" so as to be caught by a catch block.
* Must be called in a try block within the same function. The value must not
* be 0.
*/
#define al_throw(e) do { \
_al_err = (e); \
assert(_al_err != 0); \
goto _al_try_label; \
} while(0)
/** Sets an AL error on the given context, before throwing the error code. */
#define al_throwerr(ctx, err) do { \
alSetError((ctx), (err)); \
al_throw((err)); \
} while(0)
/**
* Throws an AL_INVALID_VALUE error with the given ctx if the given condition
* is false.
*/
#define CHECK_VALUE(ctx, cond) do { \
if(!(cond)) \
al_throwerr((ctx), AL_INVALID_VALUE); \
} while(0)
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,190 @@
#ifndef _AL_SOURCE_H_
#define _AL_SOURCE_H_
#define MAX_SENDS 4
#include "alMain.h"
#include "alu.h"
#include "alFilter.h"
#ifdef __cplusplus
extern "C" {
#endif
#define SRC_HISTORY_BITS (6)
#define SRC_HISTORY_LENGTH (1<<SRC_HISTORY_BITS)
#define SRC_HISTORY_MASK (SRC_HISTORY_LENGTH-1)
extern enum Resampler DefaultResampler;
extern const ALsizei ResamplerPadding[ResamplerMax];
extern const ALsizei ResamplerPrePadding[ResamplerMax];
typedef struct ALbufferlistitem
{
struct ALbuffer *buffer;
struct ALbufferlistitem *next;
struct ALbufferlistitem *prev;
} ALbufferlistitem;
typedef struct HrtfState {
ALboolean Moving;
ALuint Counter;
ALIGN(16) ALfloat History[MaxChannels][SRC_HISTORY_LENGTH];
ALIGN(16) ALfloat Values[MaxChannels][HRIR_LENGTH][2];
ALuint Offset;
} HrtfState;
typedef struct HrtfParams {
ALfloat Gain;
ALfloat Dir[3];
ALIGN(16) ALfloat Coeffs[MaxChannels][HRIR_LENGTH][2];
ALIGN(16) ALfloat CoeffStep[HRIR_LENGTH][2];
ALuint Delay[MaxChannels][2];
ALint DelayStep[2];
ALuint IrSize;
} HrtfParams;
typedef struct DirectParams {
ALfloat (*OutBuffer)[BUFFERSIZE];
ALfloat *ClickRemoval;
ALfloat *PendingClicks;
struct {
HrtfParams Params;
HrtfState *State;
} Hrtf;
/* A mixing matrix. First subscript is the channel number of the input data
* (regardless of channel configuration) and the second is the channel
* target (eg. FrontLeft). Not used with HRTF. */
ALfloat Gains[MaxChannels][MaxChannels];
/* A low-pass filter, using 2 chained one-pole filters. */
FILTER iirFilter;
ALfloat history[MaxChannels*2];
} DirectParams;
typedef struct SendParams {
struct ALeffectslot *Slot;
/* Gain control, which applies to all input channels to a single (mono)
* output buffer. */
ALfloat Gain;
/* A low-pass filter, using 2 chained one-pole filters. */
FILTER iirFilter;
ALfloat history[MaxChannels*2];
} SendParams;
typedef struct ALsource
{
/** Source properties. */
volatile ALfloat Pitch;
volatile ALfloat Gain;
volatile ALfloat OuterGain;
volatile ALfloat MinGain;
volatile ALfloat MaxGain;
volatile ALfloat InnerAngle;
volatile ALfloat OuterAngle;
volatile ALfloat RefDistance;
volatile ALfloat MaxDistance;
volatile ALfloat RollOffFactor;
volatile ALfloat Position[3];
volatile ALfloat Velocity[3];
volatile ALfloat Orientation[3];
volatile ALboolean HeadRelative;
volatile ALboolean Looping;
volatile enum DistanceModel DistanceModel;
volatile ALboolean DirectChannels;
volatile ALboolean DryGainHFAuto;
volatile ALboolean WetGainAuto;
volatile ALboolean WetGainHFAuto;
volatile ALfloat OuterGainHF;
volatile ALfloat AirAbsorptionFactor;
volatile ALfloat RoomRolloffFactor;
volatile ALfloat DopplerFactor;
enum Resampler Resampler;
/**
* Last user-specified offset, and the offset type (bytes, samples, or
* seconds).
*/
ALdouble Offset;
ALenum OffsetType;
/** Source type (static, streaming, or undetermined) */
volatile ALint SourceType;
/** Source state (initial, playing, paused, or stopped) */
volatile ALenum state;
ALenum new_state;
/**
* Source offset in samples, relative to the currently playing buffer, NOT
* the whole queue, and the fractional (fixed-point) offset to the next
* sample.
*/
ALuint position;
ALuint position_fraction;
/** Source Buffer Queue info. */
ALbufferlistitem *queue;
ALuint BuffersInQueue;
ALuint BuffersPlayed;
/** Current buffer sample info. */
ALuint NumChannels;
ALuint SampleSize;
/** Direct filter and auxiliary send info. */
ALfloat DirectGain;
ALfloat DirectGainHF;
struct {
struct ALeffectslot *Slot;
ALfloat Gain;
ALfloat GainHF;
} Send[MAX_SENDS];
/** HRTF info. */
HrtfState Hrtf;
/** Current target parameters used for mixing. */
struct {
ResamplerFunc Resample;
DryMixerFunc DryMix;
WetMixerFunc WetMix;
ALint Step;
DirectParams Direct;
SendParams Send[MAX_SENDS];
} Params;
/** Source needs to update its mixing parameters. */
volatile ALenum NeedsUpdate;
/** Method to update mixing parameters. */
ALvoid (*Update)(struct ALsource *self, const ALCcontext *context);
/** Self ID */
ALuint id;
} ALsource;
#define ALsource_Update(s,a) ((s)->Update(s,a))
ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state);
ALboolean ApplyOffset(ALsource *Source);
ALvoid ReleaseALSources(ALCcontext *Context);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,20 @@
#ifndef ALTHUNK_H
#define ALTHUNK_H
#include "alMain.h"
#ifdef __cplusplus
extern "C" {
#endif
void ThunkInit(void);
void ThunkExit(void);
ALenum NewThunkEntry(ALuint *index);
void FreeThunkEntry(ALuint index);
#ifdef __cplusplus
}
#endif
#endif //ALTHUNK_H
@@ -0,0 +1,127 @@
#ifndef _ALU_H_
#define _ALU_H_
#include "alMain.h"
#include <limits.h>
#include <math.h>
#ifdef HAVE_FLOAT_H
#include <float.h>
#endif
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
#define F_PI (3.14159265358979323846f) /* pi */
#define F_PI_2 (1.57079632679489661923f) /* pi/2 */
#ifndef FLT_EPSILON
#define FLT_EPSILON (1.19209290e-07f)
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct ALsource;
struct ALbuffer;
struct DirectParams;
struct SendParams;
typedef void (*ResamplerFunc)(const ALfloat *src, ALuint frac, ALuint increment,
ALfloat *RESTRICT dst, ALuint dstlen);
typedef ALvoid (*DryMixerFunc)(const struct DirectParams *params,
const ALfloat *RESTRICT data, ALuint srcchan,
ALuint OutPos, ALuint SamplesToDo,
ALuint BufferSize);
typedef ALvoid (*WetMixerFunc)(const struct SendParams *params,
const ALfloat *RESTRICT data,
ALuint OutPos, ALuint SamplesToDo,
ALuint BufferSize);
#define SPEEDOFSOUNDMETRESPERSEC (343.3f)
#define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
#define FRACTIONBITS (14)
#define FRACTIONONE (1<<FRACTIONBITS)
#define FRACTIONMASK (FRACTIONONE-1)
static __inline ALfloat minf(ALfloat a, ALfloat b)
{ return ((a > b) ? b : a); }
static __inline ALfloat maxf(ALfloat a, ALfloat b)
{ return ((a > b) ? a : b); }
static __inline ALfloat clampf(ALfloat val, ALfloat min, ALfloat max)
{ return minf(max, maxf(min, val)); }
static __inline ALuint minu(ALuint a, ALuint b)
{ return ((a > b) ? b : a); }
static __inline ALuint maxu(ALuint a, ALuint b)
{ return ((a > b) ? a : b); }
static __inline ALuint clampu(ALuint val, ALuint min, ALuint max)
{ return minu(max, maxu(min, val)); }
static __inline ALint mini(ALint a, ALint b)
{ return ((a > b) ? b : a); }
static __inline ALint maxi(ALint a, ALint b)
{ return ((a > b) ? a : b); }
static __inline ALint clampi(ALint val, ALint min, ALint max)
{ return mini(max, maxi(min, val)); }
static __inline ALint64 mini64(ALint64 a, ALint64 b)
{ return ((a > b) ? b : a); }
static __inline ALint64 maxi64(ALint64 a, ALint64 b)
{ return ((a > b) ? a : b); }
static __inline ALint64 clampi64(ALint64 val, ALint64 min, ALint64 max)
{ return mini64(max, maxi64(min, val)); }
static __inline ALuint64 minu64(ALuint64 a, ALuint64 b)
{ return ((a > b) ? b : a); }
static __inline ALuint64 maxu64(ALuint64 a, ALuint64 b)
{ return ((a > b) ? a : b); }
static __inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max)
{ return minu64(max, maxu64(min, val)); }
static __inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu)
{
return val1 + (val2-val1)*mu;
}
static __inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALfloat mu)
{
ALfloat mu2 = mu*mu;
ALfloat a0 = -0.5f*val0 + 1.5f*val1 + -1.5f*val2 + 0.5f*val3;
ALfloat a1 = val0 + -2.5f*val1 + 2.0f*val2 + -0.5f*val3;
ALfloat a2 = -0.5f*val0 + 0.5f*val2;
ALfloat a3 = val1;
return a0*mu*mu2 + a1*mu2 + a2*mu + a3;
}
ALvoid aluInitPanning(ALCdevice *Device);
ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat *gains);
ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
ALvoid MixSource(struct ALsource *Source, ALCdevice *Device, ALuint SamplesToDo);
ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size);
/* Caller must lock the device. */
ALvoid aluHandleDisconnect(ALCdevice *device);
extern ALfloat ConeScale;
extern ALfloat ZScale;
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,106 @@
/*-
* Copyright (c) 2005 Boris Mikhaylov
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef BS2B_H
#define BS2B_H
/* Number of crossfeed levels */
#define BS2B_CLEVELS 3
/* Normal crossfeed levels */
#define BS2B_HIGH_CLEVEL 3
#define BS2B_MIDDLE_CLEVEL 2
#define BS2B_LOW_CLEVEL 1
/* Easy crossfeed levels */
#define BS2B_HIGH_ECLEVEL BS2B_HIGH_CLEVEL + BS2B_CLEVELS
#define BS2B_MIDDLE_ECLEVEL BS2B_MIDDLE_CLEVEL + BS2B_CLEVELS
#define BS2B_LOW_ECLEVEL BS2B_LOW_CLEVEL + BS2B_CLEVELS
/* Default crossfeed levels */
#define BS2B_DEFAULT_CLEVEL BS2B_HIGH_ECLEVEL
/* Default sample rate (Hz) */
#define BS2B_DEFAULT_SRATE 44100
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct bs2b {
int level; /* Crossfeed level */
int srate; /* Sample rate (Hz) */
/* Lowpass IIR filter coefficients */
double a0_lo;
double b1_lo;
/* Highboost IIR filter coefficients */
double a0_hi;
double a1_hi;
double b1_hi;
/* Global gain against overloading */
float gain;
/* Buffer of last filtered sample.
* [0] - first channel, [1] - second channel
*/
struct t_last_sample {
double asis[2];
double lo[2];
double hi[2];
} last_sample;
};
/* Clear buffers and set new coefficients with new crossfeed level value.
* level - crossfeed level of *LEVEL values.
*/
void bs2b_set_level(struct bs2b *bs2b, int level);
/* Return current crossfeed level value */
int bs2b_get_level(struct bs2b *bs2b);
/* Clear buffers and set new coefficients with new sample rate value.
* srate - sample rate by Hz.
*/
void bs2b_set_srate(struct bs2b *bs2b, int srate);
/* Return current sample rate value */
int bs2b_get_srate(struct bs2b *bs2b);
/* Clear buffer */
void bs2b_clear(struct bs2b *bs2b);
/* Crossfeeds one stereo sample that are pointed by sample.
* [0] - first channel, [1] - second channel.
* Returns crossfided samle by sample pointer.
*/
/* sample poits to floats */
void bs2b_cross_feed(struct bs2b *bs2b, float *sample);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* BS2B_H */