Commit 5987d94e authored by Unicorn369's avatar Unicorn369 Committed by fallenstardust

add openal

parent 62d5a31f
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := openal
LOCAL_C_INCLUDES := $(LOCAL_PATH)/android \
$(LOCAL_PATH)/include \
$(LOCAL_PATH)/src/Alc \
$(LOCAL_PATH)/src/OpenAL32 \
$(LOCAL_PATH)/src/OpenAL32/Include
LOCAL_SRC_FILES := \
src/Alc/ALc.c \
src/Alc/alcConfig.c \
src/Alc/alcRing.c \
src/Alc/ALu.c \
src/Alc/ambdec.c \
src/Alc/bformatdec.c \
src/Alc/bs2b.c \
src/Alc/bsinc.c \
src/Alc/helpers.c \
src/Alc/hrtf.c \
src/Alc/mixer.c \
src/Alc/mixer_c.c \
src/Alc/panning.c \
src/Alc/uhjfilter.c \
\
src/Alc/effects/autowah.c \
src/Alc/effects/chorus.c \
src/Alc/effects/compressor.c \
src/Alc/effects/dedicated.c \
src/Alc/effects/distortion.c \
src/Alc/effects/echo.c \
src/Alc/effects/equalizer.c \
src/Alc/effects/flanger.c \
src/Alc/effects/modulator.c \
src/Alc/effects/null.c \
src/Alc/effects/reverb.c \
\
src/Alc/backends/base.c \
src/Alc/backends/loopback.c \
src/Alc/backends/null.c \
src/Alc/backends/opensl.c \
src/Alc/backends/wave.c \
\
src/OpenAL32/alAuxEffectSlot.c \
src/OpenAL32/alBuffer.c \
src/OpenAL32/alEffect.c \
src/OpenAL32/alError.c \
src/OpenAL32/alExtension.c \
src/OpenAL32/alFilter.c \
src/OpenAL32/alListener.c \
src/OpenAL32/alSource.c \
src/OpenAL32/alState.c \
src/OpenAL32/alThunk.c \
src/OpenAL32/sample_cvt.c \
\
src/common/almalloc.c \
src/common/alhelpers.c \
src/common/atomic.c \
src/common/rwlock.c \
src/common/threads.c \
src/common/uintmap.c
LOCAL_CFLAGS := -DAL_BUILD_LIBRARY -DAL_ALEXT_PROTOTYPES
include $(BUILD_STATIC_LIBRARY)
#ifndef ALHELPERS_H
#define ALHELPERS_H
#include "AL/alc.h"
#include "AL/al.h"
#include "AL/alext.h"
#include "threads.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Some helper functions to get the name from the channel and type enums. */
const char *ChannelsName(ALenum chans);
const char *TypeName(ALenum type);
/* Helpers to convert frame counts and byte lengths. */
ALsizei FramesToBytes(ALsizei size, ALenum channels, ALenum type);
ALsizei BytesToFrames(ALsizei size, ALenum channels, ALenum type);
/* Retrieves a compatible buffer format given the channel configuration and
* sample type. If an alIsBufferFormatSupportedSOFT-compatible function is
* provided, it will be called to find the closest-matching format from
* AL_SOFT_buffer_samples. Returns AL_NONE (0) if no supported format can be
* found. */
ALenum GetFormat(ALenum channels, ALenum type, LPALISBUFFERFORMATSUPPORTEDSOFT palIsBufferFormatSupportedSOFT);
/* Loads samples into a buffer using the standard alBufferData call, but with a
* LPALBUFFERSAMPLESSOFT-compatible prototype. Assumes internalformat is valid
* for alBufferData, and that channels and type match it. */
void AL_APIENTRY wrap_BufferSamples(ALuint buffer, ALuint samplerate,
ALenum internalformat, ALsizei samples,
ALenum channels, ALenum type,
const ALvoid *data);
/* Easy device init/deinit functions. InitAL returns 0 on success. */
int InitAL(void);
void CloseAL(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* ALHELPERS_H */
#ifndef AL_ALIGN_H
#define AL_ALIGN_H
#if defined(HAVE_STDALIGN_H) && defined(HAVE_C11_ALIGNAS)
#include <stdalign.h>
#endif
#ifndef alignas
#if defined(IN_IDE_PARSER)
/* KDevelop has problems with our align macro, so just use nothing for parsing. */
#define alignas(x)
#elif defined(HAVE_C11_ALIGNAS)
#define alignas _Alignas
#else
/* NOTE: Our custom ALIGN macro can't take a type name like alignas can. For
* maximum compatibility, only provide constant integer values to alignas. */
#define alignas(_x) ALIGN(_x)
#endif
#endif
#endif /* AL_ALIGN_H */
#ifndef AL_MALLOC_H
#define AL_MALLOC_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
void *al_malloc(size_t alignment, size_t size);
void *al_calloc(size_t alignment, size_t size);
void al_free(void *ptr);
#ifdef __cplusplus
}
#endif
#endif /* AL_MALLOC_H */
This diff is collapsed.
#ifndef AL_BOOL_H
#define AL_BOOL_H
#ifdef HAVE_STDBOOL_H
#include <stdbool.h>
#endif
#ifndef bool
#ifdef HAVE_C99_BOOL
#define bool _Bool
#else
#define bool int
#endif
#define false 0
#define true 1
#endif
#endif /* AL_BOOL_H */
#ifndef CONFIG_H
#define CONFIG_H
/* Define to the library version */
#define ALSOFT_VERSION "1.13"
#define ALIGN(x) __attribute__((aligned(x)))
/* Define if we have the Android backend */
#define HAVE_ANDROID 1
#define HAVE_DIRENT_H 1
/* Define if we have the ALSA backend */
/* #cmakedefine HAVE_ALSA */
/* Define if we have the OSS backend */
/* #cmakedefine HAVE_OSS */
/* Define if we have the Solaris backend */
/* #cmakedefine HAVE_SOLARIS */
/* Define if we have the SndIO backend */
/* #cmakedefine HAVE_SNDIO */
/* Define if we have the MMDevApi backend */
/* #cmakedefine HAVE_MMDEVAPI */
/* Define if we have the DSound backend */
/* #cmakedefine HAVE_DSOUND */
/* Define if we have the Windows Multimedia backend */
/* #cmakedefine HAVE_WINMM */
/* Define if we have the PortAudio backend */
/* #cmakedefine HAVE_PORTAUDIO */
/* Define if we have the PulseAudio backend */
/* #cmakedefine HAVE_PULSEAUDIO */
/* Define if we have the CoreAudio backend */
/* #cmakedefine HAVE_COREAUDIO */
/* Define if we have the OpenSL backend */
/* #cmakedefine HAVE_OPENSL */ /* THIS BACKEND WORKS ON >=2.3 Android!! */
#define HAVE_OPENSL
/* Define if we have the Wave Writer backend */
/* #cmakedefine HAVE_WAVE */
/* Define if we have dlfcn.h */
#define HAVE_DLFCN_H 1
/* Define if we have the stat function */
#define HAVE_STAT 1
/* Define if we have the powf function */
#define HAVE_POWF 1
/* Define if we have the sqrtf function */
#define HAVE_SQRTF 1
/* Define if we have the cosf function */
#define HAVE_COSF 1
/* Define if we have the sinf function */
#define HAVE_SINF 1
/* Define if we have the acosf function */
#define HAVE_ACOSF 1
/* Define if we have the asinf function */
#define HAVE_ASINF 1
/* Define if we have the atanf function */
#define HAVE_ATANF 1
/* Define if we have the atan2f function */
#define HAVE_ATAN2F 1
/* Define if we have the fabsf function */
#define HAVE_FABSF 1
/* Define if we have the log10f function */
#define HAVE_LOG10F 1
/* Define if we have the floorf function */
#define HAVE_FLOORF 1
/* Define if we have the strtof function */
#define HAVE_STRTOF 1
/* Define if we have stdint.h */
#define HAVE_STDINT_H 1
/* Define if we have the __int64 type */
/* #cmakedefine HAVE___INT64 */
/* Define to the size of a long int type */
#define SIZEOF_LONG 4
/* Define to the size of a long long int type */
#define SIZEOF_LONG_LONG 8
/* Define if we have GCC's destructor attribute */
#define HAVE_GCC_DESTRUCTOR 1
/* Define if we have GCC's format attribute */
#define HAVE_GCC_FORMAT 1
/* Define if we have pthread_np.h */
/* #cmakedefine HAVE_PTHREAD_NP_H */
/* Define if we have arm_neon.h */
/* #cmakedefine HAVE_ARM_NEON_H */
/* Define if we have guiddef.h */
/* #cmakedefine HAVE_GUIDDEF_H */
/* Define if we have guiddef.h */
/* #cmakedefine HAVE_INITGUID_H */
/* Define if we have ieeefp.h */
/* #cmakedefine HAVE_IEEEFP_H */
/* Define if we have float.h */
/* #cmakedefine HAVE_FLOAT_H */
/* Define if we have fpu_control.h */
/* #cmakedefine HAVE_FPU_CONTROL_H */
/* Define if we have fenv.h */
#define HAVE_FENV_H 1
/* Define if we have fesetround() */
/* #cmakedefine HAVE_FESETROUND */
/* Define if we have _controlfp() */
/* #cmakedefine HAVE__CONTROLFP */
/* Define if we have pthread_setschedparam() */
#define HAVE_PTHREAD_SETSCHEDPARAM 1
/* Define if we have the restrict keyword */
/* #cmakedefine HAVE_RESTRICT 1 */
/* Define if we have the __restrict keyword */
#define HAVE___RESTRICT 1
#endif
#ifndef AL_MATH_DEFS_H
#define AL_MATH_DEFS_H
#ifdef HAVE_FLOAT_H
#include <float.h>
#endif
#define F_PI (3.14159265358979323846f)
#define F_PI_2 (1.57079632679489661923f)
#define F_TAU (6.28318530717958647692f)
#ifndef FLT_EPSILON
#define FLT_EPSILON (1.19209290e-07f)
#endif
#define DEG2RAD(x) ((ALfloat)(x) * (F_PI/180.0f))
#define RAD2DEG(x) ((ALfloat)(x) * (180.0f/F_PI))
#endif /* AL_MATH_DEFS_H */
#ifndef AL_RWLOCK_H
#define AL_RWLOCK_H
#include "bool.h"
#include "atomic.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
RefCount read_count;
RefCount write_count;
ATOMIC(int) read_lock;
ATOMIC(int) read_entry_lock;
ATOMIC(int) write_lock;
} RWLock;
#define RWLOCK_STATIC_INITIALIZE { ATOMIC_INIT_STATIC(0), ATOMIC_INIT_STATIC(0), \
ATOMIC_INIT_STATIC(false), ATOMIC_INIT_STATIC(false), \
ATOMIC_INIT_STATIC(false) }
void RWLockInit(RWLock *lock);
void ReadLock(RWLock *lock);
void ReadUnlock(RWLock *lock);
void WriteLock(RWLock *lock);
void WriteUnlock(RWLock *lock);
#ifdef __cplusplus
}
#endif
#endif /* AL_RWLOCK_H */
#ifndef AL_STATIC_ASSERT_H
#define AL_STATIC_ASSERT_H
#include <assert.h>
#ifndef static_assert
#ifdef HAVE_C11_STATIC_ASSERT
#define static_assert _Static_assert
#else
#define CTASTR2(_pre,_post) _pre##_post
#define CTASTR(_pre,_post) CTASTR2(_pre,_post)
#if defined(__COUNTER__)
#define static_assert(_cond, _msg) typedef struct { int CTASTR(static_assert_failed_at_line_,__LINE__) : !!(_cond); } CTASTR(static_assertion_,__COUNTER__)
#else
#define static_assert(_cond, _msg) struct { int CTASTR(static_assert_failed_at_line_,__LINE__) : !!(_cond); }
#endif
#endif
#endif
#endif /* AL_STATIC_ASSERT_H */
#ifndef AL_THREADS_H
#define AL_THREADS_H
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
enum {
althrd_success = 0,
althrd_error,
althrd_nomem,
althrd_timedout,
althrd_busy
};
enum {
almtx_plain = 0,
almtx_recursive = 1,
almtx_timed = 2
};
typedef int (*althrd_start_t)(void*);
typedef void (*altss_dtor_t)(void*);
#define AL_TIME_UTC 1
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#if !defined(_TIMESPEC_DEFINED) && !(defined(_MSC_VER) && (_MSC_VER >= 1900))
#define _TIMESPEC_DEFINED
struct timespec {
time_t tv_sec;
long tv_nsec;
};
struct itimerspec {
struct timespec it_interval;
struct timespec it_value;
};
#endif
typedef DWORD althrd_t;
typedef CRITICAL_SECTION almtx_t;
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600
typedef CONDITION_VARIABLE alcnd_t;
#else
typedef struct { void *Ptr; } alcnd_t;
#endif
typedef DWORD altss_t;
typedef LONG alonce_flag;
#define AL_ONCE_FLAG_INIT 0
int althrd_sleep(const struct timespec *ts, struct timespec *rem);
void alcall_once(alonce_flag *once, void (*callback)(void));
inline althrd_t althrd_current(void)
{
return GetCurrentThreadId();
}
inline int althrd_equal(althrd_t thr0, althrd_t thr1)
{
return thr0 == thr1;
}
inline void althrd_exit(int res)
{
ExitThread(res);
}
inline void althrd_yield(void)
{
SwitchToThread();
}
inline int almtx_lock(almtx_t *mtx)
{
if(!mtx) return althrd_error;
EnterCriticalSection(mtx);
return althrd_success;
}
inline int almtx_unlock(almtx_t *mtx)
{
if(!mtx) return althrd_error;
LeaveCriticalSection(mtx);
return althrd_success;
}
inline int almtx_trylock(almtx_t *mtx)
{
if(!mtx) return althrd_error;
if(!TryEnterCriticalSection(mtx))
return althrd_busy;
return althrd_success;
}
inline void *altss_get(altss_t tss_id)
{
return TlsGetValue(tss_id);
}
inline int altss_set(altss_t tss_id, void *val)
{
if(TlsSetValue(tss_id, val) == 0)
return althrd_error;
return althrd_success;
}
#else
#include <stdint.h>
#include <errno.h>
#include <pthread.h>
typedef pthread_t althrd_t;
typedef pthread_mutex_t almtx_t;
typedef pthread_cond_t alcnd_t;
typedef pthread_key_t altss_t;
typedef pthread_once_t alonce_flag;
#define AL_ONCE_FLAG_INIT PTHREAD_ONCE_INIT
inline althrd_t althrd_current(void)
{
return pthread_self();
}
inline int althrd_equal(althrd_t thr0, althrd_t thr1)
{
return pthread_equal(thr0, thr1);
}
inline void althrd_exit(int res)
{
pthread_exit((void*)(intptr_t)res);
}
inline void althrd_yield(void)
{
sched_yield();
}
inline int althrd_sleep(const struct timespec *ts, struct timespec *rem)
{
int ret = nanosleep(ts, rem);
if(ret != 0)
{
ret = ((errno==EINTR) ? -1 : -2);
errno = 0;
}
return ret;
}
inline int almtx_lock(almtx_t *mtx)
{
if(pthread_mutex_lock(mtx) != 0)
return althrd_error;
return althrd_success;
}
inline int almtx_unlock(almtx_t *mtx)
{
if(pthread_mutex_unlock(mtx) != 0)
return althrd_error;
return althrd_success;
}
inline int almtx_trylock(almtx_t *mtx)
{
int ret = pthread_mutex_trylock(mtx);
switch(ret)
{
case 0: return althrd_success;
case EBUSY: return althrd_busy;
}
return althrd_error;
}
inline void *altss_get(altss_t tss_id)
{
return pthread_getspecific(tss_id);
}
inline int altss_set(altss_t tss_id, void *val)
{
if(pthread_setspecific(tss_id, val) != 0)
return althrd_error;
return althrd_success;
}
inline void alcall_once(alonce_flag *once, void (*callback)(void))
{
pthread_once(once, callback);
}
#endif
int althrd_create(althrd_t *thr, althrd_start_t func, void *arg);
int althrd_detach(althrd_t thr);
int althrd_join(althrd_t thr, int *res);
void althrd_setname(althrd_t thr, const char *name);
int almtx_init(almtx_t *mtx, int type);
void almtx_destroy(almtx_t *mtx);
int almtx_timedlock(almtx_t *mtx, const struct timespec *ts);
int alcnd_init(alcnd_t *cond);
int alcnd_signal(alcnd_t *cond);
int alcnd_broadcast(alcnd_t *cond);
int alcnd_wait(alcnd_t *cond, almtx_t *mtx);
int alcnd_timedwait(alcnd_t *cond, almtx_t *mtx, const struct timespec *time_point);
void alcnd_destroy(alcnd_t *cond);
int altss_create(altss_t *tss_id, altss_dtor_t callback);
void altss_delete(altss_t tss_id);
int altimespec_get(struct timespec *ts, int base);
void al_nssleep(unsigned long nsec);
#ifdef __cplusplus
}
#endif
#endif /* AL_THREADS_H */
#ifndef AL_UINTMAP_H
#define AL_UINTMAP_H
#include "AL/al.h"
#include "rwlock.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct UIntMap {
struct {
ALuint key;
ALvoid *value;
} *array;
ALsizei size;
ALsizei maxsize;
ALsizei limit;
RWLock lock;
} UIntMap;
#define UINTMAP_STATIC_INITIALIZE_N(_n) { NULL, 0, 0, (_n), RWLOCK_STATIC_INITIALIZE }
#define UINTMAP_STATIC_INITIALIZE UINTMAP_STATIC_INITIALIZE_N(~0)
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 *RemoveUIntMapKeyNoLock(UIntMap *map, ALuint key);
ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
ALvoid *LookupUIntMapKeyNoLock(UIntMap *map, ALuint key);
inline void LockUIntMapRead(UIntMap *map)
{ ReadLock(&map->lock); }
inline void UnlockUIntMapRead(UIntMap *map)
{ ReadUnlock(&map->lock); }
inline void LockUIntMapWrite(UIntMap *map)
{ WriteLock(&map->lock); }
inline void UnlockUIntMapWrite(UIntMap *map)
{ WriteUnlock(&map->lock); }
#ifdef __cplusplus
}
#endif
#endif /* AL_UINTMAP_H */
This diff is collapsed.
#ifndef AL_ALC_H
#define AL_ALC_H
#if defined(__cplusplus)
extern "C" {
#endif
#ifndef ALC_API
#if defined(AL_LIBTYPE_STATIC)
#define ALC_API
#elif defined(_WIN32)
#define ALC_API __declspec(dllimport)
#else
#define ALC_API extern
#endif
#endif
#if defined(_WIN32)
#define ALC_APIENTRY __cdecl
#else
#define ALC_APIENTRY
#endif
/** Deprecated macro. */
#define ALCAPI ALC_API
#define ALCAPIENTRY ALC_APIENTRY
#define ALC_INVALID 0
/** Supported ALC version? */
#define ALC_VERSION_0_1 1
/** Opaque device handle */
typedef struct ALCdevice_struct ALCdevice;
/** Opaque context handle */
typedef struct ALCcontext_struct ALCcontext;
/** 8-bit boolean */
typedef char ALCboolean;
/** character */
typedef char ALCchar;
/** signed 8-bit 2's complement integer */
typedef signed char ALCbyte;
/** unsigned 8-bit integer */
typedef unsigned char ALCubyte;
/** signed 16-bit 2's complement integer */
typedef short ALCshort;
/** unsigned 16-bit integer */
typedef unsigned short ALCushort;
/** signed 32-bit 2's complement integer */
typedef int ALCint;
/** unsigned 32-bit integer */
typedef unsigned int ALCuint;
/** non-negative 32-bit binary integer size */
typedef int ALCsizei;
/** enumerated 32-bit value */
typedef int ALCenum;
/** 32-bit IEEE754 floating-point */
typedef float ALCfloat;
/** 64-bit IEEE754 floating-point */
typedef double ALCdouble;
/** void type (for opaque pointers only) */
typedef void ALCvoid;
/* Enumerant values begin at column 50. No tabs. */
/** Boolean False. */
#define ALC_FALSE 0
/** Boolean True. */
#define ALC_TRUE 1
/** Context attribute: <int> Hz. */
#define ALC_FREQUENCY 0x1007
/** Context attribute: <int> Hz. */
#define ALC_REFRESH 0x1008
/** Context attribute: AL_TRUE or AL_FALSE. */
#define ALC_SYNC 0x1009
/** Context attribute: <int> requested Mono (3D) Sources. */
#define ALC_MONO_SOURCES 0x1010
/** Context attribute: <int> requested Stereo Sources. */
#define ALC_STEREO_SOURCES 0x1011
/** No error. */
#define ALC_NO_ERROR 0
/** Invalid device handle. */
#define ALC_INVALID_DEVICE 0xA001
/** Invalid context handle. */
#define ALC_INVALID_CONTEXT 0xA002
/** Invalid enum parameter passed to an ALC call. */
#define ALC_INVALID_ENUM 0xA003
/** Invalid value parameter passed to an ALC call. */
#define ALC_INVALID_VALUE 0xA004
/** Out of memory. */
#define ALC_OUT_OF_MEMORY 0xA005
/** Runtime ALC version. */
#define ALC_MAJOR_VERSION 0x1000
#define ALC_MINOR_VERSION 0x1001
/** Context attribute list properties. */
#define ALC_ATTRIBUTES_SIZE 0x1002
#define ALC_ALL_ATTRIBUTES 0x1003
/** String for the default device specifier. */
#define ALC_DEFAULT_DEVICE_SPECIFIER 0x1004
/**
* String for the given device's specifier.
*
* If device handle is NULL, it is instead a null-char separated list of
* strings of known device specifiers (list ends with an empty string).
*/
#define ALC_DEVICE_SPECIFIER 0x1005
/** String for space-separated list of ALC extensions. */
#define ALC_EXTENSIONS 0x1006
/** Capture extension */
#define ALC_EXT_CAPTURE 1
/**
* String for the given capture device's specifier.
*
* If device handle is NULL, it is instead a null-char separated list of
* strings of known capture device specifiers (list ends with an empty string).
*/
#define ALC_CAPTURE_DEVICE_SPECIFIER 0x310
/** String for the default capture device specifier. */
#define ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER 0x311
/** Number of sample frames available for capture. */
#define ALC_CAPTURE_SAMPLES 0x312
/** Enumerate All extension */
#define ALC_ENUMERATE_ALL_EXT 1
/** String for the default extended device specifier. */
#define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
/**
* String for the given extended device's specifier.
*
* If device handle is NULL, it is instead a null-char separated list of
* strings of known extended device specifiers (list ends with an empty string).
*/
#define ALC_ALL_DEVICES_SPECIFIER 0x1013
/** Context management. */
ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint* attrlist);
ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context);
ALC_API void ALC_APIENTRY alcProcessContext(ALCcontext *context);
ALC_API void ALC_APIENTRY alcSuspendContext(ALCcontext *context);
ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context);
ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void);
ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *context);
/** Device management. */
ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename);
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device);
/**
* Error support.
*
* Obtain the most recent Device error.
*/
ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device);
/**
* Extension support.
*
* Query for the presence of an extension, and obtain any appropriate
* function pointers and enum values.
*/
ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extname);
ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcname);
ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumname);
/** Query function. */
ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum param);
ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values);
/** Capture function. */
ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize);
ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device);
ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device);
ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device);
ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples);
/** Pointer-to-function type, useful for dynamically getting ALC entry points. */
typedef ALCcontext* (ALC_APIENTRY *LPALCCREATECONTEXT)(ALCdevice *device, const ALCint *attrlist);
typedef ALCboolean (ALC_APIENTRY *LPALCMAKECONTEXTCURRENT)(ALCcontext *context);
typedef void (ALC_APIENTRY *LPALCPROCESSCONTEXT)(ALCcontext *context);
typedef void (ALC_APIENTRY *LPALCSUSPENDCONTEXT)(ALCcontext *context);
typedef void (ALC_APIENTRY *LPALCDESTROYCONTEXT)(ALCcontext *context);
typedef ALCcontext* (ALC_APIENTRY *LPALCGETCURRENTCONTEXT)(void);
typedef ALCdevice* (ALC_APIENTRY *LPALCGETCONTEXTSDEVICE)(ALCcontext *context);
typedef ALCdevice* (ALC_APIENTRY *LPALCOPENDEVICE)(const ALCchar *devicename);
typedef ALCboolean (ALC_APIENTRY *LPALCCLOSEDEVICE)(ALCdevice *device);
typedef ALCenum (ALC_APIENTRY *LPALCGETERROR)(ALCdevice *device);
typedef ALCboolean (ALC_APIENTRY *LPALCISEXTENSIONPRESENT)(ALCdevice *device, const ALCchar *extname);
typedef void* (ALC_APIENTRY *LPALCGETPROCADDRESS)(ALCdevice *device, const ALCchar *funcname);
typedef ALCenum (ALC_APIENTRY *LPALCGETENUMVALUE)(ALCdevice *device, const ALCchar *enumname);
typedef const ALCchar* (ALC_APIENTRY *LPALCGETSTRING)(ALCdevice *device, ALCenum param);
typedef void (ALC_APIENTRY *LPALCGETINTEGERV)(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values);
typedef ALCdevice* (ALC_APIENTRY *LPALCCAPTUREOPENDEVICE)(const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize);
typedef ALCboolean (ALC_APIENTRY *LPALCCAPTURECLOSEDEVICE)(ALCdevice *device);
typedef void (ALC_APIENTRY *LPALCCAPTURESTART)(ALCdevice *device);
typedef void (ALC_APIENTRY *LPALCCAPTURESTOP)(ALCdevice *device);
typedef void (ALC_APIENTRY *LPALCCAPTURESAMPLES)(ALCdevice *device, ALCvoid *buffer, ALCsizei samples);
#if defined(__cplusplus)
}
#endif
#endif /* AL_ALC_H */
This diff is collapsed.
/* The tokens that would be defined here are already defined in efx.h. This
* empty file is here to provide compatibility with Windows-based projects
* that would include it. */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* OpenAL cross platform audio library
* Copyright (C) 2009 by Chris Robinson.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
#include "config.h"
#include <math.h>
#include <stdlib.h>
#include "alMain.h"
#include "alFilter.h"
#include "alAuxEffectSlot.h"
#include "alError.h"
#include "alu.h"
typedef struct ALechoState {
// Must be first in all effects!
ALeffectState state;
ALfp *SampleBuffer;
ALuint BufferLength;
// The echo is two tap. The delay is the number of samples from before the
// current offset
struct {
ALuint delay;
} Tap[2];
ALuint Offset;
// The LR gains for the first tap. The second tap uses the reverse
ALfp GainL;
ALfp GainR;
ALfp FeedGain;
ALfp Gain[MAXCHANNELS];
FILTER iirFilter;
ALfp history[2];
} ALechoState;
static ALvoid EchoDestroy(ALeffectState *effect)
{
ALechoState *state = (ALechoState*)effect;
if(state)
{
free(state->SampleBuffer);
state->SampleBuffer = NULL;
free(state);
}
}
static ALboolean EchoDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
{
ALechoState *state = (ALechoState*)effect;
ALuint maxlen, i;
// Use the next power of 2 for the buffer length, so the tap offsets can be
// wrapped using a mask instead of a modulo
maxlen = (ALuint)(AL_ECHO_MAX_DELAY * Device->Frequency) + 1;
maxlen += (ALuint)(AL_ECHO_MAX_LRDELAY * Device->Frequency) + 1;
maxlen = NextPowerOf2(maxlen);
if(maxlen != state->BufferLength)
{
void *temp;
temp = realloc(state->SampleBuffer, maxlen * sizeof(ALfp));
if(!temp)
return AL_FALSE;
state->SampleBuffer = temp;
state->BufferLength = maxlen;
}
for(i = 0;i < state->BufferLength;i++)
state->SampleBuffer[i] = int2ALfp(0);
for(i = 0;i < MAXCHANNELS;i++)
state->Gain[i] = int2ALfp(0);
for(i = 0;i < Device->NumChan;i++)
{
Channel chan = Device->Speaker2Chan[i];
state->Gain[chan] = int2ALfp(1);
}
return AL_TRUE;
}
static ALvoid EchoUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffect *Effect)
{
ALechoState *state = (ALechoState*)effect;
ALuint frequency = Context->Device->Frequency;
ALfp lrpan, cw, a, g;
state->Tap[0].delay = (ALuint)ALfp2int((ALfpMult(Effect->Echo.Delay, int2ALfp(frequency)) + int2ALfp(1)));
state->Tap[1].delay = (ALuint)ALfp2int(ALfpMult(Effect->Echo.LRDelay, int2ALfp(frequency)));
state->Tap[1].delay += state->Tap[0].delay;
lrpan = (ALfpMult(Effect->Echo.Spread, float2ALfp(0.5f)) + float2ALfp(0.5f));
state->GainL = aluSqrt( lrpan);
state->GainR = aluSqrt((int2ALfp(1)-lrpan));
state->FeedGain = Effect->Echo.Feedback;
cw = __cos(ALfpDiv(float2ALfp(2.0*M_PI * LOWPASSFREQCUTOFF), int2ALfp(frequency)));
g = (int2ALfp(1) - Effect->Echo.Damping);
a = int2ALfp(0);
if(g < float2ALfp(0.9999f)) /* 1-epsilon */ {
// a = (1 - g*cw - aluSqrt(2*g*(1-cw) - g*g*(1 - cw*cw))) / (1 - g);
a = ALfpDiv((int2ALfp(1) - ALfpMult(g,cw) - aluSqrt((ALfpMult(ALfpMult(int2ALfp(2),g),(int2ALfp(1)-cw)) -
ALfpMult(ALfpMult(g,g),(int2ALfp(1) - ALfpMult(cw,cw)))))),
(int2ALfp(1) - g));
}
state->iirFilter.coeff = a;
}
static ALvoid EchoProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuint SamplesToDo, const ALfp *SamplesIn, ALfp (*SamplesOut)[MAXCHANNELS])
{
ALechoState *state = (ALechoState*)effect;
const ALuint mask = state->BufferLength-1;
const ALuint tap1 = state->Tap[0].delay;
const ALuint tap2 = state->Tap[1].delay;
ALuint offset = state->Offset;
const ALfp gain = Slot->Gain;
ALfp samp[2], smp;
ALuint i;
for(i = 0;i < SamplesToDo;i++,offset++)
{
// Sample first tap
smp = state->SampleBuffer[(offset-tap1) & mask];
samp[0] = ALfpMult(smp, state->GainL);
samp[1] = ALfpMult(smp, state->GainR);
// Sample second tap. Reverse LR panning
smp = state->SampleBuffer[(offset-tap2) & mask];
samp[0] += ALfpMult(smp, state->GainR);
samp[1] += ALfpMult(smp, state->GainL);
// Apply damping and feedback gain to the second tap, and mix in the
// new sample
smp = lpFilter2P(&state->iirFilter, 0, (smp+SamplesIn[i]));
state->SampleBuffer[offset&mask] = ALfpMult(smp, state->FeedGain);
// Apply slot gain
samp[0] = ALfpMult(samp[0], gain);
samp[1] = ALfpMult(samp[1], gain);
SamplesOut[i][FRONT_LEFT] += ALfpMult(state->Gain[FRONT_LEFT], samp[0]);
SamplesOut[i][FRONT_RIGHT] += ALfpMult(state->Gain[FRONT_RIGHT], samp[1]);
#ifdef APPORTABLE_OPTIMIZED_OUT
SamplesOut[i][SIDE_LEFT] += ALfpMult(state->Gain[SIDE_LEFT], samp[0]);
SamplesOut[i][SIDE_RIGHT] += ALfpMult(state->Gain[SIDE_RIGHT], samp[1]);
SamplesOut[i][BACK_LEFT] += ALfpMult(state->Gain[BACK_LEFT], samp[0]);
SamplesOut[i][BACK_RIGHT] += ALfpMult(state->Gain[BACK_RIGHT], samp[1]);
#endif
}
state->Offset = offset;
}
ALeffectState *EchoCreate(void)
{
ALechoState *state;
state = malloc(sizeof(*state));
if(!state)
return NULL;
state->state.Destroy = EchoDestroy;
state->state.DeviceUpdate = EchoDeviceUpdate;
state->state.Update = EchoUpdate;
state->state.Process = EchoProcess;
state->BufferLength = 0;
state->SampleBuffer = NULL;
state->Tap[0].delay = 0;
state->Tap[1].delay = 0;
state->Offset = 0;
state->GainL = int2ALfp(0);
state->GainR = int2ALfp(0);
state->iirFilter.coeff = int2ALfp(0);
state->iirFilter.history[0] = int2ALfp(0);
state->iirFilter.history[1] = int2ALfp(0);
return &state->state;
}
/**
* OpenAL cross platform audio library
* Copyright (C) 2009 by Chris Robinson.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
#include "config.h"
#include <math.h>
#include <stdlib.h>
#include "alMain.h"
#include "alFilter.h"
#include "alAuxEffectSlot.h"
#include "alError.h"
#include "alu.h"
typedef struct ALmodulatorState {
// Must be first in all effects!
ALeffectState state;
enum {
SINUSOID,
SAWTOOTH,
SQUARE
} Waveform;
ALuint index;
ALuint step;
ALfp Gain[MAXCHANNELS];
FILTER iirFilter;
ALfp history[1];
} ALmodulatorState;
#define WAVEFORM_FRACBITS 16
#define WAVEFORM_FRACMASK ((1<<WAVEFORM_FRACBITS)-1)
static __inline ALfp sin_func(ALuint index)
{
return __sin(ALdfpMult(ALdfpDiv(int2ALdfp(index),double2ALdfp(1<<WAVEFORM_FRACBITS)), double2ALdfp(M_PI * 2.0f)));
}
static __inline ALfp saw_func(ALuint index)
{
return (ALfpDiv(int2ALfp(index*2), int2ALfp(1<<WAVEFORM_FRACBITS)) - int2ALfp(1));
}
static __inline ALfp square_func(ALuint index)
{
return int2ALfp((float)((index>>(WAVEFORM_FRACBITS-1))&1) ? -1 : 1);
}
static __inline ALfp hpFilter1P(FILTER *iir, ALuint offset, ALfp input)
{
ALfp *history = &iir->history[offset];
ALfp a = iir->coeff;
ALfp output = input;
output = (output + ALfpMult((history[0]-output),a));
history[0] = output;
return (input - output);
}
static ALvoid ModulatorDestroy(ALeffectState *effect)
{
ALmodulatorState *state = (ALmodulatorState*)effect;
free(state);
}
static ALboolean ModulatorDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
{
ALmodulatorState *state = (ALmodulatorState*)effect;
ALuint index;
for(index = 0;index < MAXCHANNELS;index++)
state->Gain[index] = int2ALfp(0);
for(index = 0;index < Device->NumChan;index++)
{
Channel chan = Device->Speaker2Chan[index];
state->Gain[chan] = int2ALfp(1);
}
return AL_TRUE;
}
static ALvoid ModulatorUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffect *Effect)
{
ALmodulatorState *state = (ALmodulatorState*)effect;
ALfp cw, a;
a = int2ALfp(0);
if(Effect->Modulator.Waveform == AL_RING_MODULATOR_SINUSOID)
state->Waveform = SINUSOID;
else if(Effect->Modulator.Waveform == AL_RING_MODULATOR_SAWTOOTH)
state->Waveform = SAWTOOTH;
else if(Effect->Modulator.Waveform == AL_RING_MODULATOR_SQUARE)
state->Waveform = SQUARE;
state->step = ALfp2int(ALfpDiv(ALfpMult(Effect->Modulator.Frequency,
int2ALfp(1<<WAVEFORM_FRACBITS)),
int2ALfp(Context->Device->Frequency)));
if(!state->step)
state->step = 1;
cw = __cos(ALfpDiv(ALfpMult(float2ALfp(2.0*M_PI),
Effect->Modulator.HighPassCutoff),
int2ALfp(Context->Device->Frequency)));
a = ((int2ALfp(2)-cw) -
aluSqrt((aluPow((int2ALfp(2)-cw), int2ALfp(2)) - int2ALfp(1))));
state->iirFilter.coeff = a;
}
static ALvoid ModulatorProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuint SamplesToDo, const ALfp *SamplesIn, ALfp (*SamplesOut)[MAXCHANNELS])
{
ALmodulatorState *state = (ALmodulatorState*)effect;
const ALfp gain = Slot->Gain;
const ALuint step = state->step;
ALuint index = state->index;
ALfp samp;
ALuint i;
switch(state->Waveform)
{
case SINUSOID:
for(i = 0;i < SamplesToDo;i++)
{
#ifdef APPORTABLE_OPTIMIZED_OUT
#define FILTER_OUT(func) do { \
samp = SamplesIn[i]; \
\
index += step; \
index &= WAVEFORM_FRACMASK; \
samp *= func(index); \
\
samp = hpFilter1P(&state->iirFilter, 0, samp); \
\
/* Apply slot gain */ \
samp *= gain; \
\
SamplesOut[i][FRONT_LEFT] += state->Gain[FRONT_LEFT] * samp; \
SamplesOut[i][FRONT_RIGHT] += state->Gain[FRONT_RIGHT] * samp; \
SamplesOut[i][FRONT_CENTER] += state->Gain[FRONT_CENTER] * samp; \
SamplesOut[i][SIDE_LEFT] += state->Gain[SIDE_LEFT] * samp; \
SamplesOut[i][SIDE_RIGHT] += state->Gain[SIDE_RIGHT] * samp; \
SamplesOut[i][BACK_LEFT] += state->Gain[BACK_LEFT] * samp; \
SamplesOut[i][BACK_RIGHT] += state->Gain[BACK_RIGHT] * samp; \
SamplesOut[i][BACK_CENTER] += state->Gain[BACK_CENTER] * samp; \
} while(0)
#else
//Apportable optimized version
#define FILTER_OUT(func) do { \
samp = SamplesIn[i]; \
\
index += step; \
index &= WAVEFORM_FRACMASK; \
samp = ALfpMult(samp, func(index)); \
\
samp = hpFilter1P(&state->iirFilter, 0, samp); \
\
/* Apply slot gain */ \
samp = ALfpMult(samp, gain); \
\
SamplesOut[i][FRONT_LEFT] += ALfpMult(state->Gain[FRONT_LEFT], samp); \
SamplesOut[i][FRONT_RIGHT] += ALfpMult(state->Gain[FRONT_RIGHT], samp); \
} while(0)
#endif
FILTER_OUT(sin_func);
}
break;
case SAWTOOTH:
for(i = 0;i < SamplesToDo;i++)
{
FILTER_OUT(saw_func);
}
break;
case SQUARE:
for(i = 0;i < SamplesToDo;i++)
{
FILTER_OUT(square_func);
#undef FILTER_OUT
}
break;
}
state->index = index;
}
ALeffectState *ModulatorCreate(void)
{
ALmodulatorState *state;
state = malloc(sizeof(*state));
if(!state)
return NULL;
state->state.Destroy = ModulatorDestroy;
state->state.DeviceUpdate = ModulatorDeviceUpdate;
state->state.Update = ModulatorUpdate;
state->state.Process = ModulatorProcess;
state->index = 0;
state->step = 1;
state->iirFilter.coeff = int2ALfp(0);
state->iirFilter.history[0] = int2ALfp(0);
return &state->state;
}
This diff is collapsed.
/**
* OpenAL cross platform audio library
* Copyright (C) 1999-2007 by authors.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
#include "config.h"
#include <string.h>
#include <stdlib.h>
#include "alMain.h"
#include "threads.h"
#include "almalloc.h"
#include "compat.h"
/* NOTE: This lockless ringbuffer implementation is copied from JACK, extended
* to include an element size. Consequently, parameters and return values for a
* size or count is in 'elements', not bytes. Additionally, it only supports
* single-consumer/single-provider operation. */
struct ll_ringbuffer {
volatile size_t write_ptr;
volatile size_t read_ptr;
size_t size;
size_t size_mask;
size_t elem_size;
int mlocked;
alignas(16) char buf[];
};
/* Create a new ringbuffer to hold at least `sz' elements of `elem_sz' bytes.
* The number of elements is rounded up to the next power of two. */
ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz)
{
ll_ringbuffer_t *rb;
ALuint power_of_two;
power_of_two = NextPowerOf2(sz);
if(power_of_two < sz)
return NULL;
rb = al_malloc(16, sizeof(*rb) + power_of_two*elem_sz);
if(!rb) return NULL;
rb->size = power_of_two;
rb->size_mask = rb->size - 1;
rb->elem_size = elem_sz;
rb->write_ptr = 0;
rb->read_ptr = 0;
rb->mlocked = 0;
return rb;
}
/* Free all data associated with the ringbuffer `rb'. */
void ll_ringbuffer_free(ll_ringbuffer_t *rb)
{
if(rb)
{
#ifdef USE_MLOCK
if(rb->mlocked)
munlock(rb, sizeof(*rb) + rb->size*rb->elem_size);
#endif /* USE_MLOCK */
al_free(rb);
}
}
/* Lock the data block of `rb' using the system call 'mlock'. */
int ll_ringbuffer_mlock(ll_ringbuffer_t *rb)
{
#ifdef USE_MLOCK
if(!rb->locked && mlock(rb, sizeof(*rb) + rb->size*rb->elem_size))
return -1;
#endif /* USE_MLOCK */
rb->mlocked = 1;
return 0;
}
/* Reset the read and write pointers to zero. This is not thread safe. */
void ll_ringbuffer_reset(ll_ringbuffer_t *rb)
{
rb->read_ptr = 0;
rb->write_ptr = 0;
memset(rb->buf, 0, rb->size*rb->elem_size);
}
/* Return the number of elements available for reading. This is the number of
* elements in front of the read pointer and behind the write pointer. */
size_t ll_ringbuffer_read_space(const ll_ringbuffer_t *rb)
{
size_t w = rb->write_ptr;
size_t r = rb->read_ptr;
return (rb->size+w-r) & rb->size_mask;
}
/* Return the number of elements available for writing. This is the number of
* elements in front of the write pointer and behind the read pointer. */
size_t ll_ringbuffer_write_space(const ll_ringbuffer_t *rb)
{
size_t w = rb->write_ptr;
size_t r = rb->read_ptr;
return (rb->size+r-w-1) & rb->size_mask;
}
/* The copying data reader. Copy at most `cnt' elements from `rb' to `dest'.
* Returns the actual number of elements copied. */
size_t ll_ringbuffer_read(ll_ringbuffer_t *rb, char *dest, size_t cnt)
{
size_t free_cnt;
size_t cnt2;
size_t to_read;
size_t n1, n2;
free_cnt = ll_ringbuffer_read_space(rb);
if(free_cnt == 0) return 0;
to_read = (cnt > free_cnt) ? free_cnt : cnt;
cnt2 = rb->read_ptr + to_read;
if(cnt2 > rb->size)
{
n1 = rb->size - rb->read_ptr;
n2 = cnt2 & rb->size_mask;
}
else
{
n1 = to_read;
n2 = 0;
}
memcpy(dest, &(rb->buf[rb->read_ptr*rb->elem_size]), n1*rb->elem_size);
rb->read_ptr = (rb->read_ptr + n1) & rb->size_mask;
if(n2)
{
memcpy(dest + n1*rb->elem_size, &(rb->buf[rb->read_ptr*rb->elem_size]), n2*rb->elem_size);
rb->read_ptr = (rb->read_ptr + n2) & rb->size_mask;
}
return to_read;
}
/* The copying data reader w/o read pointer advance. Copy at most `cnt'
* elements from `rb' to `dest'. Returns the actual number of elements copied.
*/
size_t ll_ringbuffer_peek(ll_ringbuffer_t *rb, char *dest, size_t cnt)
{
size_t free_cnt;
size_t cnt2;
size_t to_read;
size_t n1, n2;
size_t tmp_read_ptr;
tmp_read_ptr = rb->read_ptr;
free_cnt = ll_ringbuffer_read_space(rb);
if(free_cnt == 0) return 0;
to_read = (cnt > free_cnt) ? free_cnt : cnt;
cnt2 = tmp_read_ptr + to_read;
if(cnt2 > rb->size)
{
n1 = rb->size - tmp_read_ptr;
n2 = cnt2 & rb->size_mask;
}
else
{
n1 = to_read;
n2 = 0;
}
memcpy(dest, &(rb->buf[tmp_read_ptr*rb->elem_size]), n1*rb->elem_size);
tmp_read_ptr = (tmp_read_ptr + n1) & rb->size_mask;
if(n2)
memcpy(dest + n1*rb->elem_size, &(rb->buf[tmp_read_ptr*rb->elem_size]), n2*rb->elem_size);
return to_read;
}
/* The copying data writer. Copy at most `cnt' elements to `rb' from `src'.
* Returns the actual number of elements copied. */
size_t ll_ringbuffer_write(ll_ringbuffer_t *rb, const char *src, size_t cnt)
{
size_t free_cnt;
size_t cnt2;
size_t to_write;
size_t n1, n2;
free_cnt = ll_ringbuffer_write_space(rb);
if(free_cnt == 0) return 0;
to_write = (cnt > free_cnt) ? free_cnt : cnt;
cnt2 = rb->write_ptr + to_write;
if(cnt2 > rb->size)
{
n1 = rb->size - rb->write_ptr;
n2 = cnt2 & rb->size_mask;
}
else
{
n1 = to_write;
n2 = 0;
}
memcpy(&(rb->buf[rb->write_ptr*rb->elem_size]), src, n1*rb->elem_size);
rb->write_ptr = (rb->write_ptr + n1) & rb->size_mask;
if(n2)
{
memcpy(&(rb->buf[rb->write_ptr*rb->elem_size]), src + n1*rb->elem_size, n2*rb->elem_size);
rb->write_ptr = (rb->write_ptr + n2) & rb->size_mask;
}
return to_write;
}
/* Advance the read pointer `cnt' places. */
void ll_ringbuffer_read_advance(ll_ringbuffer_t *rb, size_t cnt)
{
size_t tmp = (rb->read_ptr + cnt) & rb->size_mask;
rb->read_ptr = tmp;
}
/* Advance the write pointer `cnt' places. */
void ll_ringbuffer_write_advance(ll_ringbuffer_t *rb, size_t cnt)
{
size_t tmp = (rb->write_ptr + cnt) & rb->size_mask;
rb->write_ptr = tmp;
}
/* The non-copying data reader. `vec' is an array of two places. Set the values
* at `vec' to hold the current readable data at `rb'. If the readable data is
* in one segment the second segment has zero length. */
void ll_ringbuffer_get_read_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_data_t * vec)
{
size_t free_cnt;
size_t cnt2;
size_t w, r;
w = rb->write_ptr;
r = rb->read_ptr;
free_cnt = (rb->size+w-r) & rb->size_mask;
cnt2 = r + free_cnt;
if(cnt2 > rb->size)
{
/* Two part vector: the rest of the buffer after the current write ptr,
* plus some from the start of the buffer. */
vec[0].buf = (char*)&(rb->buf[r*rb->elem_size]);
vec[0].len = rb->size - r;
vec[1].buf = (char*)rb->buf;
vec[1].len = cnt2 & rb->size_mask;
}
else
{
/* Single part vector: just the rest of the buffer */
vec[0].buf = (char*)&(rb->buf[r*rb->elem_size]);
vec[0].len = free_cnt;
vec[1].buf = NULL;
vec[1].len = 0;
}
}
/* The non-copying data writer. `vec' is an array of two places. Set the values
* at `vec' to hold the current writeable data at `rb'. If the writeable data
* is in one segment the second segment has zero length. */
void ll_ringbuffer_get_write_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_data_t *vec)
{
size_t free_cnt;
size_t cnt2;
size_t w, r;
w = rb->write_ptr;
r = rb->read_ptr;
free_cnt = (rb->size+r-w-1) & rb->size_mask;
cnt2 = w + free_cnt;
if(cnt2 > rb->size)
{
/* Two part vector: the rest of the buffer after the current write ptr,
* plus some from the start of the buffer. */
vec[0].buf = (char*)&(rb->buf[w*rb->elem_size]);
vec[0].len = rb->size - w;
vec[1].buf = (char*)rb->buf;
vec[1].len = cnt2 & rb->size_mask;
}
else
{
vec[0].buf = (char*)&(rb->buf[w*rb->elem_size]);
vec[0].len = free_cnt;
vec[1].buf = NULL;
vec[1].len = 0;
}
}
/**
* OpenAL cross platform audio library
* Copyright (C) 1999-2007 by authors.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
#include "config.h"
#include <stdlib.h>
#include "alMain.h"
#include "alThunk.h"
#ifdef _WIN32
typedef struct {
ALuint (*func)(ALvoid*);
ALvoid *ptr;
HANDLE thread;
} ThreadInfo;
static DWORD CALLBACK StarterFunc(void *ptr)
{
ThreadInfo *inf = (ThreadInfo*)ptr;
ALint ret;
ret = inf->func(inf->ptr);
ExitThread((DWORD)ret);
return (DWORD)ret;
}
ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr)
{
DWORD dummy;
ThreadInfo *inf = malloc(sizeof(ThreadInfo));
if(!inf) return 0;
inf->func = func;
inf->ptr = ptr;
inf->thread = CreateThread(NULL, 0, StarterFunc, inf, 0, &dummy);
if(!inf->thread)
{
free(inf);
return NULL;
}
return inf;
}
ALuint StopThread(ALvoid *thread)
{
ThreadInfo *inf = thread;
DWORD ret = 0;
WaitForSingleObject(inf->thread, INFINITE);
GetExitCodeThread(inf->thread, &ret);
CloseHandle(inf->thread);
free(inf);
return (ALuint)ret;
}
#else
#include <pthread.h>
typedef struct {
ALuint (*func)(ALvoid*);
ALvoid *ptr;
ALuint ret;
pthread_t thread;
} ThreadInfo;
static void *StarterFunc(void *ptr)
{
ThreadInfo *inf = (ThreadInfo*)ptr;
inf->ret = inf->func(inf->ptr);
return NULL;
}
ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr)
{
ThreadInfo *inf = malloc(sizeof(ThreadInfo));
if(!inf) return NULL;
inf->func = func;
inf->ptr = ptr;
if(pthread_create(&inf->thread, NULL, StarterFunc, inf) != 0)
{
free(inf);
return NULL;
}
return inf;
}
ALuint StopThread(ALvoid *thread)
{
ThreadInfo *inf = thread;
ALuint ret;
pthread_join(inf->thread, NULL);
ret = inf->ret;
free(inf);
return ret;
}
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef BFORMATDEC_H
#define BFORMATDEC_H
#include "alMain.h"
struct AmbDecConf;
struct BFormatDec;
enum BFormatDecFlags {
BFDF_DistanceComp = 1<<0
};
struct BFormatDec *bformatdec_alloc();
void bformatdec_free(struct BFormatDec *dec);
int bformatdec_getOrder(const struct BFormatDec *dec);
void bformatdec_reset(struct BFormatDec *dec, const struct AmbDecConf *conf, ALuint chancount, ALuint srate, const ALuint chanmap[MAX_OUTPUT_CHANNELS], int flags);
/* Decodes the ambisonic input to the given output channels. */
void bformatdec_process(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALuint OutChannels, ALfloat (*restrict InSamples)[BUFFERSIZE], ALuint SamplesToDo);
/* Up-samples a first-order input to the decoder's configuration. */
void bformatdec_upSample(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALfloat (*restrict InSamples)[BUFFERSIZE], ALuint InChannels, ALuint SamplesToDo);
#endif /* BFORMATDEC_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef _AL_STATE_H_
#define _AL_STATE_H_
#include "AL/al.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment